@gridsuite/commons-ui 0.165.1 → 0.165.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useEffect } from "react";
|
|
1
|
+
import { useRef, useCallback, useEffect } from "react";
|
|
2
2
|
import { useFormContext, useController } from "react-hook-form";
|
|
3
3
|
import { FieldConstants } from "../utils/constants/fieldConstants.js";
|
|
4
4
|
import "../utils/conversionUtils.js";
|
|
@@ -33,6 +33,7 @@ function useUniqueNameValidation({
|
|
|
33
33
|
});
|
|
34
34
|
const defaultFieldValue = defaultValues?.[name];
|
|
35
35
|
const directory = selectedDirectory || activeDirectory;
|
|
36
|
+
const previousDirectoryRef = useRef(directory);
|
|
36
37
|
const isValidating = errors.root?.isValidating;
|
|
37
38
|
const handleCheckName = useCallback(
|
|
38
39
|
(nameValue) => {
|
|
@@ -62,6 +63,21 @@ function useUniqueNameValidation({
|
|
|
62
63
|
const debouncedHandleCheckName = useDebounce(handleCheckName, 700);
|
|
63
64
|
useEffect(() => {
|
|
64
65
|
const trimmedValue = value.trim();
|
|
66
|
+
const triggerNameValidation = () => {
|
|
67
|
+
clearErrors(name);
|
|
68
|
+
setError("root.isValidating", {
|
|
69
|
+
type: "validate",
|
|
70
|
+
message: "use-unique-name-validation/cantSubmitWhileValidating"
|
|
71
|
+
});
|
|
72
|
+
debouncedHandleCheckName(trimmedValue);
|
|
73
|
+
};
|
|
74
|
+
if (previousDirectoryRef.current !== directory) {
|
|
75
|
+
previousDirectoryRef.current = directory;
|
|
76
|
+
if (directory && trimmedValue) {
|
|
77
|
+
triggerNameValidation();
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
65
81
|
if (selectedDirectory) {
|
|
66
82
|
debouncedHandleCheckName(trimmedValue);
|
|
67
83
|
}
|
|
@@ -77,12 +93,7 @@ function useUniqueNameValidation({
|
|
|
77
93
|
return;
|
|
78
94
|
}
|
|
79
95
|
if (trimmedValue) {
|
|
80
|
-
|
|
81
|
-
setError("root.isValidating", {
|
|
82
|
-
type: "validate",
|
|
83
|
-
message: "use-unique-name-validation/cantSubmitWhileValidating"
|
|
84
|
-
});
|
|
85
|
-
debouncedHandleCheckName(trimmedValue);
|
|
96
|
+
triggerNameValidation();
|
|
86
97
|
} else {
|
|
87
98
|
clearErrors("root.isValidating");
|
|
88
99
|
setError(name, {
|
package/dist/utils/ts-utils.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type DeepNullable<T> = {
|
|
|
12
12
|
};
|
|
13
13
|
export declare function notUndefined<T>(value: T | undefined): value is T;
|
|
14
14
|
export declare function notNull<T>(value: T | null): value is T;
|
|
15
|
-
export declare
|
|
15
|
+
export declare function removeNullFields<T extends Record<string, any>>(data: T): T;
|
|
16
16
|
export declare function parseIntData(val: string | number, defaultValue: string | number): string | number;
|
|
17
17
|
export declare function sanitizeString(val: string | null | undefined): string | null;
|
|
18
18
|
export declare const getIdOrSelf: (e: any) => any;
|
package/dist/utils/ts-utils.js
CHANGED
|
@@ -4,23 +4,20 @@ function notUndefined(value) {
|
|
|
4
4
|
function notNull(value) {
|
|
5
5
|
return value !== null;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const cleaned = removeNullFields(value);
|
|
14
|
-
if (Object.keys(cleaned).length > 0) {
|
|
15
|
-
acc[key] = cleaned;
|
|
7
|
+
function removeNullFields(data) {
|
|
8
|
+
const dataTemp = data;
|
|
9
|
+
if (dataTemp) {
|
|
10
|
+
Object.keys(dataTemp).forEach((key) => {
|
|
11
|
+
if (dataTemp[key] && dataTemp[key] !== null && typeof dataTemp[key] === "object") {
|
|
12
|
+
dataTemp[key] = removeNullFields(dataTemp[key]);
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
return
|
|
23
|
-
}
|
|
14
|
+
if (dataTemp[key] === null) {
|
|
15
|
+
delete dataTemp[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return dataTemp;
|
|
20
|
+
}
|
|
24
21
|
function parseIntData(val, defaultValue) {
|
|
25
22
|
const intValue = Number.parseInt(String(val), 10);
|
|
26
23
|
return Number.isNaN(intValue) ? defaultValue : intValue;
|