From bdef85b3c834a7fb285ae0257d6fe03b04567898 Mon Sep 17 00:00:00 2001 From: Paddy Mullen Date: Thu, 7 Nov 2024 10:44:02 -0500 Subject: [PATCH] working active column for DFViewerInfinite --- docs/examples/App.tsx | 2 +- js/components/BuckarooWidgetInfinite.tsx | 5 +- js/components/DFViewerParts/DFViewer.tsx | 4 +- .../DFViewerParts/DFViewerInfinite.tsx | 57 +++++++++++-------- js/index.ts | 5 +- 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/docs/examples/App.tsx b/docs/examples/App.tsx index 729202eb..bca1a714 100644 --- a/docs/examples/App.tsx +++ b/docs/examples/App.tsx @@ -37,7 +37,7 @@ const examples = { DFViewerInfiniteEx_large: { title: 'DFViewerInfinite large', file: 'DFViewerInfiniteEx_large', - layout: 'HBox', + layout: 'VBox', }, DFViewerEx_real_summary: { diff --git a/js/components/BuckarooWidgetInfinite.tsx b/js/components/BuckarooWidgetInfinite.tsx index b4e288b6..4f77a405 100644 --- a/js/components/BuckarooWidgetInfinite.tsx +++ b/js/components/BuckarooWidgetInfinite.tsx @@ -72,7 +72,10 @@ export function BuckarooInfiniteWidget({ on_buckaroo_state: React.Dispatch>; buckaroo_options: BuckarooOptions; }) { - const [mainDs, respCache] = useMemo(() => getDs(on_payload_args), [operations]); + const [mainDs, respCache] = useMemo( + () => getDs(on_payload_args), + [operations] + ); const cacheKey = getPayloadKey(payload_response.key); console.log('setting respCache', cacheKey, payload_response); respCache.put(getPayloadKey(payload_response.key), payload_response); diff --git a/js/components/DFViewerParts/DFViewer.tsx b/js/components/DFViewerParts/DFViewer.tsx index 621895a5..85d3463d 100644 --- a/js/components/DFViewerParts/DFViewer.tsx +++ b/js/components/DFViewerParts/DFViewer.tsx @@ -60,10 +60,12 @@ export const getGridOptions = ( onCellClicked: (event) => { const colName = event.column.getColId(); - console.log("onCellClicked", event) + console.log('onCellClicked', event); if (setActiveCol === undefined || colName === undefined) { + console.log('returning because setActiveCol is undefined'); return; } else { + console.log('calling setActiveCol with', colName); setActiveCol(colName); } }, diff --git a/js/components/DFViewerParts/DFViewerInfinite.tsx b/js/components/DFViewerParts/DFViewerInfinite.tsx index 9c8f05f7..953e6d82 100644 --- a/js/components/DFViewerParts/DFViewerInfinite.tsx +++ b/js/components/DFViewerParts/DFViewerInfinite.tsx @@ -1,4 +1,10 @@ -import React, { useRef, CSSProperties, useState, useCallback } from 'react'; +import React, { + useRef, + CSSProperties, + useState, + useCallback, + useMemo, +} from 'react'; import _ from 'lodash'; import { DFData, DFDataRow, DFViewerConfig } from './DFWhole'; @@ -59,18 +65,20 @@ export function DFViewerInfinite({ activeCol?: string; setActiveCol?: SetColumFunc; }) { - const agColsPure = dfToAgrid(df_viewer_config, summary_stats_data || []); - const selectBackground = - df_viewer_config?.component_config?.selectionBackground || - 'var(--ag-range-selection-background-color-3)'; - const styledColumns = replaceAtMatch( - _.clone(agColsPure), - activeCol || '___never', - { - cellStyle: { background: selectBackground }, - } - ); - + const styledColumns = useMemo(() => { + const agColsPure = dfToAgrid(df_viewer_config, summary_stats_data || []); + const selectBackground = + df_viewer_config?.component_config?.selectionBackground || + 'var(--ag-range-selection-background-color-3)'; + const styledColumns = replaceAtMatch( + _.clone(agColsPure), + activeCol || '___never', + { + cellStyle: { background: selectBackground }, + } + ); + return styledColumns; + }, [df_viewer_config, summary_stats_data, activeCol]); const defaultColDef = { sortable: true, type: 'rightAligned', @@ -147,6 +155,7 @@ export function DFViewerInfinite({ ref={gridRef} gridOptions={dsGridOptions} pinnedTopRowData={topRowData} + columnDefs={_.cloneDeep(styledColumns)} > @@ -156,7 +165,7 @@ export function DFViewerInfinite({ } } // used to make sure there is a different element returned when -// Raw is used, so the component properly swaps over. +// Raw is used, so the component properly swaps over. // Otherwise pinnedRows appear above the last scrolled position // of the InfiniteRowSource vs having an empty data set. @@ -180,6 +189,7 @@ const RowDataViewer = ({ @@ -251,7 +261,7 @@ export const StaticWrapDFViewerInfinite = ({ data_type: 'DataSource', datasource: { getRows: (params: IGetRowsParams) => { - console.log("StaticWrapDFViewerInfinite", params); + console.log('StaticWrapDFViewerInfinite', params); params.successCallback( df_data.slice(params.startRow, params.endRow), df_data.length @@ -262,14 +272,15 @@ export const StaticWrapDFViewerInfinite = ({ const [activeCol, setActiveCol] = useState('stoptime'); - return (
- + return ( +
+
); }; diff --git a/js/index.ts b/js/index.ts index a4c84292..430a9f53 100644 --- a/js/index.ts +++ b/js/index.ts @@ -3,7 +3,10 @@ import { ColumnsEditor } from './components/ColumnsEditor'; import { DFViewer } from './components/DFViewerParts/DFViewer'; -import { DFViewerInfinite, StaticWrapDFViewerInfinite } from './components/DFViewerParts/DFViewerInfinite'; +import { + DFViewerInfinite, + StaticWrapDFViewerInfinite, +} from './components/DFViewerParts/DFViewerInfinite'; import { WidgetDCFCell } from './components/DCFCell'; import { BuckarooInfiniteWidget } from './components/BuckarooWidgetInfinite';