Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add substation creation to voltagelevel creation form #2439

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { CustomFormProvider, useSnackMessage } from '@gridsuite/commons-ui';
import { CustomFormProvider, MODIFICATION_TYPES, useSnackMessage } from '@gridsuite/commons-ui';
import { yupResolver } from '@hookform/resolvers/yup';
import { sanitizeString } from 'components/dialogs/dialog-utils';
import EquipmentSearchDialog from 'components/dialogs/equipment-search-dialog';
Expand All @@ -14,6 +14,7 @@ import {
BUS_BAR_COUNT,
BUS_BAR_SECTION_ID1,
BUS_BAR_SECTION_ID2,
COUNTRY,
COUPLING_OMNIBUS,
EQUIPMENT_ID,
EQUIPMENT_NAME,
Expand All @@ -26,14 +27,15 @@ import {
NOMINAL_V,
SECTION_COUNT,
SUBSTATION_ID,
SUBSTATION_NAME,
SWITCH_KIND,
SWITCH_KINDS,
SWITCHES_BETWEEN_SECTIONS,
TOPOLOGY_KIND,
} from 'components/utils/field-constants';
import yup from 'components/utils/yup-config';
import PropTypes from 'prop-types';
import { useCallback, useEffect } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { useForm } from 'react-hook-form';
import ModificationDialog from 'components/dialogs/commons/modificationDialog';

Expand Down Expand Up @@ -79,6 +81,8 @@ const emptyFormData = {
[SWITCHES_BETWEEN_SECTIONS]: '',
[COUPLING_OMNIBUS]: [],
[SWITCH_KINDS]: [],
[SUBSTATION_NAME]: null,
[COUNTRY]: null,
...emptyProperties,
};

Expand Down Expand Up @@ -124,6 +128,8 @@ const formSchema = yup
.test('coupling-omnibus-between-sections', (values) =>
controlCouplingOmnibusBetweenSections(values, 'CouplingOmnibusBetweenSameBusbar')
),
[SUBSTATION_NAME]: yup.string(),
[COUNTRY]: yup.string().nullable(),
})
.concat(creationPropertiesSchema);
const VoltageLevelCreationDialog = ({
Expand All @@ -145,7 +151,7 @@ const VoltageLevelCreationDialog = ({

const { reset } = formMethods;
const intl = useIntl();

const [isSubstationCreation, setIsSubstationCreation] = useState(false);
const fromExternalDataToFormValues = useCallback(
(voltageLevel, fromCopy = true) => {
const properties = fromCopy
Expand Down Expand Up @@ -206,12 +212,21 @@ const VoltageLevelCreationDialog = ({

const onSubmit = useCallback(
(voltageLevel) => {
const substationCreation = isSubstationCreation
? {
type: MODIFICATION_TYPES.SUBSTATION_CREATION.type,
equipmentId: voltageLevel[SUBSTATION_ID],
equipmentName: voltageLevel[SUBSTATION_NAME],
country: voltageLevel[COUNTRY],
}
: null;
onCreateVoltageLevel({
studyUuid: studyUuid,
nodeUuid: currentNodeUuid,
voltageLevelId: voltageLevel[EQUIPMENT_ID],
voltageLevelName: sanitizeString(voltageLevel[EQUIPMENT_NAME]),
substationId: voltageLevel[SUBSTATION_ID],
substationCreation,
nominalV: voltageLevel[NOMINAL_V],
lowVoltageLimit: voltageLevel[LOW_VOLTAGE_LIMIT],
highVoltageLimit: voltageLevel[HIGH_VOLTAGE_LIMIT],
Expand All @@ -234,9 +249,13 @@ const VoltageLevelCreationDialog = ({
});
});
},
[onCreateVoltageLevel, studyUuid, currentNodeUuid, editData, snackError]
[onCreateVoltageLevel, isSubstationCreation, studyUuid, currentNodeUuid, editData, snackError]
);

const handleSubstationCreation = (isWithSubstationCreation) => {
setIsSubstationCreation(isWithSubstationCreation);
};

const clear = useCallback(() => {
reset(emptyFormData);
}, [reset]);
Expand All @@ -261,7 +280,11 @@ const VoltageLevelCreationDialog = ({
isDataFetching={isUpdate && editDataFetchStatus === FetchStatus.RUNNING}
{...dialogProps}
>
<VoltageLevelCreationForm currentNode={currentNode} studyUuid={studyUuid} />
<VoltageLevelCreationForm
currentNode={currentNode}
studyUuid={studyUuid}
handleSubstationCreation={handleSubstationCreation}
/>
<EquipmentSearchDialog
open={searchCopy.isDialogSearchOpen}
onClose={searchCopy.handleCloseSearchDialog}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import {
BUS_BAR_COUNT,
COUNTRY,
EQUIPMENT_ID,
EQUIPMENT_NAME,
HIGH_SHORT_CIRCUIT_CURRENT_LIMIT,
Expand All @@ -16,27 +17,35 @@ import {
NOMINAL_V,
SECTION_COUNT,
SUBSTATION_ID,
SUBSTATION_NAME,
} from 'components/utils/field-constants';
import { useEffect, useState } from 'react';
import { VoltageAdornment, KiloAmpereAdornment } from 'components/dialogs/dialog-utils';
import { FloatInput } from '@gridsuite/commons-ui';
import { TextInput } from '@gridsuite/commons-ui';
import { AutocompleteInput } from '@gridsuite/commons-ui';
import { useCallback, useEffect, useState } from 'react';
import { filledTextField, KiloAmpereAdornment, VoltageAdornment } from 'components/dialogs/dialog-utils';
import { AutocompleteInput, FloatInput, IntegerInput, TextInput } from '@gridsuite/commons-ui';
import { getObjectId } from 'components/utils/utils';
import { Box, Grid } from '@mui/material';
import { IntegerInput } from '@gridsuite/commons-ui';

import { CouplingOmnibusForm } from '../coupling-omnibus/coupling-omnibus-form';
import { SwitchesBetweenSections } from '../switches-between-sections/switches-between-sections';
import { fetchEquipmentsIds } from '../../../../../services/study/network-map';
import PropertiesForm from '../../common/properties/properties-form';
import { useWatch } from 'react-hook-form';
import { useFormContext, useWatch } from 'react-hook-form';
import GridItem from '../../../commons/grid-item';
import GridSection from '../../../commons/grid-section';

const VoltageLevelCreationForm = ({ currentNode, studyUuid }) => {
import IconButton from '@mui/material/IconButton';
import AddCircleIcon from '@mui/icons-material/AddCircle';
import Typography from '@mui/material/Typography';
import { useIntl } from 'react-intl';
import CountrySelectionInput from '../../../../utils/rhf-inputs/country-selection-input.jsx';
import DeleteIcon from '@mui/icons-material/Delete.js';
import LineSeparator from '../../../commons/line-separator';

const VoltageLevelCreationForm = ({ currentNode, studyUuid, handleSubstationCreation }) => {
const currentNodeUuid = currentNode?.id;
const intl = useIntl();
const { setValue } = useFormContext();
const [substations, setSubstations] = useState([]);
const [isWithSubstationCreation, setIsWithSubstationCreation] = useState(false);

const watchBusBarCount = useWatch({ name: BUS_BAR_COUNT });
const watchSectionCount = useWatch({ name: SECTION_COUNT });
Expand Down Expand Up @@ -106,14 +115,80 @@ const VoltageLevelCreationForm = ({ currentNode, studyUuid }) => {

const couplingOmnibusForm = <CouplingOmnibusForm />;

const substationIdField = <TextInput name={SUBSTATION_ID} label={'SubstationId'} formProps={filledTextField} />;

const substationNameField = (
<TextInput name={SUBSTATION_NAME} label={'substationName'} formProps={filledTextField} />
);

const substationCountryField = (
<CountrySelectionInput name={COUNTRY} label={'Country'} formProps={filledTextField} size={'small'} />
);

const handleAddButton = useCallback(() => {
handleSubstationCreation(true);
setIsWithSubstationCreation(true);
setValue(SUBSTATION_ID, null);
}, [handleSubstationCreation, setValue]);

const handleCloseButton = useCallback(() => {
handleSubstationCreation(false);
setIsWithSubstationCreation(false);
setValue(SUBSTATION_ID, null);
}, [handleSubstationCreation, setValue]);

return (
<>
<Grid container spacing={2}>
<GridItem size={4}>{voltageLevelIdField}</GridItem>
<GridItem size={4}>{voltageLevelNameField}</GridItem>
<GridItem size={4}>{substationField}</GridItem>
<GridItem>{voltageLevelIdField}</GridItem>
<GridItem>{voltageLevelNameField}</GridItem>
</Grid>
<GridSection title={'VoltageText'} />

{isWithSubstationCreation ? (
<Grid>
<Grid item xs={12} paddingTop={2}>
<LineSeparator />
</Grid>
<Grid item xs={12} container spacing={2}>
<Grid item xs={11}>
<GridSection title={intl.formatMessage({ id: 'CreateSubstation' })} />
</Grid>
<Grid item xs={1} sx={{ display: 'flex', justifyContent: 'right' }}>
<IconButton onClick={handleCloseButton}>
<DeleteIcon />
</IconButton>
</Grid>
</Grid>
<Grid container spacing={2}>
<Grid item xs={4}>
{substationIdField}
</Grid>
<Grid item xs={4}>
{substationNameField}
</Grid>
<Grid item xs={4}>
{substationCountryField}
</Grid>
</Grid>
</Grid>
) : (
<Grid container spacing={2}>
<Grid item xs={12} sm={6}>
{substationField}
</Grid>
<Grid item xs={12} sm={6} container alignItems="center" spacing={2}>
<Grid item>
<IconButton onClick={handleAddButton}>
<AddCircleIcon />
</IconButton>
</Grid>
<Grid item>
<Typography>{intl.formatMessage({ id: 'CreateSubstation' })}</Typography>
</Grid>
</Grid>
</Grid>
)}
<GridSection title={intl.formatMessage({ id: 'VoltageText' })} />
<Grid container spacing={2}>
<GridItem size={4}>{nominalVoltageField}</GridItem>
<GridItem size={4}>{lowVoltageLimitField}</GridItem>
Expand Down
1 change: 1 addition & 0 deletions src/components/utils/field-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

export const EQUIPMENT_ID = 'equipmentId';
export const EQUIPMENT_NAME = 'equipmentName';
export const SUBSTATION_NAME = 'substationName';
export const LOAD_TYPE = 'loadType';
export const CONNECTIVITY = 'connectivity';
export const SETPOINTS_LIMITS = 'setpointsLimits';
Expand Down
2 changes: 2 additions & 0 deletions src/services/study/network-modifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,7 @@ export function createVoltageLevel({
voltageLevelId,
voltageLevelName,
substationId,
substationCreation,
nominalV,
lowVoltageLimit,
highVoltageLimit,
Expand Down Expand Up @@ -1319,6 +1320,7 @@ export function createVoltageLevel({
equipmentId: voltageLevelId,
equipmentName: voltageLevelName,
substationId: substationId,
substationCreation: substationCreation,
nominalV: nominalV,
lowVoltageLimit: lowVoltageLimit,
highVoltageLimit: highVoltageLimit,
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@
"TabularModificationError": "Error while creating tabular modification",
"TabularModificationShuntWarning": "Both maximum reactive power (and/or type) and maximum susceptance have been submitted for the same shunt compensator. Maximum susceptance will thus be ignored.",
"equipmentId": "ID",
"substationName": "Substation name",
"activePower": "p (MW)",
"maxActivePower": "Max P (MW)",
"maxP": "Max P (MW)",
Expand Down
1 change: 1 addition & 0 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@
"TabularModificationError": "Erreur lors de la modification tabulaire",
"TabularModificationShuntWarning": "La modification tabulaire contient des valeurs pour la puissance réactive installée (et/ou le type) et la susceptance installée d'un même MCS. La susceptance installée sera donc ignorée.",
"equipmentId": "ID",
"substationName": "Nom du site",
"activePower": "p (MW)",
"maxActivePower": "P max (MW)",
"maxP": "P max (MW)",
Expand Down
Loading