From d3a7570eed8988f741f64e4f0faf6d7a02f86476 Mon Sep 17 00:00:00 2001 From: Umesh Kumar <166806589+TangoBeeAkto@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:40:02 +0530 Subject: [PATCH 1/2] fixed: not fetching subCategory and category data if it's already in local storage --- .../apps/dashboard/pages/testing/transform.js | 50 ++++++++++++------- .../VulnerabilityReport.jsx | 5 +- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js index 9ec7d9108b..ded3fe8a2a 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js @@ -597,30 +597,42 @@ const transform = { let finalDataSubCategories = [], promises = [], categories = []; let testSourceConfigs = [] const limit = 50; - for(var i = 0 ; i < 20; i++){ - promises.push( - api.fetchAllSubCategories(fetchActive, type, i * limit, limit) - ) - } - const allResults = await Promise.allSettled(promises); - for (const result of allResults) { - if (result.status === "fulfilled"){ - if(result?.value?.subCategories && result?.value?.subCategories !== undefined && result?.value?.subCategories.length > 0){ - finalDataSubCategories.push(...result.value.subCategories); - } - if(result?.value?.categories && result?.value?.categories !== undefined && result?.value?.categories.length > 0){ - if(categories.length === 0){ - categories.push(...result.value.categories); + const localSubCategoryMap = LocalStore.getState().subCategoryMap + const localCategoryMap = LocalStore.getState().categoryMap + + if ( + (!localCategoryMap || Object.keys(localCategoryMap).length === 0) || + (!localSubCategoryMap || Object.keys(localSubCategoryMap).length === 0) + ) { + for(var i = 0 ; i < 20; i++){ + promises.push( + api.fetchAllSubCategories(fetchActive, type, i * limit, limit) + ) + } + const allResults = await Promise.allSettled(promises); + for (const result of allResults) { + if (result.status === "fulfilled"){ + if(result?.value?.subCategories && result?.value?.subCategories !== undefined && result?.value?.subCategories.length > 0){ + finalDataSubCategories.push(...result.value.subCategories); + } + + if(result?.value?.categories && result?.value?.categories !== undefined && result?.value?.categories.length > 0){ + if(categories.length === 0){ + categories.push(...result.value.categories); + } } - } - if (result?.value?.testSourceConfigs && - result?.value?.testSourceConfigs !== undefined && - result?.value?.testSourceConfigs.length > 0) { - testSourceConfigs = result?.value?.testSourceConfigs + if (result?.value?.testSourceConfigs && + result?.value?.testSourceConfigs !== undefined && + result?.value?.testSourceConfigs.length > 0) { + testSourceConfigs = result?.value?.testSourceConfigs + } } } + } else { + categories = Object.values(localCategoryMap) + finalDataSubCategories = Object.values(localSubCategoryMap) } return { categories: categories, diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/vulnerability_report/VulnerabilityReport.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/vulnerability_report/VulnerabilityReport.jsx index 3e7cd8a613..c86602fd7c 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/vulnerability_report/VulnerabilityReport.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/vulnerability_report/VulnerabilityReport.jsx @@ -145,7 +145,10 @@ const VulnerabilityReport = () => { const localCategoryMap = LocalStore.getState().categoryMap const localSubCategoryMap = LocalStore.getState().subCategoryMap let shouldFetchSubcategoriesAndCategories = false - if(Object.keys(localCategoryMap).length === 0 || Object.keys(localSubCategoryMap).length === 0) { + if ( + (!localCategoryMap || Object.keys(localCategoryMap).length === 0) || + (!localSubCategoryMap || Object.keys(localSubCategoryMap).length === 0) + ) { shouldFetchSubcategoriesAndCategories = true } From 2ad26d08ef0e3c1e7540ea98ed780652e5c3d52f Mon Sep 17 00:00:00 2001 From: Umesh Kumar <166806589+TangoBeeAkto@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:16:26 +0530 Subject: [PATCH 2/2] fix: fetching subCategory data only if it's empty in apidetails --- .../observe/api_collections/ApiDetails.jsx | 14 ++++++ .../pages/observe/api_collections/RunTest.jsx | 21 +++++++- .../apps/dashboard/pages/testing/transform.js | 50 +++++++------------ 3 files changed, 52 insertions(+), 33 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 b533301542..a23c8d2f75 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,11 +16,15 @@ 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({}) @@ -32,6 +36,8 @@ 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 && @@ -130,6 +136,13 @@ function ApiDetails(props) { } useEffect(() => { + if ( + (localCategoryMap && Object.keys(localCategoryMap).length > 0) && + (localSubCategoryMap && Object.keys(localSubCategoryMap).length > 0) + ) { + setUseLocalSubCategoryData(true) + } + fetchData(); }, [apiDetail]) @@ -247,6 +260,7 @@ function ApiDetails(props) { apiCollectionId={apiDetail["apiCollectionId"]} endpoints={[apiDetail]} filtered={true} + useLocalSubCategoryData={useLocalSubCategoryData} /> 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 380d6aa322..97af965e40 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,8 +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"; -function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOutside, closeRunTest, selectedResourcesForPrimaryAction }) { +function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOutside, closeRunTest, selectedResourcesForPrimaryAction, useLocalSubCategoryData }) { const initialState = { categories: [], @@ -63,6 +64,9 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu const [optionsSelected, setOptionsSelected] = useState(initialArr) const [slackIntegrated, setSlackIntegrated] = useState(false) + const localCategoryMap = LocalStore.getState().categoryMap + const localSubCategoryMap = LocalStore.getState().subCategoryMap + function nameSuffixes(tests) { return Object.entries(tests) .filter(category => { @@ -91,7 +95,20 @@ function RunTest({ endpoints, filtered, apiCollectionId, disabled, runTestFromOu setSlackIntegrated(apiTokenList && apiTokenList.length > 0) }) - const metaDataObj = await transform.getAllSubcategoriesData(true, "runTests") + let metaDataObj = { + categories: [], + subCategories: [], + testSourceConfigs: [] + } + if(!useLocalSubCategoryData) { + metaDataObj = await transform.getAllSubcategoriesData(true, "runTests") + } else { + metaDataObj = { + categories: Object.values(localCategoryMap), + subCategories: Object.values(localSubCategoryMap), + testSourceConfigs: [] + } + } let categories = metaDataObj.categories let businessLogicSubcategories = metaDataObj.subCategories const testRolesResponse = await testingApi.fetchTestRoles() diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js index ded3fe8a2a..9ec7d9108b 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/transform.js @@ -597,42 +597,30 @@ const transform = { let finalDataSubCategories = [], promises = [], categories = []; let testSourceConfigs = [] const limit = 50; + for(var i = 0 ; i < 20; i++){ + promises.push( + api.fetchAllSubCategories(fetchActive, type, i * limit, limit) + ) + } + const allResults = await Promise.allSettled(promises); + for (const result of allResults) { + if (result.status === "fulfilled"){ + if(result?.value?.subCategories && result?.value?.subCategories !== undefined && result?.value?.subCategories.length > 0){ + finalDataSubCategories.push(...result.value.subCategories); + } - const localSubCategoryMap = LocalStore.getState().subCategoryMap - const localCategoryMap = LocalStore.getState().categoryMap - - if ( - (!localCategoryMap || Object.keys(localCategoryMap).length === 0) || - (!localSubCategoryMap || Object.keys(localSubCategoryMap).length === 0) - ) { - for(var i = 0 ; i < 20; i++){ - promises.push( - api.fetchAllSubCategories(fetchActive, type, i * limit, limit) - ) - } - const allResults = await Promise.allSettled(promises); - for (const result of allResults) { - if (result.status === "fulfilled"){ - if(result?.value?.subCategories && result?.value?.subCategories !== undefined && result?.value?.subCategories.length > 0){ - finalDataSubCategories.push(...result.value.subCategories); - } - - if(result?.value?.categories && result?.value?.categories !== undefined && result?.value?.categories.length > 0){ - if(categories.length === 0){ - categories.push(...result.value.categories); - } + if(result?.value?.categories && result?.value?.categories !== undefined && result?.value?.categories.length > 0){ + if(categories.length === 0){ + categories.push(...result.value.categories); } + } - if (result?.value?.testSourceConfigs && - result?.value?.testSourceConfigs !== undefined && - result?.value?.testSourceConfigs.length > 0) { - testSourceConfigs = result?.value?.testSourceConfigs - } + if (result?.value?.testSourceConfigs && + result?.value?.testSourceConfigs !== undefined && + result?.value?.testSourceConfigs.length > 0) { + testSourceConfigs = result?.value?.testSourceConfigs } } - } else { - categories = Object.values(localCategoryMap) - finalDataSubCategories = Object.values(localSubCategoryMap) } return { categories: categories,