@linzjs/step-ag-grid 2.2.1 → 2.3.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/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": "2.2.1",
5
+ "version": "2.3.0",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -3,6 +3,7 @@ import { GridContext } from "../contexts/GridContext";
3
3
  import { GridBaseRow } from "./Grid";
4
4
  import { ControlledMenu } from "../react-menu3";
5
5
  import { GridPopoverContext } from "../contexts/GridPopoverContext";
6
+ import { MenuCloseEvent } from "../react-menu3/types";
6
7
 
7
8
  export interface GridPopoverHookProps<RowType> {
8
9
  className: string | undefined;
@@ -45,7 +46,10 @@ export const useGridPopoverHook = <RowType extends GridBaseRow>(props: GridPopov
45
46
  anchorRef={anchorRef}
46
47
  saveButtonRef={saveButtonRef}
47
48
  menuClassName={"step-ag-grid-react-menu"}
48
- onClose={(event: { reason: string }) => triggerSave(event.reason).then()}
49
+ onClose={(event: MenuCloseEvent) => {
50
+ if (event.reason === "blur") return;
51
+ triggerSave(event.reason).then();
52
+ }}
49
53
  viewScroll={"auto"}
50
54
  dontShrinkIfDirectionIsTop={true}
51
55
  className={props.className}
@@ -1,25 +1,55 @@
1
- import { useEffect, useState } from "react";
1
+ import { useCallback, useEffect } from "react";
2
+ import { GridSubComponentProps } from "./gridForm/GridSubComponentProps";
3
+ import { TextInputFormatted } from "../lui/TextInputFormatted";
2
4
 
3
- export interface GridSubComponentTextAreaProps {
4
- setValue: (value: string) => void;
5
+ export interface GridSubComponentTextAreaProps extends GridSubComponentProps {
6
+ placeholder?: string;
7
+ required?: boolean;
8
+ maxlength?: number;
9
+ width?: string | number;
10
+ validate: (value: string) => string | null;
5
11
  }
6
12
 
7
- export const GridSubComponentTextArea = (props: GridSubComponentTextAreaProps) => {
8
- const [value, setValue] = useState("");
13
+ export const GridSubComponentTextArea = (props: GridSubComponentTextAreaProps): JSX.Element => {
14
+ const { value, setValue, setValid, triggerSave } = props;
15
+ const validate = useCallback(
16
+ (value: string) => {
17
+ if (props.required && value.length === 0) {
18
+ return `Some text is required`;
19
+ }
20
+ if (props.maxlength && value.length > props.maxlength) {
21
+ return `Text must be no longer than ${props.maxlength} characters`;
22
+ }
23
+ if (props.validate) {
24
+ return props.validate(value);
25
+ }
26
+ return null;
27
+ },
28
+ [props],
29
+ );
9
30
 
10
31
  useEffect(() => {
11
- props.setValue(value);
12
- }, [props, value]);
32
+ setValid(validate(value) == null);
33
+ }, [setValid, validate, value]);
13
34
 
14
35
  return (
15
36
  <div className={"FreeTextInput LuiDeprecatedForms"}>
16
- <textarea
17
- autoFocus
18
- maxLength={10000}
19
- spellCheck={true}
37
+ <TextInputFormatted
20
38
  className={"free-text-input"}
39
+ value={value}
40
+ onMouseEnter={(e) => {
41
+ if (document.activeElement != e.currentTarget) {
42
+ e.currentTarget.focus();
43
+ e.currentTarget.selectionStart = e.currentTarget.value.length;
44
+ }
45
+ }}
21
46
  onChange={(e) => setValue(e.target.value)}
22
- defaultValue={value}
47
+ error={validate(value)}
48
+ inputProps={{
49
+ autoFocus: true,
50
+ placeholder: props.placeholder,
51
+ onKeyDown: async (e) => e.key === "Enter" && triggerSave().then(),
52
+ }}
23
53
  />
24
54
  </div>
25
55
  );
@@ -38,6 +38,7 @@ export interface GridFormPopoutDropDownProps<RowType extends GridBaseRow, ValueT
38
38
  | "GridPopoverEditDropDown-containerSmall"
39
39
  | "GridPopoverEditDropDown-containerMedium"
40
40
  | "GridPopoverEditDropDown-containerLarge"
41
+ | "GridPopoverEditDropDown-containerUnlimited"
41
42
  | string
42
43
  | undefined;
43
44
  filtered?: "local" | "reload";
@@ -1,27 +1,27 @@
1
1
  import "../../styles/GridFormMultiSelect.scss";
2
2
 
3
3
  import { MenuItem, MenuDivider, FocusableItem } from "../../react-menu3";
4
- import { useCallback, useEffect, useRef, useState, KeyboardEvent } from "react";
4
+ import { useCallback, useEffect, useRef, useState, KeyboardEvent, useMemo } from "react";
5
5
  import { GridBaseRow } from "../Grid";
6
6
  import { ComponentLoadingWrapper } from "../ComponentLoadingWrapper";
7
- import { delay, fromPairs } from "lodash-es";
7
+ import { delay, pick, pickBy } from "lodash-es";
8
8
  import { LuiCheckboxInput } from "@linzjs/lui";
9
9
  import { useGridPopoverHook } from "../GridPopoverHook";
10
10
  import { MenuSeparatorString } from "./GridFormDropDown";
11
11
  import { CellEditorCommon, CellParams } from "../GridCell";
12
12
  import { ClickEvent } from "../../react-menu3/types";
13
+ import { GridSubComponentProps } from "./GridSubComponentProps";
13
14
 
14
15
  interface MultiFinalSelectOption<ValueType> {
15
16
  value: ValueType;
16
17
  label?: JSX.Element | string;
17
- subComponent?: (props: any, ref: any) => any;
18
+ subComponent?: (props: any) => JSX.Element;
18
19
  }
19
20
 
20
21
  export type MultiSelectOption<ValueType> = ValueType | MultiFinalSelectOption<ValueType>;
21
22
 
22
- export interface MultiSelectResult<RowType> {
23
- selectedRows: RowType[];
24
- values: Record<string, any>;
23
+ export interface SelectedOptionResult<ValueType> extends MultiFinalSelectOption<ValueType> {
24
+ subValue: any;
25
25
  }
26
26
 
27
27
  export interface GridFormMultiSelectProps<RowType extends GridBaseRow, ValueType> extends CellEditorCommon {
@@ -30,41 +30,63 @@ export interface GridFormMultiSelectProps<RowType extends GridBaseRow, ValueType
30
30
  | "GridMultiSelect-containerSmall"
31
31
  | "GridMultiSelect-containerMedium"
32
32
  | "GridMultiSelect-containerLarge"
33
+ | "GridMultiSelect-containerUnlimited"
33
34
  | string
34
35
  | undefined;
35
36
  filtered?: boolean;
36
37
  filterPlaceholder?: string;
37
- onSave?: (props: MultiSelectResult<RowType>) => Promise<boolean>;
38
+ onSave?: (selectedRows: RowType[], selectedOptions: SelectedOptionResult<ValueType>[]) => Promise<boolean>;
38
39
  options:
39
40
  | MultiSelectOption<ValueType>[]
40
41
  | ((selectedRows: RowType[]) => Promise<MultiSelectOption<ValueType>[]> | MultiSelectOption<ValueType>[]);
41
- initialSelectedValues?: (selectedRows: RowType[]) => any[];
42
+ initialSelectedValues?: (selectedRows: RowType[]) => any[] | Record<string, any>;
42
43
  }
43
44
 
44
45
  export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(
45
46
  props: GridFormMultiSelectProps<RowType, ValueType>,
46
47
  ) => {
47
48
  const { selectedRows } = props as unknown as CellParams<RowType>;
49
+
50
+ const initialiseValues = useMemo(
51
+ () => props.initialSelectedValues && props.initialSelectedValues(selectedRows),
52
+ [props, selectedRows],
53
+ );
54
+
55
+ const subComponentIsValid = useRef<Record<string, boolean>>({});
56
+ const [subSelectedValues, setSubSelectedValues] = useState<Record<string, any>>(
57
+ initialiseValues && !Array.isArray(initialiseValues)
58
+ ? pickBy(initialiseValues, (value) => typeof value !== "boolean")
59
+ : {},
60
+ );
61
+ const [selectedValues, setSelectedValues] = useState<any[]>(() =>
62
+ initialiseValues ? (Array.isArray(initialiseValues) ? initialiseValues : Object.keys(initialiseValues)) : [],
63
+ );
64
+
48
65
  const [filter, setFilter] = useState("");
49
66
  const [filteredValues, setFilteredValues] = useState<any[]>([]);
50
67
  const optionsInitialising = useRef(false);
51
68
  const [options, setOptions] = useState<MultiFinalSelectOption<ValueType>[]>();
52
- const subSelectedValues = useRef<Record<string, any>>({});
53
- const [selectedValues, setSelectedValues] = useState<any[]>(() =>
54
- props.initialSelectedValues ? props.initialSelectedValues(selectedRows) : [],
55
- );
56
69
 
57
70
  const save = useCallback(
58
71
  async (selectedRows: RowType[]): Promise<boolean> => {
59
- const values: Record<string, any> = fromPairs(
60
- selectedValues.map((value) => [value, subSelectedValues.current[value] ?? true]),
61
- );
62
72
  if (props.onSave) {
63
- return await props.onSave({ selectedRows, values });
73
+ const validations = pick(subComponentIsValid.current, selectedValues);
74
+ const notValid = Object.values(validations).some((v) => !v);
75
+ if (notValid) return false;
76
+
77
+ const selectedOptions = selectedValues.map((row) => (options ?? []).find((opt) => opt.value == row)) ?? [];
78
+ const selectedResults = selectedOptions.map(
79
+ (selectedOption) =>
80
+ ({
81
+ ...selectedOption,
82
+ subValue: subSelectedValues[`${selectedOption?.value}`],
83
+ } as SelectedOptionResult<ValueType>),
84
+ );
85
+ return await props.onSave(selectedRows, selectedResults);
64
86
  }
65
87
  return true;
66
88
  },
67
- [props, selectedValues],
89
+ [options, props, selectedValues, subSelectedValues],
68
90
  );
69
91
 
70
92
  // Load up options list if it's async function
@@ -188,14 +210,18 @@ export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(
188
210
  <FocusableItem className={"LuiDeprecatedForms"} key={`${item.value}_subcomponent`}>
189
211
  {(ref: any) =>
190
212
  item.subComponent &&
191
- item.subComponent(
192
- {
193
- setValue: (value: any) => {
194
- subSelectedValues.current[item.value as string] = value;
195
- },
196
- },
213
+ item.subComponent({
197
214
  ref,
198
- )
215
+ value: subSelectedValues[`${item.value}`],
216
+ setValue: (value: any) => {
217
+ subSelectedValues[`${item.value}`] = value;
218
+ setSubSelectedValues({ ...subSelectedValues });
219
+ },
220
+ setValid: (valid: boolean) => {
221
+ subComponentIsValid.current[`${item.value}`] = valid;
222
+ },
223
+ triggerSave,
224
+ } as GridSubComponentProps)
199
225
  }
200
226
  </FocusableItem>
201
227
  )}
@@ -63,6 +63,12 @@ export const GridFormTextInput = <RowType extends GridBaseRow>(_props: GridFormT
63
63
  onChange={(e) => setValue(e.target.value)}
64
64
  error={invalid()}
65
65
  formatted={props.units}
66
+ onMouseEnter={(e) => {
67
+ if (document.activeElement != e.currentTarget) {
68
+ e.currentTarget.focus();
69
+ e.currentTarget.selectionStart = e.currentTarget.value.length;
70
+ }
71
+ }}
66
72
  inputProps={{
67
73
  style: { width: "100%" },
68
74
  placeholder: props.placeholder,
@@ -0,0 +1,6 @@
1
+ export interface GridSubComponentProps {
2
+ value: string;
3
+ setValue: (value: string) => void;
4
+ setValid: (valid: boolean) => void;
5
+ triggerSave: () => Promise<void>;
6
+ }
@@ -7,18 +7,11 @@ export const GridPopoutEditMultiSelect = <RowType extends GridBaseRow, ValueType
7
7
  colDef: GenericCellColDef<RowType>,
8
8
  props: GenericCellEditorProps<GridFormMultiSelectProps<RowType, ValueType>>,
9
9
  ): ColDefT<RowType> =>
10
- GridCell(
11
- {
12
- initialWidth: 65,
13
- maxWidth: 150,
14
- ...colDef,
10
+ GridCell(colDef, {
11
+ editor: GridFormMultiSelect,
12
+ ...props,
13
+ editorParams: {
14
+ className: "GridMultiSelect-containerMedium",
15
+ ...(props.editorParams as GridFormMultiSelectProps<RowType, ValueType>),
15
16
  },
16
- {
17
- editor: GridFormMultiSelect,
18
- ...props,
19
- editorParams: {
20
- className: "GridMultiSelect-containerMedium",
21
- ...(props.editorParams as GridFormMultiSelectProps<RowType, ValueType>),
22
- },
23
- },
24
- );
17
+ });
@@ -7,8 +7,8 @@ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
7
7
  export const GridPopoverEditBearingLike = <RowType extends GridBaseRow>(
8
8
  colDef: GenericCellColDef<RowType>,
9
9
  props: GenericCellEditorProps<GridFormEditBearingProps<RowType>>,
10
- ): ColDefT<RowType> => {
11
- return GridCell(
10
+ ): ColDefT<RowType> =>
11
+ GridCell(
12
12
  {
13
13
  initialWidth: 65,
14
14
  maxWidth: 150,
@@ -20,13 +20,12 @@ export const GridPopoverEditBearingLike = <RowType extends GridBaseRow>(
20
20
  ...props,
21
21
  },
22
22
  );
23
- };
24
23
 
25
24
  export const GridPopoverEditBearing = <RowType extends GridBaseRow>(
26
25
  colDef: GenericCellColDef<RowType>,
27
26
  props: GenericCellEditorProps<GridFormEditBearingProps<RowType>>,
28
- ): ColDefT<RowType> => {
29
- return GridPopoverEditBearingLike(
27
+ ): ColDefT<RowType> =>
28
+ GridPopoverEditBearingLike(
30
29
  { valueFormatter: bearingValueFormatter, ...colDef },
31
30
  {
32
31
  multiEdit: !!props.multiEdit,
@@ -42,13 +41,12 @@ export const GridPopoverEditBearing = <RowType extends GridBaseRow>(
42
41
  },
43
42
  },
44
43
  );
45
- };
46
44
 
47
45
  export const GridPopoverEditBearingCorrection = <RowType extends GridBaseRow>(
48
46
  colDef: GenericCellColDef<RowType>,
49
47
  props: GenericCellEditorProps<GridFormEditBearingProps<RowType>>,
50
- ): ColDefT<RowType> => {
51
- return GridPopoverEditBearingLike(
48
+ ): ColDefT<RowType> =>
49
+ GridPopoverEditBearingLike(
52
50
  { valueFormatter: bearingCorrectionValueFormatter, ...colDef },
53
51
  {
54
52
  multiEdit: !!props.multiEdit,
@@ -64,4 +62,3 @@ export const GridPopoverEditBearingCorrection = <RowType extends GridBaseRow>(
64
62
  },
65
63
  },
66
64
  );
67
- };
@@ -7,19 +7,12 @@ export const GridPopoverEditDropDown = <RowType extends GridBaseRow, ValueType>(
7
7
  colDef: GenericCellColDef<RowType>,
8
8
  props: GenericCellEditorProps<GridFormPopoutDropDownProps<RowType, ValueType>>,
9
9
  ): ColDefT<RowType> =>
10
- GridCell(
11
- {
12
- initialWidth: 65,
13
- maxWidth: 150,
14
- ...colDef,
10
+ GridCell(colDef, {
11
+ editor: GridFormDropDown,
12
+ ...props,
13
+ editorParams: {
14
+ // Defaults to medium size container
15
+ className: "GridPopoverEditDropDown-containerMedium",
16
+ ...(props.editorParams as GridFormPopoutDropDownProps<RowType, ValueType>),
15
17
  },
16
- {
17
- editor: GridFormDropDown,
18
- ...props,
19
- editorParams: {
20
- // Defaults to medium size container
21
- className: "GridPopoverEditDropDown-containerMedium",
22
- ...(props.editorParams as GridFormPopoutDropDownProps<RowType, ValueType>),
23
- },
24
- },
25
- );
18
+ });
@@ -6,10 +6,9 @@ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
6
6
  export const GridPopoverMessage = <RowType extends GridBaseRow>(
7
7
  colDef: GenericCellColDef<RowType>,
8
8
  props: GenericCellEditorProps<GridFormMessageProps<RowType>>,
9
- ): ColDefT<RowType> => {
10
- return GridCell(
9
+ ): ColDefT<RowType> =>
10
+ GridCell(
11
11
  {
12
- maxWidth: 140,
13
12
  ...colDef,
14
13
  cellRendererParams: {
15
14
  singleClickEdit: true,
@@ -21,4 +20,3 @@ export const GridPopoverMessage = <RowType extends GridBaseRow>(
21
20
  ...props,
22
21
  },
23
22
  );
24
- };
@@ -6,11 +6,4 @@ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
6
6
  export const GridPopoverTextArea = <RowType extends GridBaseRow>(
7
7
  colDef: GenericCellColDef<RowType>,
8
8
  params: GenericCellEditorProps<GridFormTextAreaProps<RowType>>,
9
- ): ColDefT<RowType> =>
10
- GridCell(
11
- {
12
- maxWidth: 260,
13
- ...colDef,
14
- },
15
- { editor: GridFormTextArea, ...params },
16
- );
9
+ ): ColDefT<RowType> => GridCell(colDef, { editor: GridFormTextArea, ...params });
@@ -6,15 +6,8 @@ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
6
6
  export const GridPopoverTextInput = <RowType extends GridBaseRow>(
7
7
  colDef: GenericCellColDef<RowType>,
8
8
  params: GenericCellEditorProps<GridFormTextInputProps<RowType>>,
9
- ): ColDefT<RowType> => {
10
- return GridCell(
11
- {
12
- maxWidth: 140,
13
- ...colDef,
14
- },
15
- {
16
- editor: GridFormTextInput,
17
- ...params,
18
- },
19
- );
20
- };
9
+ ): ColDefT<RowType> =>
10
+ GridCell(colDef, {
11
+ editor: GridFormTextInput,
12
+ ...params,
13
+ });
@@ -16,6 +16,8 @@ export interface LuiTextInputProps {
16
16
 
17
17
  placeholder?: string;
18
18
  formatted?: string;
19
+
20
+ onMouseEnter?: (e: React.MouseEvent<HTMLTextAreaElement>) => void;
19
21
  }
20
22
 
21
23
  export const TextInputFormatted = (props: LuiTextInputProps): JSX.Element => {
@@ -33,7 +35,8 @@ export const TextInputFormatted = (props: LuiTextInputProps): JSX.Element => {
33
35
  type={"text"}
34
36
  className={"LuiTextInput-input"}
35
37
  min="0"
36
- value={props.value}
38
+ spellCheck={true}
39
+ defaultValue={props.value}
37
40
  onChange={props.onChange}
38
41
  {...props.inputProps}
39
42
  />
@@ -1,7 +1,7 @@
1
1
  import "./FormTest.scss";
2
2
 
3
3
  import { useCallback, useState } from "react";
4
- import { LuiTextInput } from "@linzjs/lui";
4
+ import { LuiAlertModal, LuiAlertModalButtons, LuiButton, LuiTextInput } from "@linzjs/lui";
5
5
  import { wait } from "../../utils/util";
6
6
  import { CellEditorCommon, CellParams } from "../../components/GridCell";
7
7
  import { useGridPopoverHook } from "../../components/GridPopoverHook";
@@ -35,19 +35,59 @@ export const FormTest = <RowType extends GridBaseRow>(_props: CellEditorCommon):
35
35
  // Close form
36
36
  return true;
37
37
  }, [nameType, numba, plan, props.selectedRows]);
38
+
39
+ const [showModal, setShowModal] = useState<boolean>(false);
40
+
38
41
  const { popoverWrapper } = useGridPopoverHook({ className: _props.className, save });
39
42
 
40
43
  return popoverWrapper(
41
- <div style={{ display: "flex", flexDirection: "row" }} className={"FormTest Grid-popoverContainer"}>
42
- <div className={"FormTest-textInput"}>
43
- <LuiTextInput label={"Name type"} value={nameType} onChange={(e) => setNameType(e.target.value)} />
44
- </div>
45
- <div className={"FormTest-textInput"}>
46
- <LuiTextInput label={"Number"} value={numba} onChange={(e) => setNumba(e.target.value)} />
47
- </div>
48
- <div className={"FormTest-textInput"}>
49
- <LuiTextInput label={"Plan"} value={plan} onChange={(e) => setPlan(e.target.value)} />
44
+ <>
45
+ {showModal && (
46
+ <LuiAlertModal
47
+ data-testid="WarningAlertWithButtons-modal"
48
+ level="warning"
49
+ // If panel is popped out, append modal to poppped out window DOM, otherwise use default
50
+ //appendToElement={() => (poppedOut && popoutElement) || document.body}
51
+ >
52
+ <h2>Header</h2>
53
+ <p className="WarningAlertWithButtons-new-line">
54
+ This modal was added to help fix a bug where the onBlur for the context menu was prematurely closing the
55
+ editor and therefore this modal.
56
+ </p>
57
+ <LuiAlertModalButtons>
58
+ <LuiButton
59
+ level="secondary"
60
+ onClick={() => {
61
+ setShowModal(false);
62
+ }}
63
+ data-testid="WarningAlertWithButtons-cancel"
64
+ >
65
+ Cancel
66
+ </LuiButton>
67
+
68
+ <LuiButton
69
+ level="primary"
70
+ onClick={() => {
71
+ setShowModal(false);
72
+ }}
73
+ data-testid="WarningAlertWithButtons-ok"
74
+ >
75
+ OK
76
+ </LuiButton>
77
+ </LuiAlertModalButtons>
78
+ </LuiAlertModal>
79
+ )}
80
+ <div style={{ display: "flex", flexDirection: "row" }} className={"FormTest Grid-popoverContainer"}>
81
+ <div className={"FormTest-textInput"}>
82
+ <LuiTextInput label={"Name type"} value={nameType} onChange={(e) => setNameType(e.target.value)} />
83
+ </div>
84
+ <div className={"FormTest-textInput"}>
85
+ <LuiTextInput label={"Number"} value={numba} onChange={(e) => setNumba(e.target.value)} />
86
+ </div>
87
+ <div className={"FormTest-textInput"}>
88
+ <LuiButton onClick={() => setShowModal(true)}>Show Modal</LuiButton>
89
+ </div>
50
90
  </div>
51
- </div>,
91
+ </>,
52
92
  );
53
93
  };
@@ -10,7 +10,6 @@ import { Grid, GridProps } from "../../components/Grid";
10
10
  import { useMemo, useState } from "react";
11
11
  import { MenuSeparator } from "../../components/gridForm/GridFormDropDown";
12
12
  import { wait } from "../../utils/util";
13
- import { MultiSelectResult } from "../../components/gridForm/GridFormMultiSelect";
14
13
  import { GridSubComponentTextArea } from "../../components/GridSubComponentTextArea";
15
14
  import { ColDefT, GridCell } from "../../components/GridCell";
16
15
  import { GridPopoutEditMultiSelect } from "../../components/gridPopoverEdit/GridPopoutEditMultiSelect";
@@ -70,6 +69,7 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
70
69
  editorParams: {
71
70
  filtered: true,
72
71
  filterPlaceholder: "Filter position",
72
+ className: "GridMultiSelect-containerUnlimited",
73
73
  options: [
74
74
  { value: "a", label: "Architect" },
75
75
  { value: "b", label: "Developer" },
@@ -78,15 +78,24 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
78
78
  { value: "e", label: "Tester" },
79
79
  MenuSeparator,
80
80
  {
81
- value: "f",
81
+ value: "other",
82
82
  label: "Other",
83
- subComponent: (props) => <GridSubComponentTextArea {...props} />,
83
+ subComponent: (props) => <GridSubComponentTextArea {...props} maxlength={2} />,
84
84
  },
85
85
  ],
86
- onSave: async (result: MultiSelectResult<ITestRow>) => {
86
+ initialSelectedValues: () => ({
87
+ other: "Hello",
88
+ }),
89
+ onSave: async (selectedRows, selectedOptions) => {
87
90
  // eslint-disable-next-line no-console
88
- console.log(result);
91
+ console.log("multiSelect result", { selectedRows, selectedOptions });
92
+
89
93
  await wait(1000);
94
+ const normalValues = selectedOptions.filter((o) => !o.subComponent).map((o) => o.label);
95
+ const subValues = selectedOptions.filter((o) => o.subComponent).map((o) => o.subValue);
96
+ selectedRows.forEach((row) => {
97
+ row.position = [...normalValues, ...subValues].join(", ");
98
+ });
90
99
  return true;
91
100
  },
92
101
  },
@@ -107,9 +116,9 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
107
116
  filterPlaceholder: "Filter position",
108
117
  initialSelectedValues: (selectedRows) => [selectedRows[0].position2],
109
118
  options: Object.entries(positionTwoMap).map(([k, v]) => ({ value: k, label: v })),
110
- onSave: async (result: MultiSelectResult<ITestRow>) => {
119
+ onSave: async (selectedRows, selectedOptions) => {
111
120
  // eslint-disable-next-line no-console
112
- console.log(result);
121
+ console.log("multiSelect result", { selectedRows, selectedOptions });
113
122
  await wait(1000);
114
123
  return true;
115
124
  },