Skip to content

Commit 7ff1895

Browse files
authored
Merge pull request #2206 from akto-api-security/hotfix/fix_store_capacity
Hotfix/fix store capacity
2 parents 004a08b + 6e7a0fd commit 7ff1895

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/dashboard/HomeDashboard.jsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function HomeDashboard() {
3333
const [testSummaryInfo, setTestSummaryInfo] = useState([])
3434

3535
const allCollections = PersistStore(state => state.allCollections)
36+
const hostNameMap = PersistStore(state => state.hostNameMap)
3637
const coverageMap = PersistStore(state => state.coverageMap)
3738
const [authMap, setAuthMap] = useState({})
3839
const [apiTypesData, setApiTypesData] = useState([{ "data": [], "color": "#D6BBFB" }])
@@ -383,9 +384,9 @@ function HomeDashboard() {
383384
}
384385

385386
function getCollectionsWithCoverage() {
386-
const validCollections = allCollections.filter(collection => collection.hostName !== null && collection.hostName !== undefined && !collection.deactivated);
387+
const validCollections = allCollections.filter(collection => hostNameMap.hasOwnProperty(collection.id) && !collection.deactivated);
387388

388-
const sortedCollections = validCollections.sort((a, b) => b.startTs - a.startTs);
389+
const sortedCollections = validCollections.sort((a, b) => b?.startTs - a?.startTs);
389390

390391
const result = sortedCollections.slice(0, 10).map(collection => {
391392
const apisTested = coverageMap[collection.id] || 0;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ function ApiCollections() {
769769
const tableComponent = (
770770
treeView ?
771771
<TreeViewTable
772-
collectionsArr={normalData.filter((x) => x?.type !== "API_GROUP")}
772+
collectionsArr={normalData.filter((x) => (!x?.deactivated && x?.type !== "API_GROUP"))}
773773
sortOptions={sortOptions}
774774
resourceName={resourceName}
775775
tableHeaders={headers.filter((x) => x.shouldMerge !== undefined)}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ function ApiEndpoints(props) {
154154
const setShowDetails = ObserveStore(state => state.setInventoryFlyout)
155155
const collectionsMap = PersistStore(state => state.collectionsMap)
156156
const allCollections = PersistStore(state => state.allCollections);
157+
const hostNameMap = PersistStore(state => state.hostNameMap);
157158
const setCollectionsMap = PersistStore(state => state.setCollectionsMap)
158159
const setAllCollections = PersistStore(state => state.setAllCollections)
159160

@@ -665,7 +666,7 @@ function ApiEndpoints(props) {
665666
</div> :
666667
null
667668
}
668-
{ !isApiGroup && !(collectionsObj?.hostName && collectionsObj?.hostName?.length > 0) ?
669+
{ !isApiGroup && !(hostNameMap.hasOwnProperty(collectionsObj?.id)) ?
669670
<UploadFile
670671
fileFormat=".har"
671672
fileChanged={file => handleFileChange(file)}

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/settings/default_payloads/DefaultPayloads.jsx

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Page, LegacyCard, TextField, VerticalStack, Button } from '@shopify/polaris'
2-
import Dropdown from '../../../components/layouts/Dropdown'
32
import DropdownSearch from '../../../components/shared/DropdownSearch'
43
import PersistStore from '@/apps/main/PersistStore';
54

@@ -9,14 +8,8 @@ import func from '@/util/func'
98
import {useState, useEffect} from 'react'
109
function DefaultPayloads() {
1110

12-
const allCollections = PersistStore(state => state.allCollections)
13-
const allHostnames = allCollections.map(x => x.hostName).filter(x => x!=null)
14-
const hostNameOptions = allHostnames.map(x => {
15-
return {
16-
label: x,
17-
value: x
18-
}
19-
})
11+
const hostNameMap = PersistStore(state => state.hostNameMap)
12+
const allHostnames = Object.keys(hostNameMap)
2013

2114

2215
const [selectedDomain, setSelectedDomain] = useState('')

apps/dashboard/web/polaris_web/web/src/apps/main/PersistStore.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,18 @@ let persistStore = (set) => ({
3737
setSubCategoryFromSourceConfigMap: (subCategoryFromSourceConfigMap) => set({ subCategoryFromSourceConfigMap }),
3838
setActive: (selected) => set({ active: selected }),
3939
setCollectionsMap: (collectionsMap) => set({ collectionsMap }),
40-
setAllCollections: (allCollections) => set({ allCollections }),
40+
setAllCollections: (allCollections) => {
41+
const optimizedCollections = allCollections.map(({ id, displayName, urlsCount, deactivated, type, automated, startTs }) => ({
42+
id,
43+
displayName,
44+
urlsCount,
45+
deactivated,
46+
type,
47+
automated,
48+
startTs
49+
}));
50+
set({ allCollections: optimizedCollections });
51+
},
4152
setHostNameMap: (hostNameMap) => set({ hostNameMap }),
4253
setLastFetchedInfo: (lastFetchedInfo) => set({ lastFetchedInfo }),
4354
setLastFetchedResp: (lastFetchedResp) => set({ lastFetchedResp }),

0 commit comments

Comments
 (0)