Skip to content

Commit 9dfea18

Browse files
authored
change endpoint to get voltage level topology (#3358)
Signed-off-by: Etienne LESOT <[email protected]>
1 parent 1743531 commit 9dfea18

File tree

7 files changed

+99
-49
lines changed

7 files changed

+99
-49
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ const VoltageLevelCreationDialog = ({
234234
voltageLevel.switchKinds?.map((switchKind) => ({
235235
[SWITCH_KIND]: switchKind,
236236
})) || [];
237-
238237
const switchesBetweenSections =
239238
voltageLevel.switchKinds?.map((switchKind) => intl.formatMessage({ id: switchKind })).join(' / ') || '';
240239

@@ -283,7 +282,7 @@ const VoltageLevelCreationDialog = ({
283282
} else {
284283
setValue(ADD_SUBSTATION_CREATION, false);
285284
}
286-
if (!voltageLevel.isRetrievedBusbarSections && fromCopy) {
285+
if (!voltageLevel.isSymmetrical && fromCopy) {
287286
snackWarning({
288287
messageId: 'BusBarSectionsCopyingNotSupported',
289288
});

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ import {
3333
MoveFeederBayInfos,
3434
MoveVoltageLevelFeederBaysInfos,
3535
} from '../../../../../services/network-modification-types';
36-
import { fetchNetworkElementInfos } from '../../../../../services/study/network';
36+
import { fetchVoltageLevelFeederBaysBusBarSectionsInfos } from '../../../../../services/study/network';
3737
import { EquipmentModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type';
38-
import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from '../../../../utils/equipment-types';
3938
import { DeepNullable } from '../../../../utils/ts-utils';
40-
import { FeederBayInfos, FeederBaysFormInfos, FeederBaysInfos } from './move-voltage-level-feeder-bays.type';
39+
import { FeederBaysFormInfos, FeederBaysInfos } from './move-voltage-level-feeder-bays.type';
4140
import { moveVoltageLevelFeederBays } from '../../../../../services/study/network-modifications';
4241
import { AnyObject, TestFunction } from 'yup';
42+
import { FeederBaysBusBarSectionsInfos } from '../../../../../services/study/network-map.type';
4343

4444
const isActiveRow = (row: FeederBaysFormInfos) => row && !row.isRemoved;
4545
const checkConnectionPositionField: TestFunction<string | undefined, AnyObject> = (currentPosition, context) => {
@@ -224,10 +224,12 @@ export default function MoveVoltageLevelFeederBaysDialog({
224224
);
225225

226226
const handleVoltageLevelDataFetch = useCallback(
227-
(voltageLevel: any) => {
228-
const busBarSectionInfos = Object.values(voltageLevel?.busBarSectionInfos || {}).flat() as string[];
229-
const feederBaysInfos: FeederBaysInfos = (
230-
Object.entries(voltageLevel?.feederBaysInfos || {}) as [string, FeederBayInfos[]][]
227+
(feederBaysBusBarSectionsInfo: FeederBaysBusBarSectionsInfos) => {
228+
const busBarSectionInfos: string[] = Object.values(
229+
feederBaysBusBarSectionsInfo?.busBarSectionsInfos.busBarSections || {}
230+
).flat();
231+
const feederBaysInfos: FeederBaysInfos = Object.entries(
232+
feederBaysBusBarSectionsInfo?.feederBaysInfos || {}
231233
).flatMap(([equipmentId, feederBayInfos]) =>
232234
feederBayInfos.map((feederBay) => ({
233235
equipmentId,
@@ -255,21 +257,18 @@ export default function MoveVoltageLevelFeederBaysDialog({
255257
);
256258

257259
const onEquipmentIdChange = useCallback(
258-
(equipmentId: string) => {
259-
if (equipmentId) {
260+
(voltageLevelId: string) => {
261+
if (voltageLevelId) {
260262
setDataFetchStatus(FetchStatus.RUNNING);
261-
fetchNetworkElementInfos(
263+
fetchVoltageLevelFeederBaysBusBarSectionsInfos(
262264
studyUuid,
263265
currentNodeUuid,
264266
currentRootNetworkUuid,
265-
EQUIPMENT_TYPES.VOLTAGE_LEVEL,
266-
EQUIPMENT_INFOS_TYPES.FORM.type,
267-
equipmentId,
268-
true
267+
voltageLevelId
269268
)
270-
.then((voltageLevel) => {
271-
if (voltageLevel) {
272-
handleVoltageLevelDataFetch(voltageLevel);
269+
.then((feederBaysBusBarSectionInfo) => {
270+
if (feederBaysBusBarSectionInfo) {
271+
handleVoltageLevelDataFetch(feederBaysBusBarSectionInfo);
273272
}
274273
})
275274
.catch(() => {

src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-dialog.tsx

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import yup from '../../../../utils/yup-config';
2929
import { FetchStatus } from 'services/utils';
3030
import { EquipmentIdSelector } from 'components/dialogs/equipment-id/equipment-id-selector';
3131
import { CreateVoltageLevelSectionForm } from './create-voltage-level-section-form';
32-
import { BusBarSectionInfos, CreateVoltageLevelSectionDialogSchemaForm } from './voltage-level-section.type';
32+
import { BusBarSections, CreateVoltageLevelSectionDialogSchemaForm } from './voltage-level-section.type';
3333
import { CreateVoltageLevelSectionInfos } from '../../../../../services/network-modification-types';
3434
import { createVoltageLevelSection } from '../../../../../services/study/network-modifications';
35-
import { EQUIPMENT_INFOS_TYPES } from '../../../../utils/equipment-types';
36-
import { fetchNetworkElementInfos } from '../../../../../services/study/network';
35+
import { fetchVoltageLevelBusBarSectionsInfos } from '../../../../../services/study/network';
3736
import { DeepNullable } from '../../../../utils/ts-utils';
37+
import { BusBarSectionsInfos } from '../../../../../services/study/network-map.type';
3838

3939
const getBusBarIndexValue = ({ busbarIndex, allBusbars }: { busbarIndex: string | null; allBusbars: boolean }) => {
4040
if (!busbarIndex) {
@@ -131,7 +131,7 @@ export default function CreateVoltageLevelSectionDialog({
131131
const [isExtensionNotFoundOrNotSupportedTopology, setIsExtensionNotFoundOrNotSupportedTopology] =
132132
useState<boolean>(false);
133133
const [isSymmetricalNbBusBarSections, setIsSymmetricalNbBusBarSections] = useState<boolean>(false);
134-
const [busBarSectionInfos, setBusBarSectionInfos] = useState<BusBarSectionInfos[]>();
134+
const [busBarSectionInfos, setBusBarSectionInfos] = useState<BusBarSections>();
135135
const [allBusbarSectionsList, setAllBusbarSectionsList] = useState<string[]>([]);
136136
const [dataFetchStatus, setDataFetchStatus] = useState<string>(FetchStatus.IDLE);
137137
const { snackError } = useSnackMessage();
@@ -152,26 +152,16 @@ export default function CreateVoltageLevelSectionDialog({
152152
(voltageLevelId: string) => {
153153
if (voltageLevelId) {
154154
setDataFetchStatus(FetchStatus.RUNNING);
155-
fetchNetworkElementInfos(
156-
studyUuid,
157-
currentNodeUuid,
158-
currentRootNetworkUuid,
159-
EquipmentType.VOLTAGE_LEVEL,
160-
EQUIPMENT_INFOS_TYPES.FORM.type,
161-
voltageLevelId,
162-
true
163-
)
164-
.then((voltageLevel) => {
165-
if (voltageLevel) {
166-
setBusBarSectionInfos(voltageLevel?.busBarSectionInfos || []);
167-
setAllBusbarSectionsList(
168-
Object.values(voltageLevel?.busBarSectionInfos || {}).flat() as string[]
169-
);
155+
fetchVoltageLevelBusBarSectionsInfos(studyUuid, currentNodeUuid, currentRootNetworkUuid, voltageLevelId)
156+
.then((busBarSectionsInfos: BusBarSectionsInfos) => {
157+
if (busBarSectionsInfos) {
158+
setBusBarSectionInfos(busBarSectionsInfos?.busBarSections || []);
159+
setAllBusbarSectionsList(Object.values(busBarSectionsInfos?.busBarSections || {}).flat());
170160
setIsExtensionNotFoundOrNotSupportedTopology(
171-
!voltageLevel.isBusbarSectionPositionFound ||
172-
voltageLevel?.topologyKind !== 'NODE_BREAKER'
161+
!busBarSectionsInfos.isBusbarSectionPositionFound ||
162+
busBarSectionsInfos?.topologyKind !== 'NODE_BREAKER'
173163
);
174-
setIsSymmetricalNbBusBarSections(voltageLevel.isRetrievedBusbarSections);
164+
setIsSymmetricalNbBusBarSections(busBarSectionsInfos.isSymmetrical);
175165
setDataFetchStatus(FetchStatus.SUCCEED);
176166
}
177167
})
@@ -233,7 +223,7 @@ export default function CreateVoltageLevelSectionDialog({
233223

234224
const findBusbarKeyForSection = useCallback(
235225
(sectionId: string) => {
236-
const infos = busBarSectionInfos as unknown as BusBarSectionInfos;
226+
const infos = busBarSectionInfos as unknown as BusBarSections;
237227
return Object.keys(infos || {}).find((key) => infos[key]?.includes(sectionId)) || null;
238228
},
239229
[busBarSectionInfos]

src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-form.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import PositionDiagramPane from 'components/grid-layout/cards/diagrams/singleLin
2727
import type { UUID } from 'node:crypto';
2828
import { POSITION_NEW_SECTION_SIDE, SWITCH_TYPE } from '../../../../network/constants';
2929
import { useFormContext, useWatch } from 'react-hook-form';
30-
import { BusBarSectionInfos } from './voltage-level-section.type';
3130
import { areIdsEqual, getObjectId } from '../../../../utils/utils';
31+
import { BusBarSections } from './voltage-level-section.type';
3232

33-
const getArrayPosition = (data: BusBarSectionInfos[], selectedOptionId: string) => {
33+
const getArrayPosition = (data: BusBarSections, selectedOptionId: string) => {
3434
if (!selectedOptionId || !data) {
3535
return { position: -1, length: 0 };
3636
}
@@ -49,7 +49,7 @@ const getArrayPosition = (data: BusBarSectionInfos[], selectedOptionId: string)
4949
type OptionWithDisabled = Option & { disabled?: boolean };
5050

5151
interface VoltageLevelSectionsCreationFormProps {
52-
busBarSectionInfos?: BusBarSectionInfos[];
52+
busBarSectionInfos?: BusBarSections;
5353
voltageLevelId: string;
5454
allBusbarSectionsList: string[];
5555
studyUuid: UUID;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ export type CreateVoltageLevelSectionDialogSchemaForm = {
1515
newSwitchStates?: boolean;
1616
};
1717

18-
export type BusBarSectionInfos = {
19-
[key: string]: string[];
20-
};
18+
export type BusBarSections = Record<string, string[]>;

src/services/study/network-map.type.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,28 @@
66
*/
77
import { CurrentLimitsData } from '../network-modification-types';
88
import { Equipment } from '../../components/dialogs/network-modifications/common/properties/property-utils';
9+
import { BusBarSections } from '../../components/dialogs/network-modifications/voltage-level/section/voltage-level-section.type';
10+
import { FeederBayInfos } from '../../components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays.type';
911

1012
export type SwitchInfos = {
1113
id: string;
1214
open: boolean;
1315
};
1416

17+
export type BusBarSectionsInfos = {
18+
topologyKind: string;
19+
busbarCount: number;
20+
sectionCount: number;
21+
isSymmetrical: boolean;
22+
isBusbarSectionPositionFound: boolean;
23+
busBarSections: BusBarSections;
24+
};
25+
26+
export type FeederBaysBusBarSectionsInfos = {
27+
feederBaysInfos: Record<string, FeederBayInfos[]>;
28+
busBarSectionsInfos: BusBarSectionsInfos;
29+
};
30+
1531
export type BranchInfos = Equipment & {
1632
name: string;
1733
voltageLevelId1: string;

src/services/study/network.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type { MapHvdcLine, MapLine, MapSubstation, MapTieLine } from '@powsybl/n
1919
import { getStudyUrlWithNodeUuidAndRootNetworkUuid, PREFIX_STUDY_QUERIES, safeEncodeURIComponent } from './index';
2020
import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES, type VoltageLevel } from '../../components/utils/equipment-types';
2121
import { getQueryParamsList, getUrlWithToken } from '../utils';
22-
import { SwitchInfos } from './network-map.type';
22+
import { BusBarSectionsInfos, FeederBaysBusBarSectionsInfos, SwitchInfos } from './network-map.type';
2323
import type { SpreadsheetEquipmentType } from '../../components/spreadsheet-view/types/spreadsheet.type';
2424
import { JSONSchema4 } from 'json-schema';
2525

@@ -161,6 +161,54 @@ export function fetchSwitchesOfVoltageLevel(
161161
return backendFetchJson(fetchSwitchesUrl);
162162
}
163163

164+
export function fetchVoltageLevelBusBarSectionsInfos(
165+
studyUuid: UUID,
166+
currentNodeUuid: UUID,
167+
currentRootNetworkUuid: UUID,
168+
voltageLevelId: string
169+
): Promise<BusBarSectionsInfos> {
170+
console.info(
171+
`Fetching bus bar sections information of study '${studyUuid}' on root network '${currentRootNetworkUuid}' and node '${currentNodeUuid}' + ' for voltage level '${voltageLevelId}'...`
172+
);
173+
const urlSearchParams = new URLSearchParams();
174+
urlSearchParams.append('inUpstreamBuiltParentNode', 'true');
175+
176+
const fetchTopologyUrl =
177+
getStudyUrlWithNodeUuidAndRootNetworkUuid(studyUuid, currentNodeUuid, currentRootNetworkUuid) +
178+
'/network/voltage-levels/' +
179+
encodeURIComponent(voltageLevelId) +
180+
'/bus-bar-sections' +
181+
'?' +
182+
urlSearchParams.toString();
183+
184+
console.debug(fetchTopologyUrl);
185+
return backendFetchJson(fetchTopologyUrl);
186+
}
187+
188+
export function fetchVoltageLevelFeederBaysBusBarSectionsInfos(
189+
studyUuid: UUID,
190+
currentNodeUuid: UUID,
191+
currentRootNetworkUuid: UUID,
192+
voltageLevelId: string
193+
): Promise<FeederBaysBusBarSectionsInfos> {
194+
console.info(
195+
`Fetching feeder bays and bus bar sections information of study '${studyUuid}' on root network '${currentRootNetworkUuid}' and node '${currentNodeUuid}' + ' for voltage level '${voltageLevelId}'...`
196+
);
197+
const urlSearchParams = new URLSearchParams();
198+
urlSearchParams.append('inUpstreamBuiltParentNode', 'true');
199+
200+
const fetchTopologyUrl =
201+
getStudyUrlWithNodeUuidAndRootNetworkUuid(studyUuid, currentNodeUuid, currentRootNetworkUuid) +
202+
'/network/voltage-levels/' +
203+
encodeURIComponent(voltageLevelId) +
204+
'/feeder-bays-and-bus-bar-sections' +
205+
'?' +
206+
urlSearchParams.toString();
207+
208+
console.debug(fetchTopologyUrl);
209+
return backendFetchJson(fetchTopologyUrl);
210+
}
211+
164212
/* substations */
165213
export function getSubstationSingleLineDiagram({
166214
studyUuid,

0 commit comments

Comments
 (0)