5
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- import { useEffect , useState } from 'react' ;
8
+ import { useEffect , useRef , useState } from 'react' ;
9
9
import { useDispatch , useSelector } from 'react-redux' ;
10
- import { cleanEquipments , removeNodeData } from 'redux/actions' ;
10
+ import { cleanEquipments , removeNodeData , resetEquipments } from 'redux/actions' ;
11
11
import { type AppState } from 'redux/reducer' ;
12
12
import type { NodeAlias } from '../../../types/node-alias.type' ;
13
13
import { useOptionalLoadingParametersForEquipments } from './use-optional-loading-parameters-for-equipments' ;
@@ -31,6 +31,8 @@ export const useSpreadsheetEquipments = (
31
31
const [ isFetching , setIsFetching ] = useState < boolean > ( false ) ;
32
32
const { fetchNodesEquipmentData } = useFetchEquipment ( type ) ;
33
33
34
+ const prevCurrentRootNetworkUuidRef = useRef ( currentRootNetworkUuid ) ;
35
+
34
36
const {
35
37
shouldLoadOptionalLoadingParameters,
36
38
equipmentsWithLoadingOptionsLoaded,
@@ -74,6 +76,14 @@ export const useSpreadsheetEquipments = (
74
76
}
75
77
} , [ active , dispatch , nodesIdsToRemove ] ) ;
76
78
79
+ // Reset equipment data on root network change
80
+ useEffect ( ( ) => {
81
+ if ( prevCurrentRootNetworkUuidRef . current !== currentRootNetworkUuid ) {
82
+ dispatch ( resetEquipments ( ) ) ;
83
+ prevCurrentRootNetworkUuidRef . current = currentRootNetworkUuid ;
84
+ }
85
+ } , [ dispatch , currentRootNetworkUuid ] ) ;
86
+
77
87
// Note: take care about the dependencies because any execution here implies equipment loading (large fetches).
78
88
// For example, we have 3 currentNode properties in deps rather than currentNode object itself.
79
89
useEffect ( ( ) => {
0 commit comments