Skip to content

Commit

Permalink
bug: added missing bearing correction export to index, made externall…
Browse files Browse the repository at this point in the history
…y selected items optional (#38)

* bug: add missing bearing correction to export

* feat: Make externally selected items optional
  • Loading branch information
matttdawson authored Oct 27, 2022
1 parent 64e926d commit 2894ea7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
30 changes: 18 additions & 12 deletions src/components/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -59,23 +59,29 @@ 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.
* If new ids are selected scroll them into view.
*/
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));
Expand Down

0 comments on commit 2894ea7

Please sign in to comment.