Skip to content

Commit 1843bb8

Browse files
authored
Add default country of a new substation in voltage level creation (#3370)
--------- Signed-off-by: Thang PHAM <[email protected]>
1 parent 40f96f2 commit 1843bb8

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

src/components/dialogs/network-modifications/substation/creation/substation-creation-dialog.jsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,19 @@ const SubstationCreationDialog = ({
8888
}
8989
}, [reset, editData]);
9090

91-
// We set the default country if there is one
91+
// We set the default country only in creation mode
9292
useEffect(() => {
93-
fetchDefaultCountry().then((country) => {
94-
if (country) {
95-
reset({
96-
...getValues(),
97-
[COUNTRY]: country,
98-
});
99-
}
100-
});
101-
}, [reset, getValues]);
93+
if (!isUpdate) {
94+
fetchDefaultCountry().then((country) => {
95+
if (country) {
96+
reset({
97+
...getValues(),
98+
[COUNTRY]: country,
99+
});
100+
}
101+
});
102+
}
103+
}, [reset, getValues, isUpdate]);
102104

103105
const clear = useCallback(() => {
104106
reset(emptyFormData);

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from 'components/utils/field-constants';
2525
import { useCallback, useEffect, useState } from 'react';
2626
import { KiloAmpereAdornment, VoltageAdornment } from 'components/dialogs/dialog-utils';
27-
import { AutocompleteInput, FloatInput, IntegerInput, TextInput } from '@gridsuite/commons-ui';
27+
import { AutocompleteInput, fetchDefaultCountry, FloatInput, IntegerInput, TextInput } from '@gridsuite/commons-ui';
2828
import { Box, Grid, Paper, Tooltip } from '@mui/material';
2929

3030
import { CouplingOmnibusForm } from '../coupling-omnibus/coupling-omnibus-form';
@@ -49,9 +49,17 @@ const VoltageLevelCreationForm = ({ currentNode, studyUuid, currentRootNetworkUu
4949
const watchBusBarCount = useWatch({ name: BUS_BAR_COUNT });
5050
const watchSectionCount = useWatch({ name: SECTION_COUNT });
5151
const watchAddSubstationCreation = useWatch({ name: ADD_SUBSTATION_CREATION });
52+
5253
useEffect(() => {
53-
setIsWithSubstationCreation(watchAddSubstationCreation);
54-
}, [watchAddSubstationCreation]);
54+
// in new substation mode, set the default country
55+
if (isWithSubstationCreation) {
56+
fetchDefaultCountry().then((country) => {
57+
if (country) {
58+
setValue(COUNTRY, country);
59+
}
60+
});
61+
}
62+
}, [setValue, isWithSubstationCreation]);
5563

5664
useEffect(() => {
5765
if (studyUuid && currentNodeUuid && currentRootNetworkUuid) {
@@ -149,6 +157,10 @@ const VoltageLevelCreationForm = ({ currentNode, studyUuid, currentRootNetworkUu
149157

150158
const handleDeleteButton = useCallback(() => {
151159
setValue(ADD_SUBSTATION_CREATION, false);
160+
// clear the fields of the new substation
161+
setValue(SUBSTATION_CREATION_ID, null);
162+
setValue(SUBSTATION_NAME, null);
163+
setValue(COUNTRY, null);
152164
setIsWithSubstationCreation(false);
153165
}, [setValue]);
154166

@@ -159,7 +171,7 @@ const VoltageLevelCreationForm = ({ currentNode, studyUuid, currentRootNetworkUu
159171
<GridItem>{voltageLevelNameField}</GridItem>
160172
</Grid>
161173

162-
{isWithSubstationCreation ? (
174+
{watchAddSubstationCreation ? (
163175
<Grid>
164176
<Grid item xs={12} container spacing={2}></Grid>
165177
<GridSection title={intl.formatMessage({ id: 'CreateSubstation' })} />

0 commit comments

Comments
 (0)