@linzjs/step-ag-grid 29.3.2 → 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.
@@ -2764,7 +2764,7 @@ agGridCommunity.ModuleRegistry.registerModules([agGridCommunity.AllCommunityModu
2764
2764
  */
2765
2765
  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 }) => {
2766
2766
  const { gridReady, gridRenderState, setApis, ensureRowVisible, getFirstRowId, selectRowsById, focusByRowById, ensureSelectedRowIsVisible, autoSizeColumns, sizeColumnsToFit, externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync, isExternalFilterPresent, doesExternalFilterPass, setOnBulkEditingComplete, getColDef, showNoRowsOverlay, prePopupOps, startCellEditing, } = useGridContext();
2767
- const { updatedDep, updatingCols } = React.useContext(GridUpdatingContext);
2767
+ const { updatedDep, anyUpdating, updatingCols } = React.useContext(GridUpdatingContext);
2768
2768
  const gridDivRef = React.useRef(null);
2769
2769
  const lastSelectedIds = React.useRef([]);
2770
2770
  const [staleGrid, setStaleGrid] = React.useState(false);
@@ -2778,7 +2778,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2778
2778
  const hasSetContentSize = React.useRef(false);
2779
2779
  const hasSetContentSizeEmpty = React.useRef(false);
2780
2780
  const needsAutoSize = React.useRef(true);
2781
- const requiresInitialSizeToFitRef = React.useRef(true);
2781
+ const requiresInitialSizeToFitRef = React.useRef(false);
2782
2782
  const autoSizeResultRef = React.useRef(null);
2783
2783
  const prevRowsVisibleRef = React.useRef(false);
2784
2784
  const setInitialContentSize = React.useCallback(() => {
@@ -2839,9 +2839,12 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2839
2839
  console.error('Unknown value returned from hasGridRendered');
2840
2840
  }
2841
2841
  }
2842
+ else {
2843
+ sizeColumnsToFit();
2844
+ }
2842
2845
  setAutoSized(true);
2843
2846
  needsAutoSize.current = false;
2844
- }, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns]);
2847
+ }, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns, sizeColumnsToFit]);
2845
2848
  const lastOwnerDocumentRef = React.useRef();
2846
2849
  const wasVisibleRef = React.useRef(false);
2847
2850
  /**
@@ -2990,7 +2993,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2990
2993
  * This will resize columns when we have at least one row.
2991
2994
  */
2992
2995
  const previousRowDataLength = React.useRef(0);
2993
- const onRowDataChanged = React.useCallback(() => {
2996
+ const onRowDataUpdated = React.useCallback(() => {
2994
2997
  const length = rowData?.length ?? 0;
2995
2998
  if (previousRowDataLength.current !== length) {
2996
2999
  // We need to autosize all cells again
@@ -3002,10 +3005,11 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3002
3005
  return;
3003
3006
  lastUpdatedDep.current = updatedDep;
3004
3007
  // Don't update while there are spinners
3005
- if (!lodashEs.isEmpty(updatingCols()))
3008
+ if (anyUpdating()) {
3006
3009
  return;
3010
+ }
3007
3011
  const skipHeader = sizeColumns === 'auto-skip-headers';
3008
- if (hasSetContentSize.current) {
3012
+ if ((sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && hasSetContentSize.current) {
3009
3013
  autoSizeColumns({
3010
3014
  skipHeader,
3011
3015
  userSizedColIds: new Set(userSizedColIds.current.keys()),
@@ -3013,7 +3017,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3013
3017
  });
3014
3018
  }
3015
3019
  colIdsEdited.current.clear();
3016
- }, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, updatingCols]);
3020
+ }, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, anyUpdating]);
3017
3021
  /**
3018
3022
  * Show/hide no rows overlay when model changes.
3019
3023
  */
@@ -3038,6 +3042,20 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3038
3042
  void startCellEditing({ rowId: event.data.id, colId: event.column.getColId() });
3039
3043
  }
3040
3044
  }, [singleClickEdit, startCellEditing]);
3045
+ const onCellEditingStopped = React.useCallback((event) => {
3046
+ const api = event.api;
3047
+ // We need to redraw on fit as the updated row heights aren't visible
3048
+ if (sizeColumns === 'fit') {
3049
+ lodashEs.delay(() => {
3050
+ // Don't update if currently editing, that will stop the edit
3051
+ if (!anyUpdating() && document.querySelectorAll('.szh-menu--state-open').length === 0) {
3052
+ if (!api.isDestroyed()) {
3053
+ api.redrawRows();
3054
+ }
3055
+ }
3056
+ }, 500);
3057
+ }
3058
+ }, [anyUpdating, sizeColumns]);
3041
3059
  /**
3042
3060
  * If cell has an edit action invoke it (if editable)
3043
3061
  */
@@ -3138,7 +3156,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3138
3156
  * Resize columns to fit if required on window/container resize
3139
3157
  */
3140
3158
  const onGridResize = React.useCallback((event) => {
3141
- if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
3159
+ if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
3142
3160
  return;
3143
3161
  }
3144
3162
  if (sizeColumns !== 'none') {
@@ -3330,9 +3348,11 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3330
3348
  // This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
3331
3349
  if (requiresInitialSizeToFitRef.current) {
3332
3350
  requiresInitialSizeToFitRef.current = false;
3333
- sizeColumnsToFit();
3351
+ lodashEs.delay(() => {
3352
+ sizeColumnsToFit();
3353
+ }, 200);
3334
3354
  }
3335
- }, 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 }) })] }));
3355
+ }, 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 }) })] }));
3336
3356
  };
3337
3357
  const quickFilterParser = (filterStr) => {
3338
3358
  // filter is exact matches exactly groups separated by commas