From 16dbebd558e882045a572644559c2813b404d282 Mon Sep 17 00:00:00 2001 From: Ghazoua Rehili Date: Thu, 9 Jan 2025 13:51:17 +0100 Subject: [PATCH] fix for edit data in line modification dialog form (#2483) Signed-off-by: Rehili Ghazwa --- .../modification/line-modification-dialog.jsx | 59 +++++++++---------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.jsx b/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.jsx index 1868d36416..72debdcb5c 100644 --- a/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.jsx +++ b/src/components/dialogs/network-modifications/line/modification/line-modification-dialog.jsx @@ -148,7 +148,7 @@ const LineModificationDialog = ({ const { reset, setValue, getValues } = formMethods; const fromEditDataToFormValues = useCallback( - (line, updatedTemporaryLimits1, updatedTemporaryLimits2) => { + (line) => { if (line?.equipmentId) { setSelectedId(line.equipmentId); } @@ -170,14 +170,10 @@ const LineModificationDialog = ({ permanentLimit1: line.currentLimits1?.permanentLimit, permanentLimit2: line.currentLimits2?.permanentLimit, temporaryLimits1: addSelectedFieldToRows( - updatedTemporaryLimits1 - ? updatedTemporaryLimits1 - : formatTemporaryLimits(line.currentLimits1?.temporaryLimits) + formatTemporaryLimits(line.currentLimits1?.temporaryLimits) ), temporaryLimits2: addSelectedFieldToRows( - updatedTemporaryLimits2 - ? updatedTemporaryLimits2 - : formatTemporaryLimits(line.currentLimits2?.temporaryLimits) + formatTemporaryLimits(line.currentLimits2?.temporaryLimits) ), }), ...getPropertiesFromModification(line.properties), @@ -188,19 +184,9 @@ const LineModificationDialog = ({ useEffect(() => { if (editData) { - fromEditDataToFormValues( - editData, - updateTemporaryLimits( - formatTemporaryLimits(editData.currentLimits1?.temporaryLimits), - formatTemporaryLimits(lineToModify?.currentLimits1?.temporaryLimits) - ), - updateTemporaryLimits( - formatTemporaryLimits(editData.currentLimits2?.temporaryLimits), - formatTemporaryLimits(lineToModify?.currentLimits2?.temporaryLimits) - ) - ); + fromEditDataToFormValues(editData); } - }, [fromEditDataToFormValues, editData, lineToModify]); + }, [fromEditDataToFormValues, editData]); const onSubmit = useCallback( (line) => { @@ -286,7 +272,10 @@ const LineModificationDialog = ({ const onEquipmentIdChange = useCallback( (equipmentId) => { - if (equipmentId) { + if (!equipmentId) { + setLineToModify(null); + reset(emptyFormData, { keepDefaultValues: true }); + } else { setDataFetchStatus(FetchStatus.RUNNING); fetchNetworkElementInfos( studyUuid, @@ -303,20 +292,33 @@ const LineModificationDialog = ({ setConnectivityValue(CONNECTIVITY_2, VOLTAGE_LEVEL, line?.voltageLevelId2); setConnectivityValue(CONNECTIVITY_1, BUS_OR_BUSBAR_SECTION, line?.busOrBusbarSectionId1); setConnectivityValue(CONNECTIVITY_2, BUS_OR_BUSBAR_SECTION, line?.busOrBusbarSectionId2); - if (editData?.equipmentId !== selectedId) { - reset((formValues) => ({ + const updatedTemporaryLimits1 = updateTemporaryLimits( + formatTemporaryLimits(getValues(`${CURRENT_LIMITS_1}.${TEMPORARY_LIMITS}`)), + formatTemporaryLimits(line?.currentLimits1?.temporaryLimits) + ); + const updatedTemporaryLimits2 = updateTemporaryLimits( + formatTemporaryLimits(getValues(`${CURRENT_LIMITS_2}.${TEMPORARY_LIMITS}`)), + formatTemporaryLimits(line?.currentLimits2?.temporaryLimits) + ); + reset( + (formValues) => ({ ...formValues, ...getLimitsFormData({ temporaryLimits1: addSelectedFieldToRows( - formatTemporaryLimits(line.currentLimits1?.temporaryLimits) + updatedTemporaryLimits1 + ? updatedTemporaryLimits1 + : formatTemporaryLimits(line.currentLimits1?.temporaryLimits) ), temporaryLimits2: addSelectedFieldToRows( - formatTemporaryLimits(line.currentLimits2?.temporaryLimits) + updatedTemporaryLimits2 + ? updatedTemporaryLimits2 + : formatTemporaryLimits(line.currentLimits2?.temporaryLimits) ), }), [ADDITIONAL_PROPERTIES]: getConcatenatedProperties(line, getValues), - })); - } + }), + { keepDefaultValues: true } + ); } setDataFetchStatus(FetchStatus.SUCCEED); }) @@ -327,12 +329,9 @@ const LineModificationDialog = ({ reset(emptyFormData); } }); - } else { - setLineToModify(null); - reset(emptyFormData, { keepDefaultValues: true }); } }, - [studyUuid, currentNodeUuid, selectedId, editData, reset, emptyFormData, getValues, setConnectivityValue] + [studyUuid, currentNodeUuid, editData, reset, emptyFormData, getValues, setConnectivityValue] ); useEffect(() => {