@linzjs/step-ag-grid 4.0.1 → 4.0.3
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/dist/index.js +89 -59
- package/dist/index.js.map +1 -1
- package/dist/src/components/GridPopoverHook.d.ts +1 -0
- package/dist/src/components/gridForm/GridFormSubComponentTextArea.d.ts +3 -2
- package/dist/src/components/gridForm/GridFormSubComponentTextInput.d.ts +3 -2
- package/dist/src/components/gridForm/GridFormTextArea.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormTextInput.d.ts +1 -1
- package/dist/src/contexts/GridSubComponentContext.d.ts +1 -0
- package/dist/src/utils/textValidator.d.ts +4 -3
- package/dist/step-ag-grid.esm.js +89 -59
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/GridPopoverHook.tsx +24 -4
- package/src/components/gridForm/GridFormDropDown.tsx +16 -5
- package/src/components/gridForm/GridFormEditBearing.tsx +15 -6
- package/src/components/gridForm/GridFormMultiSelect.tsx +2 -1
- package/src/components/gridForm/GridFormPopoverMenu.tsx +2 -1
- package/src/components/gridForm/GridFormSubComponentTextArea.tsx +9 -4
- package/src/components/gridForm/GridFormSubComponentTextInput.tsx +9 -4
- package/src/components/gridForm/GridFormTextArea.tsx +11 -7
- package/src/components/gridForm/GridFormTextInput.tsx +16 -7
- package/src/contexts/GridSubComponentContext.ts +2 -0
- package/src/stories/grid/FormTest.tsx +8 -5
- package/src/stories/grid/GridPopoutBearing.stories.tsx +3 -2
- package/src/utils/bearing.ts +1 -1
- package/src/utils/textValidator.ts +10 -4
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import { MenuCloseEvent } from "../react-menu3/types";
|
|
|
7
7
|
|
|
8
8
|
export interface GridPopoverHookProps<RowType> {
|
|
9
9
|
className: string | undefined;
|
|
10
|
+
invalid?: () => Promise<boolean | string | null> | boolean | string | null;
|
|
10
11
|
save?: (selectedRows: RowType[]) => Promise<boolean>;
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -22,12 +23,25 @@ export const useGridPopoverHook = <RowType extends GridBaseRow>(props: GridPopov
|
|
|
22
23
|
|
|
23
24
|
const triggerSave = useCallback(
|
|
24
25
|
async (reason?: string) => {
|
|
25
|
-
if (reason == "cancel"
|
|
26
|
-
setOpen(false);
|
|
26
|
+
if (reason == "cancel") {
|
|
27
27
|
stopEditing();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (props.invalid && props.invalid()) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!props.save) {
|
|
35
|
+
stopEditing();
|
|
36
|
+
} else if (props.save) {
|
|
37
|
+
// forms that don't provide an invalid fn must wait until they have saved to close
|
|
38
|
+
if (props.invalid) stopEditing();
|
|
39
|
+
if (await updateValue(props.save)) {
|
|
40
|
+
if (!props.invalid) stopEditing();
|
|
41
|
+
}
|
|
28
42
|
}
|
|
29
43
|
},
|
|
30
|
-
[props
|
|
44
|
+
[props, stopEditing, updateValue],
|
|
31
45
|
);
|
|
32
46
|
|
|
33
47
|
const onlyInputKeyboardEventHandlers: {
|
|
@@ -139,7 +153,13 @@ export const useGridPopoverHook = <RowType extends GridBaseRow>(props: GridPopov
|
|
|
139
153
|
/>
|
|
140
154
|
)}
|
|
141
155
|
{children}
|
|
142
|
-
<button
|
|
156
|
+
<button
|
|
157
|
+
ref={saveButtonRef}
|
|
158
|
+
onClick={() => {
|
|
159
|
+
triggerSave().then();
|
|
160
|
+
}}
|
|
161
|
+
style={{ display: "none" }}
|
|
162
|
+
/>
|
|
143
163
|
</ControlledMenu>
|
|
144
164
|
)}
|
|
145
165
|
</>
|
|
@@ -64,20 +64,23 @@ 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
|
+
// Save triggers during async action processing which triggers another selectItem(), this ref blocks that
|
|
71
|
+
const hasSubmitted = useRef(false);
|
|
70
72
|
const [filter, setFilter] = useState("");
|
|
71
73
|
const [filteredValues, setFilteredValues] = useState<any[]>([]);
|
|
72
74
|
const optionsInitialising = useRef(false);
|
|
73
75
|
const [options, setOptions] = useState<FinalSelectOption<ValueType>[] | null>(null);
|
|
74
76
|
const subComponentIsValid = useRef(false);
|
|
75
77
|
const [subSelectedValue, setSubSelectedValue] = useState<any>();
|
|
76
|
-
const [selectedSubComponent, setSelectedSubComponent] = useState<any>();
|
|
78
|
+
const [selectedSubComponent, setSelectedSubComponent] = useState<FinalSelectOption<any> | null>(null);
|
|
77
79
|
|
|
78
80
|
const selectItemHandler = useCallback(
|
|
79
81
|
async (value: ValueType, subComponentValue?: ValueType): Promise<boolean> => {
|
|
80
|
-
if (subComponentValue !== undefined && !subComponentIsValid.current) return false;
|
|
82
|
+
if (hasSubmitted.current || (subComponentValue !== undefined && !subComponentIsValid.current)) return false;
|
|
83
|
+
hasSubmitted.current = true;
|
|
81
84
|
|
|
82
85
|
return updateValue(async (selectedRows) => {
|
|
83
86
|
const hasChanged = selectedRows.some((row) => row[field as keyof RowType] !== value);
|
|
@@ -196,12 +199,16 @@ export const GridFormDropDown = <RowType extends GridBaseRow, ValueType>(
|
|
|
196
199
|
const save = useCallback(async () => {
|
|
197
200
|
// Handler for sub-selected value
|
|
198
201
|
if (!selectedSubComponent) return true;
|
|
199
|
-
if (!subComponentIsValid.current) return false;
|
|
202
|
+
if (selectedSubComponent.subComponent && !subComponentIsValid.current) return false;
|
|
200
203
|
await selectItemHandler(selectedSubComponent.value as ValueType, subSelectedValue);
|
|
201
204
|
return true;
|
|
202
205
|
}, [selectItemHandler, selectedSubComponent, subSelectedValue]);
|
|
203
206
|
|
|
204
|
-
const { popoverWrapper } = useGridPopoverHook({
|
|
207
|
+
const { popoverWrapper } = useGridPopoverHook({
|
|
208
|
+
className: props.className,
|
|
209
|
+
invalid: () => !!(selectedSubComponent && !subComponentIsValid.current),
|
|
210
|
+
save,
|
|
211
|
+
});
|
|
205
212
|
return popoverWrapper(
|
|
206
213
|
<>
|
|
207
214
|
{props.filtered && (
|
|
@@ -247,9 +254,11 @@ export const GridFormDropDown = <RowType extends GridBaseRow, ValueType>(
|
|
|
247
254
|
onClick={(e: ClickEvent) => {
|
|
248
255
|
if (item.subComponent) {
|
|
249
256
|
if (selectedSubComponent === item) {
|
|
257
|
+
// toggle selection off
|
|
250
258
|
setSelectedSubComponent(null);
|
|
251
259
|
subComponentIsValid.current = true;
|
|
252
260
|
} else {
|
|
261
|
+
// toggle selection on
|
|
253
262
|
setSelectedSubComponent(item);
|
|
254
263
|
}
|
|
255
264
|
e.keepOpen = true;
|
|
@@ -259,6 +268,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow, ValueType>(
|
|
|
259
268
|
}}
|
|
260
269
|
>
|
|
261
270
|
{item.label ?? (item.value == null ? `<${item.value}>` : `${item.value}`)}
|
|
271
|
+
{item.subComponent ? "..." : ""}
|
|
262
272
|
</MenuItem>
|
|
263
273
|
|
|
264
274
|
{item.subComponent && selectedSubComponent === item && (
|
|
@@ -266,6 +276,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow, ValueType>(
|
|
|
266
276
|
{(ref: MenuInstance) => (
|
|
267
277
|
<GridSubComponentContext.Provider
|
|
268
278
|
value={{
|
|
279
|
+
data,
|
|
269
280
|
value: subSelectedValue,
|
|
270
281
|
setValue: (value: any) => {
|
|
271
282
|
setSubSelectedValue(value);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../../styles/GridFormEditBearing.scss";
|
|
2
2
|
|
|
3
|
-
import { useCallback, useState } from "react";
|
|
3
|
+
import { useCallback, useMemo, useState } from "react";
|
|
4
4
|
import { GridBaseRow } from "../Grid";
|
|
5
5
|
import { TextInputFormatted } from "../../lui/TextInputFormatted";
|
|
6
6
|
import { bearingNumberParser, bearingStringValidator, convertDDToDMS } from "../../utils/bearing";
|
|
@@ -17,14 +17,21 @@ export interface GridFormEditBearingProps<RowType extends GridBaseRow> extends C
|
|
|
17
17
|
export const GridFormEditBearing = <RowType extends GridBaseRow>(props: GridFormEditBearingProps<RowType>) => {
|
|
18
18
|
const { field, value: initialValue } = useGridPopoverContext<RowType>();
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
// This clears out any scientific precision
|
|
21
|
+
const defaultValue = useMemo(
|
|
22
|
+
() => (initialValue == null ? "" : parseFloat(parseFloat(initialValue).toFixed(10)).toString()),
|
|
23
|
+
[initialValue],
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const [value, setValue] = useState<string>(defaultValue);
|
|
27
|
+
|
|
28
|
+
const invalid = useCallback(() => bearingStringValidator(value, props.range), [props.range, value]);
|
|
21
29
|
|
|
22
30
|
const save = useCallback(
|
|
23
31
|
async (selectedRows: RowType[]): Promise<boolean> => {
|
|
24
|
-
if (bearingStringValidator(value)) return false;
|
|
25
32
|
const parsedValue = bearingNumberParser(value);
|
|
26
33
|
// Value didn't change so don't save just cancel
|
|
27
|
-
if (parsedValue ===
|
|
34
|
+
if (parsedValue === bearingNumberParser(defaultValue)) {
|
|
28
35
|
return true;
|
|
29
36
|
}
|
|
30
37
|
|
|
@@ -41,17 +48,18 @@ export const GridFormEditBearing = <RowType extends GridBaseRow>(props: GridForm
|
|
|
41
48
|
}
|
|
42
49
|
return true;
|
|
43
50
|
},
|
|
44
|
-
[
|
|
51
|
+
[defaultValue, field, props, value],
|
|
45
52
|
);
|
|
46
53
|
const { popoverWrapper, onlyInputKeyboardEventHandlers } = useGridPopoverHook({
|
|
47
54
|
className: props.className,
|
|
55
|
+
invalid,
|
|
48
56
|
save,
|
|
49
57
|
});
|
|
50
58
|
|
|
51
59
|
return popoverWrapper(
|
|
52
60
|
<div className={"GridFormEditBearing-input Grid-popoverContainer"}>
|
|
53
61
|
<TextInputFormatted
|
|
54
|
-
value={
|
|
62
|
+
value={defaultValue}
|
|
55
63
|
onChange={(e) => {
|
|
56
64
|
setValue(e.target.value.trim());
|
|
57
65
|
}}
|
|
@@ -60,6 +68,7 @@ export const GridFormEditBearing = <RowType extends GridBaseRow>(props: GridForm
|
|
|
60
68
|
{...onlyInputKeyboardEventHandlers}
|
|
61
69
|
formatted={bearingStringValidator(value, props.range) ? "?" : convertDDToDMS(bearingNumberParser(value))}
|
|
62
70
|
error={bearingStringValidator(value, props.range)}
|
|
71
|
+
helpText={"Press enter or tab to save"}
|
|
63
72
|
/>
|
|
64
73
|
</div>,
|
|
65
74
|
);
|
|
@@ -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
|
|
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 =
|
|
17
|
-
|
|
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);
|
|
@@ -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
|
|
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 =
|
|
15
|
-
|
|
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);
|
|
@@ -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>
|
|
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,17 +16,15 @@ 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> => {
|
|
26
|
-
if (invalid()) return false;
|
|
27
|
-
|
|
28
28
|
if (initialVale === (value ?? "")) return true;
|
|
29
29
|
|
|
30
30
|
if (props.onSave) {
|
|
@@ -40,9 +40,13 @@ export const GridFormTextArea = <RowType extends GridBaseRow>(props: GridFormTex
|
|
|
40
40
|
});
|
|
41
41
|
return true;
|
|
42
42
|
},
|
|
43
|
-
[
|
|
43
|
+
[initialVale, value, props, field],
|
|
44
44
|
);
|
|
45
|
-
const { popoverWrapper, onlyInputKeyboardEventHandlers } = useGridPopoverHook({
|
|
45
|
+
const { popoverWrapper, onlyInputKeyboardEventHandlers } = useGridPopoverHook({
|
|
46
|
+
className: props.className,
|
|
47
|
+
invalid,
|
|
48
|
+
save,
|
|
49
|
+
});
|
|
46
50
|
return popoverWrapper(
|
|
47
51
|
<div style={{ display: "flex", flexDirection: "row", width: props.width ?? 240 }}>
|
|
48
52
|
<TextAreaInput
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { useCallback, useState } from "react";
|
|
1
|
+
import { useCallback, useContext, useMemo, useState } from "react";
|
|
2
2
|
import { TextInputFormatted } from "../../lui/TextInputFormatted";
|
|
3
3
|
import { useGridPopoverHook } from "../GridPopoverHook";
|
|
4
4
|
import { GridBaseRow } from "../Grid";
|
|
5
5
|
import { CellEditorCommon } from "../GridCell";
|
|
6
6
|
import { useGridPopoverContext } from "../../contexts/GridPopoverContext";
|
|
7
7
|
import { TextInputValidator, TextInputValidatorProps } from "../../utils/textValidator";
|
|
8
|
+
import { GridContext } from "../../contexts/GridContext";
|
|
8
9
|
|
|
9
|
-
export interface GridFormTextInputProps<RowType extends GridBaseRow>
|
|
10
|
+
export interface GridFormTextInputProps<RowType extends GridBaseRow>
|
|
11
|
+
extends TextInputValidatorProps<RowType>,
|
|
12
|
+
CellEditorCommon {
|
|
10
13
|
placeholder?: string;
|
|
11
14
|
units?: string;
|
|
12
15
|
width?: string | number;
|
|
@@ -15,18 +18,20 @@ export interface GridFormTextInputProps<RowType extends GridBaseRow> extends Tex
|
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export const GridFormTextInput = <RowType extends GridBaseRow>(props: GridFormTextInputProps<RowType>) => {
|
|
18
|
-
const {
|
|
21
|
+
const { stopEditing } = useContext(GridContext);
|
|
22
|
+
const { field, value: initialVale, data } = useGridPopoverContext<RowType>();
|
|
19
23
|
|
|
20
24
|
const helpText = props.helpText ?? "Press enter or tab to save";
|
|
21
25
|
|
|
22
|
-
const initValue = initialVale == null ? "" : `${initialVale}
|
|
26
|
+
const initValue = useMemo(() => (initialVale == null ? "" : `${initialVale}`), [initialVale]);
|
|
23
27
|
const [value, setValue] = useState(initValue);
|
|
24
28
|
|
|
25
|
-
const invalid = useCallback(() => TextInputValidator(props, value), [props, value]);
|
|
29
|
+
const invalid = useCallback(() => TextInputValidator<RowType>(props, value, data), [data, props, value]);
|
|
26
30
|
|
|
27
31
|
const save = useCallback(
|
|
28
32
|
async (selectedRows: RowType[]): Promise<boolean> => {
|
|
29
33
|
if (invalid()) return false;
|
|
34
|
+
stopEditing();
|
|
30
35
|
const trimmedValue = value.trim();
|
|
31
36
|
if (initValue === trimmedValue) return true;
|
|
32
37
|
|
|
@@ -43,9 +48,13 @@ export const GridFormTextInput = <RowType extends GridBaseRow>(props: GridFormTe
|
|
|
43
48
|
});
|
|
44
49
|
return true;
|
|
45
50
|
},
|
|
46
|
-
[invalid, value, initValue, props, field],
|
|
51
|
+
[invalid, stopEditing, value, initValue, props, field],
|
|
47
52
|
);
|
|
48
|
-
const { popoverWrapper, onlyInputKeyboardEventHandlers } = useGridPopoverHook({
|
|
53
|
+
const { popoverWrapper, onlyInputKeyboardEventHandlers } = useGridPopoverHook({
|
|
54
|
+
className: props.className,
|
|
55
|
+
invalid,
|
|
56
|
+
save,
|
|
57
|
+
});
|
|
49
58
|
|
|
50
59
|
return popoverWrapper(
|
|
51
60
|
<div style={{ display: "flex", flexDirection: "row", width: props.width ?? 240 }} className={"FormTest"}>
|
|
@@ -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
|
},
|
|
@@ -39,10 +39,12 @@ export const FormTest = (props: CellEditorCommon): JSX.Element => {
|
|
|
39
39
|
|
|
40
40
|
const [showModal, setShowModal] = useState<boolean>(false);
|
|
41
41
|
|
|
42
|
-
const { popoverWrapper, firstInputKeyboardEventHandlers, lastInputKeyboardEventHandlers } =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const { popoverWrapper, firstInputKeyboardEventHandlers, lastInputKeyboardEventHandlers, triggerSave } =
|
|
43
|
+
useGridPopoverHook({
|
|
44
|
+
className: props.className,
|
|
45
|
+
invalid: () => numba.length < 3,
|
|
46
|
+
save,
|
|
47
|
+
});
|
|
46
48
|
|
|
47
49
|
return popoverWrapper(
|
|
48
50
|
<>
|
|
@@ -50,7 +52,7 @@ export const FormTest = (props: CellEditorCommon): JSX.Element => {
|
|
|
50
52
|
<LuiAlertModal
|
|
51
53
|
data-testid="WarningAlertWithButtons-modal"
|
|
52
54
|
level="warning"
|
|
53
|
-
// If panel is popped out, append modal to
|
|
55
|
+
// If panel is popped out, append modal to popped out window DOM, otherwise use default
|
|
54
56
|
//appendToElement={() => (poppedOut && popoutElement) || document.body}
|
|
55
57
|
>
|
|
56
58
|
<h2>Header</h2>
|
|
@@ -73,6 +75,7 @@ export const FormTest = (props: CellEditorCommon): JSX.Element => {
|
|
|
73
75
|
level="primary"
|
|
74
76
|
onClick={() => {
|
|
75
77
|
setShowModal(false);
|
|
78
|
+
triggerSave().then();
|
|
76
79
|
}}
|
|
77
80
|
data-testid="WarningAlertWithButtons-ok"
|
|
78
81
|
>
|
|
@@ -37,7 +37,7 @@ export default {
|
|
|
37
37
|
|
|
38
38
|
interface ITestRow {
|
|
39
39
|
id: number;
|
|
40
|
-
bearing1: number | null;
|
|
40
|
+
bearing1: string | number | null;
|
|
41
41
|
bearingCorrection: number | null;
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -85,8 +85,9 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
85
85
|
|
|
86
86
|
const [rowData] = useState([
|
|
87
87
|
{ id: 1000, bearing1: 1.234, bearingCorrection: 90 },
|
|
88
|
-
{ id: 1001, bearing1:
|
|
88
|
+
{ id: 1001, bearing1: "0E-12", bearingCorrection: 240 },
|
|
89
89
|
{ id: 1002, bearing1: null, bearingCorrection: 355.1 },
|
|
90
|
+
{ id: 1003, bearing1: null, bearingCorrection: 0 },
|
|
90
91
|
] as ITestRow[]);
|
|
91
92
|
|
|
92
93
|
return (
|
package/src/utils/bearing.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ValueFormatterParams } from "ag-grid-community/dist/lib/entities/colDef";
|
|
2
2
|
|
|
3
3
|
export const bearingValueFormatter = (params: ValueFormatterParams): string => {
|
|
4
|
-
const value = params.value;
|
|
4
|
+
const value = typeof params.value == "string" ? parseFloat(params.value) : params.value;
|
|
5
5
|
if (value == null) {
|
|
6
6
|
return "-";
|
|
7
7
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
|
|
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 =
|
|
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
|
};
|