diff --git a/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.jsx b/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.jsx index a790028e78..630dc4ad97 100644 --- a/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.jsx +++ b/src/components/dialogs/network-modifications/voltage-level/creation/voltage-level-creation-dialog.jsx @@ -234,7 +234,6 @@ const VoltageLevelCreationDialog = ({ voltageLevel.switchKinds?.map((switchKind) => ({ [SWITCH_KIND]: switchKind, })) || []; - const switchesBetweenSections = voltageLevel.switchKinds?.map((switchKind) => intl.formatMessage({ id: switchKind })).join(' / ') || ''; @@ -283,7 +282,7 @@ const VoltageLevelCreationDialog = ({ } else { setValue(ADD_SUBSTATION_CREATION, false); } - if (!voltageLevel.isRetrievedBusbarSections && fromCopy) { + if (!voltageLevel.isSymmetrical && fromCopy) { snackWarning({ messageId: 'BusBarSectionsCopyingNotSupported', }); diff --git a/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-dialog.tsx b/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-dialog.tsx index 3a5b588a65..a5d693c4ae 100644 --- a/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-dialog.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays-dialog.tsx @@ -33,13 +33,13 @@ import { MoveFeederBayInfos, MoveVoltageLevelFeederBaysInfos, } from '../../../../../services/network-modification-types'; -import { fetchNetworkElementInfos } from '../../../../../services/study/network'; +import { fetchVoltageLevelFeederBaysBusBarSectionsInfos } from '../../../../../services/study/network'; import { EquipmentModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; -import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES } from '../../../../utils/equipment-types'; import { DeepNullable } from '../../../../utils/ts-utils'; -import { FeederBayInfos, FeederBaysFormInfos, FeederBaysInfos } from './move-voltage-level-feeder-bays.type'; +import { FeederBaysFormInfos, FeederBaysInfos } from './move-voltage-level-feeder-bays.type'; import { moveVoltageLevelFeederBays } from '../../../../../services/study/network-modifications'; import { AnyObject, TestFunction } from 'yup'; +import { FeederBaysBusBarSectionsInfos } from '../../../../../services/study/network-map.type'; const isActiveRow = (row: FeederBaysFormInfos) => row && !row.isRemoved; const checkConnectionPositionField: TestFunction = (currentPosition, context) => { @@ -224,10 +224,12 @@ export default function MoveVoltageLevelFeederBaysDialog({ ); const handleVoltageLevelDataFetch = useCallback( - (voltageLevel: any) => { - const busBarSectionInfos = Object.values(voltageLevel?.busBarSectionInfos || {}).flat() as string[]; - const feederBaysInfos: FeederBaysInfos = ( - Object.entries(voltageLevel?.feederBaysInfos || {}) as [string, FeederBayInfos[]][] + (feederBaysBusBarSectionsInfo: FeederBaysBusBarSectionsInfos) => { + const busBarSectionInfos: string[] = Object.values( + feederBaysBusBarSectionsInfo?.busBarSectionsInfos.busBarSections || {} + ).flat(); + const feederBaysInfos: FeederBaysInfos = Object.entries( + feederBaysBusBarSectionsInfo?.feederBaysInfos || {} ).flatMap(([equipmentId, feederBayInfos]) => feederBayInfos.map((feederBay) => ({ equipmentId, @@ -255,21 +257,18 @@ export default function MoveVoltageLevelFeederBaysDialog({ ); const onEquipmentIdChange = useCallback( - (equipmentId: string) => { - if (equipmentId) { + (voltageLevelId: string) => { + if (voltageLevelId) { setDataFetchStatus(FetchStatus.RUNNING); - fetchNetworkElementInfos( + fetchVoltageLevelFeederBaysBusBarSectionsInfos( studyUuid, currentNodeUuid, currentRootNetworkUuid, - EQUIPMENT_TYPES.VOLTAGE_LEVEL, - EQUIPMENT_INFOS_TYPES.FORM.type, - equipmentId, - true + voltageLevelId ) - .then((voltageLevel) => { - if (voltageLevel) { - handleVoltageLevelDataFetch(voltageLevel); + .then((feederBaysBusBarSectionInfo) => { + if (feederBaysBusBarSectionInfo) { + handleVoltageLevelDataFetch(feederBaysBusBarSectionInfo); } }) .catch(() => { diff --git a/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-dialog.tsx b/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-dialog.tsx index 1fca1529d4..ca7b5e0793 100644 --- a/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-dialog.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-dialog.tsx @@ -29,12 +29,12 @@ import yup from '../../../../utils/yup-config'; import { FetchStatus } from 'services/utils'; import { EquipmentIdSelector } from 'components/dialogs/equipment-id/equipment-id-selector'; import { CreateVoltageLevelSectionForm } from './create-voltage-level-section-form'; -import { BusBarSectionInfos, CreateVoltageLevelSectionDialogSchemaForm } from './voltage-level-section.type'; +import { BusBarSections, CreateVoltageLevelSectionDialogSchemaForm } from './voltage-level-section.type'; import { CreateVoltageLevelSectionInfos } from '../../../../../services/network-modification-types'; import { createVoltageLevelSection } from '../../../../../services/study/network-modifications'; -import { EQUIPMENT_INFOS_TYPES } from '../../../../utils/equipment-types'; -import { fetchNetworkElementInfos } from '../../../../../services/study/network'; +import { fetchVoltageLevelBusBarSectionsInfos } from '../../../../../services/study/network'; import { DeepNullable } from '../../../../utils/ts-utils'; +import { BusBarSectionsInfos } from '../../../../../services/study/network-map.type'; const getBusBarIndexValue = ({ busbarIndex, allBusbars }: { busbarIndex: string | null; allBusbars: boolean }) => { if (!busbarIndex) { @@ -131,7 +131,7 @@ export default function CreateVoltageLevelSectionDialog({ const [isExtensionNotFoundOrNotSupportedTopology, setIsExtensionNotFoundOrNotSupportedTopology] = useState(false); const [isSymmetricalNbBusBarSections, setIsSymmetricalNbBusBarSections] = useState(false); - const [busBarSectionInfos, setBusBarSectionInfos] = useState(); + const [busBarSectionInfos, setBusBarSectionInfos] = useState(); const [allBusbarSectionsList, setAllBusbarSectionsList] = useState([]); const [dataFetchStatus, setDataFetchStatus] = useState(FetchStatus.IDLE); const { snackError } = useSnackMessage(); @@ -152,26 +152,16 @@ export default function CreateVoltageLevelSectionDialog({ (voltageLevelId: string) => { if (voltageLevelId) { setDataFetchStatus(FetchStatus.RUNNING); - fetchNetworkElementInfos( - studyUuid, - currentNodeUuid, - currentRootNetworkUuid, - EquipmentType.VOLTAGE_LEVEL, - EQUIPMENT_INFOS_TYPES.FORM.type, - voltageLevelId, - true - ) - .then((voltageLevel) => { - if (voltageLevel) { - setBusBarSectionInfos(voltageLevel?.busBarSectionInfos || []); - setAllBusbarSectionsList( - Object.values(voltageLevel?.busBarSectionInfos || {}).flat() as string[] - ); + fetchVoltageLevelBusBarSectionsInfos(studyUuid, currentNodeUuid, currentRootNetworkUuid, voltageLevelId) + .then((busBarSectionsInfos: BusBarSectionsInfos) => { + if (busBarSectionsInfos) { + setBusBarSectionInfos(busBarSectionsInfos?.busBarSections || []); + setAllBusbarSectionsList(Object.values(busBarSectionsInfos?.busBarSections || {}).flat()); setIsExtensionNotFoundOrNotSupportedTopology( - !voltageLevel.isBusbarSectionPositionFound || - voltageLevel?.topologyKind !== 'NODE_BREAKER' + !busBarSectionsInfos.isBusbarSectionPositionFound || + busBarSectionsInfos?.topologyKind !== 'NODE_BREAKER' ); - setIsSymmetricalNbBusBarSections(voltageLevel.isRetrievedBusbarSections); + setIsSymmetricalNbBusBarSections(busBarSectionsInfos.isSymmetrical); setDataFetchStatus(FetchStatus.SUCCEED); } }) @@ -233,7 +223,7 @@ export default function CreateVoltageLevelSectionDialog({ const findBusbarKeyForSection = useCallback( (sectionId: string) => { - const infos = busBarSectionInfos as unknown as BusBarSectionInfos; + const infos = busBarSectionInfos as unknown as BusBarSections; return Object.keys(infos || {}).find((key) => infos[key]?.includes(sectionId)) || null; }, [busBarSectionInfos] diff --git a/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-form.tsx b/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-form.tsx index 4ef6659050..a1d26a17d0 100644 --- a/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-form.tsx +++ b/src/components/dialogs/network-modifications/voltage-level/section/create-voltage-level-section-form.tsx @@ -27,10 +27,10 @@ import PositionDiagramPane from 'components/grid-layout/cards/diagrams/singleLin import type { UUID } from 'node:crypto'; import { POSITION_NEW_SECTION_SIDE, SWITCH_TYPE } from '../../../../network/constants'; import { useFormContext, useWatch } from 'react-hook-form'; -import { BusBarSectionInfos } from './voltage-level-section.type'; import { areIdsEqual, getObjectId } from '../../../../utils/utils'; +import { BusBarSections } from './voltage-level-section.type'; -const getArrayPosition = (data: BusBarSectionInfos[], selectedOptionId: string) => { +const getArrayPosition = (data: BusBarSections, selectedOptionId: string) => { if (!selectedOptionId || !data) { return { position: -1, length: 0 }; } @@ -49,7 +49,7 @@ const getArrayPosition = (data: BusBarSectionInfos[], selectedOptionId: string) type OptionWithDisabled = Option & { disabled?: boolean }; interface VoltageLevelSectionsCreationFormProps { - busBarSectionInfos?: BusBarSectionInfos[]; + busBarSectionInfos?: BusBarSections; voltageLevelId: string; allBusbarSectionsList: string[]; studyUuid: UUID; diff --git a/src/components/dialogs/network-modifications/voltage-level/section/voltage-level-section.type.ts b/src/components/dialogs/network-modifications/voltage-level/section/voltage-level-section.type.ts index b882633a91..52e3e81276 100644 --- a/src/components/dialogs/network-modifications/voltage-level/section/voltage-level-section.type.ts +++ b/src/components/dialogs/network-modifications/voltage-level/section/voltage-level-section.type.ts @@ -15,6 +15,4 @@ export type CreateVoltageLevelSectionDialogSchemaForm = { newSwitchStates?: boolean; }; -export type BusBarSectionInfos = { - [key: string]: string[]; -}; +export type BusBarSections = Record; diff --git a/src/services/study/network-map.type.ts b/src/services/study/network-map.type.ts index a15d8bab53..4598f5d6ad 100644 --- a/src/services/study/network-map.type.ts +++ b/src/services/study/network-map.type.ts @@ -6,12 +6,28 @@ */ import { CurrentLimitsData } from '../network-modification-types'; import { Equipment } from '../../components/dialogs/network-modifications/common/properties/property-utils'; +import { BusBarSections } from '../../components/dialogs/network-modifications/voltage-level/section/voltage-level-section.type'; +import { FeederBayInfos } from '../../components/dialogs/network-modifications/voltage-level/move-feeder-bays/move-voltage-level-feeder-bays.type'; export type SwitchInfos = { id: string; open: boolean; }; +export type BusBarSectionsInfos = { + topologyKind: string; + busbarCount: number; + sectionCount: number; + isSymmetrical: boolean; + isBusbarSectionPositionFound: boolean; + busBarSections: BusBarSections; +}; + +export type FeederBaysBusBarSectionsInfos = { + feederBaysInfos: Record; + busBarSectionsInfos: BusBarSectionsInfos; +}; + export type BranchInfos = Equipment & { name: string; voltageLevelId1: string; diff --git a/src/services/study/network.ts b/src/services/study/network.ts index b71d8e204c..eedcc7e1d3 100644 --- a/src/services/study/network.ts +++ b/src/services/study/network.ts @@ -19,7 +19,7 @@ import type { MapHvdcLine, MapLine, MapSubstation, MapTieLine } from '@powsybl/n import { getStudyUrlWithNodeUuidAndRootNetworkUuid, PREFIX_STUDY_QUERIES, safeEncodeURIComponent } from './index'; import { EQUIPMENT_INFOS_TYPES, EQUIPMENT_TYPES, type VoltageLevel } from '../../components/utils/equipment-types'; import { getQueryParamsList, getUrlWithToken } from '../utils'; -import { SwitchInfos } from './network-map.type'; +import { BusBarSectionsInfos, FeederBaysBusBarSectionsInfos, SwitchInfos } from './network-map.type'; import type { SpreadsheetEquipmentType } from '../../components/spreadsheet-view/types/spreadsheet.type'; import { JSONSchema4 } from 'json-schema'; @@ -161,6 +161,54 @@ export function fetchSwitchesOfVoltageLevel( return backendFetchJson(fetchSwitchesUrl); } +export function fetchVoltageLevelBusBarSectionsInfos( + studyUuid: UUID, + currentNodeUuid: UUID, + currentRootNetworkUuid: UUID, + voltageLevelId: string +): Promise { + console.info( + `Fetching bus bar sections information of study '${studyUuid}' on root network '${currentRootNetworkUuid}' and node '${currentNodeUuid}' + ' for voltage level '${voltageLevelId}'...` + ); + const urlSearchParams = new URLSearchParams(); + urlSearchParams.append('inUpstreamBuiltParentNode', 'true'); + + const fetchTopologyUrl = + getStudyUrlWithNodeUuidAndRootNetworkUuid(studyUuid, currentNodeUuid, currentRootNetworkUuid) + + '/network/voltage-levels/' + + encodeURIComponent(voltageLevelId) + + '/bus-bar-sections' + + '?' + + urlSearchParams.toString(); + + console.debug(fetchTopologyUrl); + return backendFetchJson(fetchTopologyUrl); +} + +export function fetchVoltageLevelFeederBaysBusBarSectionsInfos( + studyUuid: UUID, + currentNodeUuid: UUID, + currentRootNetworkUuid: UUID, + voltageLevelId: string +): Promise { + console.info( + `Fetching feeder bays and bus bar sections information of study '${studyUuid}' on root network '${currentRootNetworkUuid}' and node '${currentNodeUuid}' + ' for voltage level '${voltageLevelId}'...` + ); + const urlSearchParams = new URLSearchParams(); + urlSearchParams.append('inUpstreamBuiltParentNode', 'true'); + + const fetchTopologyUrl = + getStudyUrlWithNodeUuidAndRootNetworkUuid(studyUuid, currentNodeUuid, currentRootNetworkUuid) + + '/network/voltage-levels/' + + encodeURIComponent(voltageLevelId) + + '/feeder-bays-and-bus-bar-sections' + + '?' + + urlSearchParams.toString(); + + console.debug(fetchTopologyUrl); + return backendFetchJson(fetchTopologyUrl); +} + /* substations */ export function getSubstationSingleLineDiagram({ studyUuid,