@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.
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.3.2",
5
+ "version": "29.3.3",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -26,7 +26,7 @@ import {
26
26
  } from 'ag-grid-community';
27
27
  import { AgGridReact } from 'ag-grid-react';
28
28
  import clsx from 'clsx';
29
- import { defer, difference, isEmpty, last, omit, xorBy } from 'lodash-es';
29
+ import { defer, delay, difference, isEmpty, last, omit, xorBy } from 'lodash-es';
30
30
  import { ReactElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
31
31
  import { useInterval } from 'usehooks-ts';
32
32
 
@@ -172,7 +172,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
172
172
  prePopupOps,
173
173
  startCellEditing,
174
174
  } = useGridContext<TData>();
175
- const { updatedDep, updatingCols } = useContext(GridUpdatingContext);
175
+ const { updatedDep, anyUpdating, updatingCols } = useContext(GridUpdatingContext);
176
176
 
177
177
  const gridDivRef = useRef<HTMLDivElement>(null);
178
178
  const lastSelectedIds = useRef<number[]>([]);
@@ -191,7 +191,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
191
191
  const hasSetContentSizeEmpty = useRef(false);
192
192
  const needsAutoSize = useRef(true);
193
193
 
194
- const requiresInitialSizeToFitRef = useRef(true);
194
+ const requiresInitialSizeToFitRef = useRef(false);
195
195
  const autoSizeResultRef = useRef<AutoSizeColumnsResult | null>(null);
196
196
  const prevRowsVisibleRef = useRef(false);
197
197
  const setInitialContentSize = useCallback(() => {
@@ -253,11 +253,13 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
253
253
  // It should be impossible to get here
254
254
  console.error('Unknown value returned from hasGridRendered');
255
255
  }
256
+ } else {
257
+ sizeColumnsToFit();
256
258
  }
257
259
 
258
260
  setAutoSized(true);
259
261
  needsAutoSize.current = false;
260
- }, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns]);
262
+ }, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns, sizeColumnsToFit]);
261
263
 
262
264
  const lastOwnerDocumentRef = useRef<Document>();
263
265
  const wasVisibleRef = useRef(false);
@@ -432,7 +434,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
432
434
  */
433
435
  const previousRowDataLength = useRef(0);
434
436
 
435
- const onRowDataChanged = useCallback(() => {
437
+ const onRowDataUpdated = useCallback(() => {
436
438
  const length = rowData?.length ?? 0;
437
439
  if (previousRowDataLength.current !== length) {
438
440
  // We need to autosize all cells again
@@ -445,10 +447,12 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
445
447
  lastUpdatedDep.current = updatedDep;
446
448
 
447
449
  // Don't update while there are spinners
448
- if (!isEmpty(updatingCols())) return;
450
+ if (anyUpdating()) {
451
+ return;
452
+ }
449
453
 
450
454
  const skipHeader = sizeColumns === 'auto-skip-headers';
451
- if (hasSetContentSize.current) {
455
+ if ((sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && hasSetContentSize.current) {
452
456
  autoSizeColumns({
453
457
  skipHeader,
454
458
  userSizedColIds: new Set(userSizedColIds.current.keys()),
@@ -456,7 +460,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
456
460
  });
457
461
  }
458
462
  colIdsEdited.current.clear();
459
- }, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, updatingCols]);
463
+ }, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, anyUpdating]);
460
464
 
461
465
  /**
462
466
  * Show/hide no rows overlay when model changes.
@@ -491,6 +495,24 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
491
495
  [singleClickEdit, startCellEditing],
492
496
  );
493
497
 
498
+ const onCellEditingStopped = useCallback(
499
+ (event: AgGridEvent<TData>) => {
500
+ const api = event.api;
501
+ // We need to redraw on fit as the updated row heights aren't visible
502
+ if (sizeColumns === 'fit') {
503
+ delay(() => {
504
+ // Don't update if currently editing, that will stop the edit
505
+ if (!anyUpdating() && document.querySelectorAll('.szh-menu--state-open').length === 0) {
506
+ if (!api.isDestroyed()) {
507
+ api.redrawRows();
508
+ }
509
+ }
510
+ }, 500);
511
+ }
512
+ },
513
+ [anyUpdating, sizeColumns],
514
+ );
515
+
494
516
  /**
495
517
  * If cell has an edit action invoke it (if editable)
496
518
  */
@@ -603,7 +625,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
603
625
  */
604
626
  const onGridResize = useCallback(
605
627
  (event: AgGridEvent<TData>) => {
606
- if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
628
+ if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
607
629
  return;
608
630
  }
609
631
  if (sizeColumns !== 'none') {
@@ -863,7 +885,9 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
863
885
  // This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
864
886
  if (requiresInitialSizeToFitRef.current) {
865
887
  requiresInitialSizeToFitRef.current = false;
866
- sizeColumnsToFit();
888
+ delay(() => {
889
+ sizeColumnsToFit();
890
+ }, 200);
867
891
  }
868
892
  }}
869
893
  rowHeight={rowHeight}
@@ -874,11 +898,12 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
874
898
  suppressColumnVirtualisation={suppressColumnVirtualization}
875
899
  suppressClickEdit={true}
876
900
  onColumnVisible={setInitialContentSize}
877
- onRowDataUpdated={onRowDataChanged}
901
+ onRowDataUpdated={onRowDataUpdated}
878
902
  onCellFocused={onCellFocused}
879
903
  onCellKeyDown={onCellKeyPress}
880
904
  onCellClicked={onCellClicked}
881
905
  onCellDoubleClicked={onCellDoubleClick}
906
+ onCellEditingStopped={onCellEditingStopped}
882
907
  domLayout={params.domLayout}
883
908
  onColumnResized={onColumnResized}
884
909
  defaultColDef={defaultColDef}