Skip to content

Commit fcba507

Browse files
authored
fix control for coupling creation and refactor labels (#3402)
Signed-off-by: Etienne LESOT <[email protected]>
1 parent 6ae1475 commit fcba507

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

src/components/dialogs/network-modifications/voltage-level/coupling-omnibus/coupling-omnibus-creation.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,26 @@
88
import { AutocompleteInput } from '@gridsuite/commons-ui';
99
import { BUS_BAR_SECTION_ID1, BUS_BAR_SECTION_ID2, COUPLING_OMNIBUS } from 'components/utils/field-constants';
1010
import GridItem from '../../../commons/grid-item';
11+
import { useEffect } from 'react';
12+
import { useFormContext } from 'react-hook-form';
1113

1214
// TODO should use "name" props instead of `${COUPLING_OMNIBUS}.(...)`
1315
export const CouplingOmnibusCreation = ({ index, sectionOptions }) => {
16+
const { getValues, watch, trigger } = useFormContext();
17+
// Watch BUS_BAR_SECTION_ID1 changed
18+
useEffect(() => {
19+
const subscription = watch((value, { name }) => {
20+
// force trigger validation on BUS_BAR_SECTION_ID2 if it has a value
21+
if (
22+
name === `${COUPLING_OMNIBUS}.${index}.${BUS_BAR_SECTION_ID1}` &&
23+
getValues(`${COUPLING_OMNIBUS}.${index}.${BUS_BAR_SECTION_ID2}`)
24+
) {
25+
trigger(`${COUPLING_OMNIBUS}.${index}.${BUS_BAR_SECTION_ID2}`);
26+
}
27+
});
28+
return () => subscription.unsubscribe();
29+
}, [watch, trigger, getValues, index]);
30+
1431
const busBarSectionId1Field = (
1532
<AutocompleteInput
1633
allowNewValue

src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.jsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import { useForm } from 'react-hook-form';
5151
import { ModificationDialog } from 'components/dialogs/commons/modificationDialog';
5252

5353
import VoltageLevelCreationForm from './voltage-level-creation-form';
54-
import { controlCouplingOmnibusBetweenSections } from '../voltage-level-creation-utils';
5554
import { EQUIPMENT_TYPES } from 'components/utils/equipment-types';
5655
import { useIntl } from 'react-intl';
5756
import { FORM_LOADING_DELAY } from 'components/network/constants';
@@ -167,17 +166,16 @@ const formSchema = yup
167166
is: (sectionCount) => sectionCount > 1,
168167
then: (schema) => schema.required(),
169168
}),
170-
[COUPLING_OMNIBUS]: yup
171-
.array()
172-
.of(
173-
yup.object().shape({
174-
[BUS_BAR_SECTION_ID1]: yup.string().nullable().required(),
175-
[BUS_BAR_SECTION_ID2]: yup.string().nullable().required(),
176-
})
177-
)
178-
.test('coupling-omnibus-between-sections', (values) =>
179-
controlCouplingOmnibusBetweenSections(values, 'CouplingOmnibusBetweenSameBusbar')
180-
),
169+
[COUPLING_OMNIBUS]: yup.array().of(
170+
yup.object().shape({
171+
[BUS_BAR_SECTION_ID1]: yup.string().nullable().required(),
172+
[BUS_BAR_SECTION_ID2]: yup
173+
.string()
174+
.nullable()
175+
.required()
176+
.notOneOf([yup.ref(BUS_BAR_SECTION_ID1), null], 'CreateCouplingDeviceIdenticalBusBar'),
177+
})
178+
),
181179
})
182180
.concat(creationPropertiesSchema);
183181
const VoltageLevelCreationDialog = ({

src/translations/en.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,6 @@
857857
"DISCONNECTOR": "Disconnector",
858858
"SameHorizAndVertPos": "At least two bus bar sections have same horizontal and vertical position",
859859
"DuplicateId": "Duplicate id",
860-
"CouplingOmnibusBetweenSameBusbar": "Forbidden to have a Coupler between the same bus bar section",
861860
"VoltageLevelModificationError": "Error while modifying a voltage level",
862861
"AddCouplingDeviceError": "Error while creating a coupling device",
863862
"BusBarSectionID1": "Bus bar section / bus 1",
@@ -1528,7 +1527,7 @@
15281527
"CREATE_COUPLING_DEVICE": "Add a coupling device",
15291528
"CreateVoltageLevelSection": "Add busbar section",
15301529
"CreateCouplingDeviceDiagramButton": "Show voltage level",
1531-
"CreateCouplingDeviceIdenticalBusBar": "Busbar section 1 and 2 must be different",
1530+
"CreateCouplingDeviceIdenticalBusBar": "Bus bar section / bus 1 and 2 must be different",
15321531
"builtNodeTooltipForDiagram": "Current diagram taking into account all applied modifications",
15331532
"notBuiltNodeTooltipForDiagram": "Diagram from last build node in current branch",
15341533
"CouplingDeviceText": "Bus bar sections",

src/translations/fr.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,6 @@
850850
"DISCONNECTOR": "Sectionneur",
851851
"SameHorizAndVertPos": "Au moins deux SJBs ont les mêmes positions horizontale et verticale",
852852
"DuplicateId": "Identifiant non unique",
853-
"CouplingOmnibusBetweenSameBusbar": "Couplage/omnibus interdit entre le même SJB",
854853
"VoltageLevelModificationError": "Erreur lors de la modification d'un poste",
855854
"AddCouplingDeviceError": "Erreur lors de l'ajout d'un omnibus/couplage",
856855
"BusBarSectionID1": "SJB / Nœud 1",
@@ -1527,7 +1526,7 @@
15271526
"CREATE_COUPLING_DEVICE": "Ajouter un couplage ou un omnibus",
15281527
"CreateVoltageLevelSection": "Ajouter un tronçon ou une section",
15291528
"CreateCouplingDeviceDiagramButton": "Voir le poste",
1530-
"CreateCouplingDeviceIdenticalBusBar": "Les sections de barre 1 et 2 doivent être différentes",
1529+
"CreateCouplingDeviceIdenticalBusBar": "Les SJB / Nœuds 1 et 2 doivent être différents",
15311530
"builtNodeTooltipForDiagram": "Diagramme courant prenant en compte toutes les modifications réalisées",
15321531
"notBuiltNodeTooltipForDiagram": "Diagramme du dernier nœud réalisé de la branche courante",
15331532
"CouplingDeviceText": "Sections de jeu de barre",

0 commit comments

Comments
 (0)