Skip to content

Commit 976804f

Browse files
authored
Fix twt validation error (#2441)
Signed-off-by: Rehili Ghazwa <[email protected]>
1 parent 59809d1 commit 976804f

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/components/dialogs/network-modifications/two-windings-transformer/creation/two-windings-transformer-creation-dialog.jsx

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -600,26 +600,33 @@ const TwoWindingsTransformerCreationDialog = ({
600600
[editData, studyUuid, currentNodeUuid, snackError]
601601
);
602602

603-
const onValidationError = (errors) => {
604-
let tabsInError = [];
605-
if (errors?.[PHASE_TAP_CHANGER] !== undefined) {
606-
tabsInError.push(TwoWindingsTransformerCreationDialogTab.PHASE_TAP_TAB);
607-
}
608-
if (errors?.[RATIO_TAP_CHANGER] !== undefined) {
609-
tabsInError.push(TwoWindingsTransformerCreationDialogTab.RATIO_TAP_TAB);
610-
}
611-
if (errors?.[CHARACTERISTICS] !== undefined) {
612-
tabsInError.push(TwoWindingsTransformerCreationDialogTab.CHARACTERISTICS_TAB);
613-
}
614-
if (errors?.[LIMITS] !== undefined) {
615-
tabsInError.push(TwoWindingsTransformerCreationDialogTab.LIMITS_TAB);
616-
}
603+
const onValidationError = useCallback(
604+
(errors) => {
605+
const tabsInError = [];
606+
if (errors?.[PHASE_TAP_CHANGER] !== undefined) {
607+
tabsInError.push(TwoWindingsTransformerCreationDialogTab.PHASE_TAP_TAB);
608+
}
609+
if (errors?.[RATIO_TAP_CHANGER] !== undefined) {
610+
tabsInError.push(TwoWindingsTransformerCreationDialogTab.RATIO_TAP_TAB);
611+
}
612+
if (errors?.[CHARACTERISTICS] !== undefined) {
613+
tabsInError.push(TwoWindingsTransformerCreationDialogTab.CHARACTERISTICS_TAB);
614+
}
615+
if (errors?.[LIMITS] !== undefined) {
616+
tabsInError.push(TwoWindingsTransformerCreationDialogTab.LIMITS_TAB);
617+
}
617618

618-
if (tabsInError.length > 0) {
619-
setTabIndex(tabsInError[0]);
620-
}
621-
setTabIndexesWithError(tabsInError);
622-
};
619+
if (tabsInError.includes(tabIndex)) {
620+
// error in current tab => do not change tab systematically but remove current tab in error list
621+
setTabIndexesWithError(tabsInError.filter((errorTabIndex) => errorTabIndex !== tabIndex));
622+
} else if (tabsInError.length > 0) {
623+
// switch to the first tab in the list then remove the tab in the error list
624+
setTabIndex(tabsInError[0]);
625+
setTabIndexesWithError(tabsInError.filter((errorTabIndex, index, arr) => errorTabIndex !== arr[0]));
626+
}
627+
},
628+
[tabIndex]
629+
);
623630

624631
const clear = useCallback(() => {
625632
reset(emptyFormData);

src/components/dialogs/network-modifications/two-windings-transformer/tap-changer-pane/phase-tap-changer-pane/phase-tap-changer-pane-utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,10 @@ const phaseTapChangerValidationSchema = (id) => ({
7373
[CURRENT_LIMITER_REGULATING_VALUE]: yup
7474
.number()
7575
.nullable()
76-
.positive('CurrentLimiterMustBeGreaterThanZero')
7776
.when([ENABLED, REGULATION_MODE], {
7877
is: (enabled, regulationMode) =>
7978
enabled && regulationMode === PHASE_REGULATION_MODES.CURRENT_LIMITER.id,
80-
then: (schema) => schema.required(),
79+
then: (schema) => schema.positive('CurrentLimiterMustBeGreaterThanZero').required(),
8180
}),
8281
[FLOW_SET_POINT_REGULATING_VALUE]: yup
8382
.number()

0 commit comments

Comments
 (0)