Skip to content

Commit

Permalink
Merge branch 'main' into ayolab/add-quicksearch-for-logs-containers
Browse files Browse the repository at this point in the history
  • Loading branch information
ayolab authored Jan 9, 2025
2 parents 5cfd3d5 + 16dbebd commit 51f700f
Showing 1 changed file with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const LineModificationDialog = ({
const { reset, setValue, getValues } = formMethods;

const fromEditDataToFormValues = useCallback(
(line, updatedTemporaryLimits1, updatedTemporaryLimits2) => {
(line) => {
if (line?.equipmentId) {
setSelectedId(line.equipmentId);
}
Expand All @@ -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),
Expand All @@ -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) => {
Expand Down Expand Up @@ -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,
Expand All @@ -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);
})
Expand All @@ -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(() => {
Expand Down

0 comments on commit 51f700f

Please sign in to comment.