@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.
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.1",
5
+ "version": "29.3.3",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -172,8 +172,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
172
172
  prePopupOps,
173
173
  startCellEditing,
174
174
  } = useGridContext<TData>();
175
-
176
- const { updatedDep, updatingCols } = useContext(GridUpdatingContext);
175
+ const { updatedDep, anyUpdating, updatingCols } = useContext(GridUpdatingContext);
177
176
 
178
177
  const gridDivRef = useRef<HTMLDivElement>(null);
179
178
  const lastSelectedIds = useRef<number[]>([]);
@@ -192,7 +191,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
192
191
  const hasSetContentSizeEmpty = useRef(false);
193
192
  const needsAutoSize = useRef(true);
194
193
 
195
- const requiresInitialSizeToFitRef = useRef(true);
194
+ const requiresInitialSizeToFitRef = useRef(false);
196
195
  const autoSizeResultRef = useRef<AutoSizeColumnsResult | null>(null);
197
196
  const prevRowsVisibleRef = useRef(false);
198
197
  const setInitialContentSize = useCallback(() => {
@@ -254,16 +253,8 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
254
253
  // It should be impossible to get here
255
254
  console.error('Unknown value returned from hasGridRendered');
256
255
  }
257
-
258
- // If there's no contentSize callback there'll be on onGridResize callback
259
- // which is required to run sizeColumnsToFit.
260
- // There's also the possibility that the panel was already the right size so didn't trigger onGridResize.
261
- delay(() => {
262
- if (requiresInitialSizeToFitRef.current) {
263
- requiresInitialSizeToFitRef.current = false;
264
- sizeColumnsToFit();
265
- }
266
- }, 50);
256
+ } else {
257
+ sizeColumnsToFit();
267
258
  }
268
259
 
269
260
  setAutoSized(true);
@@ -443,7 +434,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
443
434
  */
444
435
  const previousRowDataLength = useRef(0);
445
436
 
446
- const onRowDataChanged = useCallback(() => {
437
+ const onRowDataUpdated = useCallback(() => {
447
438
  const length = rowData?.length ?? 0;
448
439
  if (previousRowDataLength.current !== length) {
449
440
  // We need to autosize all cells again
@@ -456,10 +447,12 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
456
447
  lastUpdatedDep.current = updatedDep;
457
448
 
458
449
  // Don't update while there are spinners
459
- if (!isEmpty(updatingCols())) return;
450
+ if (anyUpdating()) {
451
+ return;
452
+ }
460
453
 
461
454
  const skipHeader = sizeColumns === 'auto-skip-headers';
462
- if (hasSetContentSize.current) {
455
+ if ((sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && hasSetContentSize.current) {
463
456
  autoSizeColumns({
464
457
  skipHeader,
465
458
  userSizedColIds: new Set(userSizedColIds.current.keys()),
@@ -467,7 +460,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
467
460
  });
468
461
  }
469
462
  colIdsEdited.current.clear();
470
- }, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, updatingCols]);
463
+ }, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, anyUpdating]);
471
464
 
472
465
  /**
473
466
  * Show/hide no rows overlay when model changes.
@@ -502,6 +495,24 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
502
495
  [singleClickEdit, startCellEditing],
503
496
  );
504
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
+
505
516
  /**
506
517
  * If cell has an edit action invoke it (if editable)
507
518
  */
@@ -614,6 +625,9 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
614
625
  */
615
626
  const onGridResize = useCallback(
616
627
  (event: AgGridEvent<TData>) => {
628
+ if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
629
+ return;
630
+ }
617
631
  if (sizeColumns !== 'none') {
618
632
  // Flex columns can expand to fit after resize, but they cannot shrink less than use resized value
619
633
  // Double click column resize handle to reset this behaviour
@@ -626,7 +640,6 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
626
640
  }),
627
641
  ),
628
642
  ];
629
- requiresInitialSizeToFitRef.current = false;
630
643
  defer(() => event.api.sizeColumnsToFit({ columnLimits }));
631
644
  }
632
645
  },
@@ -651,6 +664,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
651
664
  if (width == null) {
652
665
  return;
653
666
  }
667
+
654
668
  switch (e.source) {
655
669
  case 'uiColumnResized':
656
670
  userSizedColIds.current.set(colId, width);
@@ -863,10 +877,19 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
863
877
  ? {
864
878
  enableSelectionWithoutKeys: params.enableSelectionWithoutKeys ?? false,
865
879
  enableClickSelection: params.enableClickSelection ?? false,
866
- mode: rowSelection == 'single' ? 'singleRow' : 'multiRow',
880
+ mode: rowSelection === 'single' ? 'singleRow' : 'multiRow',
867
881
  }
868
882
  : undefined
869
883
  }
884
+ onDisplayedColumnsChanged={() => {
885
+ // This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
886
+ if (requiresInitialSizeToFitRef.current) {
887
+ requiresInitialSizeToFitRef.current = false;
888
+ delay(() => {
889
+ sizeColumnsToFit();
890
+ }, 200);
891
+ }
892
+ }}
870
893
  rowHeight={rowHeight}
871
894
  animateRows={params.animateRows ?? false}
872
895
  rowClassRules={params.rowClassRules}
@@ -875,11 +898,12 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
875
898
  suppressColumnVirtualisation={suppressColumnVirtualization}
876
899
  suppressClickEdit={true}
877
900
  onColumnVisible={setInitialContentSize}
878
- onRowDataUpdated={onRowDataChanged}
901
+ onRowDataUpdated={onRowDataUpdated}
879
902
  onCellFocused={onCellFocused}
880
903
  onCellKeyDown={onCellKeyPress}
881
904
  onCellClicked={onCellClicked}
882
905
  onCellDoubleClicked={onCellDoubleClick}
906
+ onCellEditingStopped={onCellEditingStopped}
883
907
  domLayout={params.domLayout}
884
908
  onColumnResized={onColumnResized}
885
909
  defaultColDef={defaultColDef}