From 2894ea75d5111875f87666f76bf7d45e500bcc94 Mon Sep 17 00:00:00 2001 From: matttdawson <89495499+matttdawson@users.noreply.github.com> Date: Thu, 27 Oct 2022 19:42:03 +1300 Subject: [PATCH] bug: added missing bearing correction export to index, made externally selected items optional (#38) * bug: add missing bearing correction to export * feat: Make externally selected items optional --- index.ts | 1 + src/components/Grid.tsx | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/index.ts b/index.ts index 759af525..3d18a7af 100644 --- a/index.ts +++ b/index.ts @@ -19,6 +19,7 @@ export { GridRenderPopoutMenuCell } from "./src/components/gridRender/GridRender export { GridPopoutEditMultiSelect } from "./src/components/gridPopoverEdit/GridPopoutEditMultiSelect"; export { GridPopoverMenu } from "./src/components/gridPopoverEdit/GridPopoverMenu"; export { GridPopoverEditBearing } from "./src/components/gridPopoverEdit/GridPopoverEditBearing"; +export { GridPopoverEditBearingCorrection } from "./src/components/gridPopoverEdit/GridPopoverEditBearing"; export { GridPopoverEditDropDown } from "./src/components/gridPopoverEdit/GridPopoverEditDropDown"; export { GridPopoverMessage } from "./src/components/gridPopoverEdit/GridPopoverMessage"; export { GridPopoverTextArea } from "./src/components/gridPopoverEdit/GridPopoverTextArea"; diff --git a/src/components/Grid.tsx b/src/components/Grid.tsx index 1b190fbb..5d2c2250 100644 --- a/src/components/Grid.tsx +++ b/src/components/Grid.tsx @@ -24,8 +24,8 @@ export interface GridProps { quickFilter?: boolean; quickFilterPlaceholder?: string; quickFilterValue?: string; - externalSelectedItems: any[]; - setExternalSelectedItems: (items: any[]) => void; + externalSelectedItems?: any[]; + setExternalSelectedItems?: (items: any[]) => void; onGridReady?: GridOptions["onGridReady"]; defaultColDef: GridOptions["defaultColDef"]; columnDefs: GridOptions["columnDefs"]; @@ -59,16 +59,21 @@ export const Grid = (params: GridProps): JSX.Element => { /** * Ensure external selected items list is in sync with panel. */ - const synchroniseExternalStateToGridSelection = ({ api }: SelectionChangedEvent) => { - const selectedRows = api.getSelectedRows(); - // We don't want to update selected Items if it hasn't changed to prevent excess renders - if ( - params.externalSelectedItems.length != selectedRows.length || - isNotEmpty(xorBy(selectedRows, params.externalSelectedItems, (row) => row.id)) - ) { - params.setExternalSelectedItems([...selectedRows]); - } - }; + const synchroniseExternalStateToGridSelection = useCallback( + ({ api }: SelectionChangedEvent) => { + if (!params.externalSelectedItems || !params.setExternalSelectedItems) return; + + const selectedRows = api.getSelectedRows(); + // We don't want to update selected Items if it hasn't changed to prevent excess renders + if ( + params.externalSelectedItems.length != selectedRows.length || + isNotEmpty(xorBy(selectedRows, params.externalSelectedItems, (row) => row.id)) + ) { + params.setExternalSelectedItems([...selectedRows]); + } + }, + [params], + ); /** * Synchronise externally selected items to grid. @@ -76,6 +81,7 @@ export const Grid = (params: GridProps): JSX.Element => { */ const synchroniseExternallySelectedItemsToGrid = useCallback(() => { if (!gridReady()) return; + if (!params.externalSelectedItems) return; const selectedIds = params.externalSelectedItems.map((row) => row.id) as number[]; const lastNewId = last(difference(selectedIds, lastSelectedIds.current));