@@ -11,24 +11,35 @@ const initialState = {
11
11
activeTabUid : null
12
12
} ;
13
13
14
+ const tabTypeAlreadyExists = ( tabs , collectionUid , type ) => {
15
+ return find ( tabs , ( tab ) => tab . collectionUid === collectionUid && tab . type === type ) ;
16
+ } ;
17
+
14
18
export const tabsSlice = createSlice ( {
15
19
name : 'tabs' ,
16
20
initialState,
17
21
reducers : {
18
22
addTab : ( state , action ) => {
19
23
const { uid, collectionUid, type, requestPaneTab, preview } = action . payload ;
24
+ const nonReplaceableTabTypes = [
25
+ "variables" ,
26
+ "collection-runner" ,
27
+ "security-settings" ,
28
+ ] ;
20
29
21
30
const existingTab = find ( state . tabs , ( tab ) => tab . uid === uid ) ;
22
-
23
31
if ( existingTab ) {
24
32
state . activeTabUid = existingTab . uid ;
25
33
return ;
26
34
}
27
- const nonReplaceableTabTypes = [
28
- "variables" ,
29
- "collection-runner" ,
30
- "security-settings" ,
31
- ] ;
35
+
36
+ if ( nonReplaceableTabTypes . includes ( type ) ) {
37
+ const existingTab = tabTypeAlreadyExists ( state . tabs , collectionUid , type ) ;
38
+ if ( existingTab ) {
39
+ state . activeTabUid = existingTab . uid ;
40
+ return ;
41
+ }
42
+ }
32
43
33
44
const lastTab = state . tabs [ state . tabs . length - 1 ] ;
34
45
if ( state . tabs . length > 0 && lastTab . preview ) {
@@ -39,7 +50,9 @@ export const tabsSlice = createSlice({
39
50
requestPaneTab : requestPaneTab || 'params' ,
40
51
responsePaneTab : 'response' ,
41
52
type : type || 'request' ,
42
- preview : true ,
53
+ preview : preview !== undefined
54
+ ? preview
55
+ : ! nonReplaceableTabTypes . includes ( type ) ,
43
56
...( uid ? { folderUid : uid } : { } )
44
57
}
45
58
0 commit comments