1
- import React , { ReactNode , useEffect , useMemo } from 'react' ;
1
+ import React , { ReactNode , useMemo } from 'react' ;
2
2
3
3
import { useDispatch , useSelector } from 'react-redux' ;
4
4
import { useHistory } from 'react-router-dom' ;
@@ -12,7 +12,6 @@ import {
12
12
} from '../../redux/actions/incidents.actions' ;
13
13
import { IRootState } from '../../redux/reducers' ;
14
14
import { ROUTES } from '../../shared/routes' ;
15
- import { urlencodeDecoder } from '../../utils' ;
16
15
import ConfirmDialog from '../CustomTree/ConfirmDialog' ;
17
16
import Header from '../Header' ;
18
17
import PageTabs from '../PageTabs' ;
@@ -24,26 +23,34 @@ interface LayoutProps {
24
23
}
25
24
26
25
const IncidentsLayout = ( { route } : LayoutProps ) => {
27
- const { objectNotFound, setObjectNotFound } = useTree ( )
28
-
26
+ const { objectNotFound, setObjectNotFound } = useTree ( ) ;
27
+
29
28
const { tabs : pageTabs , activeTab } = useSelector (
30
29
( state : IRootState ) => state . incidents
31
30
) ;
32
-
31
+
33
32
const dispatch = useDispatch ( ) ;
34
33
const history = useHistory ( ) ;
35
34
36
-
37
35
const handleChange = ( tab : TabOption ) => {
36
+ if ( tab . url === window . location . pathname ) {
37
+ return ;
38
+ }
38
39
dispatch ( setActiveFirstLevelTab ( tab . value ) ) ;
39
- history . push ( urlencodeDecoder ( tab ?. url ?? '' ) ) ;
40
+ history . push ( tab . value ) ;
40
41
} ;
41
42
42
43
const closeTab = ( value : string ) => {
44
+ const tabIndex = pageTabs . findIndex ( ( item ) => item . url === value ) ;
45
+ dispatch ( closeFirstLevelTab ( value ) ) ;
43
46
if ( pageTabs . length === 1 ) {
44
- history . push ( `/incidents` )
47
+ history . push ( `/incidents` ) ;
48
+ return ;
45
49
}
46
- dispatch ( closeFirstLevelTab ( value ) ) ;
50
+ history . push ( pageTabs [ tabIndex - 1 ] ?. url || pageTabs [ 0 ] ?. url ) ;
51
+ dispatch (
52
+ setActiveFirstLevelTab ( pageTabs [ tabIndex - 1 ] ?. url || pageTabs [ 0 ] ?. url )
53
+ ) ;
47
54
} ;
48
55
49
56
const tabOptions = useMemo ( ( ) => {
@@ -56,21 +63,14 @@ const IncidentsLayout = ({ route }: LayoutProps) => {
56
63
) ;
57
64
} , [ pageTabs ] ) ;
58
65
59
- useEffect ( ( ) => {
60
- if ( activeTab ) {
61
- dispatch ( setActiveFirstLevelTab ( activeTab ) ) ;
62
- history . push ( activeTab ) ;
63
- }
64
- } , [ activeTab ] ) ;
65
-
66
66
const getComponent = ( ) => {
67
67
switch ( route ) {
68
68
case ROUTES . PATTERNS . INCIDENT_DETAIL :
69
- return < IncidentDetail /> ;
69
+ return < IncidentDetail /> ;
70
70
case ROUTES . PATTERNS . INCIDENTS :
71
- return < Incidents /> ;
71
+ return < Incidents /> ;
72
72
case ROUTES . PATTERNS . INCIDENT_CONNECTION :
73
- return < IncidentConnection /> ;
73
+ return < IncidentConnection /> ;
74
74
default :
75
75
return null ;
76
76
}
@@ -105,17 +105,26 @@ const IncidentsLayout = ({ route }: LayoutProps) => {
105
105
limit = { 7 }
106
106
/>
107
107
< div className = "bg-white border border-gray-300 flex-auto min-h-0 overflow-auto" >
108
- { ! ! activeTab && activeTab !== '/incidents/new-tab' && < > { renderComponent } </ > }
108
+ { ! ! activeTab && activeTab !== '/incidents/new-tab' && (
109
+ < > { renderComponent } </ >
110
+ ) }
109
111
</ div >
110
112
</ div >
111
113
</ div >
112
114
</ div >
113
115
< ConfirmDialog
114
- open = { objectNotFound }
115
- onConfirm = { ( ) => new Promise ( ( ) => { dispatch ( closeFirstLevelTab ( activeTab ) ) , setObjectNotFound ( false ) } ) }
116
- isCancelExcluded = { true }
117
- onClose = { ( ) => { dispatch ( closeFirstLevelTab ( activeTab ) ) , setObjectNotFound ( false ) } }
118
- message = 'The definition of this object was deleted in the DQOps user home. The tab will be closed.' />
116
+ open = { objectNotFound }
117
+ onConfirm = { ( ) =>
118
+ new Promise ( ( ) => {
119
+ dispatch ( closeFirstLevelTab ( activeTab ) ) , setObjectNotFound ( false ) ;
120
+ } )
121
+ }
122
+ isCancelExcluded = { true }
123
+ onClose = { ( ) => {
124
+ dispatch ( closeFirstLevelTab ( activeTab ) ) , setObjectNotFound ( false ) ;
125
+ } }
126
+ message = "The definition of this object was deleted in the DQOps user home. The tab will be closed."
127
+ />
119
128
</ div >
120
129
) ;
121
130
} ;
0 commit comments