@@ -69,6 +69,7 @@ import SelectionCreationPanel from './selection-creation-panel/selection-creatio
6969import { useEquipmentMenu } from '../../hooks/use-equipment-menu' ;
7070import useEquipmentDialogs from 'hooks/use-equipment-dialogs' ;
7171import { getNominalVoltageColor } from 'utils/colors' ;
72+ import { getNominalVoltageIntervalName } from './utils/nominal-voltage-filter-utils' ;
7273
7374const INITIAL_POSITION = [ 0 , 0 ] as const ;
7475const INITIAL_ZOOM = 9 ;
@@ -184,9 +185,8 @@ export const NetworkMapPanel = forwardRef<NetworkMapPanelRef, NetworkMapPanelPro
184185
185186 const { snackError } = useSnackMessage ( ) ;
186187
187- const [ filteredNominalVoltages , setFilteredNominalVoltages ] = useState < number [ ] > (
188- mapState ?. filteredNominalVoltages ?? [ ]
189- ) ;
188+ const [ filteredNominalVoltages , setFilteredNominalVoltages ] = useState < number [ ] > ( [ ] ) ;
189+ const [ hasInitializedFilters , setHasInitializedFilters ] = useState ( false ) ;
190190 const [ geoData , setGeoData ] = useState < GeoData > ( ) ;
191191 const geoDataRef = useRef < any > ( ) ;
192192
@@ -861,6 +861,7 @@ export const NetworkMapPanel = forwardRef<NetworkMapPanelRef, NetworkMapPanelPro
861861 if ( previousCurrentRootNetworkUuid && previousCurrentRootNetworkUuid !== currentRootNetworkUuid ) {
862862 setInitialized ( false ) ;
863863 setIsRootNodeGeoDataLoaded ( false ) ;
864+ setHasInitializedFilters ( false ) ;
864865 dispatch ( resetMapEquipment ( ) ) ;
865866 return ;
866867 }
@@ -1246,23 +1247,45 @@ export const NetworkMapPanel = forwardRef<NetworkMapPanelRef, NetworkMapPanelPro
12461247 ) ;
12471248
12481249 // Set up filteredNominalVoltages once at map initialization
1249- // TODO: how do we must manage case where voltages change (like when changing node), as filters are already initialized?
12501250 const nominalVoltagesFromMapEquipments = mapEquipments ?. getNominalVoltages ( ) ;
1251+
12511252 useEffect ( ( ) => {
1253+ // Only initialize once when mapEquipments are loaded
12521254 if (
12531255 nominalVoltagesFromMapEquipments !== undefined &&
12541256 nominalVoltagesFromMapEquipments . length > 0 &&
1255- filteredNominalVoltages . length === 0 &&
1256- ! mapState ?. filteredNominalVoltages // Only initialize if no saved map state exists
1257+ ! hasInitializedFilters
12571258 ) {
1258- handleFilteredNominalVoltagesChange ( nominalVoltagesFromMapEquipments ) ;
1259+ setHasInitializedFilters ( true ) ;
1260+
1261+ // Check if we have saved state to restore
1262+ if ( mapState ?. filteredNominalVoltages && mapState . filteredNominalVoltages . length > 0 ) {
1263+ // Get intervals from saved voltages
1264+ const savedIntervals = new Set (
1265+ mapState . filteredNominalVoltages
1266+ . map ( ( v ) => getNominalVoltageIntervalName ( v ) )
1267+ . filter ( ( interval ) : interval is string => interval !== undefined )
1268+ ) ;
1269+
1270+ // Filter current voltages by matching intervals
1271+ const voltagesMatchingIntervals = nominalVoltagesFromMapEquipments . filter ( ( v ) => {
1272+ const interval = getNominalVoltageIntervalName ( v ) ;
1273+ return interval && savedIntervals . has ( interval ) ;
1274+ } ) ;
1275+
1276+ if ( voltagesMatchingIntervals . length > 0 ) {
1277+ // Restore voltages from matching intervals
1278+ setFilteredNominalVoltages ( voltagesMatchingIntervals ) ;
1279+ } else {
1280+ // No matching intervals found, initialize with all
1281+ setFilteredNominalVoltages ( nominalVoltagesFromMapEquipments ) ;
1282+ }
1283+ } else {
1284+ // No saved state, initialize with all voltages
1285+ setFilteredNominalVoltages ( nominalVoltagesFromMapEquipments ) ;
1286+ }
12591287 }
1260- } , [
1261- filteredNominalVoltages ,
1262- handleFilteredNominalVoltagesChange ,
1263- nominalVoltagesFromMapEquipments ,
1264- mapState ?. filteredNominalVoltages ,
1265- ] ) ;
1288+ } , [ nominalVoltagesFromMapEquipments , mapState ?. filteredNominalVoltages , hasInitializedFilters ] ) ;
12661289
12671290 function renderNominalVoltageFilter ( ) {
12681291 return (
0 commit comments