def choose_source_id()

in components/webui/src/dpu/components.py [0:0]


def choose_source_id(sources, label):
    # print(f'label: {label}')
    # print(f'sources: {sources}')

    st.write(f":blue[{label}: ]")
    # Render list of sources
    gb = GridOptionsBuilder()
    gb.configure_selection(
        selection_mode="single",
    )
    gb.configure_default_column(
        resizable=True,
    )
    gb.configure_column("index", header_name="#", flex=0, width=35)
    gb.configure_column("id", header_name="ID", flex=0)
    gb.configure_column("title", header_name="Title", flex=0, width=130)
    gb.configure_column("uri", header_name="GCS", flex=1)
    gb.configure_auto_height(True)
    # MIN_HEIGHT = 5
    # MAX_HEIGHT = 800
    # ROW_HEIGHT = 60
    jscode = JsCode(
        """
            function(params) {
                if (params.data.isCitation) {
                    return {
                        'color': 'rgb(52, 168, 82)',
                    }
                }
            };
            """
    )
    gridOpts = gb.build()
    gridOpts["getRowStyle"] = jscode
    df = pd.DataFrame(sources)
    res = AgGrid(
        df,
        theme=AgGridTheme.BALHAM,  # pyright: ignore[reportArgumentType]
        gridOptions=gridOpts,
        allow_unsafe_jscode=True,
        columns_auto_size_mode=ColumnsAutoSizeMode.FIT_CONTENTS,
        data_return_mode=DataReturnMode.AS_INPUT,
        enable_enterprise_modules=False,
        # height=min(MIN_HEIGHT + len(df) * ROW_HEIGHT, MAX_HEIGHT)
    )

    # Pull out selected row or initial row into selected search result
    if res.selected_rows is not None:
        found_records = res.selected_rows.to_dict("records")
        return found_records[0]["id"]  # pylint: disable=unsubscriptable-object

    return None