@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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@linzjs/step-ag-grid",
3
3
  "repository": "github:linz/step-ag-grid.git",
4
4
  "license": "MIT",
5
- "version": "1.5.1",
5
+ "version": "1.5.2",
6
6
  "main": "dist/index.js",
7
7
  "typings": "dist/index.d.ts",
8
8
  "module": "dist/step-ag-grid.esm.js",
@@ -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
- selectedValues.forEach((value) => {
52
- values[value] = subSelectedValues.current[value] ?? true;
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: selectedValues });
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
- GridCell({
52
- field: "id",
53
- headerName: "Id",
54
- initialWidth: 65,
55
- maxWidth: 85,
56
- }),
57
- GridPopoutEditMultiSelect<ITestRow, ITestRow["position"]>({
58
- field: "position",
59
- initialWidth: 65,
60
- maxWidth: 150,
61
- headerName: "Position",
62
- cellEditorParams: {
63
- multiEdit: false,
64
- filtered: true,
65
- filterPlaceholder: "Filter position",
66
- options: [
67
- { value: "a", label: "Architect" },
68
- { value: "b", label: "Developer" },
69
- { value: "c", label: "Product Owner" },
70
- { value: "d", label: "Scrum Master" },
71
- { value: "e", label: "Tester" },
72
- MenuSeparator,
73
- {
74
- value: "f",
75
- label: "Other",
76
- subComponent: (props) => <GridSubComponentTextArea {...props} />,
77
- },
78
- ],
79
- onSave: async (result: MultiSelectResult<ITestRow>) => {
80
- // eslint-disable-next-line no-console
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
- ] as ColDef[],
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
  () =>