@linzjs/step-ag-grid 29.3.1 → 29.3.3

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.
@@ -2,7 +2,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { LuiMiniSpinner, LuiStatusSpinner, LuiIcon, LuiButtonGroup, LuiButton, LuiCheckboxInput } from '@linzjs/lui';
3
3
  import { ModuleRegistry, AllCommunityModule } from 'ag-grid-community';
4
4
  import { AgGridReact } from 'ag-grid-react';
5
- import { negate, isEmpty, findIndex, defer, debounce as debounce$1, delay, xorBy, last, difference, omit, sortBy, partition, compact, pick, groupBy, fromPairs, toPairs, isEqual, pull, filter, sumBy, remove, flatten, castArray } from 'lodash-es';
5
+ import { negate, isEmpty, findIndex, defer, debounce as debounce$1, xorBy, last, difference, delay, omit, sortBy, partition, compact, pick, groupBy, fromPairs, toPairs, isEqual, pull, filter, sumBy, remove, flatten, castArray } from 'lodash-es';
6
6
  import React, { useRef, useLayoutEffect, useEffect, createContext, useContext, useState, useMemo, memo, forwardRef, useCallback, useReducer, cloneElement, useImperativeHandle, Fragment as Fragment$1, useId } from 'react';
7
7
  import { unstable_batchedUpdates, flushSync, createPortal } from 'react-dom';
8
8
 
@@ -2762,7 +2762,7 @@ ModuleRegistry.registerModules([AllCommunityModule]);
2762
2762
  */
2763
2763
  const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection = 'multiple', suppressColumnVirtualization = true, theme = 'ag-theme-step-default', sizeColumns = 'auto', selectColumnPinned = 'left', contextMenuSelectRow = false, singleClickEdit = false, rowData, rowHeight = theme === 'ag-theme-step-default' ? 40 : theme === 'ag-theme-step-compact' ? 36 : 40, selectable, onCellFocused: paramsOnCellFocused, maxInitialWidth, ...params }) => {
2764
2764
  const { gridReady, gridRenderState, setApis, ensureRowVisible, getFirstRowId, selectRowsById, focusByRowById, ensureSelectedRowIsVisible, autoSizeColumns, sizeColumnsToFit, externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync, isExternalFilterPresent, doesExternalFilterPass, setOnBulkEditingComplete, getColDef, showNoRowsOverlay, prePopupOps, startCellEditing, } = useGridContext();
2765
- const { updatedDep, updatingCols } = useContext(GridUpdatingContext);
2765
+ const { updatedDep, anyUpdating, updatingCols } = useContext(GridUpdatingContext);
2766
2766
  const gridDivRef = useRef(null);
2767
2767
  const lastSelectedIds = useRef([]);
2768
2768
  const [staleGrid, setStaleGrid] = useState(false);
@@ -2776,7 +2776,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2776
2776
  const hasSetContentSize = useRef(false);
2777
2777
  const hasSetContentSizeEmpty = useRef(false);
2778
2778
  const needsAutoSize = useRef(true);
2779
- const requiresInitialSizeToFitRef = useRef(true);
2779
+ const requiresInitialSizeToFitRef = useRef(false);
2780
2780
  const autoSizeResultRef = useRef(null);
2781
2781
  const prevRowsVisibleRef = useRef(false);
2782
2782
  const setInitialContentSize = useCallback(() => {
@@ -2836,15 +2836,9 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2836
2836
  // It should be impossible to get here
2837
2837
  console.error('Unknown value returned from hasGridRendered');
2838
2838
  }
2839
- // If there's no contentSize callback there'll be on onGridResize callback
2840
- // which is required to run sizeColumnsToFit.
2841
- // There's also the possibility that the panel was already the right size so didn't trigger onGridResize.
2842
- delay(() => {
2843
- if (requiresInitialSizeToFitRef.current) {
2844
- requiresInitialSizeToFitRef.current = false;
2845
- sizeColumnsToFit();
2846
- }
2847
- }, 50);
2839
+ }
2840
+ else {
2841
+ sizeColumnsToFit();
2848
2842
  }
2849
2843
  setAutoSized(true);
2850
2844
  needsAutoSize.current = false;
@@ -2997,7 +2991,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2997
2991
  * This will resize columns when we have at least one row.
2998
2992
  */
2999
2993
  const previousRowDataLength = useRef(0);
3000
- const onRowDataChanged = useCallback(() => {
2994
+ const onRowDataUpdated = useCallback(() => {
3001
2995
  const length = rowData?.length ?? 0;
3002
2996
  if (previousRowDataLength.current !== length) {
3003
2997
  // We need to autosize all cells again
@@ -3009,10 +3003,11 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3009
3003
  return;
3010
3004
  lastUpdatedDep.current = updatedDep;
3011
3005
  // Don't update while there are spinners
3012
- if (!isEmpty(updatingCols()))
3006
+ if (anyUpdating()) {
3013
3007
  return;
3008
+ }
3014
3009
  const skipHeader = sizeColumns === 'auto-skip-headers';
3015
- if (hasSetContentSize.current) {
3010
+ if ((sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && hasSetContentSize.current) {
3016
3011
  autoSizeColumns({
3017
3012
  skipHeader,
3018
3013
  userSizedColIds: new Set(userSizedColIds.current.keys()),
@@ -3020,7 +3015,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3020
3015
  });
3021
3016
  }
3022
3017
  colIdsEdited.current.clear();
3023
- }, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, updatingCols]);
3018
+ }, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, anyUpdating]);
3024
3019
  /**
3025
3020
  * Show/hide no rows overlay when model changes.
3026
3021
  */
@@ -3045,6 +3040,20 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3045
3040
  void startCellEditing({ rowId: event.data.id, colId: event.column.getColId() });
3046
3041
  }
3047
3042
  }, [singleClickEdit, startCellEditing]);
3043
+ const onCellEditingStopped = useCallback((event) => {
3044
+ const api = event.api;
3045
+ // We need to redraw on fit as the updated row heights aren't visible
3046
+ if (sizeColumns === 'fit') {
3047
+ delay(() => {
3048
+ // Don't update if currently editing, that will stop the edit
3049
+ if (!anyUpdating() && document.querySelectorAll('.szh-menu--state-open').length === 0) {
3050
+ if (!api.isDestroyed()) {
3051
+ api.redrawRows();
3052
+ }
3053
+ }
3054
+ }, 500);
3055
+ }
3056
+ }, [anyUpdating, sizeColumns]);
3048
3057
  /**
3049
3058
  * If cell has an edit action invoke it (if editable)
3050
3059
  */
@@ -3145,6 +3154,9 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3145
3154
  * Resize columns to fit if required on window/container resize
3146
3155
  */
3147
3156
  const onGridResize = useCallback((event) => {
3157
+ if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
3158
+ return;
3159
+ }
3148
3160
  if (sizeColumns !== 'none') {
3149
3161
  // Flex columns can expand to fit after resize, but they cannot shrink less than use resized value
3150
3162
  // Double click column resize handle to reset this behaviour
@@ -3155,7 +3167,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3155
3167
  maxWidth: w,
3156
3168
  })),
3157
3169
  ];
3158
- requiresInitialSizeToFitRef.current = false;
3159
3170
  defer(() => event.api.sizeColumnsToFit({ columnLimits }));
3160
3171
  }
3161
3172
  }, [sizeColumns]);
@@ -3329,9 +3340,17 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3329
3340
  ? {
3330
3341
  enableSelectionWithoutKeys: params.enableSelectionWithoutKeys ?? false,
3331
3342
  enableClickSelection: params.enableClickSelection ?? false,
3332
- mode: rowSelection == 'single' ? 'singleRow' : 'multiRow',
3343
+ mode: rowSelection === 'single' ? 'singleRow' : 'multiRow',
3344
+ }
3345
+ : undefined, onDisplayedColumnsChanged: () => {
3346
+ // This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
3347
+ if (requiresInitialSizeToFitRef.current) {
3348
+ requiresInitialSizeToFitRef.current = false;
3349
+ delay(() => {
3350
+ sizeColumnsToFit();
3351
+ }, 200);
3333
3352
  }
3334
- : undefined, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, onGridSizeChanged: onGridResize, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: setInitialContentSize, onRowDataUpdated: onRowDataChanged, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, 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 }) })] }));
3353
+ }, 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 }) })] }));
3335
3354
  };
3336
3355
  const quickFilterParser = (filterStr) => {
3337
3356
  // filter is exact matches exactly groups separated by commas