@linzjs/step-ag-grid 29.11.0 → 29.11.2

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.
package/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
  - Custom form
19
19
  - Context menu
20
20
 
21
- _Please note this requires React>=18, ag-grid-community >=32.3.3, and SASS._
21
+ _Please note this requires React>=18, ag-grid-community >=34.2.0, and SASS._
22
22
 
23
23
  ## Install
24
24
 
@@ -6,7 +6,6 @@ export interface AutoSizeColumnsProps {
6
6
  skipHeader?: boolean;
7
7
  colIds?: Set<string> | string[];
8
8
  userSizedColIds?: Set<string>;
9
- includeFlex?: boolean;
10
9
  }
11
10
  export type AutoSizeColumnsResult = {
12
11
  width: number;
@@ -1,6 +1,9 @@
1
- import { ProcessCellForExportParams } from 'ag-grid-community';
1
+ import { ColumnState, ProcessCellForExportParams } from 'ag-grid-community';
2
2
  import { PropsWithChildren, ReactElement } from 'react';
3
3
  import { GridBaseRow } from '../components';
4
+ export declare const colStateId: (colState: ColumnState) => string;
5
+ export declare const colStateFlexed: (colState: ColumnState) => boolean;
6
+ export declare const colStateNotFlexed: (colState: ColumnState) => boolean;
4
7
  /**
5
8
  * Context for AgGrid operations.
6
9
  * Make sure you wrap AgGrid in this.
@@ -2785,7 +2785,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2785
2785
  const hasSetContentSize = React.useRef(false);
2786
2786
  const hasSetContentSizeEmpty = React.useRef(false);
2787
2787
  const needsAutoSize = React.useRef(true);
2788
- const requiresInitialSizeToFitRef = React.useRef(false);
2789
2788
  const autoSizeResultRef = React.useRef(null);
2790
2789
  const prevRowsVisibleRef = React.useRef(false);
2791
2790
  const setInitialContentSize = React.useCallback(() => {
@@ -2814,7 +2813,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2814
2813
  autoSizeColumns({
2815
2814
  skipHeader,
2816
2815
  userSizedColIds: new Set(userSizedColIds.current.keys()),
2817
- includeFlex: true,
2818
2816
  });
2819
2817
  // Auto-size failed retry later
2820
2818
  if (!autoSizeResult) {
@@ -2829,7 +2827,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2829
2827
  // We don't do this callback if we have previously had row data, or have already called back for empty
2830
2828
  if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
2831
2829
  hasSetContentSizeEmpty.current = true;
2832
- requiresInitialSizeToFitRef.current = true;
2833
2830
  params.onContentSize?.(autoSizeResult);
2834
2831
  }
2835
2832
  }
@@ -2837,7 +2834,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2837
2834
  // we have rows now so callback grid size
2838
2835
  if (!hasSetContentSize.current) {
2839
2836
  hasSetContentSize.current = true;
2840
- requiresInitialSizeToFitRef.current = true;
2841
2837
  params.onContentSize?.(autoSizeResult);
2842
2838
  }
2843
2839
  }
@@ -2847,6 +2843,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2847
2843
  }
2848
2844
  }
2849
2845
  else {
2846
+ console.log('sizeColumnsToFit 3');
2850
2847
  sizeColumnsToFit();
2851
2848
  }
2852
2849
  setAutoSized(true);
@@ -3132,8 +3129,9 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3132
3129
  * When cell editing has completed the colId as needing auto-sizing
3133
3130
  */
3134
3131
  React.useEffect(() => {
3135
- if (lastUpdatedDep.current === updatedDep)
3132
+ if (lastUpdatedDep.current === updatedDep) {
3136
3133
  return;
3134
+ }
3137
3135
  lastUpdatedDep.current = updatedDep;
3138
3136
  const colIds = updatingCols();
3139
3137
  // Updating possibly completed
@@ -3172,26 +3170,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3172
3170
  }
3173
3171
  prevLoading.current = newLoading;
3174
3172
  }, [params.loading, rowData, showNoRowsOverlay]);
3175
- /**
3176
- * Resize columns to fit if required on window/container resize
3177
- */
3178
- const onGridResize = React.useCallback((event) => {
3179
- if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
3180
- return;
3181
- }
3182
- if (sizeColumns !== 'none') {
3183
- // Flex columns can expand to fit after resize, but they cannot shrink less than use resized value
3184
- // Double click column resize handle to reset this behaviour
3185
- const columnLimits = [
3186
- ...userSizedColIds.current.entries().map(([c, w]) => ({
3187
- key: c,
3188
- minWidth: w,
3189
- maxWidth: w,
3190
- })),
3191
- ];
3192
- lodashEs.defer(() => event.api.sizeColumnsToFit({ columnLimits }));
3193
- }
3194
- }, [sizeColumns]);
3195
3173
  /**
3196
3174
  * Set of column I'd's that are prevented from auto-sizing as they are user set
3197
3175
  */
@@ -3211,17 +3189,17 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3211
3189
  switch (e.source) {
3212
3190
  case 'uiColumnResized':
3213
3191
  userSizedColIds.current.set(colId, width);
3214
- const colDef = e.column?.getColDef();
3215
- if (!colDef?.flex) {
3192
+ /*const colDef = e.column?.getColDef();
3193
+ if (!colDef?.flex) {
3216
3194
  onGridResize(e);
3217
- }
3195
+ }*/
3218
3196
  break;
3219
3197
  case 'autosizeColumns':
3220
3198
  userSizedColIds.current.delete(colId);
3221
- onGridResize(e);
3199
+ //onGridResize(e);
3222
3200
  break;
3223
3201
  }
3224
- }, [onGridResize]);
3202
+ }, []);
3225
3203
  const gridContextMenu = useGridContextMenu({ contextMenu: params.contextMenu, contextMenuSelectRow });
3226
3204
  const startDragYRef = React.useRef(null);
3227
3205
  const clearHighlightRowClasses = React.useCallback(() => {
@@ -3364,15 +3342,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3364
3342
  enableClickSelection: params.enableClickSelection ?? false,
3365
3343
  mode: rowSelection === 'single' ? 'singleRow' : 'multiRow',
3366
3344
  }
3367
- : undefined, onDisplayedColumnsChanged: () => {
3368
- // This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
3369
- if (requiresInitialSizeToFitRef.current) {
3370
- requiresInitialSizeToFitRef.current = false;
3371
- lodashEs.delay(() => {
3372
- sizeColumnsToFit();
3373
- }, 200);
3374
- }
3375
- }, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, onGridSizeChanged: onGridResize, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: setInitialContentSize, onRowDataUpdated: onRowDataUpdated, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStopped: onCellEditingStopped, domLayout: params.domLayout, onColumnResized: onColumnResized, defaultColDef: defaultColDef, columnDefs: columnDefsAdjusted, selectionColumnDef: selectionColumnDef, rowData: rowData, postSortRows: params.onRowDragEnd || !defaultPostSort ? undefined : postSortRows, onModelUpdated: onModelUpdated, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, quickFilterParser: quickFilterParser, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, noRowsOverlayComponent: noRowsOverlayComponent, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, isExternalFilterPresent: isExternalFilterPresent, doesExternalFilterPass: doesExternalFilterPass, maintainColumnOrder: true, preventDefaultOnContextMenu: true, onCellContextMenu: gridContextMenu.cellContextMenu, rowDragText: params.rowDragText, onRowDragCancel: clearHighlightRowClasses, onRowDragMove: onRowDragMove, onRowDragEnd: onRowDragEnd, suppressCellFocus: params.suppressCellFocus, pinnedTopRowData: params.pinnedTopRowData, pinnedBottomRowData: params.pinnedBottomRowData, onRowClicked: params.onRowClicked, onRowDoubleClicked: params.onRowDoubleClicked, suppressStartEditOnTab: true }) })] }));
3345
+ : undefined, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: setInitialContentSize, onRowDataUpdated: onRowDataUpdated, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStopped: onCellEditingStopped, domLayout: params.domLayout, onColumnResized: onColumnResized, defaultColDef: defaultColDef, columnDefs: columnDefsAdjusted, selectionColumnDef: selectionColumnDef, rowData: rowData, postSortRows: params.onRowDragEnd || !defaultPostSort ? undefined : postSortRows, onModelUpdated: onModelUpdated, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, quickFilterParser: quickFilterParser, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, noRowsOverlayComponent: noRowsOverlayComponent, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, isExternalFilterPresent: isExternalFilterPresent, doesExternalFilterPass: doesExternalFilterPass, maintainColumnOrder: true, preventDefaultOnContextMenu: true, onCellContextMenu: gridContextMenu.cellContextMenu, rowDragText: params.rowDragText, onRowDragCancel: clearHighlightRowClasses, onRowDragMove: onRowDragMove, onRowDragEnd: onRowDragEnd, suppressCellFocus: params.suppressCellFocus, pinnedTopRowData: params.pinnedTopRowData, pinnedBottomRowData: params.pinnedBottomRowData, onRowClicked: params.onRowClicked, onRowDoubleClicked: params.onRowDoubleClicked, suppressStartEditOnTab: true }) })] }));
3376
3346
  };
3377
3347
  const quickFilterParser = (filterStr) => {
3378
3348
  // filter is exact matches exactly groups separated by commas
@@ -5346,6 +5316,9 @@ const waitForCondition = async (error, condition, timeoutMs) => {
5346
5316
  return false;
5347
5317
  };
5348
5318
 
5319
+ const colStateId = (colState) => colState.colId;
5320
+ const colStateFlexed = (colState) => !!colState.flex;
5321
+ const colStateNotFlexed = (colState) => !colState.flex;
5349
5322
  /**
5350
5323
  * Context for AgGrid operations.
5351
5324
  * Make sure you wrap AgGrid in this.
@@ -5627,23 +5600,45 @@ const GridContextProvider = (props) => {
5627
5600
  }, [gridApiOp]);
5628
5601
  /**
5629
5602
  * Resize columns to fit container
5603
+ *
5604
+ * This is used to calculate the preferred size of columns.
5605
+ * It sizes the flex columns first and then clears the calculated width.
5606
+ * If you don't clear flex column widths ag-grid gets confused and does random sizing's.
5607
+ * Then we size the flexed columns.
5630
5608
  */
5631
- const autoSizeColumns = React.useCallback(({ skipHeader, colIds, userSizedColIds, includeFlex } = {}) => {
5609
+ const autoSizeColumns = React.useCallback(({ skipHeader, colIds, userSizedColIds } = {}) => {
5632
5610
  if (!gridApi || !gridApi.getColumnState()) {
5633
5611
  return null;
5634
5612
  }
5635
5613
  const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
5636
- const colsToResize = gridApi.getColumnState()?.filter?.((colState) => {
5637
- const colId = colState.colId;
5638
- return ((lodashEs.isEmpty(colIdsSet) || colIdsSet.has(colId)) &&
5639
- !userSizedColIds?.has(colId) &&
5640
- (includeFlex || !colState.flex));
5641
- });
5642
- if (!lodashEs.isEmpty(colsToResize)) {
5643
- gridApi.autoSizeColumns(colsToResize.map((colState) => colState.colId), skipHeader);
5614
+ const getVisibleColStates = () => {
5615
+ const colStates = gridApi.getColumnState();
5616
+ return colStates.filter((colState) => {
5617
+ const colId = colState.colId;
5618
+ return (lodashEs.isEmpty(colIdsSet) || colIdsSet.has(colId)) && !userSizedColIds?.has(colId);
5619
+ });
5620
+ };
5621
+ const getFlexColStates = () => getVisibleColStates().filter(colStateFlexed);
5622
+ const getNonFlexColStates = () => getVisibleColStates().filter(colStateNotFlexed);
5623
+ // If we don't reset the flex columns auto size it causes issues with random resizing of flex columns
5624
+ let flexColumns = getFlexColStates();
5625
+ let width = 0;
5626
+ if (!lodashEs.isEmpty(flexColumns)) {
5627
+ gridApi.autoSizeColumns(flexColumns.map(colStateId), skipHeader);
5628
+ const flexColumnIds = flexColumns.map(colStateId);
5629
+ flexColumns = getVisibleColStates().filter((colState) => flexColumnIds.includes(colState.colId));
5630
+ width += lodashEs.sumBy(flexColumns.filter((col) => !col.hide), 'width');
5631
+ gridApi.resetColumnState();
5632
+ }
5633
+ let nonFlexColumns = getNonFlexColStates();
5634
+ if (!lodashEs.isEmpty(nonFlexColumns)) {
5635
+ gridApi.autoSizeColumns(nonFlexColumns.map(colStateId), skipHeader);
5636
+ const nonFlexColumnIds = nonFlexColumns.map(colStateId);
5637
+ nonFlexColumns = getVisibleColStates().filter((colState) => nonFlexColumnIds.includes(colState.colId));
5638
+ width += lodashEs.sumBy(nonFlexColumns.filter((col) => !col.hide), 'width');
5644
5639
  }
5645
5640
  return {
5646
- width: lodashEs.sumBy(gridApi.getColumnState().filter((col) => !col.hide), 'width'),
5641
+ width,
5647
5642
  };
5648
5643
  }, [gridApi]);
5649
5644
  /**
@@ -6208,6 +6203,9 @@ exports.bearingNumberParser = bearingNumberParser;
6208
6203
  exports.bearingRangeValidator = bearingRangeValidator;
6209
6204
  exports.bearingStringValidator = bearingStringValidator;
6210
6205
  exports.bearingValueFormatter = bearingValueFormatter;
6206
+ exports.colStateFlexed = colStateFlexed;
6207
+ exports.colStateId = colStateId;
6208
+ exports.colStateNotFlexed = colStateNotFlexed;
6211
6209
  exports.convertDDToDMS = convertDDToDMS;
6212
6210
  exports.createCheckboxMultiFilterParams = createCheckboxMultiFilterParams;
6213
6211
  exports.defaultValueFormatter = defaultValueFormatter;