From 6de1af676609cc794c3d0f790c9e8709967b40f8 Mon Sep 17 00:00:00 2001 From: achour94 Date: Thu, 19 Mar 2026 08:04:54 +0100 Subject: [PATCH 1/3] Move Voltage Level Modification functionality and related components into commons-ui Signed-off-by: achour94 --- .../voltage-level-modification-dialog.tsx | 181 ++++-------------- .../voltage-level-modification-form.tsx | 171 ----------------- .../voltage-level/voltage-level.type.ts | 23 --- src/services/network-modification-types.ts | 4 - src/services/study/network-modifications.ts | 32 +--- src/translations/en.json | 2 - src/translations/fr.json | 2 - 7 files changed, 52 insertions(+), 363 deletions(-) delete mode 100644 src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-form.tsx diff --git a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx b/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx index 77d6f7eada..707ab7930e 100644 --- a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx @@ -7,34 +7,27 @@ import { ModificationDialog } from '../../../commons/modificationDialog'; import { useCallback, useEffect, useState } from 'react'; -import VoltageLevelModificationForm from './voltage-level-modification-form'; -import { - EQUIPMENT_NAME, - HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, - HIGH_VOLTAGE_LIMIT, - LOW_SHORT_CIRCUIT_CURRENT_LIMIT, - LOW_VOLTAGE_LIMIT, - NOMINAL_V, - SUBSTATION_ID, -} from 'components/utils/field-constants'; -import yup from 'components/utils/yup-config'; -import { yupResolver } from '@hookform/resolvers/yup'; import { convertInputValue, - convertOutputValue, CustomFormProvider, - emptyProperties, + DeepNullable, EquipmentType, EquipmentWithProperties, FieldConstants, FieldType, getConcatenatedProperties, - getPropertiesFromModification, - modificationPropertiesSchema, snackWithFallback, - toModificationProperties, useSnackMessage, + VoltageLevelDto, + VoltageLevelModificationDto, + VoltageLevelModificationForm, + VoltageLevelModificationFormData, + voltageLevelModificationDtoToForm, + voltageLevelModificationEmptyFormData, + voltageLevelModificationFormSchema, + voltageLevelModificationFormToDto, } from '@gridsuite/commons-ui'; +import { yupResolver } from '@hookform/resolvers/yup'; import { useOpenShortWaitFetching } from '../../../commons/handle-modification-form'; import { FORM_LOADING_DELAY } from 'components/network/constants'; import { EQUIPMENT_INFOS_TYPES } from 'components/utils/equipment-types'; @@ -49,21 +42,8 @@ import { CurrentTreeNode } from '../../../../graph/tree-node.type'; type FetchStatusType = (typeof FetchStatus)[keyof typeof FetchStatus]; -interface EditData { - uuid?: UUID; - equipmentId?: string; - equipmentName?: { value: string }; - substationId?: { value: string }; - nominalV?: { value: number }; - lowVoltageLimit?: { value: number }; - highVoltageLimit?: { value: number }; - ipMin?: { value: number }; - ipMax?: { value: number }; - properties?: any; -} - interface VoltageLevelModificationDialogProps { - editData?: EditData; + editData?: VoltageLevelModificationDto; defaultIdValue?: string | null; currentNode: CurrentTreeNode | null; currentRootNetworkUuid: UUID; @@ -73,59 +53,6 @@ interface VoltageLevelModificationDialogProps { [key: string]: any; } -interface VoltageLevelFormData { - [EQUIPMENT_NAME]?: string; - [SUBSTATION_ID]?: string; - [NOMINAL_V]?: number; - [LOW_VOLTAGE_LIMIT]?: number; - [HIGH_VOLTAGE_LIMIT]?: number; - [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]?: number; - [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]?: number; - [FieldConstants.ADDITIONAL_PROPERTIES]?: any; - [key: string]: any; -} - -const emptyFormData = { - [EQUIPMENT_NAME]: '', - [SUBSTATION_ID]: null, - [NOMINAL_V]: null, - [LOW_VOLTAGE_LIMIT]: null, - [HIGH_VOLTAGE_LIMIT]: null, - [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]: null, - [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: null, - ...emptyProperties, -}; - -const formSchema = yup - .object() - .shape({ - [EQUIPMENT_NAME]: yup.string().nullable(), - [SUBSTATION_ID]: yup.string().nullable(), - [NOMINAL_V]: yup.number().nullable().min(0, 'mustBeGreaterOrEqualToZero'), - [LOW_VOLTAGE_LIMIT]: yup - .number() - .nullable() - .min(0, 'mustBeGreaterOrEqualToZero') - .when([HIGH_VOLTAGE_LIMIT], { - is: (highVoltageLimit: number) => highVoltageLimit != null, - then: (schema) => schema.max(yup.ref(HIGH_VOLTAGE_LIMIT), 'voltageLevelNominalVoltageMaxValueError'), - }), - [HIGH_VOLTAGE_LIMIT]: yup.number().nullable().min(0, 'mustBeGreaterOrEqualToZero'), - [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]: yup - .number() - .nullable() - .min(0, 'ShortCircuitCurrentLimitMustBeGreaterOrEqualToZero') - .when([HIGH_SHORT_CIRCUIT_CURRENT_LIMIT], { - is: (highShortCircuitCurrentLimit: number) => highShortCircuitCurrentLimit != null, - then: (schema) => - schema.max(yup.ref(HIGH_SHORT_CIRCUIT_CURRENT_LIMIT), 'ShortCircuitCurrentLimitMinMaxError'), - }), - [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: yup - .number() - .nullable() - .min(0, 'ShortCircuitCurrentLimitMustBeGreaterOrEqualToZero'), - }) - .concat(modificationPropertiesSchema); const VoltageLevelModificationDialog = ({ editData, // contains data when we try to edit an existing hypothesis from the current node's list defaultIdValue, // Used to pre-select an equipmentId when calling this dialog from the network map @@ -139,25 +66,25 @@ const VoltageLevelModificationDialog = ({ const currentNodeUuid = currentNode?.id; const { snackError } = useSnackMessage(); const [selectedId, setSelectedId] = useState(defaultIdValue ?? null); - const [voltageLevelInfos, setVoltageLevelInfos] = useState(null); + const [voltageLevelToModify, setVoltageLevelToModify] = useState(); const [dataFetchStatus, setDataFetchStatus] = useState(FetchStatus.IDLE); - const formMethods = useFormWithDirtyTracking({ - defaultValues: emptyFormData, - resolver: yupResolver(formSchema), + const formMethods = useFormWithDirtyTracking>({ + defaultValues: voltageLevelModificationEmptyFormData, + resolver: yupResolver>(voltageLevelModificationFormSchema), }); const { reset, getValues, subscribe, trigger } = formMethods; useEffect(() => { const callback = subscribe({ - name: [`${HIGH_VOLTAGE_LIMIT}`], + name: [FieldConstants.HIGH_VOLTAGE_LIMIT], formState: { values: true, }, callback: ({ isSubmitted }) => { if (isSubmitted) { - trigger(`${LOW_VOLTAGE_LIMIT}`).then(); + trigger(FieldConstants.LOW_VOLTAGE_LIMIT).then(); } }, }); @@ -166,21 +93,10 @@ const VoltageLevelModificationDialog = ({ useEffect(() => { if (editData) { - if (editData?.equipmentId) { + if (editData.equipmentId) { setSelectedId(editData.equipmentId); } - reset({ - [EQUIPMENT_NAME]: editData?.equipmentName?.value ?? '', - [SUBSTATION_ID]: editData?.substationId?.value ?? null, - [NOMINAL_V]: editData?.nominalV?.value ?? null, - [LOW_VOLTAGE_LIMIT]: editData?.lowVoltageLimit?.value ?? null, - [HIGH_VOLTAGE_LIMIT]: editData?.highVoltageLimit?.value ?? null, - [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]: - convertInputValue(FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, editData?.ipMin?.value) ?? null, - [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]: - convertInputValue(FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, editData?.ipMax?.value) ?? null, - ...getPropertiesFromModification(editData.properties), - }); + reset(voltageLevelModificationDtoToForm(editData)); } }, [editData, reset]); @@ -197,7 +113,7 @@ const VoltageLevelModificationDialog = ({ equipmentId, true ) - .then((voltageLevel: VoltageLevelFormData) => { + .then((voltageLevel: VoltageLevelDto) => { if (voltageLevel) { //We convert values of low short circuit current limit and high short circuit current limit from A to KA if (voltageLevel.identifiableShortCircuit) { @@ -210,16 +126,17 @@ const VoltageLevelModificationDialog = ({ voltageLevel.identifiableShortCircuit?.ipMin ); } - setVoltageLevelInfos(voltageLevel); + setVoltageLevelToModify(voltageLevel); setDataFetchStatus(FetchStatus.SUCCEED); reset( (formValues) => ({ ...formValues, + [FieldConstants.EQUIPMENT_ID]: equipmentId, [FieldConstants.ADDITIONAL_PROPERTIES]: getConcatenatedProperties( voltageLevel as EquipmentWithProperties, getValues ), - [SUBSTATION_ID]: voltageLevel?.substationId, + [FieldConstants.SUBSTATION_ID]: voltageLevel.substationId ?? null, }), { keepDirty: true } ); @@ -227,13 +144,16 @@ const VoltageLevelModificationDialog = ({ }) .catch(() => { setDataFetchStatus(FetchStatus.FAILED); + reset((formValues) => ({ ...formValues, [FieldConstants.EQUIPMENT_ID]: equipmentId }), { + keepDirty: true, + }); if (editData?.equipmentId !== equipmentId) { - setVoltageLevelInfos(null); + setVoltageLevelToModify(undefined); } }); } else { - setVoltageLevelInfos(null); - reset(emptyFormData, { keepDefaultValues: true }); + setVoltageLevelToModify(undefined); + reset(voltageLevelModificationEmptyFormData, { keepDefaultValues: true }); } }, [studyUuid, currentNodeUuid, currentRootNetworkUuid, reset, getValues, editData] @@ -246,36 +166,21 @@ const VoltageLevelModificationDialog = ({ }, [selectedId, onEquipmentIdChange]); const onSubmit = useCallback( - (voltageLevel: VoltageLevelFormData) => { - if (selectedId != null) { - modifyVoltageLevel({ - studyUuid: studyUuid, - nodeUuid: currentNodeUuid as UUID, - modificationUuid: editData?.uuid, - equipmentId: selectedId, - equipmentName: voltageLevel[EQUIPMENT_NAME], - nominalV: voltageLevel[NOMINAL_V], - lowVoltageLimit: voltageLevel[LOW_VOLTAGE_LIMIT], - highVoltageLimit: voltageLevel[HIGH_VOLTAGE_LIMIT], - lowShortCircuitCurrentLimit: convertOutputValue( - FieldType.LOW_SHORT_CIRCUIT_CURRENT_LIMIT, - voltageLevel[LOW_SHORT_CIRCUIT_CURRENT_LIMIT] - ), - highShortCircuitCurrentLimit: convertOutputValue( - FieldType.HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, - voltageLevel[HIGH_SHORT_CIRCUIT_CURRENT_LIMIT] - ), - properties: toModificationProperties(voltageLevel), - }).catch((error: Error) => { - snackWithFallback(snackError, error, { headerId: 'VoltageLevelModificationError' }); - }); - } + (voltageLevel: VoltageLevelModificationFormData) => { + modifyVoltageLevel({ + studyUuid, + nodeUuid: currentNodeUuid as UUID, + modificationUuid: editData?.uuid, + ...voltageLevelModificationFormToDto(voltageLevel), + }).catch((error: Error) => { + snackWithFallback(snackError, error, { headerId: 'VoltageLevelModificationError' }); + }); }, - [editData, studyUuid, currentNodeUuid, selectedId, snackError] + [editData, studyUuid, currentNodeUuid, snackError] ); const clear = useCallback(() => { - reset(emptyFormData); + reset(voltageLevelModificationEmptyFormData); }, [reset]); const open = useOpenShortWaitFetching({ @@ -288,7 +193,7 @@ const VoltageLevelModificationDialog = ({ return ( )} - {selectedId != null && ( - - )} + {selectedId != null && } ); diff --git a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-form.tsx b/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-form.tsx deleted file mode 100644 index da3381b79b..0000000000 --- a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-form.tsx +++ /dev/null @@ -1,171 +0,0 @@ -/** - * Copyright (c) 2023, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import { getObjectId } from 'components/utils/utils'; -import { - EQUIPMENT_NAME, - HIGH_SHORT_CIRCUIT_CURRENT_LIMIT, - HIGH_VOLTAGE_LIMIT, - IDENTIFIABLE_SHORT_CIRCUIT, - LOW_SHORT_CIRCUIT_CURRENT_LIMIT, - LOW_VOLTAGE_LIMIT, - NAME, - NOMINAL_V, - SUBSTATION_ID, -} from 'components/utils/field-constants'; -import { - AutocompleteInput, - FieldConstants, - filledTextField, - FloatInput, - KiloAmpereAdornment, - Properties, - PropertiesForm, - TextInput, - VoltageAdornment, -} from '@gridsuite/commons-ui'; -import { Grid, TextField } from '@mui/material'; -import GridItem from '../../../commons/grid-item'; -import GridSection from '../../../commons/grid-section'; - -interface VoltageLevelFormData { - [NAME]?: string; - [SUBSTATION_ID]?: string; - [NOMINAL_V]?: number; - [LOW_VOLTAGE_LIMIT]?: number; - [HIGH_VOLTAGE_LIMIT]?: number; - [LOW_SHORT_CIRCUIT_CURRENT_LIMIT]?: number; - [HIGH_SHORT_CIRCUIT_CURRENT_LIMIT]?: number; - [IDENTIFIABLE_SHORT_CIRCUIT]?: { ipMin: number; ipMax: number }; - [FieldConstants.ADDITIONAL_PROPERTIES]?: Properties; -} - -interface VoltageLevelModificationFormProps { - voltageLevelInfos: VoltageLevelFormData | null | undefined; - equipmentId: string; -} - -const VoltageLevelModificationForm = ({ voltageLevelInfos, equipmentId }: VoltageLevelModificationFormProps) => { - const voltageLevelIdField = ( - - ); - - const voltageLevelNameField = ( - - ); - - const substationField = ( - (value === null ? '' : value)} - outputTransform={(value) => value} - size={'small'} - formProps={filledTextField} - disabled //TODO to be removed when it is possible to change the substation of a voltage level in the backend (Powsybl) - /> - ); - - const nominalVoltageField = ( - - ); - - const lowVoltageLimitField = ( - - ); - - const highVoltageLimitField = ( - - ); - - const lowShortCircuitCurrentLimitField = ( - - ); - - const highShortCircuitCurrentLimitField = ( - - ); - - return ( - <> - - {voltageLevelIdField} - {voltageLevelNameField} - {substationField} - - - - {nominalVoltageField} - {lowVoltageLimitField} - {highVoltageLimitField} - - - - {lowShortCircuitCurrentLimitField} - {highShortCircuitCurrentLimitField} - - - - ); -}; - -export default VoltageLevelModificationForm; diff --git a/src/components/dialogs/network-modifications/voltage-level/voltage-level.type.ts b/src/components/dialogs/network-modifications/voltage-level/voltage-level.type.ts index bd0b9c0e00..7b71a201a6 100644 --- a/src/components/dialogs/network-modifications/voltage-level/voltage-level.type.ts +++ b/src/components/dialogs/network-modifications/voltage-level/voltage-level.type.ts @@ -5,32 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { SwitchKind } from '@gridsuite/commons-ui'; - export interface VoltageLevelFormInfos { equipmentId: string; equipmentName?: string | null; substationId?: string | null; topologyKind?: string | null; } - -export interface IdentifiableShortCircuitDto { - ipMin: number | null; - ipMax: number | null; -} - -export interface VoltageLevelDto { - id: string; - name: string | null; - topologyKind: string | null; - substationId: string | null; - nominalV: number; - lowVoltageLimit: number | null; - highVoltageLimit: number | null; - busbarCount: number | null; - sectionCount: number | null; - switchKinds: SwitchKind[] | null; - isSymmetrical: boolean | null; - identifiableShortCircuit: IdentifiableShortCircuitDto | null; - properties: Record | null; -} diff --git a/src/services/network-modification-types.ts b/src/services/network-modification-types.ts index 99a2313d68..ba525b5028 100644 --- a/src/services/network-modification-types.ts +++ b/src/services/network-modification-types.ts @@ -368,10 +368,6 @@ export interface VoltageLevelCreationInfo extends VoltageLeveInfo { topologyKind?: string; } -export interface VoltageLeveModificationInfo extends VoltageLeveInfo { - lowShortCircuitCurrentLimit: number | null; - highShortCircuitCurrentLimit: number | null; -} type VariationFilter = { id: string; diff --git a/src/services/study/network-modifications.ts b/src/services/study/network-modifications.ts index 42a385b688..1415b7095c 100644 --- a/src/services/study/network-modifications.ts +++ b/src/services/study/network-modifications.ts @@ -18,6 +18,7 @@ import { toModificationOperation, SubstationCreationDto, SubstationModificationDto, + VoltageLevelModificationDto, } from '@gridsuite/commons-ui'; import { getStudyUrlWithNodeUuid, getStudyUrlWithNodeUuidAndRootNetworkUuid } from './index'; import { EQUIPMENT_TYPES } from '../../components/utils/equipment-types'; @@ -56,7 +57,7 @@ import { Variations, VariationType, VoltageLevelCreationInfo, - VoltageLeveModificationInfo, + VscCreationInfos, VSCModificationInfo, } from '../network-modification-types'; @@ -1241,16 +1242,13 @@ export function createVoltageLevel({ export function modifyVoltageLevel({ studyUuid, nodeUuid, - modificationUuid = undefined, - equipmentId, - equipmentName, - nominalV, - lowVoltageLimit, - highVoltageLimit, - lowShortCircuitCurrentLimit, - highShortCircuitCurrentLimit, - properties, -}: VoltageLeveModificationInfo) { + modificationUuid, + ...dto +}: { + studyUuid: UUID; + nodeUuid: UUID; + modificationUuid?: UUID; +} & VoltageLevelModificationDto) { let modificationUrl = getNetworkModificationUrl(studyUuid, nodeUuid); const isUpdate = !!modificationUuid; @@ -1267,17 +1265,7 @@ export function modifyVoltageLevel({ Accept: 'application/json', 'Content-Type': 'application/json', }, - body: JSON.stringify({ - type: MODIFICATION_TYPES.VOLTAGE_LEVEL_MODIFICATION.type, - equipmentId, - equipmentName: toModificationOperation(equipmentName), - nominalV: toModificationOperation(nominalV), - lowVoltageLimit: toModificationOperation(lowVoltageLimit), - highVoltageLimit: toModificationOperation(highVoltageLimit), - ipMin: toModificationOperation(lowShortCircuitCurrentLimit), - ipMax: toModificationOperation(highShortCircuitCurrentLimit), - properties, - }), + body: JSON.stringify(dto), }); } diff --git a/src/translations/en.json b/src/translations/en.json index a438957e29..e968fac14a 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -866,7 +866,6 @@ "SubstationModificationError": "Error while modifying substation", "CreateVoltageLevel": "Create a voltage level", - "ModifyVoltageLevel": "Modify a voltage level", "Substation": "Substation", "BusBarSections": "Busbar section", "BusBarSectionsReference": "Busbar reference section", @@ -890,7 +889,6 @@ "DISCONNECTOR": "Disconnector", "SameHorizAndVertPos": "At least two bus bar sections have same horizontal and vertical position", "DuplicateId": "Duplicate id", - "VoltageLevelModificationError": "Error while modifying a voltage level", "AddCouplingDeviceError": "Error while creating a coupling device", "BusBarSectionID1": "Bus bar section / bus 1", "BusBarSectionID2": "Bus bar section / bus 2", diff --git a/src/translations/fr.json b/src/translations/fr.json index db11523351..2d1f1fe353 100644 --- a/src/translations/fr.json +++ b/src/translations/fr.json @@ -858,7 +858,6 @@ "SubstationModificationError": "Erreur lors de la modification d'un site", "CreateVoltageLevel": "Créer un poste", - "ModifyVoltageLevel": "Modifier un poste", "Substation": "Site", "BusBarSections": "Section de jeu de barres", "BusBarSectionsReference": "Section de jeu de barres de référence", @@ -882,7 +881,6 @@ "DISCONNECTOR": "Sectionneur", "SameHorizAndVertPos": "Au moins deux SJBs ont les mêmes positions horizontale et verticale", "DuplicateId": "Identifiant non unique", - "VoltageLevelModificationError": "Erreur lors de la modification d'un poste", "AddCouplingDeviceError": "Erreur lors de l'ajout d'un omnibus/couplage", "BusBarSectionID1": "SJB / Nœud 1", "BusBarSectionID2": "SJB / Nœud 2", From f3effeef085082bca029dda4b85d606f076f5135 Mon Sep 17 00:00:00 2001 From: achour94 Date: Fri, 20 Mar 2026 15:10:47 +0100 Subject: [PATCH 2/3] fix lint Signed-off-by: achour94 --- src/services/network-modification-types.ts | 1 - src/services/study/network-modifications.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/services/network-modification-types.ts b/src/services/network-modification-types.ts index 059735e117..9a725cb071 100644 --- a/src/services/network-modification-types.ts +++ b/src/services/network-modification-types.ts @@ -330,7 +330,6 @@ export interface VoltageLevelCreationInfo extends VoltageLeveInfo { topologyKind?: string; } - type VariationFilter = { id: string; name: string; diff --git a/src/services/study/network-modifications.ts b/src/services/study/network-modifications.ts index 4845532e0e..2a966d2192 100644 --- a/src/services/study/network-modifications.ts +++ b/src/services/study/network-modifications.ts @@ -57,7 +57,6 @@ import { Variations, VariationType, VoltageLevelCreationInfo, - VscCreationInfos, VSCModificationInfo, } from '../network-modification-types'; From e259d63796cdafa56bfe4093ab4d26c7ab71b222 Mon Sep 17 00:00:00 2001 From: achour94 Date: Tue, 24 Mar 2026 16:45:24 +0100 Subject: [PATCH 3/3] feat: add hide substation field to voltage level modification form Signed-off-by: achour94 --- .../voltage-level-modification-dialog.tsx | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx b/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx index 707ab7930e..ff2ba0c7ea 100644 --- a/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/modification/voltage-level-modification-dialog.tsx @@ -6,7 +6,7 @@ */ import { ModificationDialog } from '../../../commons/modificationDialog'; -import { useCallback, useEffect, useState } from 'react'; +import { useCallback, useEffect, useMemo, useState } from 'react'; import { convertInputValue, CustomFormProvider, @@ -69,8 +69,16 @@ const VoltageLevelModificationDialog = ({ const [voltageLevelToModify, setVoltageLevelToModify] = useState(); const [dataFetchStatus, setDataFetchStatus] = useState(FetchStatus.IDLE); + const emptyFormData = useMemo( + () => ({ + ...voltageLevelModificationEmptyFormData, + [FieldConstants.HIDE_SUBSTATION_FIELD]: false, + }), + [] + ); + const formMethods = useFormWithDirtyTracking>({ - defaultValues: voltageLevelModificationEmptyFormData, + defaultValues: emptyFormData, resolver: yupResolver>(voltageLevelModificationFormSchema), }); @@ -96,7 +104,7 @@ const VoltageLevelModificationDialog = ({ if (editData.equipmentId) { setSelectedId(editData.equipmentId); } - reset(voltageLevelModificationDtoToForm(editData)); + reset({ ...voltageLevelModificationDtoToForm(editData), [FieldConstants.HIDE_SUBSTATION_FIELD]: false }); } }, [editData, reset]); @@ -153,10 +161,10 @@ const VoltageLevelModificationDialog = ({ }); } else { setVoltageLevelToModify(undefined); - reset(voltageLevelModificationEmptyFormData, { keepDefaultValues: true }); + reset(emptyFormData, { keepDefaultValues: true }); } }, - [studyUuid, currentNodeUuid, currentRootNetworkUuid, reset, getValues, editData] + [studyUuid, currentNodeUuid, currentRootNetworkUuid, reset, getValues, editData?.equipmentId, emptyFormData] ); useEffect(() => { @@ -180,8 +188,8 @@ const VoltageLevelModificationDialog = ({ ); const clear = useCallback(() => { - reset(voltageLevelModificationEmptyFormData); - }, [reset]); + reset(emptyFormData); + }, [emptyFormData, reset]); const open = useOpenShortWaitFetching({ isDataFetched: