@linzjs/step-ag-grid 17.8.0 → 17.10.0
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/components/Grid.d.ts +1 -0
- package/dist/src/components/gridForm/GridFormPopoverMenu.d.ts +1 -0
- package/dist/src/contexts/GridContext.d.ts +1 -0
- package/dist/step-ag-grid.cjs.js +21 -5
- package/dist/step-ag-grid.cjs.js.map +1 -1
- package/dist/step-ag-grid.esm.js +21 -5
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +22 -3
- package/src/components/gridForm/GridFormPopoverMenu.tsx +21 -9
- package/src/contexts/GridContext.tsx +4 -0
- package/src/contexts/GridContextProvider.tsx +5 -0
- package/src/stories/grid/GridReadOnly.stories.tsx +24 -0
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -101,6 +101,8 @@ export interface GridProps {
|
|
|
101
101
|
* Defaults to false.
|
|
102
102
|
*/
|
|
103
103
|
singleClickEdit?: boolean;
|
|
104
|
+
|
|
105
|
+
loading?: boolean;
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
/**
|
|
@@ -136,9 +138,11 @@ export const Grid = ({
|
|
|
136
138
|
doesExternalFilterPass,
|
|
137
139
|
setOnCellEditingComplete,
|
|
138
140
|
getColDef,
|
|
141
|
+
showNoRowsOverlay,
|
|
142
|
+
prePopupOps,
|
|
143
|
+
stopEditing,
|
|
139
144
|
} = useContext(GridContext);
|
|
140
145
|
const { checkUpdating, updatedDep, updatingCols } = useContext(GridUpdatingContext);
|
|
141
|
-
const { prePopupOps } = useContext(GridContext);
|
|
142
146
|
|
|
143
147
|
const gridDivRef = useRef<HTMLDivElement>(null);
|
|
144
148
|
const lastSelectedIds = useRef<number[]>([]);
|
|
@@ -323,7 +327,11 @@ export const Grid = ({
|
|
|
323
327
|
const columnDefs = useMemo((): (ColDef | ColGroupDef)[] => {
|
|
324
328
|
const adjustColDefs = params.columnDefs.map((colDef) => {
|
|
325
329
|
const colDefEditable = colDef.editable;
|
|
326
|
-
const editable = combineEditables(
|
|
330
|
+
const editable = combineEditables(
|
|
331
|
+
params.loading !== true && params.readOnly !== true,
|
|
332
|
+
params.defaultColDef?.editable,
|
|
333
|
+
colDefEditable,
|
|
334
|
+
);
|
|
327
335
|
return {
|
|
328
336
|
...colDef,
|
|
329
337
|
editable,
|
|
@@ -369,6 +377,7 @@ export const Grid = ({
|
|
|
369
377
|
params.columnDefs,
|
|
370
378
|
params.selectable,
|
|
371
379
|
params.onRowDragEnd,
|
|
380
|
+
params.loading,
|
|
372
381
|
params.readOnly,
|
|
373
382
|
params.defaultColDef?.editable,
|
|
374
383
|
selectColumnPinned,
|
|
@@ -566,6 +575,16 @@ export const Grid = ({
|
|
|
566
575
|
}
|
|
567
576
|
}, [autoSizeColumns, getColDef, sizeColumns, updatedDep, updatingCols]);
|
|
568
577
|
|
|
578
|
+
const prevLoading = useRef(false);
|
|
579
|
+
useEffect(() => {
|
|
580
|
+
const newLoading = !rowData || params.loading === true;
|
|
581
|
+
if (newLoading && !prevLoading.current) {
|
|
582
|
+
stopEditing();
|
|
583
|
+
showNoRowsOverlay();
|
|
584
|
+
}
|
|
585
|
+
prevLoading.current = newLoading;
|
|
586
|
+
}, [params.loading, rowData, showNoRowsOverlay, stopEditing]);
|
|
587
|
+
|
|
569
588
|
/**
|
|
570
589
|
* Resize columns to fit if required on window/container resize
|
|
571
590
|
*/
|
|
@@ -691,7 +710,7 @@ export const Grid = ({
|
|
|
691
710
|
event.api.forEachNode(() => rowCount++);
|
|
692
711
|
return (
|
|
693
712
|
<GridNoRowsOverlay
|
|
694
|
-
loading={!rowData}
|
|
713
|
+
loading={!rowData || params.loading === true}
|
|
695
714
|
rowCount={rowCount}
|
|
696
715
|
headerRowHeight={headerRowCount * rowHeight}
|
|
697
716
|
filteredRowCount={event.api.getDisplayedRowCount()}
|
|
@@ -3,7 +3,7 @@ import { Fragment, ReactElement, useCallback, useEffect, useRef, useState } from
|
|
|
3
3
|
|
|
4
4
|
import { useGridPopoverContext } from "../../contexts/GridPopoverContext";
|
|
5
5
|
import { GridSubComponentContext } from "../../contexts/GridSubComponentContext";
|
|
6
|
-
import { FocusableItem, MenuDivider, MenuItem } from "../../react-menu3";
|
|
6
|
+
import { FocusableItem, MenuDivider, MenuItem, SubMenu } from "../../react-menu3";
|
|
7
7
|
import { ClickEvent } from "../../react-menu3/types";
|
|
8
8
|
import { ComponentLoadingWrapper } from "../ComponentLoadingWrapper";
|
|
9
9
|
import { GridBaseRow } from "../Grid";
|
|
@@ -29,6 +29,7 @@ export interface SelectedMenuOptionResult<RowType extends GridBaseRow> extends M
|
|
|
29
29
|
|
|
30
30
|
export interface MenuOption<RowType extends GridBaseRow> {
|
|
31
31
|
label: ReactElement | string | MenuSeparatorType;
|
|
32
|
+
subMenu?: () => ReactElement;
|
|
32
33
|
action?: (props: { selectedRows: RowType[]; menuOption: SelectedMenuOptionResult<RowType> }) => Promise<void>;
|
|
33
34
|
disabled?: string | boolean;
|
|
34
35
|
hidden?: boolean;
|
|
@@ -135,14 +136,25 @@ export const GridFormPopoverMenu = <RowType extends GridBaseRow>(props: GridForm
|
|
|
135
136
|
) : (
|
|
136
137
|
!item.hidden && (
|
|
137
138
|
<Fragment key={`${item.label}`}>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
139
|
+
{item.subMenu ? (
|
|
140
|
+
<SubMenu
|
|
141
|
+
key={`${item.label}`}
|
|
142
|
+
disabled={!!item.disabled}
|
|
143
|
+
label={item.label as string}
|
|
144
|
+
title={item.disabled && typeof item.disabled !== "boolean" ? item.disabled : ""}
|
|
145
|
+
>
|
|
146
|
+
<item.subMenu />
|
|
147
|
+
</SubMenu>
|
|
148
|
+
) : (
|
|
149
|
+
<MenuItem
|
|
150
|
+
key={`${item.label}`}
|
|
151
|
+
onClick={(e: ClickEvent) => onMenuItemClick(e, item)}
|
|
152
|
+
disabled={!!item.disabled}
|
|
153
|
+
title={item.disabled && typeof item.disabled !== "boolean" ? item.disabled : ""}
|
|
154
|
+
>
|
|
155
|
+
{item.label as ReactElement | string}
|
|
156
|
+
</MenuItem>
|
|
157
|
+
)}
|
|
146
158
|
{item.subComponent && subComponentSelected === item && (
|
|
147
159
|
<FocusableItem className={"LuiDeprecatedForms"} key={`${item.label}_subcomponent`}>
|
|
148
160
|
{() => (
|
|
@@ -65,6 +65,7 @@ export interface GridContextType<RowType extends GridBaseRow> {
|
|
|
65
65
|
setInvisibleColumnIds: (colIds: string[]) => void;
|
|
66
66
|
downloadCsv: (csvExportParams?: CsvExportParams) => void;
|
|
67
67
|
setOnCellEditingComplete: (callback: (() => void) | undefined) => void;
|
|
68
|
+
showNoRowsOverlay: () => void;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
export const GridContext = createContext<GridContextType<any>>({
|
|
@@ -201,6 +202,9 @@ export const GridContext = createContext<GridContextType<any>>({
|
|
|
201
202
|
setOnCellEditingComplete: () => {
|
|
202
203
|
console.error("no context provider for setOnCellEditingComplete");
|
|
203
204
|
},
|
|
205
|
+
showNoRowsOverlay: () => {
|
|
206
|
+
console.error("no context provider for showLoadingOverlay");
|
|
207
|
+
},
|
|
204
208
|
});
|
|
205
209
|
|
|
206
210
|
export const useGridContext = <RowType extends GridBaseRow>() => useContext<GridContextType<RowType>>(GridContext);
|
|
@@ -659,6 +659,10 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: PropsWit
|
|
|
659
659
|
[gridApi],
|
|
660
660
|
);
|
|
661
661
|
|
|
662
|
+
const showNoRowsOverlay = useCallback((): void => {
|
|
663
|
+
gridApi?.showNoRowsOverlay();
|
|
664
|
+
}, [gridApi]);
|
|
665
|
+
|
|
662
666
|
/**
|
|
663
667
|
* Apply column visibility
|
|
664
668
|
*/
|
|
@@ -755,6 +759,7 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: PropsWit
|
|
|
755
759
|
doesExternalFilterPass,
|
|
756
760
|
downloadCsv,
|
|
757
761
|
setOnCellEditingComplete,
|
|
762
|
+
showNoRowsOverlay,
|
|
758
763
|
}}
|
|
759
764
|
>
|
|
760
765
|
{props.children}
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
GridProps,
|
|
24
24
|
GridUpdatingContextProvider,
|
|
25
25
|
GridWrapper,
|
|
26
|
+
MenuItem,
|
|
26
27
|
useGridFilter,
|
|
27
28
|
wait,
|
|
28
29
|
} from "../..";
|
|
@@ -171,6 +172,10 @@ const GridReadOnlyTemplate: StoryFn<typeof Grid> = (props: GridProps) => {
|
|
|
171
172
|
await wait(1500);
|
|
172
173
|
},
|
|
173
174
|
},
|
|
175
|
+
{
|
|
176
|
+
label: "Sub menu...",
|
|
177
|
+
subMenu: () => <MenuItem>Find...</MenuItem>,
|
|
178
|
+
},
|
|
174
179
|
{
|
|
175
180
|
label: "Disabled item",
|
|
176
181
|
disabled: "Disabled for test",
|
|
@@ -215,6 +220,25 @@ const GridReadOnlyTemplate: StoryFn<typeof Grid> = (props: GridProps) => {
|
|
|
215
220
|
{ id: 1001, position: "Developer", age: 12, height: `5'3"`, desc: "Develops application", dd: "2" },
|
|
216
221
|
{ id: 1002, position: "Manager", age: 65, height: `5'9"`, desc: "Manages", dd: "3" },
|
|
217
222
|
]);
|
|
223
|
+
/*
|
|
224
|
+
Testing
|
|
225
|
+
const [loading, setLoading] = useState(false);
|
|
226
|
+
|
|
227
|
+
useTimeout(() => {
|
|
228
|
+
setRowData([
|
|
229
|
+
{ id: 1000, position: "Tester", age: 30, height: `6'4"`, desc: "Tests application", dd: "1" },
|
|
230
|
+
{ id: 1001, position: "Developer", age: 12, height: `5'3"`, desc: "Develops application", dd: "2" },
|
|
231
|
+
{ id: 1002, position: "Manager", age: 65, height: `5'9"`, desc: "Manages", dd: "3" },
|
|
232
|
+
]);
|
|
233
|
+
}, 5000);
|
|
234
|
+
|
|
235
|
+
useTimeout(() => {
|
|
236
|
+
setLoading(true);
|
|
237
|
+
}, 7000);
|
|
238
|
+
|
|
239
|
+
useTimeout(() => {
|
|
240
|
+
setLoading(false);
|
|
241
|
+
}, 9000);*/
|
|
218
242
|
|
|
219
243
|
return (
|
|
220
244
|
<GridWrapper maxHeight={400}>
|