Skip to content

Commit 874037e

Browse files
authored
Merge pull request #2538 from akto-api-security/feature/add-api-name-filter
Add API name filter
2 parents c0c16ca + e844521 commit 874037e

File tree

1 file changed

+65
-2
lines changed
  • apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/SingleTestRunPage

1 file changed

+65
-2
lines changed

apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/testing/SingleTestRunPage/SingleTestRunPage.js

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
SettingsMinor
2929
} from '@shopify/polaris-icons';
3030
import api from "../api";
31+
import observeApi from "../../observe/api";
3132
import func from '@/util/func';
3233
import { useParams } from 'react-router';
3334
import { useState, useEffect, useRef, useMemo, useReducer } from 'react';
@@ -107,6 +108,12 @@ let filterOptions = [
107108
label: 'API groups',
108109
title: 'API groups',
109110
choices: [],
111+
},
112+
{
113+
key: 'apiNameFilter',
114+
label: 'API Name',
115+
title: 'API name',
116+
choices: [],
110117
}
111118
]
112119

@@ -185,6 +192,8 @@ function SingleTestRunPage() {
185192
case 'categoryFilter':
186193
case 'testFilter':
187194
return func.convertToDisambiguateLabelObj(value, null, 2)
195+
case 'apiNameFilter':
196+
return func.convertToDisambiguateLabelObj(value, null, 1)
188197
default:
189198
return value;
190199
}
@@ -234,13 +243,13 @@ function SingleTestRunPage() {
234243
}
235244

236245
useEffect(() => {
237-
setUpdateTable(Date.now().toString())
238246
if (
239247
(localCategoryMap && Object.keys(localCategoryMap).length > 0) &&
240248
(localSubCategoryMap && Object.keys(localSubCategoryMap).length > 0)
241249
) {
242250
setUseLocalSubCategoryData(true)
243251
}
252+
setUpdateTable(Date.now().toString())
244253
}, [testingRunResultSummariesObj])
245254

246255
filterOptions = func.getCollectionFilters(filterOptions)
@@ -264,13 +273,66 @@ function SingleTestRunPage() {
264273
}
265274
})
266275

276+
const populateApiNameFilterChoices = async (testingRun) => {
277+
if (testingRun?.testingEndpoints) {
278+
const {testingEndpoints} = testingRun;
279+
let apiEndpoints = [];
280+
281+
if (testingEndpoints.type === "COLLECTION_WISE") {
282+
const collectionId = testingEndpoints.apiCollectionId;
283+
if (collectionId) {
284+
try {
285+
const response = await observeApi.fetchApiInfosForCollection(
286+
collectionId);
287+
if (response?.apiInfoList) {
288+
const limitedEndpoints = response.apiInfoList.slice(
289+
0, 5000);
290+
apiEndpoints = getApiEndpointsMap(limitedEndpoints);
291+
}
292+
} catch (error) {
293+
console.error("Error fetching collection endpoints:", error);
294+
}
295+
}
296+
} else if (testingEndpoints.type === "CUSTOM"
297+
&& testingEndpoints.apisList) {
298+
const limitedApis = testingEndpoints.apisList.slice(0, 5000);
299+
apiEndpoints = getApiEndpointsMap(limitedApis);
300+
}
301+
302+
filterOptions = filterOptions.map(filter => {
303+
if (filter.key === 'apiNameFilter') {
304+
return {
305+
...filter,
306+
choices: apiEndpoints
307+
};
308+
}
309+
return filter;
310+
});
311+
setUpdateTable(Date.now().toString());
312+
}
313+
}
314+
315+
const getApiEndpointsMap = (endpoints) => {
316+
return Array.from(
317+
new Map(
318+
endpoints
319+
.map(e => e.id)
320+
.map(e => [e.url,
321+
{label: func.convertToRelativePath(e.url), value: e.url}])
322+
).values()
323+
);
324+
}
325+
267326
const fetchTestingRunResultSummaries = async () => {
268327
let tempTestingRunResultSummaries = [];
269-
await api.fetchTestingRunResultSummaries(hexId).then(({ testingRun, testingRunResultSummaries, workflowTest, testingRunType }) => {
328+
await api.fetchTestingRunResultSummaries(hexId).then(async ({ testingRun, testingRunResultSummaries, workflowTest, testingRunType }) => {
270329
tempTestingRunResultSummaries = testingRunResultSummaries
271330
setTestingRunResultSummariesObj({
272331
testingRun, workflowTest, testingRunType
273332
})
333+
if (testingRun) {
334+
await populateApiNameFilterChoices(testingRun)
335+
}
274336
})
275337
const timeNow = func.timeNow()
276338
const defaultIgnoreTime = LocalStore.getState().defaultIgnoreSummaryTime
@@ -285,6 +347,7 @@ function SingleTestRunPage() {
285347
if (isBWithinTimeAndRunning) return 1;
286348
return b.startTimestamp - a.startTimestamp;
287349
})
350+
288351
if (tempTestingRunResultSummaries && tempTestingRunResultSummaries.length > 0) {
289352
setSummary(tempTestingRunResultSummaries[0], true)
290353
}

0 commit comments

Comments
 (0)