@linzjs/step-ag-grid 14.3.1 → 14.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/dist/src/contexts/GridContext.d.ts +3 -2
- package/dist/src/contexts/GridUpdatingContext.d.ts +1 -1
- package/dist/step-ag-grid.esm.js +61 -60
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +31 -45
- package/src/contexts/GridContext.tsx +7 -2
- package/src/contexts/GridContextProvider.tsx +26 -27
- package/src/contexts/GridUpdatingContext.tsx +3 -3
- package/src/contexts/GridUpdatingContextProvider.tsx +3 -4
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { CellClickedEvent, ColDef, ColumnResizedEvent, ModelUpdatedEvent } from "ag-grid-community";
|
|
2
2
|
import { CellClassParams, EditableCallback, EditableCallbackParams } from "ag-grid-community/dist/lib/entities/colDef";
|
|
3
3
|
import { GridOptions } from "ag-grid-community/dist/lib/entities/gridOptions";
|
|
4
|
-
import {
|
|
5
|
-
CellEditingStoppedEvent,
|
|
6
|
-
CellEvent,
|
|
7
|
-
GridReadyEvent,
|
|
8
|
-
SelectionChangedEvent,
|
|
9
|
-
} from "ag-grid-community/dist/lib/events";
|
|
4
|
+
import { CellEvent, GridReadyEvent, SelectionChangedEvent } from "ag-grid-community/dist/lib/events";
|
|
10
5
|
import { AgGridReact } from "ag-grid-react";
|
|
11
6
|
import clsx from "clsx";
|
|
12
7
|
import { difference, isEmpty, last, omit, xorBy } from "lodash-es";
|
|
@@ -101,8 +96,9 @@ export const Grid = ({
|
|
|
101
96
|
isExternalFilterPresent,
|
|
102
97
|
doesExternalFilterPass,
|
|
103
98
|
setOnCellEditingComplete,
|
|
99
|
+
getColDef,
|
|
104
100
|
} = useContext(GridContext);
|
|
105
|
-
const { checkUpdating, updatedDep,
|
|
101
|
+
const { checkUpdating, updatedDep, updatingCols } = useContext(GridUpdatingContext);
|
|
106
102
|
|
|
107
103
|
const gridDivRef = useRef<HTMLDivElement>(null);
|
|
108
104
|
|
|
@@ -351,12 +347,12 @@ export const Grid = ({
|
|
|
351
347
|
lastUpdatedDep.current = updatedDep;
|
|
352
348
|
|
|
353
349
|
// Don't update while there are spinners
|
|
354
|
-
if (
|
|
350
|
+
if (!isEmpty(updatingCols())) return;
|
|
355
351
|
|
|
356
352
|
const skipHeader = sizeColumns === "auto-skip-headers";
|
|
357
353
|
autoSizeColumns({ skipHeader, userSizedColIds: userSizedColIds.current, colIds: colIdsEdited.current });
|
|
358
354
|
colIdsEdited.current.clear();
|
|
359
|
-
}, [autoSizeColumns,
|
|
355
|
+
}, [autoSizeColumns, params.rowData?.length, setInitialContentSize, sizeColumns, updatedDep, updatingCols]);
|
|
360
356
|
|
|
361
357
|
/**
|
|
362
358
|
* Show/hide no rows overlay when model changes.
|
|
@@ -478,48 +474,39 @@ export const Grid = ({
|
|
|
478
474
|
* Set of colIds that need auto-sizing.
|
|
479
475
|
*/
|
|
480
476
|
const colIdsEdited = useRef(new Set<string>());
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* When cell editing has completed tag the colId as needing auto-sizing
|
|
484
|
-
*/
|
|
485
|
-
const onCellEditingStopped = useCallback(
|
|
486
|
-
(e: CellEditingStoppedEvent) => {
|
|
487
|
-
const skipHeader = sizeColumns === "auto-skip-headers";
|
|
488
|
-
if (sizeColumns === "auto" || skipHeader) {
|
|
489
|
-
// This may be wrong as the cell update hasn't completed?
|
|
490
|
-
const colId = e.colDef.colId;
|
|
491
|
-
if (colId && !e.colDef.flex) {
|
|
492
|
-
// This auto-sizes based on updatingContext completing
|
|
493
|
-
colIdsEdited.current.add(colId);
|
|
494
|
-
// This auto-sizes immediately in case it was an in place update
|
|
495
|
-
!isUpdating() &&
|
|
496
|
-
autoSizeColumns({
|
|
497
|
-
skipHeader,
|
|
498
|
-
userSizedColIds: userSizedColIds.current,
|
|
499
|
-
colIds: [colId],
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
},
|
|
504
|
-
[autoSizeColumns, isUpdating, sizeColumns],
|
|
505
|
-
);
|
|
506
|
-
|
|
507
477
|
const lastUpdatedDep = useRef(updatedDep);
|
|
508
478
|
|
|
509
479
|
/**
|
|
510
|
-
*
|
|
480
|
+
* When cell editing has completed the colId as needing auto-sizing
|
|
511
481
|
*/
|
|
512
482
|
useEffect(() => {
|
|
513
|
-
if (lastUpdatedDep.current === updatedDep
|
|
483
|
+
if (lastUpdatedDep.current === updatedDep) return;
|
|
514
484
|
lastUpdatedDep.current = updatedDep;
|
|
515
485
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
486
|
+
const colIds = updatingCols();
|
|
487
|
+
// Updating possibly completed
|
|
488
|
+
if (isEmpty(colIds)) {
|
|
489
|
+
// Columns to resize?
|
|
490
|
+
if (!isEmpty(colIdsEdited.current)) {
|
|
491
|
+
const skipHeader = sizeColumns === "auto-skip-headers";
|
|
492
|
+
if (sizeColumns === "auto" || skipHeader) {
|
|
493
|
+
autoSizeColumns({
|
|
494
|
+
skipHeader,
|
|
495
|
+
userSizedColIds: userSizedColIds.current,
|
|
496
|
+
colIds: colIdsEdited.current,
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
colIdsEdited.current.clear();
|
|
500
|
+
}
|
|
501
|
+
} else {
|
|
502
|
+
// Updates not complete, add them to a list of columns needing resize
|
|
503
|
+
colIds.forEach((colId) => {
|
|
504
|
+
if (colId && !getColDef(colId)?.flex) {
|
|
505
|
+
colIdsEdited.current.add(colId);
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
}, [autoSizeColumns, getColDef, sizeColumns, updatedDep, updatingCols]);
|
|
523
510
|
|
|
524
511
|
/**
|
|
525
512
|
* Resize columns to fit if required on window/container resize
|
|
@@ -583,7 +570,6 @@ export const Grid = ({
|
|
|
583
570
|
onCellDoubleClicked={onCellDoubleClick}
|
|
584
571
|
onCellEditingStarted={refreshSelectedRows}
|
|
585
572
|
domLayout={params.domLayout}
|
|
586
|
-
onCellEditingStopped={onCellEditingStopped}
|
|
587
573
|
onColumnResized={onColumnResized}
|
|
588
574
|
defaultColDef={{ minWidth: 48, ...omit(params.defaultColDef, ["editable"]) }}
|
|
589
575
|
columnDefs={columnDefsAdjusted}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColumnApi, GridApi, RowNode } from "ag-grid-community";
|
|
1
|
+
import { ColDef, ColumnApi, GridApi, RowNode } from "ag-grid-community";
|
|
2
2
|
import { CsvExportParams } from "ag-grid-community/dist/lib/interfaces/exportParams";
|
|
3
3
|
import { createContext, useContext } from "react";
|
|
4
4
|
|
|
@@ -16,6 +16,8 @@ export type AutoSizeColumnsResult = { width: number } | null;
|
|
|
16
16
|
|
|
17
17
|
export interface GridContextType<RowType extends GridBaseRow> {
|
|
18
18
|
gridReady: boolean;
|
|
19
|
+
getColDef: (colId?: string) => ColDef | undefined;
|
|
20
|
+
getColumns: () => ColDefT<RowType>[];
|
|
19
21
|
setApis: (gridApi: GridApi | undefined, columnApi: ColumnApi | undefined, dataTestId?: string) => void;
|
|
20
22
|
prePopupOps: () => void;
|
|
21
23
|
setQuickFilter: (quickFilter: string) => void;
|
|
@@ -52,7 +54,6 @@ export interface GridContextType<RowType extends GridBaseRow> {
|
|
|
52
54
|
removeExternalFilter: (filter: GridFilterExternal<RowType>) => void;
|
|
53
55
|
isExternalFilterPresent: () => boolean;
|
|
54
56
|
doesExternalFilterPass: (node: RowNode) => boolean;
|
|
55
|
-
getColumns: () => ColDefT<RowType>[];
|
|
56
57
|
invisibleColumnIds: string[];
|
|
57
58
|
setInvisibleColumnIds: (colIds: string[]) => void;
|
|
58
59
|
downloadCsv: (csvExportParams?: CsvExportParams) => void;
|
|
@@ -61,6 +62,10 @@ export interface GridContextType<RowType extends GridBaseRow> {
|
|
|
61
62
|
|
|
62
63
|
export const GridContext = createContext<GridContextType<any>>({
|
|
63
64
|
gridReady: false,
|
|
65
|
+
getColDef: () => {
|
|
66
|
+
console.error("no context provider for getColDef");
|
|
67
|
+
return undefined;
|
|
68
|
+
},
|
|
64
69
|
getColumns: () => {
|
|
65
70
|
console.error("no context provider for getColumns");
|
|
66
71
|
return [];
|
|
@@ -411,36 +411,29 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: GridCont
|
|
|
411
411
|
);
|
|
412
412
|
};
|
|
413
413
|
|
|
414
|
-
let foundEditableCell = false;
|
|
415
|
-
|
|
416
414
|
// Just in case I've missed something, we don't want the loop to hang everything
|
|
417
|
-
let maxIterations = 50;
|
|
418
|
-
|
|
419
|
-
let postRow: CellPosition | null = null;
|
|
420
|
-
do {
|
|
421
|
-
preRow = gridApi.getFocusedCell();
|
|
415
|
+
for (let maxIterations = 0; maxIterations < 50; maxIterations++) {
|
|
416
|
+
const preRow = gridApi.getFocusedCell();
|
|
422
417
|
tabDirection === 1 ? gridApi.tabToNextCell() : gridApi.tabToPreviousCell();
|
|
423
|
-
postRow = gridApi.getFocusedCell();
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
});
|
|
440
|
-
return false;
|
|
418
|
+
const postRow = gridApi.getFocusedCell();
|
|
419
|
+
if (preRow?.rowIndex !== postRow?.rowIndex || preRow?.column === postRow?.column) {
|
|
420
|
+
// We didn't find an editable cell in the same row, or the cell column didn't change
|
|
421
|
+
// implying it was start/end of grid
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
if (focusedCellIsEditable()) {
|
|
425
|
+
const focusedCell = gridApi?.getFocusedCell();
|
|
426
|
+
if (focusedCell) {
|
|
427
|
+
prePopupOps();
|
|
428
|
+
gridApi.startEditingCell({
|
|
429
|
+
rowIndex: focusedCell.rowIndex,
|
|
430
|
+
colKey: focusedCell.column.getColId(),
|
|
431
|
+
});
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
441
434
|
}
|
|
442
435
|
}
|
|
443
|
-
return
|
|
436
|
+
return false;
|
|
444
437
|
},
|
|
445
438
|
[gridApi, prePopupOps],
|
|
446
439
|
);
|
|
@@ -494,7 +487,7 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: GridCont
|
|
|
494
487
|
prePopupFocusedCell.current.rowIndex == postPopupFocusedCell.rowIndex &&
|
|
495
488
|
prePopupFocusedCell.current.column.getColId() == postPopupFocusedCell.column.getColId()
|
|
496
489
|
) {
|
|
497
|
-
if (!tabDirection || selectNextEditableCell(tabDirection)) {
|
|
490
|
+
if (!tabDirection || !selectNextEditableCell(tabDirection)) {
|
|
498
491
|
cellEditingCompleteCallbackRef.current && cellEditingCompleteCallbackRef.current();
|
|
499
492
|
}
|
|
500
493
|
}
|
|
@@ -551,6 +544,11 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: GridCont
|
|
|
551
544
|
return externalFilters.current.every((filter) => filter(node.data, node));
|
|
552
545
|
};
|
|
553
546
|
|
|
547
|
+
const getColDef = useCallback(
|
|
548
|
+
(colId?: string): ColDef | undefined => (!!colId && gridApi?.getColumnDef(colId)) || undefined,
|
|
549
|
+
[gridApi],
|
|
550
|
+
);
|
|
551
|
+
|
|
554
552
|
const getColumns: () => ColDefT<RowType>[] = useCallback(() => gridApi?.getColumnDefs() ?? [], [gridApi]);
|
|
555
553
|
|
|
556
554
|
useEffect(() => {
|
|
@@ -595,6 +593,7 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: GridCont
|
|
|
595
593
|
return (
|
|
596
594
|
<GridContext.Provider
|
|
597
595
|
value={{
|
|
596
|
+
getColDef,
|
|
598
597
|
getColumns,
|
|
599
598
|
invisibleColumnIds,
|
|
600
599
|
setInvisibleColumnIds,
|
|
@@ -2,13 +2,13 @@ import { createContext } from "react";
|
|
|
2
2
|
|
|
3
3
|
export type GridUpdatingContextType = {
|
|
4
4
|
checkUpdating: (fields: string | string[], id: number | string) => boolean;
|
|
5
|
-
isUpdating: () => boolean;
|
|
6
5
|
modifyUpdating: (
|
|
7
6
|
fields: string | string[],
|
|
8
7
|
ids: (number | string)[],
|
|
9
8
|
fn: () => void | Promise<void>,
|
|
10
9
|
) => Promise<void>;
|
|
11
10
|
updatedDep: number;
|
|
11
|
+
updatingCols: () => string[];
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export const GridUpdatingContext = createContext<GridUpdatingContextType>({
|
|
@@ -16,9 +16,9 @@ export const GridUpdatingContext = createContext<GridUpdatingContextType>({
|
|
|
16
16
|
console.error("Missing GridUpdatingContext");
|
|
17
17
|
return false;
|
|
18
18
|
},
|
|
19
|
-
|
|
19
|
+
updatingCols: () => {
|
|
20
20
|
console.error("Missing GridUpdatingContext");
|
|
21
|
-
return
|
|
21
|
+
return [];
|
|
22
22
|
},
|
|
23
23
|
modifyUpdating: async () => {
|
|
24
24
|
console.error("Missing GridUpdatingContext");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { castArray, flatten,
|
|
1
|
+
import { castArray, flatten, remove } from "lodash-es";
|
|
2
2
|
import { ReactNode, useRef, useState } from "react";
|
|
3
3
|
|
|
4
4
|
import { GridUpdatingContext } from "./GridUpdatingContext";
|
|
@@ -29,8 +29,7 @@ export const GridUpdatingContextProvider = (props: UpdatingContextProviderProps)
|
|
|
29
29
|
updating.current = mergedUpdatingBlocks;
|
|
30
30
|
setUpdatedDep((updatedDep) => updatedDep + 1);
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
const isUpdating = () => !isEmpty(updating.current);
|
|
32
|
+
const updatingCols = () => Object.keys(updating.current);
|
|
34
33
|
|
|
35
34
|
const modifyUpdating = async (
|
|
36
35
|
fields: string | string[],
|
|
@@ -55,7 +54,7 @@ export const GridUpdatingContextProvider = (props: UpdatingContextProviderProps)
|
|
|
55
54
|
castArray(fields).some((f) => updating.current[f]?.includes(id));
|
|
56
55
|
|
|
57
56
|
return (
|
|
58
|
-
<GridUpdatingContext.Provider value={{ modifyUpdating, checkUpdating,
|
|
57
|
+
<GridUpdatingContext.Provider value={{ modifyUpdating, checkUpdating, updatingCols, updatedDep }}>
|
|
59
58
|
{props.children}
|
|
60
59
|
</GridUpdatingContext.Provider>
|
|
61
60
|
);
|