Skip to content

Commit d8e2eb9

Browse files
authored
Fix Open vs Close in modifying voltage level topology (#2865)
1 parent 0187a5b commit d8e2eb9

File tree

4 files changed

+23
-35
lines changed

4 files changed

+23
-35
lines changed

src/components/dialogs/network-modifications/voltage-level-topology-modification/connection-cell-render.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ export default function ConnectionCellRenderer({ name }: Readonly<ConnectionCell
1818
return (
1919
<CheckboxNullableInput
2020
name={name}
21-
label={(value: boolean | null) =>
22-
value !== null
23-
? intl.formatMessage({ id: value ? 'Open' : 'Closed' })
21+
label={(checked: boolean | null) =>
22+
// cell value presents 'close'
23+
checked !== null
24+
? intl.formatMessage({ id: checked ? 'Closed' : 'Open' })
2425
: intl.formatMessage({ id: 'NoModification' })
2526
}
2627
/>

src/components/dialogs/network-modifications/voltage-level-topology-modification/voltage-level-topology-modification-dialog.tsx

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ const formSchema = yup.object().shape({
4242
.of(
4343
yup.object().shape({
4444
[SWITCH_ID]: yup.string(),
45-
[PREV_CONNECTION_STATUS]: yup.string(),
46-
[CURRENT_CONNECTION_STATUS]: yup.boolean().nullable(),
45+
[PREV_CONNECTION_STATUS]: yup.boolean().nullable(), // presents 'open'
46+
[CURRENT_CONNECTION_STATUS]: yup.boolean().nullable(), // presents 'close'
4747
})
4848
)
4949
.required(),
@@ -53,7 +53,7 @@ const emptyFormData = {
5353
[TOPOLOGY_MODIFICATION_TABLE]: [
5454
{
5555
[SWITCH_ID]: '',
56-
[PREV_CONNECTION_STATUS]: '',
56+
[PREV_CONNECTION_STATUS]: null,
5757
[CURRENT_CONNECTION_STATUS]: null,
5858
},
5959
],
@@ -119,7 +119,7 @@ export default function VoltageLevelTopologyModificationDialog({
119119
{
120120
[TOPOLOGY_MODIFICATION_TABLE]: switchesInfos?.map((row) => ({
121121
[SWITCH_ID]: row.id,
122-
[PREV_CONNECTION_STATUS]: row.open ? 'Open' : 'Closed',
122+
[PREV_CONNECTION_STATUS]: row.open,
123123
[CURRENT_CONNECTION_STATUS]: null,
124124
})),
125125
},
@@ -158,27 +158,18 @@ export default function VoltageLevelTopologyModificationDialog({
158158
if (topologyVLModificationInfos[TOPOLOGY_MODIFICATION_TABLE]?.length > 0) {
159159
equipmentAttributeModificationInfos = topologyVLModificationInfos[TOPOLOGY_MODIFICATION_TABLE].filter(
160160
(item) => {
161-
if (
161+
return !(
162162
item === null ||
163163
item.currentConnectionStatus === null ||
164164
item.currentConnectionStatus === undefined
165-
) {
166-
return false;
167-
}
168-
169-
const prevStatusIsClosed = item.prevConnectionStatus === 'Closed';
170-
const prevStatusIsOpen = item.prevConnectionStatus === 'Open';
171-
172-
return (
173-
item.currentConnectionStatus !== prevStatusIsClosed ||
174-
item.currentConnectionStatus !== prevStatusIsOpen
175165
);
176166
}
177167
).map((item) => ({
178168
type: MODIFICATION_TYPES.EQUIPMENT_ATTRIBUTE_MODIFICATION.type,
179169
equipmentId: item.switchId ?? '',
180170
equipmentAttributeName: 'open',
181-
equipmentAttributeValue: Boolean(item.currentConnectionStatus),
171+
// Note that 'currentConnectionStatus' which presents 'close' should be inverted when submitting open attribute
172+
equipmentAttributeValue: Boolean(!item.currentConnectionStatus),
182173
equipmentType: EquipmentType.SWITCH,
183174
}));
184175
}
@@ -247,7 +238,7 @@ export default function VoltageLevelTopologyModificationDialog({
247238
intl.formatMessage({ id: 'modifiedSwitchesSeparatorTitle' }) + ` (${modifiedSwitches.length})`,
248239
count: modifiedSwitches.length,
249240
[SWITCH_ID]: '',
250-
[PREV_CONNECTION_STATUS]: '',
241+
[PREV_CONNECTION_STATUS]: null,
251242
[CURRENT_CONNECTION_STATUS]: null,
252243
});
253244

@@ -257,22 +248,21 @@ export default function VoltageLevelTopologyModificationDialog({
257248
(attr) => attr.equipmentId === sw.switchId
258249
);
259250

260-
const currentConnectionStatus = isNodeBuilt(currentNode)
251+
const open = isNodeBuilt(currentNode)
261252
? matchingSwitchInfos?.open
262253
: (matchingAttributeEditData?.equipmentAttributeValue ?? matchingSwitchInfos?.open);
254+
255+
// Note that 'open' should be inverted when initializing CURRENT_CONNECTION_STATUS which presents 'close'
263256
result.push({
264257
...sw,
265258
type: SWITCH_TYPE,
266259
isModified: false,
267-
[CURRENT_CONNECTION_STATUS]: currentConnectionStatus,
260+
[CURRENT_CONNECTION_STATUS]: !open,
268261
});
269262
const formValues = getValues(TOPOLOGY_MODIFICATION_TABLE);
270263
const index = formValues?.findIndex((item) => item.switchId === sw.switchId);
271264
if (index !== -1) {
272-
setValue(
273-
`${TOPOLOGY_MODIFICATION_TABLE}.${index}.${CURRENT_CONNECTION_STATUS}`,
274-
currentConnectionStatus
275-
);
265+
setValue(`${TOPOLOGY_MODIFICATION_TABLE}.${index}.${CURRENT_CONNECTION_STATUS}`, !open);
276266
}
277267
});
278268

@@ -285,7 +275,7 @@ export default function VoltageLevelTopologyModificationDialog({
285275
` (${unmodifiedSwitches.length})`,
286276
count: unmodifiedSwitches.length,
287277
[SWITCH_ID]: '',
288-
[PREV_CONNECTION_STATUS]: '',
278+
[PREV_CONNECTION_STATUS]: null,
289279
[CURRENT_CONNECTION_STATUS]: null,
290280
});
291281

src/components/dialogs/network-modifications/voltage-level-topology-modification/voltage-level-topology-modification-form.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ export function VoltageLevelTopologyModificationForm({
8686
if (data.type === 'SEPARATOR') {
8787
return null;
8888
} else {
89-
return intl.formatMessage({ id: data[PREV_CONNECTION_STATUS] });
89+
// PREV_CONNECTION_STATUS presents 'open'
90+
return intl.formatMessage({ id: data[PREV_CONNECTION_STATUS] ? 'Open' : 'Closed' });
9091
}
9192
},
9293
headerComponentParams: {
@@ -132,12 +133,8 @@ export function VoltageLevelTopologyModificationForm({
132133
if (row.type === 'SEPARATOR') {
133134
return;
134135
}
135-
let newValue = null;
136-
if (row[PREV_CONNECTION_STATUS] === 'Open') {
137-
newValue = true;
138-
} else if (row[PREV_CONNECTION_STATUS] === 'Closed') {
139-
newValue = false;
140-
}
136+
// should revert because CURRENT_CONNECTION_STATUS presents 'close' while PREV_CONNECTION_STATUS presents 'open'
137+
const newValue = !row[PREV_CONNECTION_STATUS];
141138
setValue(`${TOPOLOGY_MODIFICATION_TABLE}[${index}].${CURRENT_CONNECTION_STATUS}`, newValue, {
142139
shouldDirty: true,
143140
});

src/components/dialogs/network-modifications/voltage-level-topology-modification/voltage-level-topology.type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
export type SwitchRowForm = {
99
switchId?: string;
10-
prevConnectionStatus?: string;
10+
prevConnectionStatus?: boolean | null;
1111
currentConnectionStatus?: boolean | null;
1212
type?: string;
1313
isModified?: boolean;

0 commit comments

Comments
 (0)