@linzjs/step-ag-grid 29.11.4 → 29.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/src/components/Grid.d.ts +7 -12
  2. package/dist/src/components/GridCell.d.ts +2 -19
  3. package/dist/src/components/GridCellFiller.d.ts +1 -1
  4. package/dist/src/components/GridCellMultiEditor.d.ts +1 -2
  5. package/dist/src/components/GridPopoverHook.d.ts +1 -1
  6. package/dist/src/components/gridFilter/GridFilterButtons.d.ts +1 -1
  7. package/dist/src/components/gridFilter/useGridFilter.d.ts +1 -1
  8. package/dist/src/components/gridForm/GridFormDropDown.d.ts +1 -1
  9. package/dist/src/components/gridForm/GridFormEditBearing.d.ts +1 -1
  10. package/dist/src/components/gridForm/GridFormMessage.d.ts +1 -1
  11. package/dist/src/components/gridForm/GridFormMultiSelect.d.ts +1 -1
  12. package/dist/src/components/gridForm/GridFormMultiSelectGrid.d.ts +1 -1
  13. package/dist/src/components/gridForm/GridFormPopoverMenu.d.ts +1 -1
  14. package/dist/src/components/gridForm/GridFormSubComponentTextArea.d.ts +1 -1
  15. package/dist/src/components/gridForm/GridFormSubComponentTextInput.d.ts +1 -1
  16. package/dist/src/components/gridForm/GridFormTextArea.d.ts +1 -1
  17. package/dist/src/components/gridForm/GridFormTextInput.d.ts +1 -1
  18. package/dist/src/components/gridHook/useGridContextMenu.d.ts +1 -1
  19. package/dist/src/components/gridPopoverEdit/GridButton.d.ts +1 -2
  20. package/dist/src/components/gridPopoverEdit/GridEditBoolean.d.ts +2 -2
  21. package/dist/src/components/gridPopoverEdit/GridPopoutEditMultiSelect.d.ts +2 -2
  22. package/dist/src/components/gridPopoverEdit/GridPopoutEditMultiSelectGrid.d.ts +2 -2
  23. package/dist/src/components/gridPopoverEdit/GridPopoverEditBearing.d.ts +2 -2
  24. package/dist/src/components/gridPopoverEdit/GridPopoverEditDropDown.d.ts +2 -2
  25. package/dist/src/components/gridPopoverEdit/GridPopoverMenu.d.ts +2 -2
  26. package/dist/src/components/gridPopoverEdit/GridPopoverMessage.d.ts +2 -2
  27. package/dist/src/components/gridPopoverEdit/GridPopoverTextArea.d.ts +2 -2
  28. package/dist/src/components/gridPopoverEdit/GridPopoverTextInput.d.ts +2 -2
  29. package/dist/src/components/gridRender/GridRenderGenericCell.d.ts +1 -2
  30. package/dist/src/components/index.d.ts +1 -0
  31. package/dist/src/components/types.d.ts +26 -0
  32. package/dist/src/contexts/GridContext.d.ts +12 -12
  33. package/dist/src/contexts/GridPopoverContext.d.ts +1 -1
  34. package/dist/src/utils/__tests__/storybookTestUtil.ts +28 -1
  35. package/dist/src/utils/__tests__/testQuick.ts +2 -0
  36. package/dist/src/utils/textValidator.d.ts +1 -1
  37. package/dist/src/utils/util.d.ts +1 -0
  38. package/dist/step-ag-grid.cjs +326 -214
  39. package/dist/step-ag-grid.cjs.map +1 -1
  40. package/dist/step-ag-grid.esm.js +327 -216
  41. package/dist/step-ag-grid.esm.js.map +1 -1
  42. package/package.json +5 -2
  43. package/src/components/Grid.tsx +130 -65
  44. package/src/components/GridCell.tsx +1 -25
  45. package/src/components/GridCellFiller.tsx +1 -1
  46. package/src/components/GridCellMultiEditor.tsx +2 -2
  47. package/src/components/GridPopoverHook.tsx +1 -1
  48. package/src/components/gridFilter/GridFilterButtons.tsx +1 -1
  49. package/src/components/gridFilter/useGridFilter.ts +1 -1
  50. package/src/components/gridForm/GridFormDropDown.tsx +1 -1
  51. package/src/components/gridForm/GridFormEditBearing.tsx +1 -1
  52. package/src/components/gridForm/GridFormMessage.tsx +1 -1
  53. package/src/components/gridForm/GridFormMultiSelect.tsx +1 -1
  54. package/src/components/gridForm/GridFormMultiSelectGrid.tsx +1 -1
  55. package/src/components/gridForm/GridFormPopoverMenu.tsx +1 -1
  56. package/src/components/gridForm/GridFormSubComponentTextArea.tsx +1 -1
  57. package/src/components/gridForm/GridFormSubComponentTextInput.tsx +1 -1
  58. package/src/components/gridForm/GridFormTextArea.tsx +1 -1
  59. package/src/components/gridForm/GridFormTextInput.tsx +1 -1
  60. package/src/components/gridHook/useGridContextMenu.tsx +1 -1
  61. package/src/components/gridPopoverEdit/GridButton.tsx +2 -2
  62. package/src/components/gridPopoverEdit/GridEditBoolean.tsx +2 -2
  63. package/src/components/gridPopoverEdit/GridPopoutEditMultiSelect.ts +2 -2
  64. package/src/components/gridPopoverEdit/GridPopoutEditMultiSelectGrid.ts +2 -2
  65. package/src/components/gridPopoverEdit/GridPopoverEditBearing.ts +2 -2
  66. package/src/components/gridPopoverEdit/GridPopoverEditDropDown.ts +2 -2
  67. package/src/components/gridPopoverEdit/GridPopoverMenu.tsx +2 -2
  68. package/src/components/gridPopoverEdit/GridPopoverMessage.ts +2 -2
  69. package/src/components/gridPopoverEdit/GridPopoverTextArea.ts +2 -2
  70. package/src/components/gridPopoverEdit/GridPopoverTextInput.ts +2 -2
  71. package/src/components/gridRender/GridRenderGenericCell.tsx +1 -2
  72. package/src/components/index.ts +1 -0
  73. package/src/components/types.ts +32 -0
  74. package/src/contexts/GridContext.tsx +55 -148
  75. package/src/contexts/GridContextProvider.tsx +61 -56
  76. package/src/contexts/GridPopoverContext.tsx +1 -1
  77. package/src/contexts/GridPopoverContextProvider.tsx +1 -1
  78. package/src/react-menu3/components/MenuButton.tsx +2 -2
  79. package/src/react-menu3/hooks/useItemState.ts +1 -1
  80. package/src/stories/grid/GridPopoverEditDropDown.stories.tsx +3 -3
  81. package/src/stories/grid/GridReadOnly.stories.tsx +3 -3
  82. package/src/stories/grid/GridSorting.stories.tsx +189 -0
  83. package/src/utils/__tests__/storybookTestUtil.ts +28 -1
  84. package/src/utils/__tests__/testQuick.ts +2 -0
  85. package/src/utils/textValidator.test.ts +1 -1
  86. package/src/utils/textValidator.ts +1 -1
  87. package/src/utils/util.ts +19 -0
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@linzjs/step-ag-grid",
3
3
  "repository": "github:linz/step-ag-grid.git",
4
4
  "license": "MIT",
5
- "version": "29.11.4",
5
+ "version": "29.13.0",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -38,6 +38,7 @@
38
38
  "clsx": "^2.1.1",
39
39
  "debounce-promise": "^3.1.2",
40
40
  "matcher": "^5.0.0",
41
+ "natsort": "^2.0.3",
41
42
  "react-transition-state": "^2.3.1",
42
43
  "usehooks-ts": "^3.1.1",
43
44
  "uuid": "^13.0.0"
@@ -50,7 +51,9 @@
50
51
  "css": "sass ./src/styles/index.scss:dist/index.css --no-source-map",
51
52
  "test": "cross-env NODE_OPTIONS='--no-experimental-global-navigator' vitest run",
52
53
  "test:watch": "vitest --watch",
53
- "lint": "eslint ./src --ext .js,.ts,.tsx --cache --ignore-path .gitignore",
54
+ "lint": "run-s lint:eslint lint:circulardeps",
55
+ "lint:eslint": "eslint ./src --ext .js,.ts,.tsx --cache --ignore-path .gitignore",
56
+ "lint:circulardeps": "npx madge --circular --extensions ts,tsx ./src",
54
57
  "lint:fix": "eslint ./src --ext .js,.ts,.tsx --fix --cache --ignore-path .gitignore",
55
58
  "storybook": "storybook dev -p 6006",
56
59
  "build-storybook": "storybook build",
@@ -23,6 +23,7 @@ import {
23
23
  RowDragMoveEvent,
24
24
  SelectionChangedEvent,
25
25
  SelectionColumnDef,
26
+ ValueFormatterParams,
26
27
  } from 'ag-grid-community';
27
28
  import { AgGridReact } from 'ag-grid-react';
28
29
  import clsx from 'clsx';
@@ -32,25 +33,16 @@ import { useInterval } from 'usehooks-ts';
32
33
 
33
34
  import { AutoSizeColumnsResult, StartCellEditingProps, useGridContext } from '../contexts/GridContext';
34
35
  import { GridUpdatingContext } from '../contexts/GridUpdatingContext';
35
- import { fnOrVar, isNotEmpty } from '../utils/util';
36
+ import { compareNaturalInsensitive, fnOrVar, isNotEmpty } from '../utils/util';
36
37
  import { clickInputWhenContainingCellClicked } from './clickInputWhenContainingCellClicked';
37
38
  import { GridHeaderSelect } from './gridHeader';
38
39
  import { GridContextMenuComponent, useGridContextMenu } from './gridHook';
39
40
  import { GridNoRowsOverlay } from './GridNoRowsOverlay';
40
41
  import { usePostSortRowsHook } from './PostSortRowsHook';
42
+ import { GridBaseRow, GridOnRowDragEndProps } from './types';
41
43
 
42
44
  ModuleRegistry.registerModules([AllCommunityModule]);
43
45
 
44
- export interface GridBaseRow {
45
- id: string | number;
46
- }
47
-
48
- export interface GridOnRowDragEndProps<TData extends GridBaseRow> {
49
- movedRow: TData;
50
- targetRow: TData;
51
- direction: -1 | 1;
52
- }
53
-
54
46
  export interface GridProps<TData extends GridBaseRow = GridBaseRow> {
55
47
  readOnly?: boolean; // set all editables to false when read only, make all styles black, otherwise style is gray for not editable
56
48
  defaultPostSort?: boolean; // Retain sort order after edit, Defaults to true.
@@ -61,8 +53,10 @@ export interface GridProps<TData extends GridBaseRow = GridBaseRow> {
61
53
  theme?: string; // should have prefix ag-theme-
62
54
  ['data-testid']?: string;
63
55
  domLayout?: GridOptions['domLayout'];
64
- externalSelectedItems?: any[];
65
- setExternalSelectedItems?: (items: any[]) => void;
56
+ externalSelectedItems?: TData[];
57
+ externalSelectedIds?: TData['id'][];
58
+ setExternalSelectedItems?: (items: TData[]) => void;
59
+ setExternalSelectedIds?: (ids: TData['id'][]) => void;
66
60
  defaultColDef?: GridOptions['defaultColDef'];
67
61
  columnDefs: ColDef<TData>[] | ColGroupDef<TData>[];
68
62
  rowData: GridOptions['rowData'];
@@ -112,7 +106,7 @@ export interface GridProps<TData extends GridBaseRow = GridBaseRow> {
112
106
  /**
113
107
  * Context menu definition if required.
114
108
  */
115
- contextMenu?: GridContextMenuComponent<any>;
109
+ contextMenu?: GridContextMenuComponent<TData>;
116
110
 
117
111
  /**
118
112
  * Whether to select row on context menu.
@@ -148,9 +142,14 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
148
142
  rowData,
149
143
  rowHeight = theme === 'ag-theme-step-default' ? 40 : theme === 'ag-theme-step-compact' ? 36 : 40,
150
144
  selectable,
145
+ autoSelectFirstRow,
151
146
  onCellFocused: paramsOnCellFocused,
152
147
  maxInitialWidth,
153
148
  suppressReadOnlyStyle = false,
149
+ externalSelectedItems,
150
+ setExternalSelectedItems,
151
+ externalSelectedIds,
152
+ setExternalSelectedIds,
154
153
  ...params
155
154
  }: GridProps<TData>): ReactElement => {
156
155
  const {
@@ -177,7 +176,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
177
176
  // CellEditingStop event happens too much for one edit
178
177
  const startedEditRef = useRef(false);
179
178
  const startCellEditing = useCallback(
180
- (props: StartCellEditingProps) => {
179
+ (props: StartCellEditingProps<TData>) => {
181
180
  startedEditRef.current = true;
182
181
  return propStartCellEditing(props);
183
182
  },
@@ -187,7 +186,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
187
186
  const { updatedDep, anyUpdating, updatingCols } = useContext(GridUpdatingContext);
188
187
 
189
188
  const gridDivRef = useRef<HTMLDivElement>(null);
190
- const lastSelectedIds = useRef<number[]>([]);
189
+ const lastSelectedIds = useRef<TData['id'][] | undefined>();
191
190
 
192
191
  const [staleGrid, setStaleGrid] = useState(false);
193
192
  const [autoSized, setAutoSized] = useState(false);
@@ -325,11 +324,13 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
325
324
  */
326
325
  const hasSelectedFirstItem = useRef(false);
327
326
  useEffect(() => {
328
- if (!gridReady || hasSelectedFirstItem.current || !rowData || !externallySelectedItemsAreInSync) return;
327
+ if (!gridReady || hasSelectedFirstItem.current || !rowData || !externallySelectedItemsAreInSync) {
328
+ return;
329
+ }
329
330
  hasSelectedFirstItem.current = true;
330
- if (isNotEmpty(rowData) && isEmpty(params.externalSelectedItems)) {
331
+ if (isNotEmpty(rowData) && isEmpty(externalSelectedItems)) {
331
332
  const firstRowId = getFirstRowId();
332
- if (params.autoSelectFirstRow) {
333
+ if (autoSelectFirstRow && selectable) {
333
334
  selectRowsById([firstRowId]);
334
335
  } else {
335
336
  focusByRowById(firstRowId, true);
@@ -339,11 +340,12 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
339
340
  externallySelectedItemsAreInSync,
340
341
  focusByRowById,
341
342
  gridReady,
342
- params.externalSelectedItems,
343
- params.autoSelectFirstRow,
343
+ externalSelectedItems,
344
+ autoSelectFirstRow,
344
345
  rowData,
345
346
  selectRowsById,
346
347
  getFirstRowId,
348
+ selectable,
347
349
  ]);
348
350
 
349
351
  /**
@@ -351,24 +353,43 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
351
353
  */
352
354
  const synchroniseExternalStateToGridSelection = useCallback(
353
355
  ({ api }: SelectionChangedEvent) => {
354
- if (!params.externalSelectedItems || !params.setExternalSelectedItems) {
355
- setExternallySelectedItemsAreInSync(true);
356
- return;
357
- }
358
-
359
- const selectedRows = api.getSelectedRows();
360
- // We don't want to update selected Items if it hasn't changed to prevent excess renders
361
- if (
362
- params.externalSelectedItems.length !== selectedRows.length ||
363
- isNotEmpty(xorBy(selectedRows, params.externalSelectedItems, (row) => row.id))
364
- ) {
365
- setExternallySelectedItemsAreInSync(false);
366
- params.setExternalSelectedItems([...selectedRows]);
356
+ if (externalSelectedIds && setExternalSelectedIds) {
357
+ const selectedRowsIds = api.getSelectedRows().map((row: TData) => row.id);
358
+
359
+ // We don't want to update selected Items if it hasn't changed to prevent excess renders
360
+ if (
361
+ externalSelectedIds.length !== selectedRowsIds.length ||
362
+ isNotEmpty(xorBy(selectedRowsIds, externalSelectedIds))
363
+ ) {
364
+ setExternallySelectedItemsAreInSync(false);
365
+ setExternalSelectedIds([...selectedRowsIds]);
366
+ } else {
367
+ setExternallySelectedItemsAreInSync(true);
368
+ }
369
+ } else if (externalSelectedItems && setExternalSelectedItems) {
370
+ const selectedRows = api.getSelectedRows();
371
+
372
+ // We don't want to update selected Items if it hasn't changed to prevent excess renders
373
+ if (
374
+ externalSelectedItems.length !== selectedRows.length ||
375
+ isNotEmpty(xorBy(selectedRows, externalSelectedItems, (row) => row.id))
376
+ ) {
377
+ setExternallySelectedItemsAreInSync(false);
378
+ setExternalSelectedItems([...selectedRows]);
379
+ } else {
380
+ setExternallySelectedItemsAreInSync(true);
381
+ }
367
382
  } else {
368
383
  setExternallySelectedItemsAreInSync(true);
369
384
  }
370
385
  },
371
- [params, setExternallySelectedItemsAreInSync],
386
+ [
387
+ externalSelectedIds,
388
+ externalSelectedItems,
389
+ setExternalSelectedIds,
390
+ setExternalSelectedItems,
391
+ setExternallySelectedItemsAreInSync,
392
+ ],
372
393
  );
373
394
 
374
395
  /**
@@ -377,20 +398,27 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
377
398
  */
378
399
  const synchroniseExternallySelectedItemsToGrid = useCallback(() => {
379
400
  if (!gridReady) return;
380
- if (!params.externalSelectedItems) {
401
+ if (!externalSelectedItems && !externalSelectedIds) {
381
402
  setExternallySelectedItemsAreInSync(true);
382
403
  return;
383
404
  }
384
405
 
385
- const selectedIds = params.externalSelectedItems.map((row) => row.id) as number[];
386
- const lastNewId = last(difference(selectedIds, lastSelectedIds.current));
406
+ const selectedIds = externalSelectedIds ?? externalSelectedItems?.map((row) => row.id);
407
+ const lastNewId = last(difference(selectedIds, lastSelectedIds.current ?? []));
387
408
  if (lastNewId != null) {
388
409
  ensureRowVisible(lastNewId);
389
410
  }
390
411
  lastSelectedIds.current = selectedIds;
391
412
  selectRowsById(selectedIds);
392
413
  setExternallySelectedItemsAreInSync(true);
393
- }, [gridReady, params.externalSelectedItems, ensureRowVisible, selectRowsById, setExternallySelectedItemsAreInSync]);
414
+ }, [
415
+ gridReady,
416
+ externalSelectedItems,
417
+ externalSelectedIds,
418
+ selectRowsById,
419
+ setExternallySelectedItemsAreInSync,
420
+ ensureRowVisible,
421
+ ]);
394
422
 
395
423
  /**
396
424
  * Combine grid and cell editable into one function
@@ -430,7 +458,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
430
458
  cellClassRules: {
431
459
  ...colDef.cellClassRules,
432
460
  'GridCell-readonly': (ccp: CellClassParams<TData>) =>
433
- !suppressReadOnlyStyle && !editable(ccp as any as EditableCallbackParams<TData>),
461
+ !suppressReadOnlyStyle && !editable(ccp as unknown as EditableCallbackParams<TData>),
434
462
  },
435
463
  };
436
464
  }
@@ -445,7 +473,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
445
473
  return params.columnDefs.map(mapColDef);
446
474
  }, [params.columnDefs, mapColDef]);
447
475
 
448
- const hasExternallySelectedItems = !!params.setExternalSelectedItems;
476
+ const hasExternallySelectedItems = !!setExternalSelectedItems || !!setExternalSelectedIds;
449
477
 
450
478
  /**
451
479
  * When grid is ready set the apis to the grid context and sync selected items to grid.
@@ -600,18 +628,51 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
600
628
 
601
629
  const adjustColDef = (colDef: ColDef<TData>): ColDef<TData> => {
602
630
  const flex = colDef.flex ?? (sizeColumns === 'fit' ? 1 : undefined);
603
- return {
631
+ const valueFormatter = colDef.valueFormatter;
632
+ const sortable = colDef.sortable && params.defaultColDef?.sortable !== false;
633
+ let comparator = colDef.comparator;
634
+ if (sortable && !comparator) {
635
+ comparator = (value1, value2, node1, node2) => {
636
+ let r;
637
+ if (typeof valueFormatter === 'function') {
638
+ r = compareNaturalInsensitive(
639
+ valueFormatter({
640
+ data: node1.data,
641
+ value: value1,
642
+ node: node1,
643
+ colDef: adjustedColDef,
644
+ ...NotAGridValueFormatterCall,
645
+ } as ValueFormatterParams<TData>),
646
+ valueFormatter({
647
+ data: node2.data,
648
+ value: value2,
649
+ node: node2,
650
+ colDef: adjustedColDef,
651
+ ...NotAGridValueFormatterCall,
652
+ } as ValueFormatterParams<TData>),
653
+ );
654
+ } else {
655
+ r = compareNaturalInsensitive(value1, value2);
656
+ }
657
+ // secondary compare as primary sort column rows are equal
658
+ return r === 0 ? compareNaturalInsensitive(node1.data?.id, node2.data?.id) : r;
659
+ };
660
+ }
661
+ const adjustedColDef = {
604
662
  ...colDef,
605
663
  // You cannot pass a width to a flex
606
664
  width: !!colDef.flex ? undefined : colDef.width,
607
- flexAutoSizeWidth: colDef.width,
665
+ ...(!!colDef.flex && { flexAutoSizeWidth: colDef.width }),
608
666
  // If this is allowed flex columns don't size based on flex
609
667
  suppressSizeToFit: true,
610
668
  // Auto-sizing flex columns breaks everything
611
669
  flex,
612
670
  suppressAutoSize: !!flex,
613
- sortable: colDef.sortable && params.defaultColDef?.sortable !== false,
671
+ sortable,
672
+ comparator,
614
673
  } as ColDef<TData> & { flexAutoSizeWidth?: number };
674
+
675
+ return adjustedColDef;
615
676
  };
616
677
 
617
678
  return columnDefs.map((colDef) => adjustColDefOrGroup(colDef));
@@ -794,14 +855,19 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
794
855
  [params, clearHighlightRowClasses],
795
856
  );
796
857
 
797
- useEffect(() => {
798
- if (params.setExternalSelectedItems && selectable == null) {
799
- console.warn(
800
- '<Grid/> has setExternalSelectedItems parameter, but is missing selectable parameter,' +
801
- 'this will cause weird delays in editing.\nIf you need to hide selection column use hideSelectColumn=true',
802
- );
803
- }
804
- }, [params.setExternalSelectedItems, selectable]);
858
+ useEffect(
859
+ () => {
860
+ if ((setExternalSelectedItems || setExternalSelectedIds) && selectable == null) {
861
+ console.warn(
862
+ '<Grid/> has setExternalSelectedItems/setExternalSelectedIds parameter, but is missing selectable parameter,' +
863
+ 'this will cause weird delays in editing.\nIf you need to hide selection column use hideSelectColumn=true',
864
+ );
865
+ }
866
+ },
867
+ // Only needs to run on startup
868
+ // eslint-disable-next-line react-hooks/exhaustive-deps
869
+ [selectable],
870
+ );
805
871
 
806
872
  // This is setting a ref in the GridContext so won't be triggering an update loop
807
873
  setOnBulkEditingComplete(params.onBulkEditingComplete);
@@ -863,20 +929,9 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
863
929
  }
864
930
  return false;
865
931
  },
866
- onCellClicked:
867
- params.enableSelectionWithoutKeys || params.enableClickSelection
868
- ? undefined
869
- : clickInputWhenContainingCellClicked,
932
+ onCellClicked: clickInputWhenContainingCellClicked,
870
933
  };
871
- }, [
872
- params.enableClickSelection,
873
- params.enableSelectionWithoutKeys,
874
- params.hideSelectColumn,
875
- params.onRowDragEnd,
876
- rowSelection,
877
- selectColumnPinned,
878
- selectable,
879
- ]);
934
+ }, [params.hideSelectColumn, params.onRowDragEnd, rowSelection, selectColumnPinned, selectable]);
880
935
 
881
936
  const onGridSizeChanged = useCallback(
882
937
  (event: GridSizeChangedEvent<TData>) => {
@@ -969,3 +1024,13 @@ const quickFilterParser = (filterStr: string) => {
969
1024
  // filter is exact matches exactly groups separated by commas
970
1025
  return filterStr.split(',').map((str) => str.trim());
971
1026
  };
1027
+
1028
+ /**
1029
+ * Columns to indicate to user when they debug why things are broken in the default comparator if their valueFormatter
1030
+ * is too complicated.
1031
+ */
1032
+ const NotAGridValueFormatterCall = {
1033
+ column: 'Default comparator has no access to column, write your own comparator' as unknown,
1034
+ api: 'Default comparator has no access to api, write your own comparator' as unknown,
1035
+ context: 'Default comparator has no access to context, write your own comparator' as unknown,
1036
+ };
@@ -1,26 +1,22 @@
1
1
  import {
2
2
  ColDef,
3
- EditableCallback,
4
3
  GetQuickFilterTextParams,
5
4
  ICellEditorParams,
6
5
  ICellRendererParams,
7
- } from 'ag-grid-community';
8
- import {
9
6
  SuppressKeyboardEventParams,
10
7
  ValueFormatterFunc,
11
8
  ValueFormatterParams,
12
- ValueGetterFunc,
13
9
  } from 'ag-grid-community';
14
10
  import { forwardRef, ReactElement, useContext } from 'react';
15
11
 
16
12
  import { GridPopoverContextProvider } from '../contexts/GridPopoverContextProvider';
17
13
  import { GridUpdatingContext } from '../contexts/GridUpdatingContext';
18
14
  import { fnOrVar } from '../utils/util';
19
- import { GridBaseRow } from './Grid';
20
15
  import { GridCellMultiSelectClassRules } from './GridCellMultiSelectClassRules';
21
16
  import { GridIcon } from './GridIcon';
22
17
  import { GridLoadableCell } from './GridLoadableCell';
23
18
  import { GenericCellColDef, GenericCellRendererParams } from './gridRender';
19
+ import { ColDefT, GridBaseRow } from './types';
24
20
 
25
21
  export interface GenericCellEditorProps<E> {
26
22
  multiEdit?: boolean;
@@ -74,26 +70,6 @@ export const GridCellRenderer = (props: ICellRendererParams) => {
74
70
  );
75
71
  };
76
72
 
77
- // This is so that typescript retains the row type to pass to the GridCells
78
- export interface ColDefT<TData extends GridBaseRow, ValueType = any> extends ColDef<TData, ValueType> {
79
- editable?: boolean | EditableCallback<TData, ValueType>;
80
- valueGetter?: string | ValueGetterFunc<TData, ValueType>;
81
- valueFormatter?: string | ValueFormatterFunc<TData, ValueType>;
82
- cellRenderer?:
83
- | ((props: ICellRendererParams<TData, ValueType>) => ReactElement | string | false | null | undefined)
84
- | string;
85
- cellRendererParams?: {
86
- rightHoverElement?: ReactElement;
87
- originalCellRenderer?: any;
88
- editAction?: (selectedRows: TData[]) => void;
89
- shortcutKeys?: Record<string, () => void>;
90
- error?: (props: ICellRendererParams<TData, ValueType>) => ReactElement | string | false | null | undefined;
91
- warning?: (props: ICellRendererParams<TData, ValueType>) => ReactElement | string | false | null | undefined;
92
- info?: (props: ICellRendererParams<TData, ValueType>) => ReactElement | string | false | null | undefined;
93
- };
94
- editor?: (editorProps: any) => ReactElement;
95
- }
96
-
97
73
  export const suppressCellKeyboardEvents = (e: SuppressKeyboardEventParams) => {
98
74
  const shortcutKeys = e.colDef.cellRendererParams?.shortcutKeys ?? {};
99
75
  const exec = shortcutKeys[e.event.key];
@@ -1,6 +1,6 @@
1
1
  import { ColDef } from 'ag-grid-community';
2
2
 
3
- import { GridBaseRow } from './Grid';
3
+ import { GridBaseRow } from './types';
4
4
 
5
5
  export const GridCellFillerColId = 'gridCellFiller';
6
6
 
@@ -2,10 +2,10 @@ import { CellEditorSelectorResult } from 'ag-grid-community';
2
2
  import { ICellEditorParams } from 'ag-grid-community';
3
3
  import { ComponentProps, ReactElement } from 'react';
4
4
 
5
- import { GridBaseRow } from './Grid';
6
- import { ColDefT, GenericCellEditorComponentWrapper, GridCell } from './GridCell';
5
+ import { GenericCellEditorComponentWrapper, GridCell } from './GridCell';
7
6
  import { GridCellMultiSelectClassRules } from './GridCellMultiSelectClassRules';
8
7
  import { GenericCellColDef } from './gridRender';
8
+ import { ColDefT, GridBaseRow } from './types';
9
9
 
10
10
  export const Editor = <FN extends (param: any) => ReactElement>(props: {
11
11
  multiEdit: boolean;
@@ -4,7 +4,7 @@ import { useGridPopoverContext } from '../contexts/GridPopoverContext';
4
4
  import { ControlledMenu } from '../react-menu3';
5
5
  import { MenuCloseEvent } from '../react-menu3/types';
6
6
  import { CloseReason } from '../react-menu3/utils';
7
- import { GridBaseRow } from './Grid';
7
+ import { GridBaseRow } from './types';
8
8
 
9
9
  export interface GridPopoverHookProps<TData> {
10
10
  className: string | undefined;
@@ -4,7 +4,7 @@ import clsx, { ClassValue } from 'clsx';
4
4
  import { ReactElement, useMemo, useState } from 'react';
5
5
 
6
6
  import { GridFilterExternal } from '../../contexts/GridContext';
7
- import { GridBaseRow } from '../Grid';
7
+ import { GridBaseRow } from '../types';
8
8
  import { useGridFilter } from './useGridFilter';
9
9
 
10
10
  export interface GridFilterButtonsOption<TData extends GridBaseRow> {
@@ -1,7 +1,7 @@
1
1
  import { useEffect } from 'react';
2
2
 
3
3
  import { GridFilterExternal, useGridContext } from '../../contexts/GridContext';
4
- import { GridBaseRow } from '../Grid';
4
+ import { GridBaseRow } from '../types';
5
5
 
6
6
  export const useGridFilter = <TData extends GridBaseRow>(filter: GridFilterExternal<TData> | undefined) => {
7
7
  const { addExternalFilter, removeExternalFilter } = useGridContext<TData>();
@@ -11,9 +11,9 @@ import { ClickEvent } from '../../react-menu3/types';
11
11
  import { textMatch } from '../../utils/textMatcher';
12
12
  import { isNotEmpty } from '../../utils/util';
13
13
  import { ComponentLoadingWrapper } from '../ComponentLoadingWrapper';
14
- import { GridBaseRow } from '../Grid';
15
14
  import { CellEditorCommon } from '../GridCell';
16
15
  import { useGridPopoverHook } from '../GridPopoverHook';
16
+ import { GridBaseRow } from '../types';
17
17
 
18
18
  export interface GridPopoutEditDropDownSelectedItem<TData extends GridBaseRow, TOption> {
19
19
  // Note the row that was clicked on will be first
@@ -3,9 +3,9 @@ import { useCallback, useMemo, useState } from 'react';
3
3
  import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
4
4
  import { TextInputFormatted } from '../../lui/TextInputFormatted';
5
5
  import { bearingNumberParser, bearingStringValidator } from '../../utils/bearing';
6
- import { GridBaseRow } from '../Grid';
7
6
  import { CellEditorCommon } from '../GridCell';
8
7
  import { useGridPopoverHook } from '../GridPopoverHook';
8
+ import { GridBaseRow } from '../types';
9
9
 
10
10
  export interface GridFormEditBearingProps<TData extends GridBaseRow> extends CellEditorCommon {
11
11
  formatValue?: (value: any) => string;
@@ -3,9 +3,9 @@ import { ReactElement, useEffect, useState } from 'react';
3
3
 
4
4
  import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
5
5
  import { ComponentLoadingWrapper } from '../ComponentLoadingWrapper';
6
- import { GridBaseRow } from '../Grid';
7
6
  import { CellEditorCommon } from '../GridCell';
8
7
  import { useGridPopoverHook } from '../GridPopoverHook';
8
+ import { GridBaseRow } from '../types';
9
9
 
10
10
  export interface GridFormMessageProps<TData extends GridBaseRow> extends CellEditorCommon {
11
11
  message: (selectedRows: TData[]) => Promise<string | ReactElement> | string | ReactElement;
@@ -21,10 +21,10 @@ import { FocusableItem, MenuDivider, MenuHeader, MenuItem } from '../../react-me
21
21
  import { ClickEvent } from '../../react-menu3/types';
22
22
  import { textMatch } from '../../utils/textMatcher';
23
23
  import { ComponentLoadingWrapper } from '../ComponentLoadingWrapper';
24
- import { GridBaseRow } from '../Grid';
25
24
  import { CellEditorCommon } from '../GridCell';
26
25
  import { GridIcon } from '../GridIcon';
27
26
  import { useGridPopoverHook } from '../GridPopoverHook';
27
+ import { GridBaseRow } from '../types';
28
28
  import { MenuSeparatorString } from './GridFormDropDown';
29
29
 
30
30
  type HeaderGroupType = Record<string, MultiSelectOption[]> | undefined;
@@ -5,10 +5,10 @@ import { ReactElement, useCallback, useEffect, useRef, useState } from 'react';
5
5
  import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
6
6
  import { MenuItem } from '../../react-menu3';
7
7
  import { ClickEvent } from '../../react-menu3/types';
8
- import { GridBaseRow } from '../Grid';
9
8
  import { CellEditorCommon } from '../GridCell';
10
9
  import { GridIcon } from '../GridIcon';
11
10
  import { useGridPopoverHook } from '../GridPopoverHook';
11
+ import { GridBaseRow } from '../types';
12
12
 
13
13
  export interface MultiSelectGridOption {
14
14
  value: any;
@@ -6,9 +6,9 @@ import { GridSubComponentContext } from '../../contexts/GridSubComponentContext'
6
6
  import { FocusableItem, MenuDivider, MenuItem, SubMenu } from '../../react-menu3';
7
7
  import { ClickEvent } from '../../react-menu3/types';
8
8
  import { ComponentLoadingWrapper } from '../ComponentLoadingWrapper';
9
- import { GridBaseRow } from '../Grid';
10
9
  import { CellEditorCommon } from '../GridCell';
11
10
  import { useGridPopoverHook } from '../GridPopoverHook';
11
+ import { GridBaseRow } from '../types';
12
12
 
13
13
  export interface GridFormPopoverMenuProps<TData extends GridBaseRow> extends CellEditorCommon {
14
14
  options: (selectedRows: TData[]) => Promise<MenuOption<TData>[]> | MenuOption<TData>[];
@@ -4,8 +4,8 @@ import { ReactElement, useCallback, useContext, useEffect } from 'react';
4
4
  import { GridSubComponentContext } from '../../contexts/GridSubComponentContext';
5
5
  import { TextAreaInput } from '../../lui/TextAreaInput';
6
6
  import { TextInputValidator, TextInputValidatorProps } from '../../utils/textValidator';
7
- import { GridBaseRow } from '../Grid';
8
7
  import { CellEditorCommon } from '../GridCell';
8
+ import { GridBaseRow } from '../types';
9
9
 
10
10
  export interface GridSubComponentTextAreaProps<TData extends GridBaseRow>
11
11
  extends TextInputValidatorProps<TData>,
@@ -3,8 +3,8 @@ import { ReactElement, useCallback, useContext, useEffect } from 'react';
3
3
  import { GridSubComponentContext } from '../../contexts/GridSubComponentContext';
4
4
  import { TextInputFormatted } from '../../lui/TextInputFormatted';
5
5
  import { TextInputValidator, TextInputValidatorProps } from '../../utils/textValidator';
6
- import { GridBaseRow } from '../Grid';
7
6
  import { CellEditorCommon } from '../GridCell';
7
+ import { GridBaseRow } from '../types';
8
8
 
9
9
  export interface GridFormSubComponentTextInputProps<TData extends GridBaseRow>
10
10
  extends TextInputValidatorProps<TData>,
@@ -3,9 +3,9 @@ import { ReactElement, useCallback, useMemo, useState } from 'react';
3
3
  import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
4
4
  import { TextAreaInput } from '../../lui/TextAreaInput';
5
5
  import { TextInputValidator, TextInputValidatorProps } from '../../utils/textValidator';
6
- import { GridBaseRow } from '../Grid';
7
6
  import { CellEditorCommon } from '../GridCell';
8
7
  import { useGridPopoverHook } from '../GridPopoverHook';
8
+ import { GridBaseRow } from '../types';
9
9
 
10
10
  export interface GridFormTextAreaProps<TData extends GridBaseRow>
11
11
  extends TextInputValidatorProps<TData>,
@@ -3,9 +3,9 @@ import { useCallback, useMemo, useState } from 'react';
3
3
  import { useGridPopoverContext } from '../../contexts/GridPopoverContext';
4
4
  import { TextInputFormatted } from '../../lui/TextInputFormatted';
5
5
  import { TextInputValidator, TextInputValidatorProps } from '../../utils/textValidator';
6
- import { GridBaseRow } from '../Grid';
7
6
  import { CellEditorCommon } from '../GridCell';
8
7
  import { useGridPopoverHook } from '../GridPopoverHook';
8
+ import { GridBaseRow } from '../types';
9
9
 
10
10
  export interface GridFormTextInputProps<TData extends GridBaseRow>
11
11
  extends TextInputValidatorProps<TData>,
@@ -4,7 +4,7 @@ import { ReactElement, useCallback, useContext, useRef, useState } from 'react';
4
4
 
5
5
  import { GridContext } from '../../contexts/GridContext';
6
6
  import { ControlledMenu } from '../../react-menu3';
7
- import { GridBaseRow } from '../Grid';
7
+ import { GridBaseRow } from '../types';
8
8
 
9
9
  export interface GridContextMenuComponentProps<TData extends GridBaseRow> {
10
10
  selectedRows: TData[];
@@ -2,9 +2,9 @@ import { LuiButton, LuiIcon } from '@linzjs/lui';
2
2
  import { CellFocusedEvent, ICellEditorParams, ICellRendererParams } from 'ag-grid-community';
3
3
  import { useEffect, useRef } from 'react';
4
4
 
5
- import { GridBaseRow } from '../Grid';
6
- import { ColDefT, GridCell } from '../GridCell';
5
+ import { GridCell } from '../GridCell';
7
6
  import { GenericCellColDef } from '../gridRender';
7
+ import { ColDefT, GridBaseRow } from '../types';
8
8
 
9
9
  const ButtonCellRenderer = <TData extends GridBaseRow>(props: ICellRendererParams<TData>) => {
10
10
  const { data, node, column, colDef, api } = props;
@@ -5,9 +5,9 @@ import { useEffect, useRef } from 'react';
5
5
 
6
6
  import { fnOrVar } from '../../utils/util';
7
7
  import { clickInputWhenContainingCellClicked } from '../clickInputWhenContainingCellClicked';
8
- import { GridBaseRow } from '../Grid';
9
- import { CellEditorCommon, ColDefT, GridCell } from '../GridCell';
8
+ import { CellEditorCommon, GridCell } from '../GridCell';
10
9
  import { GenericCellColDef } from '../gridRender';
10
+ import { ColDefT, GridBaseRow } from '../types';
11
11
 
12
12
  const BooleanCellRenderer = (props: CustomCellEditorProps) => {
13
13
  const { onValueChange, value, api, node, column, colDef, data } = props;
@@ -1,9 +1,9 @@
1
1
  import clsx from 'clsx';
2
2
 
3
- import { GridBaseRow } from '../Grid';
4
- import { ColDefT, GenericCellEditorProps, GridCell } from '../GridCell';
3
+ import { GenericCellEditorProps, GridCell } from '../GridCell';
5
4
  import { GridFormMultiSelect, GridFormMultiSelectProps } from '../gridForm/GridFormMultiSelect';
6
5
  import { GenericCellColDef } from '../gridRender/GridRenderGenericCell';
6
+ import { ColDefT, GridBaseRow } from '../types';
7
7
 
8
8
  export const GridPopoutEditMultiSelect = <TData extends GridBaseRow, TValue = any>(
9
9
  colDef: GenericCellColDef<TData, TValue>,