@gridsuite/commons-ui 0.165.0 → 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.
- package/dist/hooks/use-unique-name-validation.js +18 -7
- package/dist/translations/en/businessErrorsEn.d.ts +7 -0
- package/dist/translations/en/businessErrorsEn.js +8 -1
- package/dist/translations/fr/businessErrorsFr.d.ts +7 -0
- package/dist/translations/fr/businessErrorsFr.js +8 -1
- package/dist/utils/ts-utils.d.ts +1 -1
- package/dist/utils/ts-utils.js +13 -16
- package/dist/utils/types/types.d.ts +3 -3
- package/package.json +1 -1
|
@@ -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, {
|
|
@@ -67,4 +67,11 @@ export declare const businessErrorsEn: {
|
|
|
67
67
|
'dynamicSimulation.mappingNotLastRuleWithEmptyFilterError': string;
|
|
68
68
|
'sensitivityAnalysis.tooManyFactors': string;
|
|
69
69
|
'pccMin.missingFilter': string;
|
|
70
|
+
'diagram.invalidEquipmentType': string;
|
|
71
|
+
'diagram.invalidSubstationLayout': string;
|
|
72
|
+
'diagram.invalidDisplayMode': string;
|
|
73
|
+
'diagram.maxVoltageLevelDisplayed': string;
|
|
74
|
+
'diagram.equipmentNotFound': string;
|
|
75
|
+
'diagram.noConfiguredPosition': string;
|
|
76
|
+
'diagram.noVoltageLevelFound': string;
|
|
70
77
|
};
|
|
@@ -60,7 +60,14 @@ const businessErrorsEn = {
|
|
|
60
60
|
"dynamicSimulation.mappingNotProvided": "Dynamic simulation mapping not provided.",
|
|
61
61
|
"dynamicSimulation.mappingNotLastRuleWithEmptyFilterError": "Only last rule can have empty filter: type {equipmentType}, rule index {index}.",
|
|
62
62
|
"sensitivityAnalysis.tooManyFactors": "Too many factors to run sensitivity analysis: {resultCount} results (limit: {resultCountLimit}) and {variableCount} variables (limit: {variableCountLimit}).",
|
|
63
|
-
"pccMin.missingFilter": "The configuration contains one filter that has been deleted."
|
|
63
|
+
"pccMin.missingFilter": "The configuration contains one filter that has been deleted.",
|
|
64
|
+
"diagram.invalidEquipmentType": "The equipment {id} of type {equipmentType} is not a substation or voltage level in given network",
|
|
65
|
+
"diagram.invalidSubstationLayout": "Given substation layout {substationLayout} doesn't exist",
|
|
66
|
+
"diagram.invalidDisplayMode": "Given sld display mode {sldDisplayMode} doesn't exist",
|
|
67
|
+
"diagram.maxVoltageLevelDisplayed": "You need to reduce the number of voltage levels to be displayed in the network area diagram (current {nbVoltageLevels}, maximum {maxVoltageLevels})",
|
|
68
|
+
"diagram.equipmentNotFound": "Voltage level or substation {id} not found",
|
|
69
|
+
"diagram.noConfiguredPosition": "No configured position found",
|
|
70
|
+
"diagram.noVoltageLevelFound": "No voltage level found for this network area diagram"
|
|
64
71
|
};
|
|
65
72
|
export {
|
|
66
73
|
businessErrorsEn
|
|
@@ -67,4 +67,11 @@ export declare const businessErrorsFr: {
|
|
|
67
67
|
'dynamicSimulation.mappingNotLastRuleWithEmptyFilterError': string;
|
|
68
68
|
'sensitivityAnalysis.tooManyFactors': string;
|
|
69
69
|
'pccMin.missingFilter': string;
|
|
70
|
+
'diagram.invalidEquipmentType': string;
|
|
71
|
+
'diagram.invalidSubstationLayout': string;
|
|
72
|
+
'diagram.invalidDisplayMode': string;
|
|
73
|
+
'diagram.maxVoltageLevelDisplayed': string;
|
|
74
|
+
'diagram.equipmentNotFound': string;
|
|
75
|
+
'diagram.noConfiguredPosition': string;
|
|
76
|
+
'diagram.noVoltageLevelFound': string;
|
|
70
77
|
};
|
|
@@ -60,7 +60,14 @@ const businessErrorsFr = {
|
|
|
60
60
|
"dynamicSimulation.mappingNotProvided": "Mapping pour la simulation dynamique non fourni.",
|
|
61
61
|
"dynamicSimulation.mappingNotLastRuleWithEmptyFilterError": "Seule la dernière règle peut avoir un filtre vide : type {equipmentType}, indice de la règle : {index}.",
|
|
62
62
|
"sensitivityAnalysis.tooManyFactors": "Trop de facteurs pour exécuter l’analyse de sensibilité : {resultCount} résultats (limite : {resultCountLimit}) et {variableCount} variables (limite : {variableCountLimit}).",
|
|
63
|
-
"pccMin.missingFilter": "La configuration contient un filtre qui a été supprimé."
|
|
63
|
+
"pccMin.missingFilter": "La configuration contient un filtre qui a été supprimé.",
|
|
64
|
+
"diagram.invalidEquipmentType": "L'équipement {id} de type {equipmentType} n'est pas un site ou poste dans le réseau courant",
|
|
65
|
+
"diagram.invalidSubstationLayout": "Le mode d'affichage de site {substationLayout} n'existe pas",
|
|
66
|
+
"diagram.invalidDisplayMode": "Le mode d'affichage de schéma unifilaire {sldDisplayMode} n'existe pas",
|
|
67
|
+
"diagram.maxVoltageLevelDisplayed": "Vous devez réduire le nombre de postes à afficher dans l'image nodale de zone (nombre actuel {nbVoltageLevels}, nombre maximum {maxVoltageLevels})",
|
|
68
|
+
"diagram.equipmentNotFound": "Poste ou site {id} non trouvé",
|
|
69
|
+
"diagram.noConfiguredPosition": "Aucune position configurée trouvée",
|
|
70
|
+
"diagram.noVoltageLevelFound": "Aucun poste trouvé pour cette image nodale de zone"
|
|
64
71
|
};
|
|
65
72
|
export {
|
|
66
73
|
businessErrorsFr
|
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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { MessageDescriptor, PrimitiveType } from 'react-intl';
|
|
3
3
|
import { ElementType } from './elementType';
|
|
4
4
|
export type Input = string | number;
|
|
5
5
|
export type ElementAttributes = {
|
|
@@ -61,8 +61,8 @@ export declare enum ArrayAction {
|
|
|
61
61
|
ADD = "ADD",
|
|
62
62
|
REMOVE = "REMOVE"
|
|
63
63
|
}
|
|
64
|
-
export type FormatValues =
|
|
64
|
+
export type FormatValues = Record<string, PrimitiveType>;
|
|
65
65
|
export type ErrorMessageDescriptor = {
|
|
66
|
-
descriptor:
|
|
66
|
+
descriptor: MessageDescriptor;
|
|
67
67
|
values?: FormatValues;
|
|
68
68
|
};
|