Skip to content

Commit 09536c3

Browse files
authored
Move feeder bays: accept duplicated feeder ids for internal branch (#3391)
Signed-off-by: Rehili Ghazwa <[email protected]>
1 parent 71975f6 commit 09536c3

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-dialog.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export default function MoveVoltageLevelFeederBaysDialog({
161161
connectionDirection: bay.connectablePositionInfos.connectionDirection || null,
162162
connectionPosition: bay.connectablePositionInfos.connectionPosition || null,
163163
isRemoved: false,
164+
rowId: null,
164165
}));
165166
} else if (editData?.uuid && isNodeBuiltValue && editData?.feederBays && editData?.feederBays?.length > 0) {
166167
const feederBaysEditData = editData.feederBays;
@@ -175,6 +176,7 @@ export default function MoveVoltageLevelFeederBaysDialog({
175176
connectionDirection: bay.connectablePositionInfos.connectionDirection,
176177
connectionPosition: bay.connectablePositionInfos.connectionPosition || '0',
177178
isRemoved: false,
179+
rowId: null,
178180
});
179181
});
180182
const deletedFeederBays = feederBaysEditData.filter(
@@ -193,6 +195,7 @@ export default function MoveVoltageLevelFeederBaysDialog({
193195
connectionDirection: bay.connectionDirection,
194196
connectionPosition: bay.connectionPosition,
195197
isRemoved: true,
198+
rowId: null,
196199
});
197200
});
198201
}
@@ -212,6 +215,7 @@ export default function MoveVoltageLevelFeederBaysDialog({
212215
connectionDirection: bay.connectionDirection,
213216
connectionPosition: bay.connectionPosition,
214217
isRemoved: false,
218+
rowId: null,
215219
}));
216220
}
217221
return mergedRowData;
@@ -224,20 +228,23 @@ export default function MoveVoltageLevelFeederBaysDialog({
224228
const busBarSectionInfos = Object.values(voltageLevel?.busBarSectionInfos || {}).flat() as string[];
225229
const feederBaysInfos: FeederBaysInfos = (
226230
Object.entries(voltageLevel?.feederBaysInfos || {}) as [string, FeederBayInfos[]][]
227-
)
228-
.flatMap(([equipmentId, feederBayInfos]) =>
229-
feederBayInfos.map((feederBay) => ({
230-
equipmentId,
231-
...feederBay,
232-
}))
233-
)
234-
.filter((item, index, arr) => arr.findIndex((x) => x.equipmentId === item.equipmentId) === index);
231+
).flatMap(([equipmentId, feederBayInfos]) =>
232+
feederBayInfos.map((feederBay) => ({
233+
equipmentId,
234+
...feederBay,
235+
}))
236+
);
235237
// merge row data between actual values in network and user's modification infos
236238
const mergedRowData = mergeRowData(feederBaysInfos, busBarSectionInfos);
239+
// Enrich rows with unique identifiers to track form rows
240+
const mergedRowDataWithKeys = mergedRowData.map((item, index) => ({
241+
...item,
242+
rowId: `${item.equipmentId}-${index}`,
243+
}));
237244
// reset default values for RHF state
238245
reset(
239246
{
240-
[MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE]: mergedRowData,
247+
[MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE]: mergedRowDataWithKeys,
241248
},
242249
{ keepDirty: true }
243250
);

src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-form.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import GridItem from '../../../commons/grid-item';
2828
import Button from '@mui/material/Button';
2929
import { InfoOutlined } from '@mui/icons-material';
3030
import type { UUID } from 'node:crypto';
31-
import { FeederBaysFormInfos, FeederBaysInfos } from './move-voltage-level-feeder-bays.type';
31+
import { FeederBaysFormInfos } from './move-voltage-level-feeder-bays.type';
3232
import PositionDiagramPane from '../../../../grid-layout/cards/diagrams/singleLineDiagram/positionDiagram/position-diagram-pane';
3333
import SeparatorCellRenderer from '../topology-modification/separator-cell-renderer';
3434

@@ -147,8 +147,8 @@ export function MoveVoltageLevelFeederBaysForm({
147147

148148
const renderEquipmentIdCell = useCallback(
149149
({ data }: { data?: any }) => {
150-
const watchTable: FeederBaysInfos = getValues(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE);
151-
const formIndex = watchTable?.findIndex((item) => item.equipmentId === data.equipmentId);
150+
const watchTable: FeederBaysFormInfos[] = getValues(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE);
151+
const formIndex = watchTable?.findIndex((item) => item.rowId === data.rowId) ?? -1;
152152

153153
return (
154154
<TextInput
@@ -177,8 +177,8 @@ export function MoveVoltageLevelFeederBaysForm({
177177

178178
const renderConnectionNameCell = useCallback(
179179
({ data }: { data?: any }) => {
180-
const watchTable: FeederBaysInfos = getValues(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE);
181-
const formIndex = watchTable?.findIndex((item) => item.equipmentId === data.equipmentId);
180+
const watchTable: FeederBaysFormInfos[] = getValues(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE);
181+
const formIndex = watchTable?.findIndex((item) => item.rowId === data.rowId) ?? -1;
182182

183183
return (
184184
<TextInput
@@ -196,7 +196,7 @@ export function MoveVoltageLevelFeederBaysForm({
196196
},
197197
},
198198
}}
199-
previousValue={watchTable[formIndex]?.connectablePositionInfos?.connectionName ?? ''}
199+
previousValue={watchTable[formIndex]?.connectionName ?? ''}
200200
/>
201201
);
202202
},
@@ -205,8 +205,8 @@ export function MoveVoltageLevelFeederBaysForm({
205205

206206
const renderBusbarSectionCell = useCallback(
207207
({ data }: { data?: any }) => {
208-
const watchTable: FeederBaysInfos = getValues(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE);
209-
const formIndex = watchTable?.findIndex((item) => item.equipmentId === data.equipmentId);
208+
const watchTable: FeederBaysFormInfos[] = getValues(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE);
209+
const formIndex = watchTable?.findIndex((item) => item.rowId === data.rowId) ?? -1;
210210
const busBarSectionIds = getValues(
211211
`${MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE}[${formIndex}].${BUSBAR_SECTION_IDS}`
212212
);
@@ -219,7 +219,7 @@ export function MoveVoltageLevelFeederBaysForm({
219219
sx={{ padding: '1rem' }}
220220
disabled={data.isRemoved}
221221
disableClearable
222-
previousValue={watchTable[formIndex]?.busbarSectionId}
222+
previousValue={watchTable[formIndex]?.busbarSectionId ?? undefined}
223223
/>
224224
);
225225
},
@@ -228,8 +228,8 @@ export function MoveVoltageLevelFeederBaysForm({
228228

229229
const renderConnectionDirectionCell = useCallback(
230230
({ data }: { data?: any }) => {
231-
const watchTable: FeederBaysInfos = getValues(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE);
232-
const formIndex = watchTable?.findIndex((item) => item.equipmentId === data.equipmentId);
231+
const watchTable: FeederBaysFormInfos[] = getValues(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE);
232+
const formIndex = watchTable?.findIndex((item) => item.rowId === data.rowId) ?? -1;
233233

234234
return FeederBayDirectionCellRenderer({
235235
name: `${MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE}[${formIndex}].${CONNECTION_DIRECTION}`,
@@ -241,9 +241,8 @@ export function MoveVoltageLevelFeederBaysForm({
241241

242242
const renderConnectionPositionCell = useCallback(
243243
({ data }: { data?: any }) => {
244-
const watchTable: FeederBaysInfos = getValues(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE);
245-
const formIndex = watchTable?.findIndex((item) => item.equipmentId === data.equipmentId);
246-
244+
const watchTable: FeederBaysFormInfos[] = getValues(MOVE_VOLTAGE_LEVEL_FEEDER_BAYS_TABLE);
245+
const formIndex = watchTable?.findIndex((item) => item.rowId === data.rowId) ?? -1;
247246
return (
248247
<div style={{ position: 'relative' }}>
249248
<IntegerInput

src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type FeederBaysFormInfos = {
1515
connectionDirection: string | null;
1616
connectionPosition: string | null;
1717
isRemoved: boolean;
18+
rowId: string | null;
1819
};
1920

2021
export type FeederBayInfos = {

0 commit comments

Comments
 (0)