@linzjs/step-ag-grid 14.3.2 → 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 +41 -37
- 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 +6 -0
- 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 [];
|
|
@@ -544,6 +544,11 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: GridCont
|
|
|
544
544
|
return externalFilters.current.every((filter) => filter(node.data, node));
|
|
545
545
|
};
|
|
546
546
|
|
|
547
|
+
const getColDef = useCallback(
|
|
548
|
+
(colId?: string): ColDef | undefined => (!!colId && gridApi?.getColumnDef(colId)) || undefined,
|
|
549
|
+
[gridApi],
|
|
550
|
+
);
|
|
551
|
+
|
|
547
552
|
const getColumns: () => ColDefT<RowType>[] = useCallback(() => gridApi?.getColumnDefs() ?? [], [gridApi]);
|
|
548
553
|
|
|
549
554
|
useEffect(() => {
|
|
@@ -588,6 +593,7 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: GridCont
|
|
|
588
593
|
return (
|
|
589
594
|
<GridContext.Provider
|
|
590
595
|
value={{
|
|
596
|
+
getColDef,
|
|
591
597
|
getColumns,
|
|
592
598
|
invisibleColumnIds,
|
|
593
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
|
);
|