@linzjs/step-ag-grid 14.9.3 → 14.9.4
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 +1 -1
- package/dist/step-ag-grid.esm.js +52 -24
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +29 -11
- package/src/components/gridFilter/GridFilterColumnsToggle.tsx +21 -10
- package/src/contexts/GridContext.tsx +2 -2
- package/src/contexts/GridContextProvider.tsx +14 -8
- package/src/stories/grid/GridReadOnly.stories.tsx +19 -7
|
@@ -53,7 +53,7 @@ export interface GridContextType<RowType extends GridBaseRow> {
|
|
|
53
53
|
removeExternalFilter: (filter: GridFilterExternal<RowType>) => void;
|
|
54
54
|
isExternalFilterPresent: () => boolean;
|
|
55
55
|
doesExternalFilterPass: (node: RowNode) => boolean;
|
|
56
|
-
invisibleColumnIds: string[];
|
|
56
|
+
invisibleColumnIds: string[] | undefined;
|
|
57
57
|
setInvisibleColumnIds: (colIds: string[]) => void;
|
|
58
58
|
downloadCsv: (csvExportParams?: CsvExportParams) => void;
|
|
59
59
|
setOnCellEditingComplete: (callback: (() => void) | undefined) => void;
|
package/dist/step-ag-grid.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { LuiMiniSpinner, LuiIcon, LuiButton, LuiCheckboxInput, LuiButtonGroup } from '@linzjs/lui';
|
|
3
3
|
import { AgGridReact } from 'ag-grid-react';
|
|
4
|
-
import { negate, isEmpty, xorBy, last, difference, defer as defer$1, omit, sortBy, findIndex, debounce as debounce$1, delay, partition, pick, groupBy, fromPairs, toPairs, isEqual, sumBy,
|
|
4
|
+
import { negate, isEmpty, xorBy, last, difference, defer as defer$1, omit, sortBy, findIndex, debounce as debounce$1, compact, delay, partition, pick, groupBy, fromPairs, toPairs, isEqual, sumBy, remove, castArray, flatten } from 'lodash-es';
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import { createContext, useContext, useRef, useEffect, useCallback, useState, useMemo, forwardRef, useLayoutEffect, memo, useReducer, cloneElement, useImperativeHandle, Fragment as Fragment$1 } from 'react';
|
|
7
7
|
import ReactDOM, { unstable_batchedUpdates, flushSync, createPortal } from 'react-dom';
|
|
@@ -42,7 +42,7 @@ const GridContext = createContext({
|
|
|
42
42
|
console.error("no context provider for getColumns");
|
|
43
43
|
return [];
|
|
44
44
|
},
|
|
45
|
-
invisibleColumnIds:
|
|
45
|
+
invisibleColumnIds: undefined,
|
|
46
46
|
setInvisibleColumnIds: () => {
|
|
47
47
|
console.error("no context provider for setInvisibleColumnIds");
|
|
48
48
|
},
|
|
@@ -518,11 +518,20 @@ const Grid = ({ "data-testid": dataTestId, rowSelection = "multiple", suppressCo
|
|
|
518
518
|
}
|
|
519
519
|
needsAutoSize.current = false;
|
|
520
520
|
}, [autoSizeColumns, params, sizeColumns, sizeColumnsToFit]);
|
|
521
|
+
const lastOwnerDocumentRef = useRef();
|
|
521
522
|
/**
|
|
522
523
|
* Auto-size windows that had deferred auto-size
|
|
523
524
|
*/
|
|
524
525
|
useIntervalHook({
|
|
525
526
|
callback: () => {
|
|
527
|
+
// Check if window has been popped out and needs resize
|
|
528
|
+
const currentDocument = gridDivRef.current?.ownerDocument;
|
|
529
|
+
if (currentDocument !== lastOwnerDocumentRef.current) {
|
|
530
|
+
lastOwnerDocumentRef.current = currentDocument;
|
|
531
|
+
if (currentDocument) {
|
|
532
|
+
needsAutoSize.current = true;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
526
535
|
if (needsAutoSize.current) {
|
|
527
536
|
needsAutoSize.current = false;
|
|
528
537
|
setInitialContentSize();
|
|
@@ -801,11 +810,19 @@ const Grid = ({ "data-testid": dataTestId, rowSelection = "multiple", suppressCo
|
|
|
801
810
|
* Once the grid has auto-sized we want to run fit to fit the grid in its container,
|
|
802
811
|
* but we don't want the non-flex auto-sized columns to "fit" size, so suppressSizeToFit is set to true.
|
|
803
812
|
*/
|
|
804
|
-
const columnDefsAdjusted = useMemo(() =>
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
813
|
+
const columnDefsAdjusted = useMemo(() => {
|
|
814
|
+
const adjustColDefOrGroup = (colDef) => "children" in colDef ? adjustGroupColDef(colDef) : adjustColDef(colDef);
|
|
815
|
+
const adjustGroupColDef = (colDef) => ({
|
|
816
|
+
...colDef,
|
|
817
|
+
children: colDef.children.map((colDef) => adjustColDefOrGroup(colDef)),
|
|
818
|
+
});
|
|
819
|
+
const adjustColDef = (colDef) => ({
|
|
820
|
+
...colDef,
|
|
821
|
+
suppressSizeToFit: (sizeColumns === "auto" || sizeColumns === "auto-skip-headers") && !colDef.flex,
|
|
822
|
+
sortable: colDef.sortable && params.defaultColDef?.sortable !== false,
|
|
823
|
+
});
|
|
824
|
+
return columnDefs.map((colDef) => adjustColDefOrGroup(colDef));
|
|
825
|
+
}, [columnDefs, params.defaultColDef?.sortable, sizeColumns]);
|
|
809
826
|
/**
|
|
810
827
|
* Set of colIds that need auto-sizing.
|
|
811
828
|
*/
|
|
@@ -2900,15 +2917,23 @@ const GridFilterColumnsToggle = ({ saveState = true }) => {
|
|
|
2900
2917
|
if (saveState) {
|
|
2901
2918
|
try {
|
|
2902
2919
|
const stored = window.localStorage.getItem(columnStorageKey);
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
console.error(`stored invisible ids not strings: ${stored}`);
|
|
2920
|
+
if (!stored) {
|
|
2921
|
+
// infer the invisible ids from colDefs
|
|
2922
|
+
setInvisibleColumnIds(compact(getColumns()
|
|
2923
|
+
.filter((col) => col.initialHide)
|
|
2924
|
+
.map((col) => col.colId)));
|
|
2909
2925
|
}
|
|
2910
2926
|
else {
|
|
2911
|
-
invisibleIds
|
|
2927
|
+
const invisibleIds = JSON.parse(stored ?? "[]");
|
|
2928
|
+
if (!Array.isArray(invisibleIds)) {
|
|
2929
|
+
console.error(`stored invisible ids not an array: ${stored}`);
|
|
2930
|
+
}
|
|
2931
|
+
else if (!invisibleIds.every((id) => typeof id === "string")) {
|
|
2932
|
+
console.error(`stored invisible ids not strings: ${stored}`);
|
|
2933
|
+
}
|
|
2934
|
+
else {
|
|
2935
|
+
invisibleIds && setInvisibleColumnIds(invisibleIds);
|
|
2936
|
+
}
|
|
2912
2937
|
}
|
|
2913
2938
|
}
|
|
2914
2939
|
catch (ex) {
|
|
@@ -2916,7 +2941,7 @@ const GridFilterColumnsToggle = ({ saveState = true }) => {
|
|
|
2916
2941
|
}
|
|
2917
2942
|
setLoaded(true);
|
|
2918
2943
|
}
|
|
2919
|
-
}, [columnStorageKey, loaded, saveState, setInvisibleColumnIds]);
|
|
2944
|
+
}, [columnStorageKey, getColumns, loaded, saveState, setInvisibleColumnIds]);
|
|
2920
2945
|
// Save state on column visibility change
|
|
2921
2946
|
useEffect(() => {
|
|
2922
2947
|
loaded &&
|
|
@@ -2925,7 +2950,7 @@ const GridFilterColumnsToggle = ({ saveState = true }) => {
|
|
|
2925
2950
|
window.localStorage.setItem(columnStorageKey, JSON.stringify(invisibleColumnIds));
|
|
2926
2951
|
}, [columnStorageKey, invisibleColumnIds, loaded, saveState]);
|
|
2927
2952
|
const toggleColumn = useCallback((colId) => {
|
|
2928
|
-
if (!colId)
|
|
2953
|
+
if (!colId || !invisibleColumnIds)
|
|
2929
2954
|
return;
|
|
2930
2955
|
setInvisibleColumnIds(invisibleColumnIds.includes(colId)
|
|
2931
2956
|
? invisibleColumnIds.filter((id) => id !== colId)
|
|
@@ -2948,7 +2973,7 @@ const GridFilterColumnsToggle = ({ saveState = true }) => {
|
|
|
2948
2973
|
toggleColumn(col.colId);
|
|
2949
2974
|
}
|
|
2950
2975
|
}
|
|
2951
|
-
}, children: jsx(LuiCheckboxInput, { isChecked: !invisibleColumnIds.includes(col.colId ?? ""), value: `${col.colId}`, label: col.headerName ?? "", isDisabled: isNonManageableColumn(col), inputProps: {
|
|
2976
|
+
}, children: jsx(LuiCheckboxInput, { isChecked: !!invisibleColumnIds && !invisibleColumnIds.includes(col.colId ?? ""), value: `${col.colId}`, label: col.headerName ?? "", isDisabled: isNonManageableColumn(col), inputProps: {
|
|
2952
2977
|
onClick: (e) => {
|
|
2953
2978
|
// Click is handled by MenuItem onClick so keyboard events work
|
|
2954
2979
|
e.preventDefault();
|
|
@@ -4430,7 +4455,7 @@ const GridContextProvider = (props) => {
|
|
|
4430
4455
|
const [columnApi, setColumnApi] = useState();
|
|
4431
4456
|
const [gridReady, setGridReady] = useState(false);
|
|
4432
4457
|
const [quickFilter, setQuickFilter] = useState("");
|
|
4433
|
-
const [invisibleColumnIds, setInvisibleColumnIds] = useState(
|
|
4458
|
+
const [invisibleColumnIds, setInvisibleColumnIds] = useState();
|
|
4434
4459
|
const testId = useRef();
|
|
4435
4460
|
const idsBeforeUpdate = useRef([]);
|
|
4436
4461
|
const prePopupFocusedCell = useRef();
|
|
@@ -4550,6 +4575,10 @@ const GridContextProvider = (props) => {
|
|
|
4550
4575
|
.map((rowId) => gridApi.getRowNode("" + rowId)) //
|
|
4551
4576
|
.filter((r) => r), () => []);
|
|
4552
4577
|
}, [gridApiOp]);
|
|
4578
|
+
/**
|
|
4579
|
+
* Get ColDefs, with flattened ColGroupDefs
|
|
4580
|
+
*/
|
|
4581
|
+
const getColumns = useCallback(() => columnApi?.getAllColumns()?.map((col) => col.getColDef()) ?? [], [columnApi]);
|
|
4553
4582
|
/**
|
|
4554
4583
|
* Internal method for selecting and flashing rows.
|
|
4555
4584
|
*
|
|
@@ -4573,9 +4602,9 @@ const GridContextProvider = (props) => {
|
|
|
4573
4602
|
const firstNode = rowsThatNeedSelecting[0];
|
|
4574
4603
|
if (firstNode) {
|
|
4575
4604
|
defer$1(() => gridApi.ensureNodeVisible(firstNode));
|
|
4576
|
-
const colDefs =
|
|
4577
|
-
if (colDefs
|
|
4578
|
-
const col = colDefs[0];
|
|
4605
|
+
const colDefs = getColumns();
|
|
4606
|
+
if (!isEmpty(colDefs)) {
|
|
4607
|
+
const col = colDefs[0];
|
|
4579
4608
|
const rowIndex = firstNode.rowIndex;
|
|
4580
4609
|
if (rowIndex != null && col != null) {
|
|
4581
4610
|
const colId = col.colId;
|
|
@@ -4606,7 +4635,7 @@ const GridContextProvider = (props) => {
|
|
|
4606
4635
|
}, 250);
|
|
4607
4636
|
}
|
|
4608
4637
|
});
|
|
4609
|
-
}, [_getNewNodes, _rowIdsToNodes, gridApiOp]);
|
|
4638
|
+
}, [_getNewNodes, _rowIdsToNodes, getColumns, gridApiOp]);
|
|
4610
4639
|
const selectRowsById = useCallback((rowIds) => _selectRowsWithOptionalFlash(rowIds, true, false), [_selectRowsWithOptionalFlash]);
|
|
4611
4640
|
const selectRowsByIdWithFlash = useCallback((rowIds) => _selectRowsWithOptionalFlash(rowIds, true, true), [_selectRowsWithOptionalFlash]);
|
|
4612
4641
|
const flashRows = useCallback((rowIds) => _selectRowsWithOptionalFlash(rowIds, false, true), [_selectRowsWithOptionalFlash]);
|
|
@@ -4839,9 +4868,8 @@ const GridContextProvider = (props) => {
|
|
|
4839
4868
|
return externalFilters.current.every((filter) => filter(node.data, node));
|
|
4840
4869
|
};
|
|
4841
4870
|
const getColDef = useCallback((colId) => (!!colId && gridApi?.getColumnDef(colId)) || undefined, [gridApi]);
|
|
4842
|
-
const getColumns = useCallback(() => gridApi?.getColumnDefs() ?? [], [gridApi]);
|
|
4843
4871
|
useEffect(() => {
|
|
4844
|
-
if (columnApi) {
|
|
4872
|
+
if (columnApi && invisibleColumnIds) {
|
|
4845
4873
|
// show all columns that aren't invisible
|
|
4846
4874
|
columnApi.setColumnsVisible(compact(getColumns()
|
|
4847
4875
|
.filter((col) => !col.lockVisible && col.colId && !invisibleColumnIds.includes(col.colId))
|