Skip to content

Commit fe6e8e8

Browse files
fix(spreadsheet): destroy component on node change and keep updates on notifications alive (#3322)
Signed-off-by: Joris Mancini <[email protected]>
1 parent 0c8c778 commit fe6e8e8

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/components/spreadsheet-view/hooks/use-node-aliases.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export const useNodeAliases = () => {
8585

8686
useNotificationsListener(NotificationsUrlKeys.STUDY, {
8787
listenerCallbackMessage: listenerAliasesUpdated,
88+
propsId: 'node-aliases',
8889
});
8990

9091
const updateNodeAliases = useCallback(

src/components/spreadsheet-view/spreadsheet-view.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { initTableDefinitions, setActiveSpreadsheetTab } from 'redux/actions';
2323
import { type MuiStyles, PopupConfirmationDialog, useSnackMessage } from '@gridsuite/commons-ui';
2424
import { processSpreadsheetsCollectionData } from './add-spreadsheet/dialogs/add-spreadsheet-utils';
2525
import { DiagramType } from 'components/grid-layout/cards/diagrams/diagram.type';
26-
import { useUpdateEquipmentsOnNotification } from './hooks/use-update-equipments-on-notification';
2726

2827
const styles = {
2928
invalidNode: {
@@ -61,8 +60,6 @@ export const SpreadsheetView: FunctionComponent<SpreadsheetViewProps> = ({
6160
const studyUuid = useSelector((state: AppState) => state.studyUuid);
6261
const [resetConfirmationDialogOpen, setResetConfirmationDialogOpen] = useState(false);
6362

64-
useUpdateEquipmentsOnNotification(nodeAliases);
65-
6663
const handleSwitchTab = useCallback(
6764
(tabUuid: UUID) => {
6865
dispatch(setActiveSpreadsheetTab(tabUuid));

src/components/study-pane.jsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import HorizontalToolbar from './horizontal-toolbar';
2121
import { openDiagram, setToggleOptions } from '../redux/actions.js';
2222
import { useDispatch, useSelector } from 'react-redux';
2323
import { StudyDisplayMode } from './network-modification.type';
24+
import { useNodeAliases } from './spreadsheet-view/hooks/use-node-aliases.js';
25+
import { useUpdateEquipmentsOnNotification } from './spreadsheet-view/hooks/use-update-equipments-on-notification.js';
2426

2527
const styles = {
2628
tabsContainer: (theme) => {
@@ -89,6 +91,9 @@ const StudyPane = ({
8991

9092
const handleTableEquipmentChanged = useCallback((newTableEquipment) => setTableEquipment(newTableEquipment), []);
9193

94+
const { nodeAliases } = useNodeAliases();
95+
useUpdateEquipmentsOnNotification(nodeAliases);
96+
9297
return (
9398
<Box sx={styles.paneContainer}>
9499
<HorizontalToolbar />
@@ -109,9 +114,9 @@ const StudyPane = ({
109114
showGrid={showGrid}
110115
/>
111116
</div>
112-
{/* This TabPanelLazy is used on a multi-node component so we don't want to reset it at each node change,
113-
so we don't specify a key */}
114-
<TabPanelLazy selected={view === StudyView.SPREADSHEET}>
117+
{/* using a key in these TabPanelLazy because we can change the nodeUuid in these components,
118+
and we want to reset the components at each node change*/}
119+
<TabPanelLazy key={`spreadsheet-${currentNode?.id}`} selected={view === StudyView.SPREADSHEET}>
115120
<SpreadsheetView
116121
studyUuid={studyUuid}
117122
currentNode={currentNode}
@@ -122,8 +127,6 @@ const StudyPane = ({
122127
openDiagram={openVoltageLevelDiagram}
123128
/>
124129
</TabPanelLazy>
125-
{/* using a key in these TabPanelLazy because we can change the nodeUuid in this component,
126-
and we want to reset the component at each node change*/}
127130
<TabPanelLazy key={`results-${currentNode?.id}`} selected={view === StudyView.RESULTS}>
128131
<ResultViewTab
129132
studyUuid={studyUuid}
@@ -134,13 +137,9 @@ const StudyPane = ({
134137
view={view}
135138
/>
136139
</TabPanelLazy>
137-
{/* using a key in these TabPanelLazy because we can change the nodeUuid in this component,
138-
and we want to reset the component at each node change*/}
139140
<TabPanelLazy selected={view === StudyView.LOGS} key={`logs-${currentNode?.id}`}>
140141
<ReportViewerTab visible={view === StudyView.LOGS} currentNode={currentNode} disabled={disabled} />
141142
</TabPanelLazy>
142-
{/* using a key in these TabPanelLazy because we can change the nodeUuid in this component,
143-
and we want to reset the component at each node change*/}
144143
<TabPanelLazy key={`parameters-${currentNode?.id}`} selected={view === StudyView.PARAMETERS}>
145144
<ParametersTabs view={view} />
146145
</TabPanelLazy>

0 commit comments

Comments
 (0)