@linzjs/step-ag-grid 1.5.1 → 1.5.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.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist/src/components/gridForm/GridFormMultiSelect.d.ts +1 -0
- package/dist/step-ag-grid.esm.js +6 -8
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/gridForm/GridFormMultiSelect.tsx +9 -7
- package/src/stories/components/GridPopoutEditMultiSelect.stories.tsx +63 -40
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import { MenuItem, MenuDivider, FocusableItem, ClickEvent } from "@react-menu3";
|
|
|
4
4
|
import { Fragment, useCallback, useEffect, useRef, useState, KeyboardEvent } from "react";
|
|
5
5
|
import { GridBaseRow } from "../Grid";
|
|
6
6
|
import { ComponentLoadingWrapper } from "../ComponentLoadingWrapper";
|
|
7
|
-
import { delay } from "lodash-es";
|
|
7
|
+
import { delay, fromPairs } from "lodash-es";
|
|
8
8
|
import { LuiCheckboxInput } from "@linzjs/lui";
|
|
9
9
|
import { GenericCellEditorParams, GridFormProps } from "../GridCell";
|
|
10
10
|
import { useGridPopoverHook } from "../GridPopoverHook";
|
|
@@ -33,6 +33,7 @@ export interface GridFormMultiSelectProps<RowType extends GridBaseRow, ValueType
|
|
|
33
33
|
options:
|
|
34
34
|
| SelectOption<ValueType>[]
|
|
35
35
|
| ((selectedRows: RowType[]) => Promise<SelectOption<ValueType>[]> | SelectOption<ValueType>[]);
|
|
36
|
+
initialSelectedValues?: (selectedRows: RowType[]) => any[];
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(props: GridFormProps<RowType>) => {
|
|
@@ -43,16 +44,17 @@ export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(prop
|
|
|
43
44
|
const optionsInitialising = useRef(false);
|
|
44
45
|
const [options, setOptions] = useState<FinalSelectOption<ValueType>[]>();
|
|
45
46
|
const subSelectedValues = useRef<Record<string, any>>({});
|
|
46
|
-
const [selectedValues, setSelectedValues] = useState<any[]>(
|
|
47
|
+
const [selectedValues, setSelectedValues] = useState<any[]>(() =>
|
|
48
|
+
formProps.initialSelectedValues ? formProps.initialSelectedValues(props.selectedRows) : [],
|
|
49
|
+
);
|
|
47
50
|
|
|
48
51
|
const save = useCallback(
|
|
49
52
|
async (selectedRows: RowType[]): Promise<boolean> => {
|
|
50
|
-
const values: Record<string, any> =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
53
|
+
const values: Record<string, any> = fromPairs(
|
|
54
|
+
selectedValues.map((value) => [value, subSelectedValues.current[value] ?? true]),
|
|
55
|
+
);
|
|
54
56
|
if (formProps.onSave) {
|
|
55
|
-
return await formProps.onSave({ selectedRows, values
|
|
57
|
+
return await formProps.onSave({ selectedRows, values });
|
|
56
58
|
}
|
|
57
59
|
return true;
|
|
58
60
|
},
|
|
@@ -45,48 +45,71 @@ interface ITestRow {
|
|
|
45
45
|
const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridProps) => {
|
|
46
46
|
const [externalSelectedItems, setExternalSelectedItems] = useState<any[]>([]);
|
|
47
47
|
|
|
48
|
-
const columnDefs = useMemo(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
console.log(result);
|
|
82
|
-
await wait(1000);
|
|
83
|
-
return true;
|
|
48
|
+
const columnDefs = useMemo(() => {
|
|
49
|
+
const positionTwoMap: Record<string, string> = {
|
|
50
|
+
"1": "One",
|
|
51
|
+
"2": "Two",
|
|
52
|
+
"3": "Three",
|
|
53
|
+
};
|
|
54
|
+
return [
|
|
55
|
+
GridCell({
|
|
56
|
+
field: "id",
|
|
57
|
+
headerName: "Id",
|
|
58
|
+
initialWidth: 65,
|
|
59
|
+
maxWidth: 85,
|
|
60
|
+
}),
|
|
61
|
+
GridPopoutEditMultiSelect<ITestRow, ITestRow["position"]>({
|
|
62
|
+
field: "position",
|
|
63
|
+
initialWidth: 65,
|
|
64
|
+
maxWidth: 150,
|
|
65
|
+
headerName: "Position",
|
|
66
|
+
cellEditorParams: {
|
|
67
|
+
multiEdit: false,
|
|
68
|
+
filtered: true,
|
|
69
|
+
filterPlaceholder: "Filter position",
|
|
70
|
+
options: [
|
|
71
|
+
{ value: "a", label: "Architect" },
|
|
72
|
+
{ value: "b", label: "Developer" },
|
|
73
|
+
{ value: "c", label: "Product Owner" },
|
|
74
|
+
{ value: "d", label: "Scrum Master" },
|
|
75
|
+
{ value: "e", label: "Tester" },
|
|
76
|
+
MenuSeparator,
|
|
77
|
+
{
|
|
78
|
+
value: "f",
|
|
79
|
+
label: "Other",
|
|
80
|
+
subComponent: (props) => <GridSubComponentTextArea {...props} />,
|
|
84
81
|
},
|
|
82
|
+
],
|
|
83
|
+
onSave: async (result: MultiSelectResult<ITestRow>) => {
|
|
84
|
+
// eslint-disable-next-line no-console
|
|
85
|
+
console.log(result);
|
|
86
|
+
await wait(1000);
|
|
87
|
+
return true;
|
|
85
88
|
},
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
GridPopoutEditMultiSelect<ITestRow, ITestRow["position2"]>({
|
|
92
|
+
field: "position2",
|
|
93
|
+
initialWidth: 65,
|
|
94
|
+
maxWidth: 150,
|
|
95
|
+
headerName: "Inital editor values ",
|
|
96
|
+
valueGetter: (props) => positionTwoMap[props.data.position2],
|
|
97
|
+
cellEditorParams: {
|
|
98
|
+
multiEdit: false,
|
|
99
|
+
filtered: true,
|
|
100
|
+
filterPlaceholder: "Filter position",
|
|
101
|
+
initialSelectedValues: (selectedRows) => [selectedRows[0].position2],
|
|
102
|
+
options: Object.entries(positionTwoMap).map(([k, v]) => ({ value: k, label: v })),
|
|
103
|
+
onSave: async (result: MultiSelectResult<ITestRow>) => {
|
|
104
|
+
// eslint-disable-next-line no-console
|
|
105
|
+
console.log(result);
|
|
106
|
+
await wait(1000);
|
|
107
|
+
return true;
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
111
|
+
] as ColDef[];
|
|
112
|
+
}, []);
|
|
90
113
|
|
|
91
114
|
const rowData = useMemo(
|
|
92
115
|
() =>
|