From 4a1172972624c5e6341a78e27b36969e4204faa5 Mon Sep 17 00:00:00 2001 From: fenil Date: Thu, 12 Sep 2024 16:20:29 +0530 Subject: [PATCH 1/4] Added deactivated collection tab --- .../dashboard/pages/dashboard/transform.js | 19 +++++----- .../api_collections/ApiCollections.jsx | 36 +++++++++++-------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/dashboard/transform.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/dashboard/transform.js index 1e96effe10..4842a56304 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/dashboard/transform.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/dashboard/transform.js @@ -114,16 +114,19 @@ const transform = { }, getCountInfo: (collectionsArr, coverageObject) => { - let urlsCount = 0 ; - let coverageCount = 0 ; - collectionsArr.forEach((x) =>{ + let urlsCount = 0; + let coverageCount = 0; + collectionsArr.forEach((x) => { if (x.hasOwnProperty('type') && x.type === 'API_GROUP') { - return + return; } - - urlsCount += x.urlsCount; - coverageCount += coverageObject[x.id] || 0 ; - }) + + // Only count active collections + if (!x.deactivated) { + urlsCount += x.urlsCount; + coverageCount += coverageObject[x.id] || 0; + } + }); return { totalUrls: urlsCount, coverage: urlsCount === 0 ? "0%" : Math.ceil((coverageCount * 100) / urlsCount) + '%' diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx index 29f1c96acc..080b012257 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx @@ -176,12 +176,13 @@ const convertToNewData = (collectionsArr, sensitiveInfoMap, severityInfoMap, cov ...c, displayNameComp: (), testedEndpoints: coverageMap[c.id] ? coverageMap[c.id] : 0, - sensitiveInRespTypes: sensitiveInfoMap[c.id] ? sensitiveInfoMap[c.id] : [], - severityInfo: severityInfoMap[c.id] ? severityInfoMap[c.id] : {}, + sensitiveInRespTypes: sensitiveInfoMap[c.id] || [], + severityInfo: severityInfoMap[c.id] || {}, detected: func.prettifyEpoch(trafficInfoMap[c.id] || 0), - detectedTimestamp : trafficInfoMap[c.id] || 0, - riskScore: riskScoreMap[c.id] ? riskScoreMap[c.id] : 0, + detectedTimestamp: trafficInfoMap[c.id] || 0, + riskScore: riskScoreMap[c.id] || 0, discovered: func.prettifyEpoch(c.startTs || 0), + deactivated: !!c.deactivated, } }) @@ -208,7 +209,7 @@ function ApiCollections() { // const dummyData = dummyJson; - const definedTableTabs = ['All', 'Hostname', 'Groups', 'Custom'] + const definedTableTabs = ['All', 'Hostname', 'Groups', 'Custom', 'Deactivated'] const { tabsInfo, selectItems } = useTable() const tableCountObj = func.getTabsCount(definedTableTabs, data) @@ -341,23 +342,28 @@ function ApiCollections() { dataObj = convertToNewData(tmp, sensitiveInfo.sensitiveInfoMap, severityObj, coverageInfo, trafficInfo, riskScoreObj?.riskScoreMap, false); setNormalData(dataObj.normal) - const summary = transform.getSummaryData(dataObj.normal) + + // Separate active and deactivated collections + const activeCollections = dataObj.prettify.filter(c => !c.deactivated); + const deactivatedCollections = dataObj.prettify.filter(c => c.deactivated); + + // Calculate summary data only for active collections + const summary = transform.getSummaryData(activeCollections) summary.totalCriticalEndpoints = riskScoreObj.criticalUrls; summary.totalSensitiveEndpoints = sensitiveInfo.sensitiveUrls setSummaryData(summary) - - setCollectionsMap(func.mapCollectionIdToName(tmp)) - const allHostNameMap = func.mapCollectionIdToHostName(tmp) - setHostNameMap(allHostNameMap) - tmp = {} - tmp.all = dataObj.prettify - tmp.hostname = dataObj.prettify.filter((c) => c.hostName !== null && c.hostName !== undefined) - tmp.groups = dataObj.prettify.filter((c) => c.type === "API_GROUP") - tmp.custom = tmp.all.filter(x => !tmp.hostname.includes(x) && !tmp.groups.includes(x)); + tmp.all = activeCollections + tmp.hostname = activeCollections.filter((c) => c.hostName !== null && c.hostName !== undefined) + tmp.groups = activeCollections.filter((c) => c.type === "API_GROUP") + tmp.custom = activeCollections.filter(x => x.hostName === null || x.hostName === undefined && x.type !== "API_GROUP") + tmp.deactivated = deactivatedCollections setData(tmp); + + // Update the API collection store with active collection count + setApiCounts(activeCollections.length, deactivatedCollections.length); } function disambiguateLabel(key, value) { From 7d533edd1f235dc799c971fb47b59f4ec31424b2 Mon Sep 17 00:00:00 2001 From: fenil Date: Thu, 12 Sep 2024 16:56:14 +0530 Subject: [PATCH 2/4] changes to deactivate collection tab --- .../observe/api_collections/ApiCollections.jsx | 16 ++++++---------- .../apps/dashboard/pages/observe/transform.js | 4 +++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx index 080b012257..27720ce698 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx @@ -182,7 +182,7 @@ const convertToNewData = (collectionsArr, sensitiveInfoMap, severityInfoMap, cov detectedTimestamp: trafficInfoMap[c.id] || 0, riskScore: riskScoreMap[c.id] || 0, discovered: func.prettifyEpoch(c.startTs || 0), - deactivated: !!c.deactivated, + deactivated: c.deactivated, } }) @@ -344,26 +344,22 @@ function ApiCollections() { setNormalData(dataObj.normal) // Separate active and deactivated collections - const activeCollections = dataObj.prettify.filter(c => !c.deactivated); const deactivatedCollections = dataObj.prettify.filter(c => c.deactivated); // Calculate summary data only for active collections - const summary = transform.getSummaryData(activeCollections) + const summary = transform.getSummaryData(dataObj.normal) summary.totalCriticalEndpoints = riskScoreObj.criticalUrls; summary.totalSensitiveEndpoints = sensitiveInfo.sensitiveUrls setSummaryData(summary) tmp = {} - tmp.all = activeCollections - tmp.hostname = activeCollections.filter((c) => c.hostName !== null && c.hostName !== undefined) - tmp.groups = activeCollections.filter((c) => c.type === "API_GROUP") - tmp.custom = activeCollections.filter(x => x.hostName === null || x.hostName === undefined && x.type !== "API_GROUP") + tmp.all = dataObj.prettify + tmp.hostname = dataObj.prettify.filter((c) => c.hostName !== null && c.hostName !== undefined) + tmp.groups = dataObj.prettify.filter((c) => c.type === "API_GROUP") + tmp.custom = tmp.all.filter(x => !tmp.hostname.includes(x) && !x.deactivated && !tmp.groups.includes(x)); tmp.deactivated = deactivatedCollections setData(tmp); - - // Update the API collection store with active collection count - setApiCounts(activeCollections.length, deactivatedCollections.length); } function disambiguateLabel(key, value) { diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/transform.js b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/transform.js index b1d210bfad..ad1e3ba2a1 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/transform.js +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/transform.js @@ -457,7 +457,9 @@ const transform = { if (c.hasOwnProperty('type') && c.type === 'API_GROUP') { return } - + if (c.deactivated) { + return + } totalUrl += c.urlsCount ; totalTested += c.testedEndpoints; }) From 04690d966d624a06f6dd2a04bf910b92fd67e8ae Mon Sep 17 00:00:00 2001 From: fenil Date: Thu, 12 Sep 2024 17:10:56 +0530 Subject: [PATCH 3/4] Worked on comments --- .../pages/observe/api_collections/ApiCollections.jsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx index 27720ce698..ff092dfe51 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx @@ -176,13 +176,12 @@ const convertToNewData = (collectionsArr, sensitiveInfoMap, severityInfoMap, cov ...c, displayNameComp: (), testedEndpoints: coverageMap[c.id] ? coverageMap[c.id] : 0, - sensitiveInRespTypes: sensitiveInfoMap[c.id] || [], - severityInfo: severityInfoMap[c.id] || {}, + sensitiveInRespTypes: sensitiveInfoMap[c.id] ? sensitiveInfoMap[c.id] : [], + severityInfo: severityInfoMap[c.id] ? sensitiveInfoMap[c.id] : {}, detected: func.prettifyEpoch(trafficInfoMap[c.id] || 0), detectedTimestamp: trafficInfoMap[c.id] || 0, - riskScore: riskScoreMap[c.id] || 0, + riskScore: riskScoreMap[c.id] ? riskScoreMap[c.id] : 0, discovered: func.prettifyEpoch(c.startTs || 0), - deactivated: c.deactivated, } }) @@ -352,6 +351,10 @@ function ApiCollections() { summary.totalSensitiveEndpoints = sensitiveInfo.sensitiveUrls setSummaryData(summary) + setCollectionsMap(func.mapCollectionIdToName(tmp)) + const allHostNameMap = func.mapCollectionIdToHostName(tmp) + setHostNameMap(allHostNameMap) + tmp = {} tmp.all = dataObj.prettify tmp.hostname = dataObj.prettify.filter((c) => c.hostName !== null && c.hostName !== undefined) From a4b386c8a5da7421785e582856d214f65b5660c8 Mon Sep 17 00:00:00 2001 From: fenil Date: Thu, 12 Sep 2024 17:14:07 +0530 Subject: [PATCH 4/4] comments resolved --- .../dashboard/pages/observe/api_collections/ApiCollections.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx index ff092dfe51..19d7cfb33b 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/observe/api_collections/ApiCollections.jsx @@ -177,7 +177,7 @@ const convertToNewData = (collectionsArr, sensitiveInfoMap, severityInfoMap, cov displayNameComp: (), testedEndpoints: coverageMap[c.id] ? coverageMap[c.id] : 0, sensitiveInRespTypes: sensitiveInfoMap[c.id] ? sensitiveInfoMap[c.id] : [], - severityInfo: severityInfoMap[c.id] ? sensitiveInfoMap[c.id] : {}, + severityInfo: severityInfoMap[c.id] ? severityInfoMap[c.id] : {}, detected: func.prettifyEpoch(trafficInfoMap[c.id] || 0), detectedTimestamp: trafficInfoMap[c.id] || 0, riskScore: riskScoreMap[c.id] ? riskScoreMap[c.id] : 0,