Skip to content

Commit

Permalink
Merge branch 'main' into mutualize-unit-conversion-into-one-file
Browse files Browse the repository at this point in the history
  • Loading branch information
ghazwarhili authored Jan 9, 2025
2 parents c498b1b + 16dbebd commit 0f0821a
Showing 1 changed file with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const LineModificationDialog = ({
const { reset, setValue, getValues } = formMethods;

const fromEditDataToFormValues = useCallback(
(line, updatedTemporaryLimits1, updatedTemporaryLimits2) => {
(line) => {
if (line?.equipmentId) {
setSelectedId(line.equipmentId);
}
Expand All @@ -175,14 +175,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),
Expand All @@ -193,19 +189,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) => {
Expand Down Expand Up @@ -291,7 +277,10 @@ const LineModificationDialog = ({

const onEquipmentIdChange = useCallback(
(equipmentId) => {
if (equipmentId) {
if (!equipmentId) {
setLineToModify(null);
reset(emptyFormData, { keepDefaultValues: true });
} else {
setDataFetchStatus(FetchStatus.RUNNING);
fetchNetworkElementInfos(
studyUuid,
Expand All @@ -308,20 +297,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);
})
Expand All @@ -332,12 +334,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(() => {
Expand Down

0 comments on commit 0f0821a

Please sign in to comment.