Skip to content

Commit 2e46738

Browse files
fix(spreadsheet): reset spreadsheet data on root-network change (#3323)
Signed-off-by: Joris Mancini <[email protected]>
1 parent fe6e8e8 commit 2e46738

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/components/spreadsheet-view/hooks/use-built-nodes-ids.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ import type { NodeAlias } from '../types/node-alias.type';
1717
export function useBuiltNodesIds(nodeAliases: NodeAlias[] | undefined) {
1818
const currentNode = useSelector((state: AppState) => state.currentTreeNode);
1919
const treeNodes = useSelector((state: AppState) => state.networkModificationTreeModel?.treeNodes);
20+
const isTreeModelUpToDate = useSelector((state: AppState) => state.isNetworkModificationTreeModelUpToDate);
2021

2122
return useStableComputedSet(() => {
23+
if (!isTreeModelUpToDate) {
24+
return new Set<UUID>();
25+
}
2226
const aliasedNodesIds = nodeAliases
2327
?.filter((nodeAlias) => validAlias(nodeAlias))
2428
.map((nodeAlias) => nodeAlias.id);

src/components/spreadsheet-view/spreadsheet/spreadsheet-content/hooks/use-spreadsheet-equipments.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import { useEffect, useState } from 'react';
8+
import { useEffect, useRef, useState } from 'react';
99
import { useDispatch, useSelector } from 'react-redux';
10-
import { cleanEquipments, removeNodeData } from 'redux/actions';
10+
import { cleanEquipments, removeNodeData, resetEquipments } from 'redux/actions';
1111
import { type AppState } from 'redux/reducer';
1212
import type { NodeAlias } from '../../../types/node-alias.type';
1313
import { useOptionalLoadingParametersForEquipments } from './use-optional-loading-parameters-for-equipments';
@@ -31,6 +31,8 @@ export const useSpreadsheetEquipments = (
3131
const [isFetching, setIsFetching] = useState<boolean>(false);
3232
const { fetchNodesEquipmentData } = useFetchEquipment(type);
3333

34+
const prevCurrentRootNetworkUuidRef = useRef(currentRootNetworkUuid);
35+
3436
const {
3537
shouldLoadOptionalLoadingParameters,
3638
equipmentsWithLoadingOptionsLoaded,
@@ -74,6 +76,14 @@ export const useSpreadsheetEquipments = (
7476
}
7577
}, [active, dispatch, nodesIdsToRemove]);
7678

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+
7787
// Note: take care about the dependencies because any execution here implies equipment loading (large fetches).
7888
// For example, we have 3 currentNode properties in deps rather than currentNode object itself.
7989
useEffect(() => {

0 commit comments

Comments
 (0)