@linzjs/step-ag-grid 2.3.1 → 2.4.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.3.1",
5
+ "version": "2.4.0",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -1,24 +1,36 @@
1
- import { useCallback, useEffect } from "react";
2
- import { GridSubComponentProps } from "./gridForm/GridSubComponentProps";
1
+ import { useCallback, useContext, useEffect } from "react";
3
2
  import { TextInputFormatted } from "../lui/TextInputFormatted";
3
+ import { GridSubComponentContext } from "../contexts/GridSubComponentContext";
4
4
 
5
- export interface GridSubComponentTextAreaProps extends GridSubComponentProps {
5
+ export interface GridSubComponentTextAreaProps {
6
6
  placeholder?: string;
7
7
  required?: boolean;
8
- maxlength?: number;
8
+ maxLength?: number;
9
9
  width?: string | number;
10
- validate: (value: string) => string | null;
10
+ validate?: (value: string) => string | null;
11
+ defaultValue: string;
11
12
  }
12
13
 
13
14
  export const GridSubComponentTextArea = (props: GridSubComponentTextAreaProps): JSX.Element => {
14
- const { value, setValue, setValid, triggerSave } = props;
15
+ const { value, setValue, setValid, triggerSave } = useContext(GridSubComponentContext);
16
+
17
+ // If is not initialised yet as it's just been created then set the default value
18
+ useEffect(() => {
19
+ if (value == null) setValue(props.defaultValue);
20
+ }, [props.defaultValue, setValue, value]);
21
+
15
22
  const validate = useCallback(
16
- (value: string) => {
23
+ (value: string | null) => {
24
+ if (value == null) return null;
25
+ // This can happen because subcomponent is invoked without type safety
26
+ if (typeof value !== "string") {
27
+ console.error("Value is not a string", value);
28
+ }
17
29
  if (props.required && value.length === 0) {
18
30
  return `Some text is required`;
19
31
  }
20
- if (props.maxlength && value.length > props.maxlength) {
21
- return `Text must be no longer than ${props.maxlength} characters`;
32
+ if (props.maxLength && value.length > props.maxLength) {
33
+ return `Text must be no longer than ${props.maxLength} characters`;
22
34
  }
23
35
  if (props.validate) {
24
36
  return props.validate(value);
@@ -29,7 +41,7 @@ export const GridSubComponentTextArea = (props: GridSubComponentTextAreaProps):
29
41
  );
30
42
 
31
43
  useEffect(() => {
32
- setValid(validate(value) == null);
44
+ setValid(value != null && validate(value) == null);
33
45
  }, [setValid, validate, value]);
34
46
 
35
47
  return (
@@ -10,7 +10,7 @@ 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
+ import { GridSubComponentContext } from "contexts/GridSubComponentContext";
14
14
 
15
15
  interface MultiFinalSelectOption<ValueType> {
16
16
  value: ValueType;
@@ -208,20 +208,24 @@ export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(
208
208
 
209
209
  {selectedValues.includes(item.value) && item.subComponent && (
210
210
  <FocusableItem className={"LuiDeprecatedForms"} key={`${item.value}_subcomponent`}>
211
- {(ref: any) =>
212
- item.subComponent &&
213
- item.subComponent({
214
- ref,
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)
211
+ {(_: any) =>
212
+ item.subComponent && (
213
+ <GridSubComponentContext.Provider
214
+ value={{
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
+ }}
225
+ >
226
+ <item.subComponent />
227
+ </GridSubComponentContext.Provider>
228
+ )
225
229
  }
226
230
  </FocusableItem>
227
231
  )}
@@ -7,7 +7,7 @@ import { CellEditorCommon, CellParams } from "../GridCell";
7
7
  export interface GridFormTextAreaProps<RowType extends GridBaseRow> extends CellEditorCommon {
8
8
  placeholder?: string;
9
9
  required?: boolean;
10
- maxlength?: number;
10
+ maxLength?: number;
11
11
  width?: string | number;
12
12
  validate?: (value: string) => string | null;
13
13
  onSave?: (selectedRows: RowType[], value: string) => Promise<boolean>;
@@ -21,8 +21,8 @@ export const GridFormTextArea = <RowType extends GridBaseRow>(_props: GridFormTe
21
21
  if (props.required && value.length == 0) {
22
22
  return `Some text is required`;
23
23
  }
24
- if (props.maxlength && value.length > props.maxlength) {
25
- return `Text must be no longer than ${props.maxlength} characters`;
24
+ if (props.maxLength && value.length > props.maxLength) {
25
+ return `Text must be no longer than ${props.maxLength} characters`;
26
26
  }
27
27
  if (props.validate) {
28
28
  return props.validate(value);
@@ -8,7 +8,7 @@ export interface GridFormTextInputProps<RowType extends GridBaseRow> extends Cel
8
8
  placeholder?: string;
9
9
  units?: string;
10
10
  required?: boolean;
11
- maxlength?: number;
11
+ maxLength?: number;
12
12
  width?: string | number;
13
13
  // Return null for ok, otherwise an error string
14
14
  validate?: (value: string, data: RowType) => string | null;
@@ -25,8 +25,8 @@ export const GridFormTextInput = <RowType extends GridBaseRow>(_props: GridFormT
25
25
  if (props.required && trimmedValue.length == 0) {
26
26
  return `Some text is required`;
27
27
  }
28
- if (props.maxlength && trimmedValue.length > props.maxlength) {
29
- return `Text must be no longer than ${props.maxlength} characters`;
28
+ if (props.maxLength && trimmedValue.length > props.maxLength) {
29
+ return `Text must be no longer than ${props.maxLength} characters`;
30
30
  }
31
31
  if (props.validate) {
32
32
  return props.validate(trimmedValue, props.data);
@@ -0,0 +1,21 @@
1
+ import { createContext } from "react";
2
+
3
+ export interface GridSubComponentContextType {
4
+ value: any;
5
+ setValue: (value: string) => void;
6
+ setValid: (valid: boolean) => void;
7
+ triggerSave: () => Promise<void>;
8
+ }
9
+
10
+ export const GridSubComponentContext = createContext<GridSubComponentContextType>({
11
+ value: "GridSubComponentContext value no context",
12
+ setValue: () => {
13
+ console.error("GridSubComponentContext setValue no context");
14
+ },
15
+ setValid: () => {
16
+ console.error("GridSubComponentContext setValid no context");
17
+ },
18
+ triggerSave: async () => {
19
+ console.error("GridSubComponentContext triggerSave no context");
20
+ },
21
+ });
@@ -7,7 +7,7 @@ import { useCallback, useState } from "react";
7
7
  import { wait } from "../../utils/util";
8
8
 
9
9
  export default {
10
- title: "Components / ButtonTextWithIcon",
10
+ title: "Components / ActionButton",
11
11
  component: ActionButton,
12
12
  args: {},
13
13
  } as ComponentMeta<typeof ActionButton>;
@@ -18,23 +18,22 @@ export interface IFormTestRow {
18
18
 
19
19
  export const FormTest = <RowType extends GridBaseRow>(_props: CellEditorCommon): JSX.Element => {
20
20
  const props = _props as CellParams<RowType>;
21
- const [v1, v2, ...v3] = props.value.split(" ");
21
+ const [v1, ...v2] = props.value.split(" ");
22
22
 
23
23
  const [nameType, setNameType] = useState(v1);
24
- const [numba, setNumba] = useState(v2);
25
- const [plan, setPlan] = useState(v3.join(" "));
24
+ const [numba, setNumba] = useState(v2.join(" "));
26
25
 
27
26
  const save = useCallback(async (): Promise<boolean> => {
28
27
  // eslint-disable-next-line no-console
29
- console.log("onSave", props.selectedRows, nameType, numba, plan);
28
+ console.log("onSave", props.selectedRows, nameType, numba);
30
29
 
31
30
  // @ts-ignore
32
- props.selectedRows.forEach((row) => (row["name"] = [nameType, numba, plan].join(" ")));
31
+ props.selectedRows.forEach((row) => (row["name"] = [nameType, numba].join(" ")));
33
32
  await wait(1000);
34
33
 
35
34
  // Close form
36
35
  return true;
37
- }, [nameType, numba, plan, props.selectedRows]);
36
+ }, [nameType, numba, props.selectedRows]);
38
37
 
39
38
  const [showModal, setShowModal] = useState<boolean>(false);
40
39
 
@@ -83,7 +83,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
83
83
  [],
84
84
  );
85
85
 
86
- const [rowData, setRowData] = useState([
86
+ const [rowData] = useState([
87
87
  { id: 1000, bearing1: 1.234, bearingCorrection: 90 },
88
88
  { id: 1001, bearing1: 1.565, bearingCorrection: 240 },
89
89
  { id: 1002, bearing1: null, bearingCorrection: 355.1 },
@@ -245,7 +245,7 @@ const GridEditDropDownTemplate: ComponentStory<typeof Grid> = (props: GridProps)
245
245
  [optionsFn, optionsObjects],
246
246
  );
247
247
 
248
- const [rowData, setRowData] = useState([
248
+ const [rowData] = useState([
249
249
  {
250
250
  id: 1000,
251
251
  position: "Tester",
@@ -57,7 +57,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
57
57
  [],
58
58
  );
59
59
 
60
- const [rowData, setRowData] = useState([
60
+ const [rowData] = useState([
61
61
  { id: 1000, name: "IS IS DP12345", nameType: "IS", numba: "IX", plan: "DP 12345" },
62
62
  { id: 1001, name: "PEG V SD523", nameType: "PEG", numba: "V", plan: "SD 523" },
63
63
  ] as IFormTestRow[]);
@@ -61,7 +61,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
61
61
  multiEdit: true,
62
62
  editorParams: {
63
63
  required: true,
64
- maxlength: 12,
64
+ maxLength: 12,
65
65
  placeholder: "Enter some text...",
66
66
  validate: (value: string) => {
67
67
  if (value === "never") return "The value 'never' is not allowed";
@@ -88,7 +88,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
88
88
  {
89
89
  multiEdit: true,
90
90
  editorParams: {
91
- maxlength: 12,
91
+ maxLength: 12,
92
92
  placeholder: "Enter distance...",
93
93
  units: "m",
94
94
  validate: (value: string) => {
@@ -115,7 +115,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
115
115
  multiEdit: true,
116
116
  editorParams: {
117
117
  required: true,
118
- maxlength: 32,
118
+ maxLength: 32,
119
119
  placeholder: "Enter some text...",
120
120
 
121
121
  validate: (value: string) => {
@@ -80,7 +80,7 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
80
80
  {
81
81
  value: "other",
82
82
  label: "Other",
83
- subComponent: (props) => <GridSubComponentTextArea {...props} maxlength={2} />,
83
+ subComponent: () => <GridSubComponentTextArea maxLength={2} defaultValue={""} />,
84
84
  },
85
85
  ],
86
86
  initialSelectedValues: () => ({
@@ -128,7 +128,7 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
128
128
  ];
129
129
  }, []);
130
130
 
131
- const [rowData, setRowData] = useState([
131
+ const [rowData] = useState([
132
132
  { id: 1000, position: "Tester", position2: "1", position3: "Tester" },
133
133
  { id: 1001, position: "Developer", position2: "2", position3: "Developer" },
134
134
  ] as ITestRow[]);
@@ -151,7 +151,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
151
151
  [],
152
152
  );
153
153
 
154
- const [rowData, setRowData] = useState([
154
+ const [rowData] = useState([
155
155
  { id: 1000, position: "Tester", age: 30, desc: "Tests application", dd: "1" },
156
156
  { id: 1001, position: "Developer", age: 12, desc: "Develops application", dd: "2" },
157
157
  ]);
@@ -1,6 +0,0 @@
1
- export interface GridSubComponentProps {
2
- value: string;
3
- setValue: (value: string) => void;
4
- setValid: (valid: boolean) => void;
5
- triggerSave: () => Promise<void>;
6
- }
@@ -1,6 +0,0 @@
1
- export interface GridSubComponentProps {
2
- value: string;
3
- setValue: (value: string) => void;
4
- setValid: (valid: boolean) => void;
5
- triggerSave: () => Promise<void>;
6
- }