@@ -24,7 +24,7 @@ import {
2424} from 'components/utils/field-constants' ;
2525import { useCallback , useEffect , useState } from 'react' ;
2626import { 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' ;
2828import { Box , Grid , Paper , Tooltip } from '@mui/material' ;
2929
3030import { 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