Skip to content

Commit e949fe4

Browse files
committed
fix: stop calling unused api calls in the run test
1 parent ddd1501 commit e949fe4

File tree

3 files changed

+56
-35
lines changed

3 files changed

+56
-35
lines changed

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiDetails.jsx

+1-14
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ import PersistStore from "../../../../main/PersistStore";
1616
import values from "@/util/values";
1717

1818
import { HorizontalDotsMinor, FileMinor } from "@shopify/polaris-icons"
19-
import LocalStore from "../../../../main/LocalStorageStore";
2019

2120
function ApiDetails(props) {
2221

2322
const { showDetails, setShowDetails, apiDetail, headers, getStatus, isGptActive } = props
2423

25-
const localCategoryMap = LocalStore.getState().categoryMap
26-
const localSubCategoryMap = LocalStore.getState().subCategoryMap
27-
2824
const [sampleData, setSampleData] = useState([])
2925
const [paramList, setParamList] = useState([])
3026
const [selectedUrl, setSelectedUrl] = useState({})
@@ -36,8 +32,6 @@ function ApiDetails(props) {
3632
const setSelectedSampleApi = PersistStore(state => state.setSelectedSampleApi)
3733
const [disabledTabs, setDisabledTabs] = useState([])
3834

39-
const [useLocalSubCategoryData, setUseLocalSubCategoryData] = useState(false)
40-
4135
const statusFunc = getStatus ? getStatus : (x) => {
4236
try {
4337
if (paramList && paramList.length > 0 &&
@@ -136,13 +130,6 @@ function ApiDetails(props) {
136130
}
137131

138132
useEffect(() => {
139-
if (
140-
(localCategoryMap && Object.keys(localCategoryMap).length > 0) &&
141-
(localSubCategoryMap && Object.keys(localSubCategoryMap).length > 0)
142-
) {
143-
setUseLocalSubCategoryData(true)
144-
}
145-
146133
fetchData();
147134
}, [apiDetail])
148135

@@ -260,7 +247,7 @@ function ApiDetails(props) {
260247
apiCollectionId={apiDetail["apiCollectionId"]}
261248
endpoints={[apiDetail]}
262249
filtered={true}
263-
useLocalSubCategoryData={useLocalSubCategoryData}
250+
useLocalData={true}
264251
/>
265252
<Box>
266253
<Tooltip content="Open URL in test editor" dismissOnMouseOut>

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx

+50-21
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import func from "@/util/func"
99
import { useNavigate } from "react-router-dom"
1010
import PersistStore from "../../../../main/PersistStore";
1111
import transform from "../../testing/transform";
12-
import LocalStore from "../../../../main/LocalStorageStore";
12+
import ObserveStore from "../observeStore";
1313

14-
function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOutside, closeRunTest, selectedResourcesForPrimaryAction, useLocalSubCategoryData }) {
14+
function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOutside, closeRunTest, selectedResourcesForPrimaryAction, useLocalData }) {
1515

1616
const initialState = {
1717
categories: [],
@@ -66,8 +66,8 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
6666

6767
const [testAlreadyRunning, setTestAlreadyRunning] = useState(false)
6868

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)
7171

7272
function nameSuffixes(tests) {
7373
return Object.entries(tests)
@@ -91,29 +91,45 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
9191

9292
async function fetchData() {
9393
setLoading(true)
94+
let tempRunTestModalData = {}
9495

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+
})
104107
}
105-
if(!useLocalSubCategoryData) {
106-
metaDataObj = await transform.getAllSubcategoriesData(true, "runTests")
108+
109+
let metaDataObj = {}
110+
if(runTestModalData.metaDataObj != null) {
111+
metaDataObj = runTestModalData.metaDataObj
107112
} 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
112117
}
113118
}
114119
let categories = metaDataObj.categories
115120
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+
}
117133
var testRoles = testRolesResponse.testRoles.map(testRole => {
118134
return {
119135
"label": testRole.name,
@@ -145,7 +161,16 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
145161

146162
//Auth Mechanism
147163
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+
}
149174
if (authMechanismDataResponse.authMechanism)
150175
authMechanismPresent = true
151176

@@ -158,6 +183,10 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu
158183
authMechanismPresent: authMechanismPresent
159184
}))
160185

186+
if(tempRunTestModalData != null && Object.keys(tempRunTestModalData).length > 0) {
187+
setRunTestModalData(tempRunTestModalData)
188+
}
189+
161190
setLoading(false)
162191
}
163192

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/observeStore.js

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ let observeStore = (set)=>({
2222
setSelectedUrl:(selectedUrl)=>{
2323
set({selectedUrl: selectedUrl})
2424
},
25+
26+
runTestModalData: {},
27+
setRunTestModalData: (runTestModalData)=>{
28+
set({runTestModalData: runTestModalData})
29+
}
2530
})
2631

2732
observeStore = devtools(observeStore)

0 commit comments

Comments
 (0)