@@ -9,9 +9,9 @@ import func from "@/util/func"
9
9
import { useNavigate } from "react-router-dom"
10
10
import PersistStore from "../../../../main/PersistStore" ;
11
11
import transform from "../../testing/transform" ;
12
- import LocalStore from "../../../../main/LocalStorageStore " ;
12
+ import ObserveStore from "../observeStore " ;
13
13
14
- function RunTest ( { endpoints, filtered, apiCollectionId, disabled, runTestFromOutside, closeRunTest, selectedResourcesForPrimaryAction, useLocalSubCategoryData } ) {
14
+ function RunTest ( { endpoints, filtered, apiCollectionId, disabled, runTestFromOutside, closeRunTest, selectedResourcesForPrimaryAction, useLocalData } ) {
15
15
16
16
const initialState = {
17
17
categories : [ ] ,
@@ -66,8 +66,8 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
66
66
67
67
const [ testAlreadyRunning , setTestAlreadyRunning ] = useState ( false )
68
68
69
- const localCategoryMap = LocalStore . getState ( ) . categoryMap
70
- const localSubCategoryMap = LocalStore . getState ( ) . subCategoryMap
69
+ const runTestModalData = useLocalData ? ObserveStore ( state => state . runTestModalData ) : { }
70
+ const setRunTestModalData = ObserveStore ( state => state . setRunTestModalData )
71
71
72
72
function nameSuffixes ( tests ) {
73
73
return Object . entries ( tests )
@@ -91,29 +91,45 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
91
91
92
92
async function fetchData ( ) {
93
93
setLoading ( true )
94
+ let tempRunTestModalData = { }
94
95
95
- observeApi . fetchSlackWebhooks ( ) . then ( ( resp ) => {
96
- const apiTokenList = resp . apiTokenList
97
- setSlackIntegrated ( apiTokenList && apiTokenList . length > 0 )
98
- } )
99
-
100
- let metaDataObj = {
101
- categories : [ ] ,
102
- subCategories : [ ] ,
103
- testSourceConfigs : [ ]
96
+ if ( runTestModalData . slackIntegrated != null ) {
97
+ setSlackIntegrated ( runTestModalData . slackIntegrated )
98
+ } else {
99
+ observeApi . fetchSlackWebhooks ( ) . then ( ( resp ) => {
100
+ const apiTokenList = resp . apiTokenList
101
+ setSlackIntegrated ( apiTokenList && apiTokenList . length > 0 )
102
+ tempRunTestModalData = {
103
+ ...tempRunTestModalData ,
104
+ slackIntegrated : ( apiTokenList && apiTokenList . length > 0 )
105
+ }
106
+ } )
104
107
}
105
- if ( ! useLocalSubCategoryData ) {
106
- metaDataObj = await transform . getAllSubcategoriesData ( true , "runTests" )
108
+
109
+ let metaDataObj = { }
110
+ if ( runTestModalData . metaDataObj != null ) {
111
+ metaDataObj = runTestModalData . metaDataObj
107
112
} else {
108
- metaDataObj = {
109
- categories : Object . values ( localCategoryMap ) ,
110
- subCategories : Object . values ( localSubCategoryMap ) ,
111
- testSourceConfigs : [ ]
113
+ metaDataObj = await transform . getAllSubcategoriesData ( true , "runTests" )
114
+ tempRunTestModalData = {
115
+ ... tempRunTestModalData ,
116
+ metaDataObj
112
117
}
113
118
}
114
119
let categories = metaDataObj . categories
115
120
let businessLogicSubcategories = metaDataObj . subCategories
116
- const testRolesResponse = await testingApi . fetchTestRoles ( )
121
+
122
+
123
+ let testRolesResponse
124
+ if ( runTestModalData . testRolesResponse != null ) {
125
+ testRolesResponse = runTestModalData . testRolesResponse
126
+ } else {
127
+ testRolesResponse = await testingApi . fetchTestRoles ( )
128
+ tempRunTestModalData = {
129
+ ...tempRunTestModalData ,
130
+ testRolesResponse
131
+ }
132
+ }
117
133
var testRoles = testRolesResponse . testRoles . map ( testRole => {
118
134
return {
119
135
"label" : testRole . name ,
@@ -145,7 +161,16 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
145
161
146
162
//Auth Mechanism
147
163
let authMechanismPresent = false
148
- const authMechanismDataResponse = await testingApi . fetchAuthMechanismData ( )
164
+ let authMechanismDataResponse
165
+ if ( runTestModalData . authMechanismDataResponse != null ) {
166
+ authMechanismDataResponse = runTestModalData . authMechanismDataResponse
167
+ } else {
168
+ authMechanismDataResponse = await testingApi . fetchAuthMechanismData ( )
169
+ tempRunTestModalData = {
170
+ ...tempRunTestModalData ,
171
+ authMechanismDataResponse
172
+ }
173
+ }
149
174
if ( authMechanismDataResponse . authMechanism )
150
175
authMechanismPresent = true
151
176
@@ -158,6 +183,10 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
158
183
authMechanismPresent : authMechanismPresent
159
184
} ) )
160
185
186
+ if ( tempRunTestModalData != null && Object . keys ( tempRunTestModalData ) . length > 0 ) {
187
+ setRunTestModalData ( tempRunTestModalData )
188
+ }
189
+
161
190
setLoading ( false )
162
191
}
163
192
0 commit comments