Skip to content

Commit

Permalink
fix: stop calling unused api calls in the run test
Browse files Browse the repository at this point in the history
  • Loading branch information
TangoBeeAkto committed Nov 22, 2024
1 parent ddd1501 commit e949fe4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ import PersistStore from "../../../../main/PersistStore";
import values from "@/util/values";

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

function ApiDetails(props) {

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

const localCategoryMap = LocalStore.getState().categoryMap
const localSubCategoryMap = LocalStore.getState().subCategoryMap

const [sampleData, setSampleData] = useState([])
const [paramList, setParamList] = useState([])
const [selectedUrl, setSelectedUrl] = useState({})
Expand All @@ -36,8 +32,6 @@ function ApiDetails(props) {
const setSelectedSampleApi = PersistStore(state => state.setSelectedSampleApi)
const [disabledTabs, setDisabledTabs] = useState([])

const [useLocalSubCategoryData, setUseLocalSubCategoryData] = useState(false)

const statusFunc = getStatus ? getStatus : (x) => {
try {
if (paramList && paramList.length > 0 &&
Expand Down Expand Up @@ -136,13 +130,6 @@ function ApiDetails(props) {
}

useEffect(() => {
if (
(localCategoryMap && Object.keys(localCategoryMap).length > 0) &&
(localSubCategoryMap && Object.keys(localSubCategoryMap).length > 0)
) {
setUseLocalSubCategoryData(true)
}

fetchData();
}, [apiDetail])

Expand Down Expand Up @@ -260,7 +247,7 @@ function ApiDetails(props) {
apiCollectionId={apiDetail["apiCollectionId"]}
endpoints={[apiDetail]}
filtered={true}
useLocalSubCategoryData={useLocalSubCategoryData}
useLocalData={true}
/>
<Box>
<Tooltip content="Open URL in test editor" dismissOnMouseOut>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import func from "@/util/func"
import { useNavigate } from "react-router-dom"
import PersistStore from "../../../../main/PersistStore";
import transform from "../../testing/transform";
import LocalStore from "../../../../main/LocalStorageStore";
import ObserveStore from "../observeStore";

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

const initialState = {
categories: [],
Expand Down Expand Up @@ -66,8 +66,8 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu

const [testAlreadyRunning, setTestAlreadyRunning] = useState(false)

const localCategoryMap = LocalStore.getState().categoryMap
const localSubCategoryMap = LocalStore.getState().subCategoryMap
const runTestModalData = useLocalData ? ObserveStore(state => state.runTestModalData) : {}
const setRunTestModalData = ObserveStore(state => state.setRunTestModalData)

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

async function fetchData() {
setLoading(true)
let tempRunTestModalData = {}

observeApi.fetchSlackWebhooks().then((resp) => {
const apiTokenList = resp.apiTokenList
setSlackIntegrated(apiTokenList && apiTokenList.length > 0)
})

let metaDataObj = {
categories: [],
subCategories: [],
testSourceConfigs: []
if(runTestModalData.slackIntegrated != null) {
setSlackIntegrated(runTestModalData.slackIntegrated)
} else {
observeApi.fetchSlackWebhooks().then((resp) => {
const apiTokenList = resp.apiTokenList
setSlackIntegrated(apiTokenList && apiTokenList.length > 0)
tempRunTestModalData = {
...tempRunTestModalData,
slackIntegrated: (apiTokenList && apiTokenList.length > 0)
}
})
}
if(!useLocalSubCategoryData) {
metaDataObj = await transform.getAllSubcategoriesData(true, "runTests")

let metaDataObj = {}
if(runTestModalData.metaDataObj != null) {
metaDataObj = runTestModalData.metaDataObj
} else {
metaDataObj = {
categories: Object.values(localCategoryMap),
subCategories: Object.values(localSubCategoryMap),
testSourceConfigs: []
metaDataObj = await transform.getAllSubcategoriesData(true, "runTests")
tempRunTestModalData = {
...tempRunTestModalData,
metaDataObj
}
}
let categories = metaDataObj.categories
let businessLogicSubcategories = metaDataObj.subCategories
const testRolesResponse = await testingApi.fetchTestRoles()


let testRolesResponse
if(runTestModalData.testRolesResponse != null) {
testRolesResponse = runTestModalData.testRolesResponse
} else {
testRolesResponse = await testingApi.fetchTestRoles()
tempRunTestModalData = {
...tempRunTestModalData,
testRolesResponse
}
}
var testRoles = testRolesResponse.testRoles.map(testRole => {
return {
"label": testRole.name,
Expand Down Expand Up @@ -145,7 +161,16 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu

//Auth Mechanism
let authMechanismPresent = false
const authMechanismDataResponse = await testingApi.fetchAuthMechanismData()
let authMechanismDataResponse
if(runTestModalData.authMechanismDataResponse != null) {
authMechanismDataResponse = runTestModalData.authMechanismDataResponse
} else {
authMechanismDataResponse = await testingApi.fetchAuthMechanismData()
tempRunTestModalData = {
...tempRunTestModalData,
authMechanismDataResponse
}
}
if (authMechanismDataResponse.authMechanism)
authMechanismPresent = true

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

if(tempRunTestModalData != null && Object.keys(tempRunTestModalData).length > 0) {
setRunTestModalData(tempRunTestModalData)
}

setLoading(false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ let observeStore = (set)=>({
setSelectedUrl:(selectedUrl)=>{
set({selectedUrl: selectedUrl})
},

runTestModalData: {},
setRunTestModalData: (runTestModalData)=>{
set({runTestModalData: runTestModalData})
}
})

observeStore = devtools(observeStore)
Expand Down

0 comments on commit e949fe4

Please sign in to comment.