From 0ac83d234260b9d009bd721174b6e8780a678fe7 Mon Sep 17 00:00:00 2001 From: Umesh Kumar <166806589+TangoBeeAkto@users.noreply.github.com> Date: Fri, 22 Nov 2024 17:53:02 +0530 Subject: [PATCH] fix: stop calling unused api calls in the run test --- .../observe/api_collections/ApiDetails.jsx | 15 +--- .../pages/observe/api_collections/RunTest.jsx | 74 +++++++++++++------ .../dashboard/pages/observe/observeStore.js | 5 ++ 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiDetails.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiDetails.jsx index a23c8d2f75..fb07dd001e 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiDetails.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiDetails.jsx @@ -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({}) @@ -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 && @@ -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]) @@ -260,7 +247,7 @@ function ApiDetails(props) { apiCollectionId={apiDetail["apiCollectionId"]} endpoints={[apiDetail]} filtered={true} - useLocalSubCategoryData={useLocalSubCategoryData} + useLocalData={true} /> diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx index c1058f988b..f75d4bc017 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/RunTest.jsx @@ -9,13 +9,11 @@ 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 AdvancedSettingsComponent from "./component/AdvancedSettingsComponent"; - import {produce} from "immer" +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: [], @@ -70,12 +68,11 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu const [testAlreadyRunning, setTestAlreadyRunning] = useState(false) + const runTestModalData = useLocalData ? ObserveStore(state => state.runTestModalData) : {} + const setRunTestModalData = ObserveStore(state => state.setRunTestModalData) const emptyCondition = {data: {key: '', value: ''}, operator: {'type': 'ADD_HEADER'}} const [conditions, dispatchConditions] = useReducer(produce((draft, action) => func.conditionsReducer(draft, action)), [emptyCondition]); - const localCategoryMap = LocalStore.getState().categoryMap - const localSubCategoryMap = LocalStore.getState().subCategoryMap - function nameSuffixes(tests) { return Object.entries(tests) .filter(category => { @@ -98,29 +95,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, @@ -152,7 +165,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 @@ -165,6 +187,10 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu authMechanismPresent: authMechanismPresent })) + if(tempRunTestModalData != null && Object.keys(tempRunTestModalData).length > 0) { + setRunTestModalData(tempRunTestModalData) + } + setLoading(false) } diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/observeStore.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/observeStore.js index 3723ec584a..4cda332554 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/observeStore.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/observeStore.js @@ -22,6 +22,11 @@ let observeStore = (set)=>({ setSelectedUrl:(selectedUrl)=>{ set({selectedUrl: selectedUrl}) }, + + runTestModalData: {}, + setRunTestModalData: (runTestModalData)=>{ + set({runTestModalData: runTestModalData}) + } }) observeStore = devtools(observeStore)