@linzjs/step-ag-grid 1.4.0 → 1.4.2
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/index.d.ts +1 -0
- package/dist/index.js +19 -5
- package/dist/index.js.map +1 -1
- package/dist/src/components/Grid.d.ts +3 -2
- package/dist/src/components/gridForm/GridFormPopoutMenu.d.ts +1 -1
- package/dist/step-ag-grid.esm.js +19 -6
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +20 -12
- package/src/components/GridPopoverHook.tsx +2 -1
- package/src/components/gridForm/GridFormPopoutMenu.tsx +2 -2
- package/src/stories/components/GridReadOnly.stories.tsx +3 -3
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -24,8 +24,9 @@ export interface GridProps {
|
|
|
24
24
|
quickFilter?: boolean;
|
|
25
25
|
quickFilterPlaceholder?: string;
|
|
26
26
|
quickFilterValue?: string;
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
domLayout?: GridOptions["domLayout"];
|
|
28
|
+
externalSelectedItems?: any[];
|
|
29
|
+
setExternalSelectedItems?: (items: any[]) => void;
|
|
29
30
|
onGridReady?: GridOptions["onGridReady"];
|
|
30
31
|
defaultColDef: GridOptions["defaultColDef"];
|
|
31
32
|
columnDefs: GridOptions["columnDefs"];
|
|
@@ -59,16 +60,21 @@ export const Grid = (params: GridProps): JSX.Element => {
|
|
|
59
60
|
/**
|
|
60
61
|
* Ensure external selected items list is in sync with panel.
|
|
61
62
|
*/
|
|
62
|
-
const synchroniseExternalStateToGridSelection = (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
const synchroniseExternalStateToGridSelection = useCallback(
|
|
64
|
+
({ api }: SelectionChangedEvent) => {
|
|
65
|
+
if (!params.externalSelectedItems || !params.setExternalSelectedItems) return;
|
|
66
|
+
|
|
67
|
+
const selectedRows = api.getSelectedRows();
|
|
68
|
+
// We don't want to update selected Items if it hasn't changed to prevent excess renders
|
|
69
|
+
if (
|
|
70
|
+
params.externalSelectedItems.length != selectedRows.length ||
|
|
71
|
+
isNotEmpty(xorBy(selectedRows, params.externalSelectedItems, (row) => row.id))
|
|
72
|
+
) {
|
|
73
|
+
params.setExternalSelectedItems([...selectedRows]);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
[params],
|
|
77
|
+
);
|
|
72
78
|
|
|
73
79
|
/**
|
|
74
80
|
* Synchronise externally selected items to grid.
|
|
@@ -76,6 +82,7 @@ export const Grid = (params: GridProps): JSX.Element => {
|
|
|
76
82
|
*/
|
|
77
83
|
const synchroniseExternallySelectedItemsToGrid = useCallback(() => {
|
|
78
84
|
if (!gridReady()) return;
|
|
85
|
+
if (!params.externalSelectedItems) return;
|
|
79
86
|
|
|
80
87
|
const selectedIds = params.externalSelectedItems.map((row) => row.id) as number[];
|
|
81
88
|
const lastNewId = last(difference(selectedIds, lastSelectedIds.current));
|
|
@@ -253,6 +260,7 @@ export const Grid = (params: GridProps): JSX.Element => {
|
|
|
253
260
|
onCellDoubleClicked={onCellDoubleClick}
|
|
254
261
|
onCellEditingStarted={refreshSelectedRows}
|
|
255
262
|
onCellEditingStopped={onCellEditingStopped}
|
|
263
|
+
domLayout={params.domLayout}
|
|
256
264
|
columnDefs={columnDefs}
|
|
257
265
|
rowData={params.rowData}
|
|
258
266
|
noRowsOverlayComponent={noRowsOverlayComponent}
|
|
@@ -5,6 +5,7 @@ import { ControlledMenu } from "@szhsin/react-menu";
|
|
|
5
5
|
import { GridFormProps } from "./GridCell";
|
|
6
6
|
import { hasParentClass } from "@utils/util";
|
|
7
7
|
import { GridBaseRow } from "./Grid";
|
|
8
|
+
import { isEmpty } from "lodash-es";
|
|
8
9
|
|
|
9
10
|
export const useGridPopoverHook = <RowType extends GridBaseRow>(
|
|
10
11
|
props: GridFormProps<RowType>,
|
|
@@ -84,7 +85,7 @@ export const useGridPopoverHook = <RowType extends GridBaseRow>(
|
|
|
84
85
|
{anchorRef.current && (
|
|
85
86
|
<ControlledMenu
|
|
86
87
|
state={isOpen ? "open" : "closed"}
|
|
87
|
-
portal={
|
|
88
|
+
portal={isEmpty(document.querySelectorAll(".PopoutWindowContainer"))}
|
|
88
89
|
unmountOnClose={true}
|
|
89
90
|
anchorRef={anchorRef}
|
|
90
91
|
menuClassName={"lui-menu"}
|
|
@@ -21,7 +21,7 @@ export interface MenuOption<RowType> {
|
|
|
21
21
|
label: JSX.Element | string | MenuSeparatorType;
|
|
22
22
|
action?: (selectedRows: RowType[]) => Promise<boolean>;
|
|
23
23
|
disabled?: string | boolean;
|
|
24
|
-
|
|
24
|
+
supportsMultiEdit: boolean;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -65,7 +65,7 @@ export const GridFormPopoutMenu = <RowType extends GridBaseRow>(props: GridFormP
|
|
|
65
65
|
const selectedRowCount = props.selectedRows.length;
|
|
66
66
|
|
|
67
67
|
const filteredOptions = options?.filter((menuOption) => {
|
|
68
|
-
return menuOption.label === MenuSeparator || selectedRowCount === 1 || menuOption.
|
|
68
|
+
return menuOption.label === MenuSeparator || selectedRowCount === 1 || menuOption.supportsMultiEdit;
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
const { popoverWrapper } = useGridPopoverHook(props);
|
|
@@ -98,7 +98,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
98
98
|
await wait(1500);
|
|
99
99
|
return true;
|
|
100
100
|
},
|
|
101
|
-
|
|
101
|
+
supportsMultiEdit: false,
|
|
102
102
|
},
|
|
103
103
|
{
|
|
104
104
|
label: "Multi-edit",
|
|
@@ -107,12 +107,12 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
107
107
|
await wait(1500);
|
|
108
108
|
return true;
|
|
109
109
|
},
|
|
110
|
-
|
|
110
|
+
supportsMultiEdit: true,
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
113
|
label: "Disabled item",
|
|
114
114
|
disabled: "Disabled for test",
|
|
115
|
-
|
|
115
|
+
supportsMultiEdit: true,
|
|
116
116
|
},
|
|
117
117
|
];
|
|
118
118
|
},
|