@@ -10,12 +10,7 @@ import { Controls, MiniMap, ReactFlow, useEdgesState, useNodesState, useReactFlo
10
10
import MapIcon from '@mui/icons-material/Map' ;
11
11
import CenterFocusIcon from '@mui/icons-material/CenterFocusStrong' ;
12
12
import { useCallback , useEffect , useLayoutEffect , useMemo , useRef , useState } from 'react' ;
13
- import {
14
- reorderNetworkModificationTreeNodes ,
15
- setCurrentTreeNode ,
16
- setModificationsDrawerOpen ,
17
- setToggleOptions ,
18
- } from '../redux/actions' ;
13
+ import { reorderNetworkModificationTreeNodes , setModificationsDrawerOpen , setToggleOptions } from '../redux/actions' ;
19
14
import { useDispatch , useSelector } from 'react-redux' ;
20
15
import { isSameNode } from './graph/util/model-functions' ;
21
16
import PropTypes from 'prop-types' ;
@@ -36,6 +31,8 @@ import { updateNodesColumnPositions } from '../services/study/tree-subtree.ts';
36
31
import { useSnackMessage } from '@gridsuite/commons-ui' ;
37
32
import { groupIdSuffix } from './graph/nodes/labeled-group-node.type' ;
38
33
import { StudyDisplayMode } from './network-modification.type' ;
34
+ import { useSyncNavigationActions } from 'hooks/use-sync-navigation-actions' ;
35
+ import { NodeType } from './graph/tree-node.type' ;
39
36
40
37
const styles = ( theme ) => ( {
41
38
flexGrow : 1 ,
@@ -57,6 +54,7 @@ const NetworkModificationTree = ({ onNodeContextMenu, studyUuid, onTreePanelResi
57
54
const { snackError } = useSnackMessage ( ) ;
58
55
59
56
const currentNode = useSelector ( ( state ) => state . currentTreeNode ) ;
57
+ const { setCurrentTreeNodeWithSync } = useSyncNavigationActions ( ) ;
60
58
61
59
const treeModel = useSelector ( ( state ) => state . networkModificationTreeModel ) ;
62
60
@@ -125,24 +123,26 @@ const NetworkModificationTree = ({ onNodeContextMenu, studyUuid, onTreePanelResi
125
123
) ;
126
124
} , [ ] ) ;
127
125
126
+ // close modifications/ event scenario when current node is root
127
+ useEffect ( ( ) => {
128
+ if ( currentNode ?. type === NodeType . ROOT ) {
129
+ const newOptions = handleRootNodeClick ( toggleOptions ) ;
130
+ if ( newOptions !== toggleOptions ) {
131
+ dispatch ( setToggleOptions ( newOptions ) ) ;
132
+ }
133
+ }
134
+ } , [ currentNode , dispatch , handleRootNodeClick , toggleOptions ] ) ;
135
+
128
136
const onNodeClick = useCallback (
129
137
( event , node ) => {
130
- if ( node . type === ' NETWORK_MODIFICATION' ) {
138
+ if ( node . type === NodeType . NETWORK_MODIFICATION ) {
131
139
dispatch ( setModificationsDrawerOpen ( ) ) ;
132
140
}
133
- if ( node . type === 'ROOT' ) {
134
- handleRootNodeClick ( toggleOptions , dispatch ) ;
135
-
136
- const newOptions = handleRootNodeClick ( toggleOptions ) ;
137
- if ( newOptions !== toggleOptions ) {
138
- dispatch ( setToggleOptions ( newOptions ) ) ;
139
- }
140
- }
141
141
if ( ! isSameNode ( currentNode , node ) ) {
142
- dispatch ( setCurrentTreeNode ( node ) ) ;
142
+ setCurrentTreeNodeWithSync ( node ) ;
143
143
}
144
144
} ,
145
- [ currentNode , dispatch , handleRootNodeClick , toggleOptions ]
145
+ [ currentNode , dispatch , setCurrentTreeNodeWithSync ]
146
146
) ;
147
147
148
148
const toggleMinimap = useCallback ( ( ) => {
0 commit comments