@linzjs/step-ag-grid 2.4.0 → 2.4.1

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.4.0",
5
+ "version": "2.4.1",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -14,12 +14,14 @@ export interface GridPopoutEditDropDownSelectedItem<RowType, ValueType> {
14
14
  // Note the row that was clicked on will be first
15
15
  selectedRows: RowType[];
16
16
  value: ValueType;
17
+ subComponentValue?: ValueType;
17
18
  }
18
19
 
19
20
  interface FinalSelectOption<ValueType> {
20
21
  value: ValueType;
21
22
  label?: JSX.Element | string;
22
23
  disabled?: boolean | string;
24
+ subComponent?: (props: any, ref: any) => any;
23
25
  }
24
26
 
25
27
  export const MenuSeparatorString = "_____MENU_SEPARATOR_____";
@@ -61,15 +63,16 @@ export const GridFormDropDown = <RowType extends GridBaseRow, ValueType>(
61
63
  const [filteredValues, setFilteredValues] = useState<any[]>([]);
62
64
  const optionsInitialising = useRef(false);
63
65
  const [options, setOptions] = useState<FinalSelectOption<ValueType>[] | null>(null);
66
+ const [subComponentValues, setSubComponentValues] = useState<{ optionValue: any; subComponentValue: any }[]>([]);
64
67
 
65
68
  const selectItemHandler = useCallback(
66
- async (value: ValueType): Promise<boolean> => {
69
+ async (value: ValueType, subComponentValue?: ValueType): Promise<boolean> => {
67
70
  const field = props.field;
68
71
  return await updatingCells({ selectedRows: props.selectedRows, field }, async (selectedRows) => {
69
72
  const hasChanged = selectedRows.some((row) => row[field as keyof RowType] !== value);
70
73
  if (hasChanged) {
71
74
  if (props.onSelectedItem) {
72
- await props.onSelectedItem({ selectedRows, value });
75
+ await props.onSelectedItem({ selectedRows, value, subComponentValue });
73
76
  } else {
74
77
  selectedRows.forEach((row) => (row[field as keyof RowType] = value));
75
78
  }
@@ -214,15 +217,56 @@ export const GridFormDropDown = <RowType extends GridBaseRow, ValueType>(
214
217
  ) : item.value === MenuHeaderString ? (
215
218
  <MenuHeader>{item.label}</MenuHeader>
216
219
  ) : filteredValues.includes(item.value) ? null : (
217
- <MenuItem
218
- key={`${props.field}-${index}`}
219
- disabled={!!item.disabled}
220
- title={item.disabled && typeof item.disabled !== "boolean" ? item.disabled : ""}
221
- value={item.value}
222
- onClick={() => selectItemHandler(item.value)}
223
- >
224
- {item.label ?? (item.value == null ? `<${item.value}>` : `${item.value}`)}
225
- </MenuItem>
220
+ <>
221
+ {!item.subComponent ? (
222
+ <MenuItem
223
+ key={`${props.field}-${index}`}
224
+ disabled={!!item.disabled}
225
+ title={item.disabled && typeof item.disabled !== "boolean" ? item.disabled : ""}
226
+ value={item.value}
227
+ onClick={() => {
228
+ selectItemHandler(item.value);
229
+ }}
230
+ >
231
+ {item.label ?? (item.value == null ? `<${item.value}>` : `${item.value}`)}
232
+ </MenuItem>
233
+ ) : (
234
+ <FocusableItem className={"LuiDeprecatedForms"} key={`${props.field}-${index}_subcomponent`}>
235
+ {(ref: any) =>
236
+ item.subComponent &&
237
+ item.subComponent(
238
+ {
239
+ setValue: (value: any) => {
240
+ const localSubComponentValues = [...subComponentValues];
241
+ const subComponentValueIndex = localSubComponentValues.findIndex(
242
+ ({ optionValue }) => optionValue === item.value,
243
+ );
244
+ if (subComponentValueIndex !== -1) {
245
+ localSubComponentValues[subComponentValueIndex].subComponentValue = value;
246
+ } else {
247
+ localSubComponentValues.push({
248
+ subComponentValue: value,
249
+ optionValue: item.value,
250
+ });
251
+ }
252
+ setSubComponentValues(localSubComponentValues);
253
+ },
254
+ keyDown: (key: string) => {
255
+ const subComponentItem = subComponentValues.find(
256
+ ({ optionValue }) => optionValue === item.value,
257
+ );
258
+ if (key === "Enter" && subComponentItem) {
259
+ selectItemHandler(item.value, subComponentItem.subComponentValue);
260
+ ref.closeMenu();
261
+ }
262
+ },
263
+ },
264
+ ref,
265
+ )
266
+ }
267
+ </FocusableItem>
268
+ )}
269
+ </>
226
270
  ),
227
271
  )}
228
272
  </>
@@ -0,0 +1,34 @@
1
+ import { useState } from "react";
2
+ import { TextInputFormatted } from "../../lui/TextInputFormatted";
3
+
4
+ export interface GridFormSubComponentTextInput {
5
+ setValue: (value: string) => void;
6
+ keyDown: (key: string) => void;
7
+ placeholder?: string;
8
+ }
9
+
10
+ export const GridFormSubComponentTextInput = ({ keyDown, placeholder, setValue }: GridFormSubComponentTextInput) => {
11
+ const placeholderText = placeholder || "Other...";
12
+ const [inputValue, setInputValue] = useState("");
13
+ return (
14
+ <>
15
+ <TextInputFormatted
16
+ value={inputValue}
17
+ onChange={(e) => {
18
+ const value = e.target.value;
19
+ setValue(value);
20
+ setInputValue(value);
21
+ }}
22
+ inputProps={{
23
+ onKeyDown: (k: any) => keyDown(k.key),
24
+ placeholder: placeholderText,
25
+ onMouseEnter: (e) => {
26
+ if (document.activeElement != e.currentTarget) {
27
+ e.currentTarget.focus();
28
+ }
29
+ },
30
+ }}
31
+ />
32
+ </>
33
+ );
34
+ };
package/src/index.ts CHANGED
@@ -27,6 +27,7 @@ export { GridPopoverEditDropDown } from "./components/gridPopoverEdit/GridPopove
27
27
  export { GridPopoverMessage } from "./components/gridPopoverEdit/GridPopoverMessage";
28
28
  export { GridPopoverTextArea } from "./components/gridPopoverEdit/GridPopoverTextArea";
29
29
  export { GridPopoverTextInput } from "./components/gridPopoverEdit/GridPopoverTextInput";
30
+ export { GridFormSubComponentTextInput } from "./components/gridForm/GridFormSubComponentTextInput";
30
31
  export * from "./components/gridForm/GridFormDropDown";
31
32
  export * from "./components/gridForm/GridFormMultiSelect";
32
33
  export * from "./components/gridForm/GridFormPopoutMenu";
@@ -12,6 +12,7 @@ import { MenuHeaderItem, MenuSeparator, MenuSeparatorString } from "../../compon
12
12
  import { wait } from "../../utils/util";
13
13
  import { ColDefT, GridCell } from "../../components/GridCell";
14
14
  import { GridPopoverEditDropDown } from "../../components/gridPopoverEdit/GridPopoverEditDropDown";
15
+ import { GridFormSubComponentTextInput } from "../../components/gridForm/GridFormSubComponentTextInput";
15
16
 
16
17
  export default {
17
18
  title: "Components / Grids",
@@ -40,6 +41,7 @@ interface ITestRow {
40
41
  position3: string | null;
41
42
  position4: ICode | null;
42
43
  code: string | null;
44
+ sub: string | null;
43
45
  }
44
46
 
45
47
  interface ICode {
@@ -241,6 +243,43 @@ const GridEditDropDownTemplate: ComponentStory<typeof Grid> = (props: GridProps)
241
243
  },
242
244
  },
243
245
  ),
246
+ GridPopoverEditDropDown(
247
+ {
248
+ field: "sub",
249
+ initialWidth: 65,
250
+ maxWidth: 150,
251
+ headerName: "Subcomponent",
252
+ valueGetter: (params) => params.data.sub,
253
+ },
254
+ {
255
+ multiEdit: true,
256
+ editorParams: {
257
+ filtered: "local",
258
+ filterPlaceholder: "Filter this",
259
+ options: [
260
+ {
261
+ value: "one",
262
+ label: "One",
263
+ },
264
+ {
265
+ value: "two",
266
+ label: "Two",
267
+ },
268
+ {
269
+ value: "oth",
270
+ label: "Other",
271
+ subComponent: (props) => (
272
+ <GridFormSubComponentTextInput {...props} placeholder={"Subcomponent value"} />
273
+ ),
274
+ },
275
+ ],
276
+ onSelectedItem: async (selected) => {
277
+ // eslint-disable-next-line no-console
278
+ console.log("onSelectedItem", selected);
279
+ },
280
+ },
281
+ },
282
+ ),
244
283
  ],
245
284
  [optionsFn, optionsObjects],
246
285
  );
@@ -253,6 +292,7 @@ const GridEditDropDownTemplate: ComponentStory<typeof Grid> = (props: GridProps)
253
292
  position3: "Tester",
254
293
  position4: { code: "O1", desc: "Object One" },
255
294
  code: "O1",
295
+ sub: "two",
256
296
  },
257
297
  {
258
298
  id: 1001,
@@ -261,6 +301,7 @@ const GridEditDropDownTemplate: ComponentStory<typeof Grid> = (props: GridProps)
261
301
  position3: "Developer",
262
302
  position4: { code: "O2", desc: "Object Two" },
263
303
  code: "O2",
304
+ sub: "one",
264
305
  },
265
306
  ] as ITestRow[]);
266
307