diff --git a/src/components/dialogs/active-power-control/active-power-control-form.tsx b/src/components/dialogs/active-power-control/active-power-control-form.tsx index 916c43a52f..d3d45eee42 100644 --- a/src/components/dialogs/active-power-control/active-power-control-form.tsx +++ b/src/components/dialogs/active-power-control/active-power-control-form.tsx @@ -8,9 +8,8 @@ import { useWatch } from 'react-hook-form'; import { DROOP, FREQUENCY_REGULATION } from 'components/utils/field-constants'; import { useMemo } from 'react'; -import { FloatInput, SwitchInput } from '@gridsuite/commons-ui'; +import { CheckboxNullableInput, FloatInput, SwitchInput } from '@gridsuite/commons-ui'; import { FormattedMessage, useIntl } from 'react-intl'; -import CheckboxNullableInput from 'components/utils/rhf-inputs/boolean-nullable-input'; import { Box, Tooltip } from '@mui/material'; import GridItem from '../commons/grid-item'; import { ActivePowerControlInfos } from './active-power-control.type'; diff --git a/src/components/dialogs/connectivity/branch-connectivity-form.tsx b/src/components/dialogs/connectivity/branch-connectivity-form.tsx deleted file mode 100644 index bea0d48845..0000000000 --- a/src/components/dialogs/connectivity/branch-connectivity-form.tsx +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright (c) 2024, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import { Grid } from '@mui/material'; -import { ConnectivityForm } from './connectivity-form'; -import { CONNECTIVITY, CONNECTIVITY_1, CONNECTIVITY_2 } from 'components/utils/field-constants'; -import useVoltageLevelsListInfos from '../../../hooks/use-voltage-levels-list-infos'; -import type { UUID } from 'node:crypto'; -import GridSection from '../commons/grid-section'; -import GridItem from '../commons/grid-item'; -import { CurrentTreeNode } from '../../graph/tree-node.type'; - -interface BranchConnectivityFormProps { - currentNode: CurrentTreeNode; - studyUuid: UUID; - currentRootNetworkUuid: UUID; - isModification?: boolean; - previousValues?: any; -} - -export function BranchConnectivityForm({ - currentNode, - studyUuid, - currentRootNetworkUuid, - isModification = false, - previousValues, -}: Readonly) { - const voltageLevelOptions = useVoltageLevelsListInfos(studyUuid, currentNode.id, currentRootNetworkUuid); - const id1 = `${CONNECTIVITY}.${CONNECTIVITY_1}`; - const id2 = `${CONNECTIVITY}.${CONNECTIVITY_2}`; - - const connectivity1Field = ( - - ); - - const connectivity2Field = ( - - ); - - return ( - <> - - - {connectivity1Field} - - - - {connectivity2Field} - - - ); -} diff --git a/src/components/dialogs/connectivity/connectivity-form-utils.ts b/src/components/dialogs/connectivity/connectivity-form-utils.ts deleted file mode 100644 index 8a63edd950..0000000000 --- a/src/components/dialogs/connectivity/connectivity-form-utils.ts +++ /dev/null @@ -1,221 +0,0 @@ -/** - * Copyright (c) 2022, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import { - BUS_OR_BUSBAR_SECTION, - CONNECTED, - CONNECTION_DIRECTION, - CONNECTION_NAME, - CONNECTION_POSITION, - CONNECTIVITY, - CONNECTIVITY_1, - CONNECTIVITY_2, - ID, - VOLTAGE_LEVEL, -} from 'components/utils/field-constants'; -import yup from '../../utils/yup-config'; -import { VoltageLevelFormInfos } from '../network-modifications/voltage-level/voltage-level.type'; - -const getVoltageLevelAndBusOrBusBarSectionFieldsSchema = ( - isEquipmentModification: boolean, - relatedFieldName: string -) => { - return yup - .object() - .nullable() - .when({ - is: () => !isEquipmentModification, - then: (schema) => schema.required(), - }) - .shape({ - [ID]: yup.string().when([], { - is: () => isEquipmentModification, - then: (schema) => schema.nullable(), - }), - }) - .test('YupRequired', 'YupRequired', (value, context) => { - const isEmpty = value?.[ID] === null || value?.[ID] === undefined || value?.[ID] === ''; - const isEmptyRelatedField = - context.parent?.[relatedFieldName] === null || - context.parent?.[relatedFieldName]?.[ID] === '' || - context.parent?.[relatedFieldName]?.[ID] === undefined; - return !(isEmpty && !isEmptyRelatedField); - }); -}; - -export const getConnectivityPropertiesValidationSchema = (isEquipmentModification = false) => { - return { - [VOLTAGE_LEVEL]: getVoltageLevelAndBusOrBusBarSectionFieldsSchema( - isEquipmentModification, - BUS_OR_BUSBAR_SECTION - ), - [BUS_OR_BUSBAR_SECTION]: getVoltageLevelAndBusOrBusBarSectionFieldsSchema( - isEquipmentModification, - VOLTAGE_LEVEL - ), - }; -}; - -export const getCon1andCon2WithPositionValidationSchema = (isEquipmentModification = false, id = CONNECTIVITY) => ({ - [id]: yup.object().shape({ - ...getConnectivityWithPositionValidationSchema(isEquipmentModification, CONNECTIVITY_1), - ...getConnectivityWithPositionValidationSchema(isEquipmentModification, CONNECTIVITY_2), - }), -}); - -export const getConnectivityWithPositionSchema = (isEquipmentModification = false) => - yup.object().shape({ - [CONNECTION_DIRECTION]: yup.string().nullable(), - [CONNECTION_NAME]: yup.string(), - [CONNECTION_POSITION]: yup.number().nullable(), - [CONNECTED]: yup - .bool() - .nullable() - .when([], { - is: () => !isEquipmentModification, - then: (schema) => schema.required(), - }), - ...getConnectivityPropertiesValidationSchema(isEquipmentModification), - }); - -export const getConnectivityWithPositionValidationSchema = (isEquipmentModification = false, id = CONNECTIVITY) => ({ - [id]: getConnectivityWithPositionSchema(isEquipmentModification), -}); - -export const getConnectivityWithoutPositionValidationSchema = (id = CONNECTIVITY) => { - return { - [id]: yup.object().shape(getConnectivityPropertiesValidationSchema()), - }; -}; - -export const getConnectivityPropertiesEmptyFormData = (isEquipmentModification = false) => { - return { - [VOLTAGE_LEVEL]: null, - [BUS_OR_BUSBAR_SECTION]: null, - [CONNECTED]: isEquipmentModification ? null : true, - }; -}; - -export const getCont1Cont2WithPositionEmptyFormData = (isEquipmentModification = false, id = CONNECTIVITY) => ({ - [id]: { - ...getConnectivityWithPositionEmptyFormData(isEquipmentModification, CONNECTIVITY_1), - ...getConnectivityWithPositionEmptyFormData(isEquipmentModification, CONNECTIVITY_2), - }, -}); - -export const getConnectivityWithPositionEmptyFormData = (isEquipmentModification = false, id = CONNECTIVITY) => ({ - [id]: { - ...getConnectivityPropertiesEmptyFormData(isEquipmentModification), - [CONNECTION_DIRECTION]: null, - [CONNECTION_NAME]: '', - [CONNECTION_POSITION]: null, - }, -}); - -export const getConnectivityWithoutPositionEmptyFormData = (id = CONNECTIVITY) => ({ - [id]: getConnectivityPropertiesEmptyFormData(), -}); - -export const getConnectivityVoltageLevelData = ({ voltageLevelId }: { voltageLevelId?: string | null }) => { - if (!voltageLevelId) { - return null; - } - - return { - [ID]: voltageLevelId, - }; -}; - -export const getConnectivityBusBarSectionData = ({ busbarSectionId }: { busbarSectionId?: string | null }) => { - if (!busbarSectionId) { - return null; - } - - return { - [ID]: busbarSectionId, - }; -}; - -export const getConnectivityPropertiesData = ({ - voltageLevelId, - busbarSectionId, -}: { - voltageLevelId?: string | null; - busbarSectionId?: string | null; -}) => { - return { - [VOLTAGE_LEVEL]: getConnectivityVoltageLevelData({ - voltageLevelId, - }), - [BUS_OR_BUSBAR_SECTION]: getConnectivityBusBarSectionData({ - busbarSectionId, - }), - }; -}; - -export const getNewVoltageLevelData = (newVoltageLevel: VoltageLevelFormInfos) => ({ - id: newVoltageLevel.equipmentId, - name: newVoltageLevel.equipmentName ?? '', - substationId: newVoltageLevel.substationId, - topologyKind: newVoltageLevel.topologyKind, -}); - -export const getConnectivityData = ( - { voltageLevelId, busbarSectionId }: { voltageLevelId?: string | null; busbarSectionId?: string | null }, - id = CONNECTIVITY -) => { - return { - [id]: getConnectivityPropertiesData({ - voltageLevelId, - busbarSectionId, - }), - }; -}; - -export const getConnectivityFormData = ( - { - voltageLevelId, - busbarSectionId, - connectionDirection, - connectionName, - connectionPosition, - terminalConnected, - isEquipmentModification = false, - }: { - voltageLevelId?: string | null; - busbarSectionId?: string | null; - connectionDirection?: string | null; - connectionName?: string | null; - connectionPosition?: number | null; - terminalConnected?: boolean | null; - isEquipmentModification?: boolean; - }, - id = CONNECTIVITY -) => { - return { - [id]: { - ...getConnectivityPropertiesData({ - voltageLevelId, - busbarSectionId, - }), - [CONNECTION_DIRECTION]: connectionDirection ?? null, - [CONNECTION_NAME]: connectionName ?? '', - [CONNECTION_POSITION]: connectionPosition ?? null, - [CONNECTED]: terminalConnected ?? (isEquipmentModification ? null : true), - }, - }; -}; - -export const createConnectivityData = (equipmentToModify: any, index: number) => ({ - busbarSectionId: equipmentToModify?.[`busOrBusbarSectionId${index}`]?.value ?? null, - connectionDirection: equipmentToModify?.[`connectionDirection${index}`]?.value ?? null, - connectionName: equipmentToModify?.[`connectionName${index}`]?.value ?? '', - connectionPosition: equipmentToModify?.[`connectionPosition${index}`]?.value ?? null, - voltageLevelId: equipmentToModify?.[`voltageLevelId${index}`]?.value ?? null, - terminalConnected: equipmentToModify?.[`terminal${index}Connected`]?.value ?? null, - isEquipmentModification: true, -}); diff --git a/src/components/dialogs/connectivity/connectivity-form.tsx b/src/components/dialogs/connectivity/connectivity-form.tsx deleted file mode 100644 index 822a5817b6..0000000000 --- a/src/components/dialogs/connectivity/connectivity-form.tsx +++ /dev/null @@ -1,361 +0,0 @@ -/** - * Copyright (c) 2022, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import ExploreOffOutlinedIcon from '@mui/icons-material/ExploreOffOutlined'; -import ExploreOutlinedIcon from '@mui/icons-material/ExploreOutlined'; -import { GridDirection, IconButton, Tooltip } from '@mui/material'; -import Grid from '@mui/material/Grid'; -import { - BUS_OR_BUSBAR_SECTION, - CONNECTED, - CONNECTION_DIRECTION, - CONNECTION_NAME, - CONNECTION_POSITION, - CONNECTIVITY, - ID, - VOLTAGE_LEVEL, -} from 'components/utils/field-constants'; -import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; -import { useFormContext, useWatch } from 'react-hook-form'; -import { useIntl } from 'react-intl'; -import PositionDiagramPane from '../../grid-layout/cards/diagrams/singleLineDiagram/positionDiagram/position-diagram-pane'; -import { isNodeBuilt } from '../../graph/util/model-functions'; -import { CONNECTION_DIRECTIONS, getConnectionDirectionLabel } from '../../network/constants'; -import { - AutocompleteInput, - Identifiable, - IntegerInput, - Option, - SelectInput, - SwitchInput, - TextInput, -} from '@gridsuite/commons-ui'; -import { fetchBusesOrBusbarSectionsForVoltageLevel } from 'services/study/network'; -import CheckboxNullableInput from '../../utils/rhf-inputs/boolean-nullable-input'; -import { areIdsEqual, getObjectId } from '../../utils/utils'; -import { getConnectivityBusBarSectionData, getConnectivityVoltageLevelData } from './connectivity-form-utils'; -import type { UUID } from 'node:crypto'; -import { ConnectablePositionFormInfos } from './connectivity.type'; -import { CurrentTreeNode } from '../../graph/tree-node.type'; - -/** - * Hook to handle a 'connectivity value' (voltage level, bus or bus bar section) - * @param id optional id that has to be defined if the component is used more than once in a form - * @param voltageLevelSelectLabel label to display for the voltage level auto complete component - * @param direction direction of placement. Either 'row' or 'column', 'row' by default. - * @param withDirectionsInfos - * @param withPosition - * @param voltageLevelOptions list of network voltage levels - * @param newBusOrBusbarSectionOptions list of bus or bus bar sections for the newly created voltage level - * @param studyUuid the study we are currently working on - * @param currentNode the currently selected tree node - * @param currentRootNetworkUuid The root network uuid we are currently working on - * @param onVoltageLevelChangeCallback callback to be called when the voltage level changes - * @param isEquipmentModification connectivity form is used in a modification form or not - * @param previousValues previous values of connectivity form's fields - * @returns JSX.Element - */ - -interface ConnectivityFormProps { - id?: string; - voltageLevelSelectLabel?: string; - direction?: GridDirection; - withDirectionsInfos?: boolean; - withPosition: boolean; - voltageLevelOptions?: Identifiable[]; - newBusOrBusbarSectionOptions?: Option[]; - studyUuid: UUID; - currentNode: CurrentTreeNode; - currentRootNetworkUuid: UUID; - onVoltageLevelChangeCallback?: () => void; - isEquipmentModification?: boolean; - previousValues?: { - connectablePosition?: ConnectablePositionFormInfos; - voltageLevelId?: string; - busOrBusbarSectionId?: string; - terminalConnected?: boolean | null; - }; -} - -export function ConnectivityForm({ - id = CONNECTIVITY, - voltageLevelSelectLabel = 'VOLTAGE_LEVEL', - direction = 'row', - withDirectionsInfos = true, - withPosition = false, - voltageLevelOptions = [], - newBusOrBusbarSectionOptions = [], - studyUuid, - currentNode, - currentRootNetworkUuid, - onVoltageLevelChangeCallback = undefined, - isEquipmentModification = false, - previousValues, -}: Readonly) { - const currentNodeUuid = currentNode?.id; - const [busOrBusbarSectionOptions, setBusOrBusbarSectionOptions] = useState([]); - - const [isDiagramPaneOpen, setIsDiagramPaneOpen] = useState(false); - - const lastFetchedBusesVlIds = useRef(null); - const intl = useIntl(); - - const { setValue, getValues } = useFormContext(); - - const watchVoltageLevelId = useWatch({ - name: `${id}.${VOLTAGE_LEVEL}.${ID}`, - }); - - const vlOptions = useMemo( - () => - voltageLevelOptions.map((item) => ({ - id: item.id, - label: item.name ?? '', - })), - [voltageLevelOptions] - ); - - useEffect(() => { - if (watchVoltageLevelId) { - const existingVoltageLevelOption = voltageLevelOptions.find((option) => option.id === watchVoltageLevelId); - if (existingVoltageLevelOption) { - fetchBusesOrBusbarSectionsForVoltageLevel( - studyUuid, - currentNodeUuid, - currentRootNetworkUuid, - watchVoltageLevelId - ).then((busesOrbusbarSections) => { - lastFetchedBusesVlIds.current = watchVoltageLevelId; - setBusOrBusbarSectionOptions( - busesOrbusbarSections?.map((busesOrbusbarSection) => ({ - id: busesOrbusbarSection.id, - label: busesOrbusbarSection?.name ?? '', - })) || [] - ); - }); - } - if (watchVoltageLevelId !== lastFetchedBusesVlIds.current) { - setBusOrBusbarSectionOptions([]); - } - } else { - setBusOrBusbarSectionOptions([]); - } - }, [watchVoltageLevelId, studyUuid, currentNodeUuid, currentRootNetworkUuid, voltageLevelOptions, id]); - - useEffect(() => { - if (newBusOrBusbarSectionOptions?.length > 0) { - setBusOrBusbarSectionOptions(newBusOrBusbarSectionOptions); - } - }, [newBusOrBusbarSectionOptions]); - - const handleChangeVoltageLevel = useCallback(() => { - onVoltageLevelChangeCallback?.(); - setValue(`${id}.${BUS_OR_BUSBAR_SECTION}`, null); - }, [id, onVoltageLevelChangeCallback, setValue]); - - useEffect(() => { - const currentBusOrBusbarSection = getValues(`${id}.${BUS_OR_BUSBAR_SECTION}`); - if (busOrBusbarSectionOptions?.length > 0 && currentBusOrBusbarSection?.id !== null) { - setValue(`${id}.${BUS_OR_BUSBAR_SECTION}`, currentBusOrBusbarSection); - } - }, [busOrBusbarSectionOptions, setValue, id, getValues]); - - const newVoltageLevelField = ( - { - if (typeof value === 'string') { - const data = getConnectivityVoltageLevelData({ voltageLevelId: value }); - return { id: data?.id ?? '', label: '' }; - } - return value; - }} - previousValue={isEquipmentModification ? previousValues?.voltageLevelId : undefined} - onChangeCallback={handleChangeVoltageLevel} - allowNewValue - forcePopupIcon - selectOnFocus - name={`${id}.${VOLTAGE_LEVEL}`} - label={voltageLevelSelectLabel} - options={vlOptions} - getOptionLabel={getObjectId} - size={'small'} - /> - ); - - const previousConnectedField = useMemo(() => { - if (!isEquipmentModification) { - return null; - } - return previousValues?.terminalConnected - ? intl.formatMessage({ id: 'connected' }) - : intl.formatMessage({ id: 'disconnected' }); - }, [intl, previousValues, isEquipmentModification]); - - const getTooltipMessageId = useMemo(() => { - if (!isNodeBuilt(currentNode)) { - return 'NodeNotBuildPositionMessage'; - } else if (watchVoltageLevelId) { - return 'DisplayTakenPositions'; - } else { - return 'NoVoltageLevelPositionMessage'; - } - }, [currentNode, watchVoltageLevelId]); - - const connectedField = isEquipmentModification ? ( - - ) : ( - - ); - - const newBusOrBusbarSectionField = ( - value ?? ''} - outputTransform={(value) => { - if (typeof value === 'string') { - const data = getConnectivityBusBarSectionData({ busbarSectionId: value }); - return { id: data?.id ?? '', label: '' }; - } - return value; - }} - size={'small'} - /> - ); - - const newConnectionNameField = ( - - ); - - const previousConnectionDirectionLabel = isEquipmentModification - ? (getConnectionDirectionLabel(previousValues?.connectablePosition?.connectionDirection) ?? null) - : null; - - const newConnectionDirectionField = ( - - ); - - const handleClickOpenDiagramPane = useCallback(() => { - setIsDiagramPaneOpen(true); - }, []); - - const handleCloseDiagramPane = useCallback(() => { - setIsDiagramPaneOpen(false); - }, []); - - const newConnectionPositionField = ( - - ); - - const newPositionIconField = ( - - - {isNodeBuilt(currentNode) && watchVoltageLevelId ? ( - - ) : ( - - )} - - - ); - - const gridSize = direction && (direction === 'column' || direction === 'column-reverse') ? 24 : 12; - const conditionalSize = withPosition && withDirectionsInfos ? 8 : gridSize; - return ( - <> - - - {newVoltageLevelField} - - - {newBusOrBusbarSectionField} - - - {withDirectionsInfos && ( - <> - - {connectedField} - - - {newConnectionNameField} - - - {newConnectionDirectionField} - - {withPosition && ( - <> - - {newConnectionPositionField} - - - {newPositionIconField} - - - )} - - )} - - - - ); -} diff --git a/src/components/dialogs/connectivity/connectivity.type.ts b/src/components/dialogs/connectivity/connectivity.type.ts deleted file mode 100644 index f0ef37c91a..0000000000 --- a/src/components/dialogs/connectivity/connectivity.type.ts +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2025, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -export interface ConnectablePositionFormInfos { - connectionDirection: string | null; - connectionName?: string | null; - connectionPosition?: number | null; -} - -export interface ConnectablePositionInfos { - connectionDirection: string | null; - connectionName?: string | null; - connectionPosition?: number | null; -} - -export interface Connectivity { - voltageLevel: { id?: string }; - busOrBusbarSection: { id?: string }; - connectionDirection?: string; - connectionName?: string; - connectionPosition?: number; - terminalConnected?: boolean; -} diff --git a/src/components/dialogs/line-types-catalog/line-types-catalog-selector-form.tsx b/src/components/dialogs/line-types-catalog/line-types-catalog-selector-form.tsx index 1e6145f18b..886c445a59 100644 --- a/src/components/dialogs/line-types-catalog/line-types-catalog-selector-form.tsx +++ b/src/components/dialogs/line-types-catalog/line-types-catalog-selector-form.tsx @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { AutocompleteInput, Option } from '@gridsuite/commons-ui'; +import { areIdsEqual, AutocompleteInput, Option } from '@gridsuite/commons-ui'; import GridItem from '../commons/grid-item'; import GridSection from '../commons/grid-section'; import { Grid, Tab, Tabs } from '@mui/material'; @@ -16,7 +16,6 @@ import { UNDERGROUND_SHAPE_FACTORS, } from '../../utils/field-constants'; import { CATEGORIES_TABS, LineTypeInfo } from './line-catalog.type'; -import { areIdsEqual } from '../../utils/utils'; import { useFormContext } from 'react-hook-form'; import { FormattedMessage } from 'react-intl'; import LimitCustomAgGrid from './limit-custom-aggrid'; diff --git a/src/components/dialogs/network-modifications/battery/battery-dialog.type.ts b/src/components/dialogs/network-modifications/battery/battery-dialog.type.ts index 7f92555981..192091661f 100644 --- a/src/components/dialogs/network-modifications/battery/battery-dialog.type.ts +++ b/src/components/dialogs/network-modifications/battery/battery-dialog.type.ts @@ -30,14 +30,13 @@ import { TRANSIENT_REACTANCE, VOLTAGE_LEVEL, } from '../../../utils/field-constants'; -import { ConnectablePositionFormInfos } from '../../connectivity/connectivity.type'; import { MinMaxReactiveLimitsFormInfos, ReactiveCapabilityCurvePoints, } from '../../reactive-limits/reactive-limits.type'; import { ActivePowerControlInfos } from '../../active-power-control/active-power-control.type'; import { ShortCircuitFormInfos } from '../../short-circuit/short-circuit-utils'; -import { FieldConstants, Property } from '@gridsuite/commons-ui'; +import { ConnectablePositionFormInfos, FieldConstants, Property } from '@gridsuite/commons-ui'; export type BatteryDialogSchemaBaseForm = { [EQUIPMENT_NAME]?: string; diff --git a/src/components/dialogs/network-modifications/battery/creation/battery-creation-dialog.tsx b/src/components/dialogs/network-modifications/battery/creation/battery-creation-dialog.tsx index 69a84aa409..bb8a6bee75 100644 --- a/src/components/dialogs/network-modifications/battery/creation/battery-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/battery/creation/battery-creation-dialog.tsx @@ -23,6 +23,12 @@ import { useSnackMessage, DeepNullable, sanitizeString, + getConnectivityWithPositionEmptyFormData, + getConnectivityWithPositionSchema, + getConnectivityFormData, + getSetPointsSchema, + getSetPointsEmptyFormData, + UNDEFINED_CONNECTION_DIRECTION, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; @@ -51,12 +57,7 @@ import { TRANSIENT_REACTANCE, VOLTAGE_LEVEL, } from 'components/utils/field-constants'; -import { - getConnectivityFormData, - getConnectivityWithPositionEmptyFormData, - getConnectivityWithPositionSchema, -} from '../../../connectivity/connectivity-form-utils'; -import { FORM_LOADING_DELAY, UNDEFINED_CONNECTION_DIRECTION } from 'components/network/constants'; +import { FORM_LOADING_DELAY } from 'components/network/constants'; import { getReactiveLimitsEmptyFormData, getReactiveLimitsFormData, @@ -72,7 +73,7 @@ import { } from '../../../active-power-control/active-power-control-utils'; import { BatteryCreationInfos } from '../../../../../services/network-modification-types'; import BatteryCreationForm from './battery-creation-form'; -import { getSetPointsEmptyFormData, getSetPointsSchema } from '../../../set-points/set-points-utils'; +import { isNodeBuilt } from 'components/graph/util/model-functions'; import { NetworkModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; import { getShortCircuitEmptyFormData, @@ -260,7 +261,7 @@ export default function BatteryCreationDialog({ delay: FORM_LOADING_DELAY, }); return ( - + ) { const voltageLevelOptions = useVoltageLevelsListInfos(studyUuid, currentNode.id, currentRootNetworkUuid); + const fetchBusesOrBusbarSections = useCallback( + (voltageLevelId: string) => + fetchBusesOrBusbarSectionsForVoltageLevel( + studyUuid, + currentNode.id, + currentRootNetworkUuid, + voltageLevelId + ), + [studyUuid, currentNode.id, currentRootNetworkUuid] + ); + const batteryIdField = ( ); @@ -45,11 +65,10 @@ export default function BatteryCreationForm({ const connectivityForm = ( ); diff --git a/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.tsx b/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.tsx index 5240af6b16..e246b837c7 100644 --- a/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/battery/modification/battery-modification-dialog.tsx @@ -21,6 +21,11 @@ import { sanitizeString, FieldConstants, toModificationOperation, + getConnectivityWithPositionEmptyFormData, + getConnectivityFormData, + getConnectivityWithPositionSchema, + getSetPointsEmptyFormData, + getSetPointsSchema, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; @@ -62,11 +67,6 @@ import { EQUIPMENT_INFOS_TYPES } from 'components/utils/equipment-types'; import { EquipmentIdSelector } from '../../../equipment-id/equipment-id-selector'; import { modifyBattery } from '../../../../../services/study/network-modifications'; import { fetchNetworkElementInfos } from '../../../../../services/study/network'; -import { - getConnectivityFormData, - getConnectivityWithPositionEmptyFormData, - getConnectivityWithPositionSchema, -} from '../../../connectivity/connectivity-form-utils'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; import { BatteryFormInfos, BatteryModificationDialogSchemaForm } from '../battery-dialog.type'; import { FetchStatus } from '../../../../../services/utils.type'; @@ -76,7 +76,6 @@ import { } from '../../../active-power-control/active-power-control-utils'; import { BatteryModificationInfos } from '../../../../../services/network-modification-types'; import BatteryModificationForm from './battery-modification-form'; -import { getSetPointsEmptyFormData, getSetPointsSchema } from '../../../set-points/set-points-utils'; import { ModificationDialog } from '../../../commons/modificationDialog'; import { EquipmentModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; import { useFormWithDirtyTracking } from 'components/dialogs/commons/use-form-with-dirty-tracking'; diff --git a/src/components/dialogs/network-modifications/battery/modification/battery-modification-form.tsx b/src/components/dialogs/network-modifications/battery/modification/battery-modification-form.tsx index 67a39ef8a3..0614621370 100644 --- a/src/components/dialogs/network-modifications/battery/modification/battery-modification-form.tsx +++ b/src/components/dialogs/network-modifications/battery/modification/battery-modification-form.tsx @@ -15,6 +15,7 @@ import { import { Grid, TextField } from '@mui/material'; import { ActivePowerAdornment, + ConnectivityForm, filledTextField, FloatInput, PropertiesForm, @@ -23,7 +24,6 @@ import { } from '@gridsuite/commons-ui'; import { ReactiveLimitsForm } from '../../../reactive-limits/reactive-limits-form'; import { FormattedMessage } from 'react-intl'; -import { ConnectivityForm } from '../../../connectivity/connectivity-form'; import GridItem from '../../../commons/grid-item'; import GridSection from '../../../commons/grid-section'; import { ActivePowerControlForm } from '../../../active-power-control/active-power-control-form'; @@ -33,6 +33,9 @@ import { BatteryFormInfos } from '../battery-dialog.type'; import { CurrentTreeNode } from '../../../../graph/tree-node.type'; import useVoltageLevelsListInfos from '../../../../../hooks/use-voltage-levels-list-infos'; import ShortCircuitForm from '../../../short-circuit/short-circuit-form'; +import PositionDiagramPane from '../../../../grid-layout/cards/diagrams/singleLineDiagram/positionDiagram/position-diagram-pane'; +import { useCallback } from 'react'; +import { fetchBusesOrBusbarSectionsForVoltageLevel } from '../../../../../services/study/network'; export interface BatteryModificationFormProps { studyUuid: UUID; @@ -53,6 +56,18 @@ export default function BatteryModificationForm({ equipmentId, }: Readonly) { const voltageLevelOptions = useVoltageLevelsListInfos(studyUuid, currentNode?.id, currentRootNetworkUuid); + + const fetchBusesOrBusbarSections = useCallback( + (voltageLevelId: string) => + fetchBusesOrBusbarSectionsForVoltageLevel( + studyUuid, + currentNode.id, + currentRootNetworkUuid, + voltageLevelId + ), + [studyUuid, currentNode.id, currentRootNetworkUuid] + ); + const batteryIdField = ( ); diff --git a/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-constants.ts b/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-constants.ts index f18e6ac66d..fdd7a8adf2 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-constants.ts +++ b/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-constants.ts @@ -7,12 +7,12 @@ import type { ReadonlyDeep } from 'type-fest'; import { DataType, FieldOptionType } from './assignment.type'; -import { LOAD_TYPES } from '../../../../../network/constants'; import { EquipmentType, FieldType, KILO_AMPERE, KILO_VOLT, + LOAD_TYPES, MEGA_VAR, MEGA_VOLT_AMPERE, MEGA_WATT, diff --git a/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-form.tsx b/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-form.tsx index c45fe7b9ea..f700d2cc45 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-form.tsx +++ b/src/components/dialogs/network-modifications/by-filter/by-assignment/assignment/assignment-form.tsx @@ -7,6 +7,7 @@ import { FC, useCallback, useMemo } from 'react'; import { + areIdsEqual, AutocompleteInput, DirectoryItemsInput, ElementType, @@ -32,7 +33,7 @@ import { import { useFormContext, useWatch } from 'react-hook-form'; import { getIdOrValue } from '../../../../commons/utils'; import { DataType } from './assignment.type'; -import { areIdsEqual, comparatorStrIgnoreCase } from '../../../../../utils/utils'; +import { comparatorStrIgnoreCase } from '../../../../../utils/utils'; import GridItem from '../../../../commons/grid-item'; import { useIntl } from 'react-intl'; import { EQUIPMENTS_FIELDS, EquipmentTypeOptionType } from './assignment-constants'; diff --git a/src/components/dialogs/network-modifications/by-filter/by-formula/formula/reference-autocomplete-input.tsx b/src/components/dialogs/network-modifications/by-filter/by-formula/formula/reference-autocomplete-input.tsx index 860c767921..376de05c77 100644 --- a/src/components/dialogs/network-modifications/by-filter/by-formula/formula/reference-autocomplete-input.tsx +++ b/src/components/dialogs/network-modifications/by-filter/by-formula/formula/reference-autocomplete-input.tsx @@ -9,8 +9,7 @@ import { FunctionComponent, useCallback, useState } from 'react'; import { useController } from 'react-hook-form'; import { FilterOptionsState } from '@mui/material'; import { useIntl } from 'react-intl'; -import { AutocompleteInput } from '@gridsuite/commons-ui'; -import { areIdsEqual } from '../../../../../utils/utils'; +import { areIdsEqual, AutocompleteInput } from '@gridsuite/commons-ui'; const ReferenceAutocompleteInput: FunctionComponent<{ name: string; diff --git a/src/components/dialogs/network-modifications/common/measurements/branch-active-reactive-power-form-utils.ts b/src/components/dialogs/network-modifications/common/measurements/branch-active-reactive-power-form-utils.ts deleted file mode 100644 index 101280fa72..0000000000 --- a/src/components/dialogs/network-modifications/common/measurements/branch-active-reactive-power-form-utils.ts +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2025, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import { MEASUREMENT_P1, MEASUREMENT_Q1, MEASUREMENT_P2, MEASUREMENT_Q2 } from 'components/utils/field-constants'; -import { - getPowerWithValidityEditData, - getPowerWithValidityEmptyFormData, - getPowerWithValidityValidationSchema, -} from './power-with-validity-utils'; -import yup from '../../../../utils/yup-config'; - -export function getBranchActiveReactivePowerEmptyFormDataProperties() { - return { - ...getPowerWithValidityEmptyFormData(MEASUREMENT_P1), - ...getPowerWithValidityEmptyFormData(MEASUREMENT_Q1), - ...getPowerWithValidityEmptyFormData(MEASUREMENT_P2), - ...getPowerWithValidityEmptyFormData(MEASUREMENT_Q2), - }; -} -export function getBranchActiveReactivePowerEmptyFormData(id: string) { - return { - [id]: { - ...getBranchActiveReactivePowerEmptyFormDataProperties(), - }, - }; -} - -export const getBranchActiveReactivePowerValidationSchemaProperties = () => ({ - ...getPowerWithValidityValidationSchema(MEASUREMENT_P1), - ...getPowerWithValidityValidationSchema(MEASUREMENT_Q1), - ...getPowerWithValidityValidationSchema(MEASUREMENT_P2), - ...getPowerWithValidityValidationSchema(MEASUREMENT_Q2), -}); -export const getBranchActiveReactivePowerValidationSchema = (id: string) => ({ - [id]: yup.object().shape({ - ...getBranchActiveReactivePowerValidationSchemaProperties(), - }), -}); - -export function getBranchActiveReactivePowerEditDataProperties(branchData: any) { - return { - ...getPowerWithValidityEditData(MEASUREMENT_P1, { - value: branchData?.p1MeasurementValue?.value, - validity: branchData?.p1MeasurementValidity?.value, - }), - ...getPowerWithValidityEditData(MEASUREMENT_Q1, { - value: branchData?.q1MeasurementValue?.value, - validity: branchData?.q1MeasurementValidity?.value, - }), - ...getPowerWithValidityEditData(MEASUREMENT_P2, { - value: branchData?.p2MeasurementValue?.value, - validity: branchData?.p2MeasurementValidity?.value, - }), - ...getPowerWithValidityEditData(MEASUREMENT_Q2, { - value: branchData?.q2MeasurementValue?.value, - validity: branchData?.q2MeasurementValidity?.value, - }), - }; -} -export function getBranchActiveReactivePowerEditData(id: string, branchData: any) { - return { - [id]: { - ...getBranchActiveReactivePowerEditDataProperties(branchData), - }, - }; -} diff --git a/src/components/dialogs/network-modifications/common/measurements/branch-active-reactive-power-form.tsx b/src/components/dialogs/network-modifications/common/measurements/branch-active-reactive-power-form.tsx deleted file mode 100644 index 305737802f..0000000000 --- a/src/components/dialogs/network-modifications/common/measurements/branch-active-reactive-power-form.tsx +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (c) 2025, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import { FunctionComponent } from 'react'; -import GridSection from '../../../commons/grid-section'; -import { BranchActiveReactivePowerMeasurementsFormProps } from './measurement.type'; -import { PowerMeasurementsForm } from './power-measurements-form'; -import { type MuiStyles } from '@gridsuite/commons-ui'; - -const styles = { - h3: { - marginTop: 0, - marginBottom: 0, - }, -} as const satisfies MuiStyles; - -const BranchActiveReactivePowerMeasurementsForm: FunctionComponent = ({ - equipmentToModify, -}) => { - return ( - <> - - - - - - - ); -}; - -export default BranchActiveReactivePowerMeasurementsForm; diff --git a/src/components/dialogs/network-modifications/common/measurements/injection-active-reactive-power-form-utils.ts b/src/components/dialogs/network-modifications/common/measurements/injection-active-reactive-power-form-utils.ts deleted file mode 100644 index 30cac2e551..0000000000 --- a/src/components/dialogs/network-modifications/common/measurements/injection-active-reactive-power-form-utils.ts +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (c) 2025, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import { MEASUREMENT_P, MEASUREMENT_Q } from 'components/utils/field-constants'; -import { - getPowerWithValidityEditData, - getPowerWithValidityEmptyFormData, - getPowerWithValidityValidationSchema, -} from './power-with-validity-utils'; -import yup from '../../../../utils/yup-config'; - -export function getInjectionActiveReactivePowerEmptyFormDataProperties() { - return { - ...getPowerWithValidityEmptyFormData(MEASUREMENT_P), - ...getPowerWithValidityEmptyFormData(MEASUREMENT_Q), - }; -} -export function getInjectionActiveReactivePowerEmptyFormData(id: string) { - return { - [id]: { - ...getInjectionActiveReactivePowerEmptyFormDataProperties(), - }, - }; -} - -export const getInjectionActiveReactivePowerValidationSchemaProperties = () => - yup.object().shape({ - ...getPowerWithValidityValidationSchema(MEASUREMENT_P), - ...getPowerWithValidityValidationSchema(MEASUREMENT_Q), - }); - -export const getInjectionActiveReactivePowerValidationSchema = (id: string) => ({ - [id]: getInjectionActiveReactivePowerValidationSchemaProperties(), -}); - -export function getInjectionActiveReactivePowerEditDataProperties(injectionData: any) { - return { - ...getPowerWithValidityEditData(MEASUREMENT_P, { - value: injectionData?.pMeasurementValue?.value, - validity: injectionData?.pMeasurementValidity?.value, - }), - ...getPowerWithValidityEditData(MEASUREMENT_Q, { - value: injectionData?.qMeasurementValue?.value, - validity: injectionData?.qMeasurementValidity?.value, - }), - }; -} -export function getInjectionActiveReactivePowerEditData(id: string, injectionData: any) { - return { - [id]: { - ...getInjectionActiveReactivePowerEditDataProperties(injectionData), - }, - }; -} diff --git a/src/components/dialogs/network-modifications/common/measurements/measurement.type.ts b/src/components/dialogs/network-modifications/common/measurements/measurement.type.ts deleted file mode 100644 index 0cde764dad..0000000000 --- a/src/components/dialogs/network-modifications/common/measurements/measurement.type.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2025, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import { type FieldType } from '@gridsuite/commons-ui'; - -export interface BranchActiveReactivePowerMeasurementsFormProps { - equipmentToModify: any; -} - -export interface MeasurementInfo { - value: number; - validity: boolean; -} - -export interface MeasurementProps { - id: string; - field: FieldType; - measurement?: MeasurementInfo; -} diff --git a/src/components/dialogs/network-modifications/common/measurements/power-measurements-form.tsx b/src/components/dialogs/network-modifications/common/measurements/power-measurements-form.tsx deleted file mode 100644 index 87c28ff8df..0000000000 --- a/src/components/dialogs/network-modifications/common/measurements/power-measurements-form.tsx +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (c) 2025, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import { Grid } from '@mui/material'; -import { FunctionComponent } from 'react'; -import GridItem from '../../../commons/grid-item'; -import { PowerWithValidityForm } from './power-with-validity-form'; -import { FieldType } from '@gridsuite/commons-ui'; -import { - STATE_ESTIMATION, - MEASUREMENT_P1, - MEASUREMENT_P2, - MEASUREMENT_Q1, - MEASUREMENT_Q2, - MEASUREMENT_P, - MEASUREMENT_Q, -} from 'components/utils/field-constants'; -import { MeasurementInfo } from './measurement.type'; - -interface PowerMeasurementsFormProps { - side?: 1 | 2; - activePowerMeasurement?: MeasurementInfo; - reactivePowerMeasurement?: MeasurementInfo; - reactivePowerOnly?: boolean; -} - -export const PowerMeasurementsForm: FunctionComponent = ({ - side, - activePowerMeasurement, - reactivePowerMeasurement, - reactivePowerOnly = false, -}) => { - const getActiveMeasurementType = (side: number | null | undefined) => { - if (!side) { - return MEASUREMENT_P; - } - return side === 1 ? MEASUREMENT_P1 : MEASUREMENT_P2; - }; - - const getReactiveMeasurementType = (side: number | null | undefined) => { - if (!side) { - return MEASUREMENT_Q; - } - return side === 1 ? MEASUREMENT_Q1 : MEASUREMENT_Q2; - }; - - const activePowerId = `${STATE_ESTIMATION}.${getActiveMeasurementType(side)}`; - const reactivePowerId = `${STATE_ESTIMATION}.${getReactiveMeasurementType(side)}`; - - return ( - - {!reactivePowerOnly && ( - - - - )} - - - - - ); -}; diff --git a/src/components/dialogs/network-modifications/common/measurements/power-with-validity-form.tsx b/src/components/dialogs/network-modifications/common/measurements/power-with-validity-form.tsx deleted file mode 100644 index 39cd7101c5..0000000000 --- a/src/components/dialogs/network-modifications/common/measurements/power-with-validity-form.tsx +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (c) 2025, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import Grid from '@mui/material/Grid'; -import { FunctionComponent, useMemo } from 'react'; -import { useIntl } from 'react-intl'; -import { - ActivePowerAdornment, - convertInputValue, - FieldConstants, - FieldType, - FloatInput, - ReactivePowerAdornment, -} from '@gridsuite/commons-ui'; -import { MeasurementProps } from './measurement.type'; -import CheckboxNullableInput from '../../../../utils/rhf-inputs/boolean-nullable-input'; -import GridItem from '../../../commons/grid-item'; -import { VALIDITY } from '../../../../utils/field-constants'; - -export const PowerWithValidityForm: FunctionComponent = ({ id, field, measurement }) => { - const intl = useIntl(); - - const previousValidityField = useMemo(() => { - if (measurement?.validity == null) { - return ''; - } - return measurement.validity - ? intl.formatMessage({ id: 'ValidMeasurement' }) - : intl.formatMessage({ id: 'InvalidMeasurement' }); - }, [intl, measurement?.validity]); - - const valueField = ( - - ); - - const validityField = ( - - ); - - return ( - - {valueField} - {validityField} - - ); -}; diff --git a/src/components/dialogs/network-modifications/common/measurements/power-with-validity-utils.ts b/src/components/dialogs/network-modifications/common/measurements/power-with-validity-utils.ts deleted file mode 100644 index 76f423978f..0000000000 --- a/src/components/dialogs/network-modifications/common/measurements/power-with-validity-utils.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (c) 2025, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import yup from '../../../../utils/yup-config'; -import { VALIDITY } from '../../../../utils/field-constants'; -import { MeasurementInfo } from './measurement.type'; -import { FieldConstants } from '@gridsuite/commons-ui'; - -export function getPowerWithValidityEmptyFormData(id: string) { - return { - [id]: { - [FieldConstants.VALUE]: null, - [VALIDITY]: null, - }, - }; -} - -export function getPowerWithValidityValidationSchema(id: string) { - return { - [id]: yup.object().shape({ - [FieldConstants.VALUE]: yup.number().nullable(), - [VALIDITY]: yup.boolean().nullable(), - }), - }; -} - -export function getPowerWithValidityEditData(id: string, measurement: MeasurementInfo) { - return { - [id]: { - [FieldConstants.VALUE]: measurement?.value ?? null, - [VALIDITY]: measurement?.validity ?? null, - }, - }; -} diff --git a/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-dialog.tsx b/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-dialog.tsx index 5170758ae3..fbab7b50e2 100644 --- a/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-dialog.tsx +++ b/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-dialog.tsx @@ -198,10 +198,8 @@ export default function CreateCouplingDeviceDialog({ {selectedId != null && ( )} diff --git a/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-form.tsx b/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-form.tsx index e4a3281fea..ce3993f7e3 100644 --- a/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-form.tsx +++ b/src/components/dialogs/network-modifications/coupling-device/modification/create-coupling-device-form.tsx @@ -5,10 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { AutocompleteInput, filledTextField, Option } from '@gridsuite/commons-ui'; +import { AutocompleteInput, filledTextField, getObjectId, Option } from '@gridsuite/commons-ui'; import { BUS_BAR_SECTION_ID1, BUS_BAR_SECTION_ID2 } from 'components/utils/field-constants'; import GridItem from '../../../commons/grid-item'; -import { getObjectId } from '../../../../utils/utils'; import { Box, Grid, TextField, Tooltip } from '@mui/material'; import { InfoOutlined } from '@mui/icons-material'; import PositionDiagramPane from '../../../../grid-layout/cards/diagrams/singleLineDiagram/positionDiagram/position-diagram-pane'; @@ -16,24 +15,19 @@ import { useCallback, useState } from 'react'; import Button from '@mui/material/Button'; import { FormattedMessage, useIntl } from 'react-intl'; import GridSection from '../../../commons/grid-section'; -import type { UUID } from 'node:crypto'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; import { CurrentTreeNode } from '../../../../graph/tree-node.type'; export interface CreateCouplingDeviceFormProps { sectionOptions: Option[]; voltageLevelId: string; - studyUuid: UUID; currentNode: CurrentTreeNode; - currentRootNetworkUuid: UUID; } export default function CreateCouplingDeviceForm({ sectionOptions, - studyUuid, voltageLevelId, currentNode, - currentRootNetworkUuid, }: Readonly) { const [isDiagramPaneOpen, setIsDiagramPaneOpen] = useState(false); const intl = useIntl(); @@ -116,12 +110,9 @@ export default function CreateCouplingDeviceForm({ diff --git a/src/components/dialogs/network-modifications/delete-attaching-line/delete-attaching-line-form.tsx b/src/components/dialogs/network-modifications/delete-attaching-line/delete-attaching-line-form.tsx index a70bd3066d..6edb4e65b9 100644 --- a/src/components/dialogs/network-modifications/delete-attaching-line/delete-attaching-line-form.tsx +++ b/src/components/dialogs/network-modifications/delete-attaching-line/delete-attaching-line-form.tsx @@ -7,7 +7,7 @@ import { Grid } from '@mui/material'; import { Fragment, useCallback, useEffect, useState } from 'react'; -import { AutocompleteInput, EquipmentType, Option, TextInput } from '@gridsuite/commons-ui'; +import { areIdsEqual, AutocompleteInput, EquipmentType, getObjectId, Option, TextInput } from '@gridsuite/commons-ui'; import { ATTACHED_LINE_ID, LINE_TO_ATTACH_TO_1_ID, @@ -15,7 +15,6 @@ import { REPLACING_LINE_1_ID, REPLACING_LINE_1_NAME, } from 'components/utils/field-constants'; -import { areIdsEqual, getObjectId } from 'components/utils/utils'; import { fetchEquipmentsIds } from '../../../../services/study/network-map'; import GridSection from '../../commons/grid-section'; import GridItem from '../../commons/grid-item'; diff --git a/src/components/dialogs/network-modifications/delete-voltage-level-on-line/delete-voltage-level-on-line-form.tsx b/src/components/dialogs/network-modifications/delete-voltage-level-on-line/delete-voltage-level-on-line-form.tsx index d4c5929c40..e2f911badf 100644 --- a/src/components/dialogs/network-modifications/delete-voltage-level-on-line/delete-voltage-level-on-line-form.tsx +++ b/src/components/dialogs/network-modifications/delete-voltage-level-on-line/delete-voltage-level-on-line-form.tsx @@ -7,14 +7,13 @@ import { Grid } from '@mui/material'; import { useEffect, useState } from 'react'; -import { AutocompleteInput, EquipmentType, TextInput } from '@gridsuite/commons-ui'; +import { areIdsEqual, AutocompleteInput, EquipmentType, getObjectId, TextInput } from '@gridsuite/commons-ui'; import { LINE_TO_ATTACH_TO_1_ID, LINE_TO_ATTACH_TO_2_ID, REPLACING_LINE_1_ID, REPLACING_LINE_1_NAME, } from 'components/utils/field-constants'; -import { areIdsEqual, getObjectId } from 'components/utils/utils'; import { fetchEquipmentsIds } from '../../../../services/study/network-map'; import GridSection from '../../commons/grid-section'; import GridItem from '../../commons/grid-item'; diff --git a/src/components/dialogs/network-modifications/equipment-deletion/equipment-deletion-form.tsx b/src/components/dialogs/network-modifications/equipment-deletion/equipment-deletion-form.tsx index a133d574b4..5099c75157 100644 --- a/src/components/dialogs/network-modifications/equipment-deletion/equipment-deletion-form.tsx +++ b/src/components/dialogs/network-modifications/equipment-deletion/equipment-deletion-form.tsx @@ -14,6 +14,8 @@ import { EquipmentType, filledTextField, snackWithFallback, + getObjectId, + areIdsEqual, } from '@gridsuite/commons-ui'; import { DELETION_SPECIFIC_DATA, @@ -21,7 +23,7 @@ import { HVDC_LINE_LCC_DELETION_SPECIFIC_TYPE, TYPE, } from 'components/utils/field-constants'; -import { areIdsEqual, getObjectId, richTypeEquals } from 'components/utils/utils'; +import { richTypeEquals } from 'components/utils/utils'; import { EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import HvdcLccDeletionSpecificForm from './hvdc-lcc-deletion/hvdc-lcc-deletion-specific-form'; diff --git a/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx b/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx index 6913b4cefa..f6a2976c7c 100644 --- a/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/generator/creation/generator-creation-dialog.tsx @@ -23,6 +23,13 @@ import { useSnackMessage, DeepNullable, sanitizeString, + getConnectivityFormData, + getConnectivityWithPositionEmptyFormData, + getConnectivityWithPositionSchema, + getSetPointsSchema, + testValueWithinPowerInterval, + getSetPointsEmptyFormData, + UNDEFINED_CONNECTION_DIRECTION, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; @@ -59,14 +66,9 @@ import { VOLTAGE_REGULATION_TYPE, VOLTAGE_SET_POINT, } from 'components/utils/field-constants'; -import { - getConnectivityFormData, - getConnectivityWithPositionEmptyFormData, - getConnectivityWithPositionSchema, -} from '../../../connectivity/connectivity-form-utils'; import GeneratorCreationForm from './generator-creation-form'; import { getRegulatingTerminalFormData } from '../../../regulating-terminal/regulating-terminal-form-utils'; -import { FORM_LOADING_DELAY, REGULATION_TYPES, UNDEFINED_CONNECTION_DIRECTION } from 'components/network/constants'; +import { FORM_LOADING_DELAY, REGULATION_TYPES } from 'components/network/constants'; import { getReactiveLimitsEmptyFormData, getReactiveLimitsFormData, @@ -85,17 +87,13 @@ import { } from '../../../active-power-control/active-power-control-utils'; import { GeneratorCreationInfos } from '../../../../../services/network-modification-types'; import { GeneratorCreationDialogSchemaForm, GeneratorFormInfos } from '../generator-dialog.type'; -import { - getSetPointsEmptyFormData, - getSetPointsSchema, - testValueWithinPowerInterval, -} from '../../../set-points/set-points-utils'; import { NetworkModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; import { getShortCircuitEmptyFormData, getShortCircuitFormData, getShortCircuitFormSchema, } from '../../../short-circuit/short-circuit-utils'; +import { isNodeBuilt } from 'components/graph/util/model-functions'; import { toReactiveCapabilityCurveChoiceForGeneratorCreation } from '../../../reactive-limits/reactive-capability-curve/reactive-capability-utils'; const emptyFormData = { @@ -353,7 +351,7 @@ export default function GeneratorCreationDialog({ delay: FORM_LOADING_DELAY, }); return ( - + + fetchBusesOrBusbarSectionsForVoltageLevel( + studyUuid, + currentNode.id, + currentRootNetworkUuid, + voltageLevelId + ), + [studyUuid, currentNode.id, currentRootNetworkUuid] + ); + const generatorIdField = ( ); @@ -82,11 +96,10 @@ export default function GeneratorCreationForm({ const connectivityForm = ( ); diff --git a/src/components/dialogs/network-modifications/generator/generator-dialog.type.ts b/src/components/dialogs/network-modifications/generator/generator-dialog.type.ts index bc586d3632..c4cf65c35e 100644 --- a/src/components/dialogs/network-modifications/generator/generator-dialog.type.ts +++ b/src/components/dialogs/network-modifications/generator/generator-dialog.type.ts @@ -46,14 +46,13 @@ import { VOLTAGE_REGULATION_TYPE, VOLTAGE_SET_POINT, } from '../../../utils/field-constants'; -import { ConnectablePositionFormInfos } from '../../connectivity/connectivity.type'; import { MinMaxReactiveLimitsFormInfos, ReactiveCapabilityCurvePoints, } from '../../reactive-limits/reactive-limits.type'; import { ActivePowerControlInfos } from '../../active-power-control/active-power-control.type'; import { ShortCircuitFormInfos } from '../../short-circuit/short-circuit-utils'; -import { FieldConstants, Property } from '@gridsuite/commons-ui'; +import { ConnectablePositionFormInfos, FieldConstants, Property } from '@gridsuite/commons-ui'; export type GeneratorDialogSchemaBaseForm = { [EQUIPMENT_NAME]?: string; diff --git a/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.tsx b/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.tsx index 2ab8d374cc..b724aa52ea 100644 --- a/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.tsx +++ b/src/components/dialogs/network-modifications/generator/modification/generator-modification-dialog.tsx @@ -22,6 +22,11 @@ import { sanitizeString, FieldConstants, toModificationOperation, + getConnectivityFormData, + getConnectivityWithPositionSchema, + getConnectivityWithPositionEmptyFormData, + getSetPointsSchema, + getSetPointsEmptyFormData, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import yup from 'components/utils/yup-config'; @@ -64,7 +69,6 @@ import { VOLTAGE_SET_POINT, } from 'components/utils/field-constants'; import GeneratorModificationForm from './generator-modification-form'; -import { getSetPointsEmptyFormData, getSetPointsSchema } from '../../../set-points/set-points-utils'; import { getReactiveLimitsEmptyFormData, getReactiveLimitsFormData, @@ -81,11 +85,6 @@ import { EquipmentIdSelector } from '../../../equipment-id/equipment-id-selector import { modifyGenerator } from '../../../../../services/study/network-modifications'; import { fetchNetworkElementInfos } from '../../../../../services/study/network'; import { FetchStatus } from '../../../../../services/utils.type'; -import { - getConnectivityFormData, - getConnectivityWithPositionEmptyFormData, - getConnectivityWithPositionSchema, -} from '../../../connectivity/connectivity-form-utils'; import { isNodeBuilt } from '../../../../graph/util/model-functions'; import { getVoltageRegulationEmptyFormData, diff --git a/src/components/dialogs/network-modifications/generator/modification/generator-modification-form.tsx b/src/components/dialogs/network-modifications/generator/modification/generator-modification-form.tsx index 2278722a50..42f83bd6ef 100644 --- a/src/components/dialogs/network-modifications/generator/modification/generator-modification-form.tsx +++ b/src/components/dialogs/network-modifications/generator/modification/generator-modification-form.tsx @@ -7,12 +7,15 @@ import { ActivePowerAdornment, + CheckboxNullableInput, + ConnectivityForm, filledTextField, FloatInput, MVAPowerAdornment, + PropertiesForm, SelectInput, + SetPointsForm, TextInput, - PropertiesForm, } from '@gridsuite/commons-ui'; import { ENERGY_SOURCE, @@ -30,19 +33,19 @@ import { ENERGY_SOURCES, getEnergySourceLabel } from 'components/network/constan import { ReactiveLimitsForm } from '../../../reactive-limits/reactive-limits-form'; import { FormattedMessage, useIntl } from 'react-intl'; import { Box, Grid, TextField } from '@mui/material'; -import { ConnectivityForm } from '../../../connectivity/connectivity-form'; import useVoltageLevelsListInfos from '../../../../../hooks/use-voltage-levels-list-infos'; import GridItem from '../../../commons/grid-item'; import GridSection from '../../../commons/grid-section'; import { ActivePowerControlForm } from '../../../active-power-control/active-power-control-form'; -import CheckboxNullableInput from '../../../../utils/rhf-inputs/boolean-nullable-input'; import { VoltageRegulationForm } from '../../../voltage-regulation/voltage-regulation-form'; import { useWatch } from 'react-hook-form'; -import { SetPointsForm } from '../../../set-points/set-points-form'; import type { UUID } from 'node:crypto'; import { GeneratorFormInfos } from '../generator-dialog.type'; import { CurrentTreeNode } from '../../../../graph/tree-node.type'; import ShortCircuitForm from '../../../short-circuit/short-circuit-form'; +import PositionDiagramPane from '../../../../grid-layout/cards/diagrams/singleLineDiagram/positionDiagram/position-diagram-pane'; +import { useCallback } from 'react'; +import { fetchBusesOrBusbarSectionsForVoltageLevel } from '../../../../../services/study/network'; export interface GeneratorModificationFormProps { studyUuid: UUID; @@ -65,6 +68,17 @@ export default function GeneratorModificationForm({ const intl = useIntl(); const voltageLevelOptions = useVoltageLevelsListInfos(studyUuid, currentNodeUuid, currentRootNetworkUuid); + const fetchBusesOrBusbarSections = useCallback( + (voltageLevelId: string) => + fetchBusesOrBusbarSectionsForVoltageLevel( + studyUuid, + currentNode.id, + currentRootNetworkUuid, + voltageLevelId + ), + [studyUuid, currentNode.id, currentRootNetworkUuid] + ); + const energySourceLabelId = getEnergySourceLabel(generatorToModify?.energySource); const previousEnergySourceLabel = energySourceLabelId ? intl.formatMessage({ @@ -218,11 +232,7 @@ export default function GeneratorModificationForm({ const connectivityForm = ( ); diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-converter-station.tsx b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-converter-station.tsx index 7b8858d138..f2c713fca7 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-converter-station.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-converter-station.tsx @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { FloatInput, PercentageAdornment, TextInput } from '@gridsuite/commons-ui'; +import { ConnectivityForm, FloatInput, PercentageAdornment, TextInput } from '@gridsuite/commons-ui'; import { CONNECTIVITY, CONVERTER_STATION_ID, @@ -14,7 +14,6 @@ import { POWER_FACTOR, } from '../../../../../utils/field-constants'; import type { UUID } from 'node:crypto'; -import { ConnectivityForm } from '../../../../connectivity/connectivity-form'; import { Grid } from '@mui/material'; import useVoltageLevelsListInfos from '../../../../../../hooks/use-voltage-levels-list-infos'; import GridSection from '../../../../commons/grid-section'; @@ -25,6 +24,8 @@ import { CurrentTreeNode } from '../../../../../graph/tree-node.type'; import { LccConverterStationFormInfos } from './lcc-type'; import ModificationFiltersShuntCompensatorTable from '../modification/filter-shunt-compensator-table-modification'; import { useCallback } from 'react'; +import PositionDiagramPane from '../../../../../grid-layout/cards/diagrams/singleLineDiagram/positionDiagram/position-diagram-pane'; +import { fetchBusesOrBusbarSectionsForVoltageLevel } from '../../../../../../services/study/network'; interface LccConverterStationProps { id: string; @@ -47,6 +48,17 @@ export default function LccConverterStation({ }: Readonly) { const voltageLevelOptions = useVoltageLevelsListInfos(studyUuid, currentNode?.id, currentRootNetworkUuid); + const fetchBusesOrBusbarSections = useCallback( + (voltageLevelId: string) => + fetchBusesOrBusbarSectionsForVoltageLevel( + studyUuid, + currentNode.id, + currentRootNetworkUuid, + voltageLevelId + ), + [studyUuid, currentNode.id, currentRootNetworkUuid] + ); + const stationNameField = ( ); diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-type.ts b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-type.ts index 2982bb6ae2..8c7ee452d2 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-type.ts +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-type.ts @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { EQUIPMENT_TYPES } from '../../../../../utils/equipment-types'; -import { ConnectablePositionInfos } from '../../../../connectivity/connectivity.type'; import { ACTIVE_POWER_SETPOINT, CONVERTER_STATION_1, @@ -22,7 +21,7 @@ import { R, } from '../../../../../utils/field-constants'; import { LccShuntCompensatorInfos } from '../../../../../../services/network-modification-types'; -import { FieldConstants, Property } from '@gridsuite/commons-ui'; +import { ConnectablePositionInfos, FieldConstants, Property } from '@gridsuite/commons-ui'; export const LccDialogTab = { HVDC_LINE_TAB: 0, diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-utils.ts b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-utils.ts index 1e58cc44c7..0c15b968e0 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-utils.ts +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/common/lcc-utils.ts @@ -28,10 +28,6 @@ import { SHUNT_COMPENSATOR_SELECTED, VOLTAGE_LEVEL, } from '../../../../../utils/field-constants'; -import { - getConnectivityFormData, - getConnectivityWithPositionEmptyFormData, -} from '../../../../connectivity/connectivity-form-utils'; import yup from '../../../../../utils/yup-config'; import { LccConverterStationCreationInfos, @@ -42,19 +38,21 @@ import { ShuntCompensatorModificationFormSchema, } from './lcc-type'; import { + Connectivity, copyEquipmentPropertiesForCreation, creationPropertiesSchema, emptyProperties, FieldConstants, + getConnectivityFormData, + getConnectivityWithPositionEmptyFormData, + getConnectivityWithPositionSchema, getPropertiesFromModification, MODIFICATION_TYPES, modificationPropertiesSchema, sanitizeString, toModificationOperation, + UNDEFINED_CONNECTION_DIRECTION, } from '@gridsuite/commons-ui'; -import { UNDEFINED_CONNECTION_DIRECTION } from '../../../../../network/constants'; -import { getConnectivityWithPositionSchema } from 'components/dialogs/connectivity/connectivity-form-utils'; -import { Connectivity } from 'components/dialogs/connectivity/connectivity.type'; import { LccConverterStationModificationInfos, LccModificationInfos, diff --git a/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog.tsx b/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog.tsx index 6a3c518db2..2aa3b197a4 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/lcc/creation/lcc-creation-dialog.tsx @@ -38,6 +38,7 @@ import { DeepNullable, sanitizeString, FieldConstants, + Connectivity, } from '@gridsuite/commons-ui'; import { ModificationDialog } from '../../../../commons/modificationDialog'; import EquipmentSearchDialog from '../../../../equipment-search-dialog'; @@ -60,8 +61,8 @@ import { getLccHvdcLineFromSearchCopy, getLccHvdcLineSchema, } from '../common/lcc-utils'; +import { isNodeBuilt } from '../../../../../graph/util/model-functions'; import { NetworkModificationDialogProps } from '../../../../../graph/menus/network-modifications/network-modification-menu.type'; -import { Connectivity } from '../../../../connectivity/connectivity.type'; export type LccCreationSchemaForm = { [EQUIPMENT_ID]: string; @@ -231,7 +232,7 @@ export function LccCreationDialog({ ); return ( - + = ({ const { trigger } = useFormContext(); + const fetchBusesOrBusbarSections = useCallback( + (voltageLevelId: string) => + fetchBusesOrBusbarSectionsForVoltageLevel( + studyUuid, + currentNode.id, + currentRootNetworkUuid, + voltageLevelId + ), + [studyUuid, currentNode.id, currentRootNetworkUuid] + ); + const voltageRegulationOnWatch = useWatch({ name: `${id}.${VOLTAGE_REGULATION_ON}`, }); @@ -101,11 +114,7 @@ const ConverterStationPane: FunctionComponent = ({ const connectivityForm = ( = ({ busOrBusbarSectionId: previousValues?.busOrBusbarSectionId, terminalConnected: previousValues?.terminalConnected, }} + voltageLevelOptions={voltageLevelOptions} + PositionDiagramPane={PositionDiagramPane} + fetchBusesOrBusbarSections={fetchBusesOrBusbarSections} /> ); diff --git a/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-type.ts b/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-type.ts index 45e4f5a004..f3d982edbf 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-type.ts +++ b/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-type.ts @@ -8,7 +8,6 @@ import { MinMaxReactiveLimitsFormInfos, ReactiveCapabilityCurvePoints, } from '../../../../reactive-limits/reactive-limits.type'; -import { ConnectablePositionInfos } from '../../../../connectivity/connectivity.type'; import { BUS_OR_BUSBAR_SECTION, CONNECTED, @@ -30,6 +29,7 @@ import { VOLTAGE_LEVEL, VOLTAGE_REGULATION_ON, } from '../../../../../utils/field-constants'; +import { ConnectablePositionInfos } from '@gridsuite/commons-ui'; export interface VscConverterStationFormInfos { id: string; diff --git a/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-utils.tsx b/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-utils.tsx index 732112f13d..ba3ec9c22e 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-utils.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/vsc/converter-station/converter-station-utils.tsx @@ -7,9 +7,13 @@ import { AttributeModification, + getConnectivityFormData, + getConnectivityWithPositionEmptyFormData, + getConnectivityWithPositionValidationSchema, MODIFICATION_TYPES, sanitizeString, toModificationOperation, + UNDEFINED_CONNECTION_DIRECTION, } from '@gridsuite/commons-ui'; import yup from '../../../../../utils/yup-config'; import { @@ -33,17 +37,11 @@ import { VOLTAGE_LEVEL, VOLTAGE_REGULATION_ON, } from '../../../../../utils/field-constants'; -import { - getConnectivityFormData, - getConnectivityWithPositionEmptyFormData, - getConnectivityWithPositionValidationSchema, -} from '../../../../connectivity/connectivity-form-utils'; import { getReactiveLimitsEmptyFormData, getReactiveLimitsFormData, getReactiveLimitsSchema, } from '../../../../reactive-limits/reactive-limits-utils'; -import { UNDEFINED_CONNECTION_DIRECTION } from '../../../../../network/constants'; import { VscConverterStationFormInfos, ConverterStationElementModificationInfos } from './converter-station-type'; import { ReactiveCapabilityCurvePoints } from '../../../../reactive-limits/reactive-limits.type'; import { ConverterStationCreationInfos } from '../../../../../../services/network-modification-types'; diff --git a/src/components/dialogs/network-modifications/hvdc-line/vsc/creation/vsc-creation-dialog.tsx b/src/components/dialogs/network-modifications/hvdc-line/vsc/creation/vsc-creation-dialog.tsx index 6c6e7ebfd6..018f84c0c7 100644 --- a/src/components/dialogs/network-modifications/hvdc-line/vsc/creation/vsc-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/hvdc-line/vsc/creation/vsc-creation-dialog.tsx @@ -54,6 +54,7 @@ import { useFormSearchCopy } from '../../../../commons/use-form-search-copy'; import EquipmentSearchDialog from '../../../../equipment-search-dialog'; import GridItem from '../../../../commons/grid-item'; import { VSC_CREATION_TABS } from '../vsc-utils'; +import { isNodeBuilt } from 'components/graph/util/model-functions'; import { NetworkModificationDialogProps } from '../../../../../graph/menus/network-modifications/network-modification-menu.type'; import { VscCreationInfos } from '../../../../../../services/network-modification-types'; import { VscCreationDialogSchemaForm, VscFormInfos } from '../vsc-dialog.type'; @@ -232,7 +233,7 @@ export default function VscCreationDialog({ ); return ( - + + fetchBusesOrBusbarSectionsForVoltageLevel( + studyUuid, + currentNode.id, + currentRootNetworkUuid, + voltageLevelId + ), + [studyUuid, currentNode.id, currentRootNetworkUuid] + ); + const onLineDialogClose = () => { setLineDialogOpen(false); }; @@ -165,11 +176,9 @@ const LineAttachToVoltageLevelForm = ({ voltageLevelSelectLabel={'AttachedVoltageLevelId'} withPosition={false} withDirectionsInfos={false} - voltageLevelOptions={allVoltageLevelOptions} newBusOrBusbarSectionOptions={busbarSectionOptions} - studyUuid={studyUuid} - currentNode={currentNode} - currentRootNetworkUuid={currentRootNetworkUuid} + voltageLevelOptions={allVoltageLevelOptions} + fetchBusesOrBusbarSections={fetchBusesOrBusbarSections} /> ); diff --git a/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-dialog.tsx b/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-dialog.tsx index 632abbd471..4c16c25959 100644 --- a/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-dialog.tsx +++ b/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-dialog.tsx @@ -12,6 +12,10 @@ import { useSnackMessage, DeepNullable, sanitizeString, + getNewVoltageLevelData, + getConnectivityData, + getConnectivityWithoutPositionValidationSchema, + getConnectivityWithoutPositionEmptyFormData, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; import { @@ -33,12 +37,6 @@ import { useCallback, useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; import yup from 'components/utils/yup-config'; import { ModificationDialog } from '../../commons/modificationDialog'; -import { - getConnectivityData, - getConnectivityWithoutPositionEmptyFormData, - getConnectivityWithoutPositionValidationSchema, - getNewVoltageLevelData, -} from '../../connectivity/connectivity-form-utils'; import LineSplitWithVoltageLevelForm, { ExtendedVoltageLevelFormInfos } from './line-split-with-voltage-level-form'; import LineSplitWithVoltageLevelIllustration from './line-split-with-voltage-level-illustration'; import { diff --git a/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-form.tsx b/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-form.tsx index a190692365..4305d165c4 100644 --- a/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-form.tsx +++ b/src/components/dialogs/network-modifications/line-split-with-voltage-level/line-split-with-voltage-level-form.tsx @@ -7,11 +7,10 @@ import Grid from '@mui/material/Grid'; import { LINE1_ID, LINE1_NAME, LINE2_ID, LINE2_NAME } from 'components/utils/field-constants'; -import { useMemo, useState } from 'react'; +import { useCallback, useMemo, useState } from 'react'; import AddIcon from '@mui/icons-material/ControlPoint'; import EditIcon from '@mui/icons-material/Edit'; -import { Identifiable, Option, TextInput } from '@gridsuite/commons-ui'; -import { ConnectivityForm } from '../../connectivity/connectivity-form'; +import { ConnectivityForm, Identifiable, Option, TextInput } from '@gridsuite/commons-ui'; import { Button, Typography } from '@mui/material'; import { FormattedMessage } from 'react-intl'; import { LineToAttachOrSplitForm } from '../line-to-attach-or-split-form/line-to-attach-or-split-form'; @@ -25,6 +24,7 @@ import { VoltageLevelFormInfos } from '../voltage-level/voltage-level.type'; import { CurrentTreeNode } from '../../../graph/tree-node.type'; import { FetchStatus } from '../../../../services/utils.type'; import { VoltageLevelCreationInfo } from '../../../../services/network-modification-types'; +import { fetchBusesOrBusbarSectionsForVoltageLevel } from '../../../../services/study/network'; export interface ExtendedVoltageLevelFormInfos extends VoltageLevelFormInfos { busbarSections?: Option[]; @@ -56,6 +56,17 @@ const LineSplitWithVoltageLevelForm = ({ }: LineSplitWithVoltageLevelFormProps) => { const [voltageLevelDialogOpen, setVoltageLevelDialogOpen] = useState(false); + const fetchBusesOrBusbarSections = useCallback( + (voltageLevelId: string) => + fetchBusesOrBusbarSectionsForVoltageLevel( + studyUuid, + currentNode.id, + currentRootNetworkUuid, + voltageLevelId + ), + [studyUuid, currentNode.id, currentRootNetworkUuid] + ); + const voltageLevelIdWatch = useWatch({ name: `${CONNECTIVITY}.${VOLTAGE_LEVEL}.${ID}`, }); @@ -96,11 +107,9 @@ const LineSplitWithVoltageLevelForm = ({ voltageLevelSelectLabel={'VoltageLevelToSplitAt'} withPosition={false} withDirectionsInfos={false} - voltageLevelOptions={allVoltageLevelOptions} newBusOrBusbarSectionOptions={busbarSectionOptions} - studyUuid={studyUuid} - currentNode={currentNode} - currentRootNetworkUuid={currentRootNetworkUuid} + voltageLevelOptions={allVoltageLevelOptions} + fetchBusesOrBusbarSections={fetchBusesOrBusbarSections} /> ); diff --git a/src/components/dialogs/network-modifications/line-to-attach-or-split-form/line-to-attach-or-split-form.jsx b/src/components/dialogs/network-modifications/line-to-attach-or-split-form/line-to-attach-or-split-form.jsx index 62f2866e72..01ace45474 100644 --- a/src/components/dialogs/network-modifications/line-to-attach-or-split-form/line-to-attach-or-split-form.jsx +++ b/src/components/dialogs/network-modifications/line-to-attach-or-split-form/line-to-attach-or-split-form.jsx @@ -6,8 +6,7 @@ */ import { Grid, Typography } from '@mui/material'; -import { AutocompleteInput, snackWithFallback } from '@gridsuite/commons-ui'; -import { areIdsEqual, getObjectId } from 'components/utils/utils'; +import { areIdsEqual, AutocompleteInput, getObjectId, snackWithFallback } from '@gridsuite/commons-ui'; import { useEffect, useState } from 'react'; import { PercentageArea } from '../../percentage-area/percentage-area'; import { useWatch } from 'react-hook-form'; diff --git a/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane-utils.ts b/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane-utils.ts index fbfecd8fdf..6cd1372dc3 100644 --- a/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane-utils.ts +++ b/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane-utils.ts @@ -17,12 +17,13 @@ import { X, } from 'components/utils/field-constants'; import yup from 'components/utils/yup-config'; +import { LineCharacteristics } from '../modification/line-modification-type'; import { + Connectivity, + FieldConstants, getConnectivityWithPositionEmptyFormData, getConnectivityWithPositionValidationSchema, -} from '../../../connectivity/connectivity-form-utils'; -import { LineCharacteristics } from '../modification/line-modification-type'; -import { Connectivity } from 'components/dialogs/connectivity/connectivity.type'; +} from '@gridsuite/commons-ui'; const characteristicsValidationSchema = (id: string, displayConnectivity: boolean, modification: boolean) => ({ [id]: yup.object().shape({ @@ -34,8 +35,8 @@ const characteristicsValidationSchema = (id: string, displayConnectivity: boolea [G1]: yup.number().nullable().min(0, 'mustBeGreaterOrEqualToZero'), [B2]: yup.number().nullable(), [G2]: yup.number().nullable().min(0, 'mustBeGreaterOrEqualToZero'), - ...(displayConnectivity && getConnectivityWithPositionValidationSchema(false, CONNECTIVITY_1)), - ...(displayConnectivity && getConnectivityWithPositionValidationSchema(false, CONNECTIVITY_2)), + ...(displayConnectivity && getConnectivityWithPositionValidationSchema(false, FieldConstants.CONNECTIVITY_1)), + ...(displayConnectivity && getConnectivityWithPositionValidationSchema(false, FieldConstants.CONNECTIVITY_2)), }), }); @@ -55,8 +56,8 @@ const characteristicsEmptyFormData = (id: string, displayConnectivity: boolean = [G1]: null, [B2]: null, [G2]: null, - ...(displayConnectivity && getConnectivityWithPositionEmptyFormData(false, CONNECTIVITY_1)), - ...(displayConnectivity && getConnectivityWithPositionEmptyFormData(false, CONNECTIVITY_2)), + ...(displayConnectivity && getConnectivityWithPositionEmptyFormData(false, FieldConstants.CONNECTIVITY_1)), + ...(displayConnectivity && getConnectivityWithPositionEmptyFormData(false, FieldConstants.CONNECTIVITY_2)), }, }); diff --git a/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.tsx b/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.tsx index c92f097b69..613e8206a1 100644 --- a/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.tsx +++ b/src/components/dialogs/network-modifications/line/characteristics-pane/line-characteristics-pane.tsx @@ -7,6 +7,7 @@ import { Grid } from '@mui/material'; import { + ConnectivityForm, convertInputValue, FieldType, FloatInput, @@ -14,7 +15,6 @@ import { OhmAdornment, PropertiesForm, } from '@gridsuite/commons-ui'; -import { ConnectivityForm } from '../../../connectivity/connectivity-form'; import { B1, B2, @@ -32,6 +32,9 @@ import GridItem from '../../../commons/grid-item'; import { UUID } from 'node:crypto'; import { CurrentTreeNode } from '../../../../graph/tree-node.type'; import { BranchInfos } from '../../../../../services/study/network-map.type'; +import PositionDiagramPane from '../../../../grid-layout/cards/diagrams/singleLineDiagram/positionDiagram/position-diagram-pane'; +import { useCallback } from 'react'; +import { fetchBusesOrBusbarSectionsForVoltageLevel } from '../../../../../services/study/network'; const styles = { h3: { @@ -63,6 +66,17 @@ const LineCharacteristicsPane = ({ const currentNodeUuid = currentNode.id; const voltageLevelOptions = useVoltageLevelsListInfos(studyUuid, currentNodeUuid, currentRootNetworkUuid); + const fetchBusesOrBusbarSections = useCallback( + (voltageLevelId: string) => + fetchBusesOrBusbarSectionsForVoltageLevel( + studyUuid, + currentNode.id, + currentRootNetworkUuid, + voltageLevelId + ), + [studyUuid, currentNode.id, currentRootNetworkUuid] + ); + const seriesResistanceField = ( ); const connectivity2Field = ( ); diff --git a/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.tsx b/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.tsx index 5899dc71b1..80b90dbde8 100644 --- a/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.tsx +++ b/src/components/dialogs/network-modifications/line/creation/line-creation-dialog.tsx @@ -13,14 +13,17 @@ import { CustomFormProvider, emptyProperties, EquipmentType, + FieldConstants, FieldType, filledTextField, + getConnectivityFormData, getPropertiesFromModification, ModificationType, sanitizeString, snackWithFallback, TextInput, toModificationProperties, + UNDEFINED_CONNECTION_DIRECTION, useSnackMessage, } from '@gridsuite/commons-ui'; import { yupResolver } from '@hookform/resolvers/yup'; @@ -57,10 +60,9 @@ import { EQUIPMENT_TYPES } from 'components/utils/equipment-types'; import { useCallback, useEffect, useState } from 'react'; import { FieldErrors, useForm } from 'react-hook-form'; import { FetchStatus } from '../../../../../services/utils'; -import { APPLICABILITY, FORM_LOADING_DELAY, UNDEFINED_CONNECTION_DIRECTION } from 'components/network/constants'; +import { APPLICABILITY, FORM_LOADING_DELAY } from 'components/network/constants'; import yup from 'components/utils/yup-config'; import { ModificationDialog } from '../../../commons/modificationDialog'; -import { getConnectivityFormData } from '../../../connectivity/connectivity-form-utils'; import LineCharacteristicsPane from '../characteristics-pane/line-characteristics-pane'; import { getCharacteristicsEmptyFormData, @@ -92,6 +94,7 @@ import { LineCreationInfos } from '../../../../../services/network-modification- import { LineModificationFormSchema } from '../modification/line-modification-type'; import { ComputedLineCharacteristics, CurrentLimitsInfo } from '../../../line-types-catalog/line-catalog.type'; import { LineCreationFormSchema, LineFormInfos } from './line-creation-type'; +import { isNodeBuilt } from 'components/graph/util/model-functions'; import { OperationalLimitsGroupFormSchema, TemporaryLimitFormSchema, @@ -184,7 +187,7 @@ const LineCreationDialog = ({ connectionPosition: line.connectablePosition1.connectionPosition, terminalConnected: line.terminal1Connected, }, - CONNECTIVITY_1 + FieldConstants.CONNECTIVITY_1 ), ...getConnectivityFormData( { @@ -195,7 +198,7 @@ const LineCreationDialog = ({ connectionPosition: line.connectablePosition2.connectionPosition, terminalConnected: line.terminal2Connected, }, - CONNECTIVITY_2 + FieldConstants.CONNECTIVITY_2 ), }), ...getAllLimitsFormData( @@ -231,7 +234,7 @@ const LineCreationDialog = ({ voltageLevelId: line.voltageLevelId1, terminalConnected: line.connected1, }, - CONNECTIVITY_1 + FieldConstants.CONNECTIVITY_1 ), ...getConnectivityFormData( { @@ -242,7 +245,7 @@ const LineCreationDialog = ({ voltageLevelId: line.voltageLevelId2, terminalConnected: line.connected2, }, - CONNECTIVITY_2 + FieldConstants.CONNECTIVITY_2 ), }), ...getAllLimitsFormData( @@ -412,7 +415,7 @@ const LineCreationDialog = ({ }); return ( - + ): JSX.Element => { + const voltageLevelOptions = useVoltageLevelsListInfos(studyUuid, currentNode.id, currentRootNetworkUuid); + const fetchBusesOrBusbarSections = useCallback( + (voltageLevelId: string) => + fetchBusesOrBusbarSectionsForVoltageLevel( + studyUuid, + currentNode.id, + currentRootNetworkUuid, + voltageLevelId + ), + [studyUuid, currentNode.id, currentRootNetworkUuid] + ); + return ( <>