@linzjs/step-ag-grid 4.0.0 → 4.0.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": "4.0.0",
5
+ "version": "4.0.2",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -64,7 +64,7 @@ const fieldToString = (field: any) => {
64
64
  export const GridFormDropDown = <RowType extends GridBaseRow, ValueType>(
65
65
  props: GridFormPopoutDropDownProps<RowType, ValueType>,
66
66
  ) => {
67
- const { selectedRows, field, updateValue } = useGridPopoverContext<RowType>();
67
+ const { selectedRows, field, updateValue, data } = useGridPopoverContext<RowType>();
68
68
  const { stopEditing } = useContext(GridContext);
69
69
 
70
70
  const [filter, setFilter] = useState("");
@@ -266,6 +266,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow, ValueType>(
266
266
  {(ref: MenuInstance) => (
267
267
  <GridSubComponentContext.Provider
268
268
  value={{
269
+ data,
269
270
  value: subSelectedValue,
270
271
  setValue: (value: any) => {
271
272
  setSubSelectedValue(value);
@@ -45,7 +45,7 @@ export interface GridFormMultiSelectProps<RowType extends GridBaseRow, ValueType
45
45
  export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(
46
46
  props: GridFormMultiSelectProps<RowType, ValueType>,
47
47
  ) => {
48
- const { selectedRows } = useGridPopoverContext<RowType>();
48
+ const { selectedRows, data } = useGridPopoverContext<RowType>();
49
49
 
50
50
  const initialiseValues = useMemo(() => {
51
51
  const r = props.initialSelectedValues && props.initialSelectedValues(selectedRows);
@@ -214,6 +214,7 @@ export const GridFormMultiSelect = <RowType extends GridBaseRow, ValueType>(
214
214
  item.subComponent && (
215
215
  <GridSubComponentContext.Provider
216
216
  value={{
217
+ data,
217
218
  value: selectedValues[`${item.value}`],
218
219
  setValue: (value: any) => {
219
220
  setSelectedValues({
@@ -38,7 +38,7 @@ export interface MenuOption<RowType extends GridBaseRow> {
38
38
  * you need a useMemo around your columnDefs
39
39
  */
40
40
  export const GridFormPopoverMenu = <RowType extends GridBaseRow>(props: GridFormPopoutMenuProps<RowType>) => {
41
- const { selectedRows, updateValue } = useGridPopoverContext<RowType>();
41
+ const { selectedRows, updateValue, data } = useGridPopoverContext<RowType>();
42
42
 
43
43
  const optionsInitialising = useRef(false);
44
44
  const [options, setOptions] = useState<MenuOption<RowType>[]>();
@@ -148,6 +148,7 @@ export const GridFormPopoverMenu = <RowType extends GridBaseRow>(props: GridForm
148
148
  item.subComponent && (
149
149
  <GridSubComponentContext.Provider
150
150
  value={{
151
+ data,
151
152
  value: subSelectedValue,
152
153
  setValue: (value: any) => {
153
154
  setSubSelectedValue(value);
@@ -4,8 +4,11 @@ import { CellEditorCommon } from "../GridCell";
4
4
  import clsx from "clsx";
5
5
  import { TextAreaInput } from "../../lui/TextAreaInput";
6
6
  import { TextInputValidator, TextInputValidatorProps } from "../../utils/textValidator";
7
+ import { GridBaseRow } from "../Grid";
7
8
 
8
- export interface GridSubComponentTextAreaProps extends TextInputValidatorProps, CellEditorCommon {
9
+ export interface GridSubComponentTextAreaProps<RowType extends GridBaseRow>
10
+ extends TextInputValidatorProps<RowType>,
11
+ CellEditorCommon {
9
12
  placeholder?: string;
10
13
  width?: string | number;
11
14
  defaultValue: string;
@@ -13,8 +16,10 @@ export interface GridSubComponentTextAreaProps extends TextInputValidatorProps,
13
16
  helpText?: string;
14
17
  }
15
18
 
16
- export const GridFormSubComponentTextArea = (props: GridSubComponentTextAreaProps): JSX.Element => {
17
- const { value, setValue, setValid, triggerSave } = useContext(GridSubComponentContext);
19
+ export const GridFormSubComponentTextArea = <RowType extends GridBaseRow>(
20
+ props: GridSubComponentTextAreaProps<RowType>,
21
+ ): JSX.Element => {
22
+ const { value, data, setValue, setValid, triggerSave } = useContext(GridSubComponentContext);
18
23
 
19
24
  const helpText = props.helpText ?? "Press tab to save";
20
25
 
@@ -23,7 +28,7 @@ export const GridFormSubComponentTextArea = (props: GridSubComponentTextAreaProp
23
28
  if (value == null) setValue(props.defaultValue);
24
29
  }, [props.defaultValue, setValue, value]);
25
30
 
26
- const invalid = useCallback(() => TextInputValidator(props, value), [props, value]);
31
+ const invalid = useCallback(() => TextInputValidator(props, value, data), [data, props, value]);
27
32
 
28
33
  useEffect(() => {
29
34
  setValid(value != null && invalid() == null);
@@ -47,9 +52,9 @@ export const GridFormSubComponentTextArea = (props: GridSubComponentTextAreaProp
47
52
  }}
48
53
  onKeyUp={(e) => {
49
54
  if (e.key === "Tab") {
50
- !e.shiftKey && triggerSave().then();
51
55
  e.preventDefault();
52
56
  e.stopPropagation();
57
+ !e.shiftKey && triggerSave().then();
53
58
  }
54
59
  }}
55
60
  />
@@ -3,16 +3,21 @@ import { GridSubComponentContext } from "../../contexts/GridSubComponentContext"
3
3
  import { TextInputFormatted } from "../../lui/TextInputFormatted";
4
4
  import { TextInputValidator, TextInputValidatorProps } from "../../utils/textValidator";
5
5
  import { CellEditorCommon } from "../GridCell";
6
+ import { GridBaseRow } from "../Grid";
6
7
 
7
- export interface GridFormSubComponentTextInputProps extends TextInputValidatorProps, CellEditorCommon {
8
+ export interface GridFormSubComponentTextInputProps<RowType extends GridBaseRow>
9
+ extends TextInputValidatorProps<RowType>,
10
+ CellEditorCommon {
8
11
  placeholder?: string;
9
12
  width?: string | number;
10
13
  defaultValue: string;
11
14
  helpText?: string;
12
15
  }
13
16
 
14
- export const GridFormSubComponentTextInput = (props: GridFormSubComponentTextInputProps): JSX.Element => {
15
- const { value, setValue, setValid, triggerSave } = useContext(GridSubComponentContext);
17
+ export const GridFormSubComponentTextInput = <RowType extends GridBaseRow>(
18
+ props: GridFormSubComponentTextInputProps<RowType>,
19
+ ): JSX.Element => {
20
+ const { value, setValue, setValid, triggerSave, data } = useContext(GridSubComponentContext);
16
21
 
17
22
  const helpText = props.helpText ?? "Press enter or tab to save";
18
23
 
@@ -21,7 +26,7 @@ export const GridFormSubComponentTextInput = (props: GridFormSubComponentTextInp
21
26
  if (value == null) setValue(props.defaultValue);
22
27
  }, [props.defaultValue, setValue, value]);
23
28
 
24
- const invalid = useCallback(() => TextInputValidator(props, value), [props, value]);
29
+ const invalid = useCallback(() => TextInputValidator(props, value, data), [data, props, value]);
25
30
 
26
31
  useEffect(() => {
27
32
  setValid(value != null && invalid() == null);
@@ -42,9 +47,9 @@ export const GridFormSubComponentTextInput = (props: GridFormSubComponentTextInp
42
47
  }}
43
48
  onKeyUp={(e) => {
44
49
  if (e.key === "Tab") {
45
- !e.shiftKey && triggerSave().then();
46
50
  e.preventDefault();
47
51
  e.stopPropagation();
52
+ !e.shiftKey && triggerSave().then();
48
53
  } else if (e.key === "Enter") {
49
54
  triggerSave().then();
50
55
  e.preventDefault();
@@ -6,7 +6,9 @@ import { CellEditorCommon } from "../GridCell";
6
6
  import { useGridPopoverContext } from "../../contexts/GridPopoverContext";
7
7
  import { TextInputValidator, TextInputValidatorProps } from "../../utils/textValidator";
8
8
 
9
- export interface GridFormTextAreaProps<RowType extends GridBaseRow> extends TextInputValidatorProps, CellEditorCommon {
9
+ export interface GridFormTextAreaProps<RowType extends GridBaseRow>
10
+ extends TextInputValidatorProps<RowType>,
11
+ CellEditorCommon {
10
12
  placeholder?: string;
11
13
  width?: string | number;
12
14
  onSave?: (selectedRows: RowType[], value: string) => Promise<boolean>;
@@ -14,12 +16,12 @@ export interface GridFormTextAreaProps<RowType extends GridBaseRow> extends Text
14
16
  }
15
17
 
16
18
  export const GridFormTextArea = <RowType extends GridBaseRow>(props: GridFormTextAreaProps<RowType>) => {
17
- const { field, value: initialVale } = useGridPopoverContext<RowType>();
19
+ const { field, value: initialVale, data } = useGridPopoverContext<RowType>();
18
20
  const [value, setValue] = useState(initialVale != null ? `${initialVale}` : "");
19
21
 
20
22
  const helpText = props.helpText ?? "Press tab to save";
21
23
 
22
- const invalid = useCallback(() => TextInputValidator(props, value), [props, value]);
24
+ const invalid = useCallback(() => TextInputValidator(props, value, data), [props, value, data]);
23
25
 
24
26
  const save = useCallback(
25
27
  async (selectedRows: RowType[]): Promise<boolean> => {
@@ -42,7 +44,7 @@ export const GridFormTextArea = <RowType extends GridBaseRow>(props: GridFormTex
42
44
  },
43
45
  [invalid, initialVale, value, props, field],
44
46
  );
45
- const { popoverWrapper, lastInputKeyboardEventHandlers } = useGridPopoverHook({ className: props.className, save });
47
+ const { popoverWrapper, onlyInputKeyboardEventHandlers } = useGridPopoverHook({ className: props.className, save });
46
48
  return popoverWrapper(
47
49
  <div style={{ display: "flex", flexDirection: "row", width: props.width ?? 240 }}>
48
50
  <TextAreaInput
@@ -51,7 +53,7 @@ export const GridFormTextArea = <RowType extends GridBaseRow>(props: GridFormTex
51
53
  error={invalid()}
52
54
  placeholder={props.placeholder}
53
55
  helpText={helpText}
54
- {...lastInputKeyboardEventHandlers}
56
+ {...onlyInputKeyboardEventHandlers}
55
57
  />
56
58
  </div>,
57
59
  );
@@ -6,7 +6,9 @@ import { CellEditorCommon } from "../GridCell";
6
6
  import { useGridPopoverContext } from "../../contexts/GridPopoverContext";
7
7
  import { TextInputValidator, TextInputValidatorProps } from "../../utils/textValidator";
8
8
 
9
- export interface GridFormTextInputProps<RowType extends GridBaseRow> extends TextInputValidatorProps, CellEditorCommon {
9
+ export interface GridFormTextInputProps<RowType extends GridBaseRow>
10
+ extends TextInputValidatorProps<RowType>,
11
+ CellEditorCommon {
10
12
  placeholder?: string;
11
13
  units?: string;
12
14
  width?: string | number;
@@ -15,14 +17,14 @@ export interface GridFormTextInputProps<RowType extends GridBaseRow> extends Tex
15
17
  }
16
18
 
17
19
  export const GridFormTextInput = <RowType extends GridBaseRow>(props: GridFormTextInputProps<RowType>) => {
18
- const { field, value: initialVale } = useGridPopoverContext<RowType>();
20
+ const { field, value: initialVale, data } = useGridPopoverContext<RowType>();
19
21
 
20
22
  const helpText = props.helpText ?? "Press enter or tab to save";
21
23
 
22
24
  const initValue = initialVale == null ? "" : `${initialVale}`;
23
25
  const [value, setValue] = useState(initValue);
24
26
 
25
- const invalid = useCallback(() => TextInputValidator(props, value), [props, value]);
27
+ const invalid = useCallback(() => TextInputValidator<RowType>(props, value, data), [data, props, value]);
26
28
 
27
29
  const save = useCallback(
28
30
  async (selectedRows: RowType[]): Promise<boolean> => {
@@ -45,7 +47,7 @@ export const GridFormTextInput = <RowType extends GridBaseRow>(props: GridFormTe
45
47
  },
46
48
  [invalid, value, initValue, props, field],
47
49
  );
48
- const { popoverWrapper, lastInputKeyboardEventHandlers } = useGridPopoverHook({ className: props.className, save });
50
+ const { popoverWrapper, onlyInputKeyboardEventHandlers } = useGridPopoverHook({ className: props.className, save });
49
51
 
50
52
  return popoverWrapper(
51
53
  <div style={{ display: "flex", flexDirection: "row", width: props.width ?? 240 }} className={"FormTest"}>
@@ -56,7 +58,7 @@ export const GridFormTextInput = <RowType extends GridBaseRow>(props: GridFormTe
56
58
  formatted={props.units}
57
59
  style={{ width: "100%" }}
58
60
  placeholder={props.placeholder}
59
- {...lastInputKeyboardEventHandlers}
61
+ {...onlyInputKeyboardEventHandlers}
60
62
  helpText={helpText}
61
63
  />
62
64
  </div>,
@@ -2,6 +2,7 @@ import { createContext } from "react";
2
2
 
3
3
  export interface GridSubComponentContextType {
4
4
  value: any;
5
+ data: any;
5
6
  setValue: (value: string) => void;
6
7
  setValid: (valid: boolean) => void;
7
8
  triggerSave: () => Promise<void>;
@@ -9,6 +10,7 @@ export interface GridSubComponentContextType {
9
10
 
10
11
  export const GridSubComponentContext = createContext<GridSubComponentContextType>({
11
12
  value: "GridSubComponentContext value no context",
13
+ data: {},
12
14
  setValue: () => {
13
15
  console.error("GridSubComponentContext setValue no context");
14
16
  },
@@ -1,10 +1,16 @@
1
- export interface TextInputValidatorProps {
1
+ import { GridBaseRow } from "../components/Grid";
2
+
3
+ export interface TextInputValidatorProps<RowType extends GridBaseRow> {
2
4
  required?: boolean;
3
5
  maxLength?: number;
4
- validate?: (value: string) => string | null;
6
+ validate?: (value: string, data: RowType) => string | null;
5
7
  }
6
8
 
7
- export const TextInputValidator = (props: TextInputValidatorProps, value: string | null) => {
9
+ export const TextInputValidator = <RowType extends GridBaseRow>(
10
+ props: TextInputValidatorProps<RowType>,
11
+ value: string | null,
12
+ data: RowType,
13
+ ) => {
8
14
  if (value == null) return null;
9
15
 
10
16
  // This can happen because subcomponent is invoked without type safety
@@ -18,7 +24,7 @@ export const TextInputValidator = (props: TextInputValidatorProps, value: string
18
24
  return `Text must be no longer than ${props.maxLength} characters`;
19
25
  }
20
26
  if (props.validate) {
21
- return props.validate(value);
27
+ return props.validate(value, data);
22
28
  }
23
29
  return null;
24
30
  };