Skip to content

Commit

Permalink
Merge pull request #1745 from akto-api-security/fix/remove_unnecessar…
Browse files Browse the repository at this point in the history
…y_api_calls

fixed: not fetching subCategory and category data if it's already in …
  • Loading branch information
Ark2307 authored Nov 20, 2024
2 parents 7f17f57 + 2ad26d0 commit b5cf5ae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
Expand All @@ -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 &&
Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -247,6 +260,7 @@ function ApiDetails(props) {
apiCollectionId={apiDetail["apiCollectionId"]}
endpoints={[apiDetail]}
filtered={true}
useLocalSubCategoryData={useLocalSubCategoryData}
/>
<Box>
<Tooltip content="Open URL in test editor" dismissOnMouseOut>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit b5cf5ae

Please sign in to comment.