Skip to content

Commit

Permalink
Merge pull request #1817 from akto-api-security/hotfix/api_groups_sort
Browse files Browse the repository at this point in the history
API groups sort
  • Loading branch information
Ark2307 authored Dec 12, 2024
2 parents 8d848c1 + e7edaea commit 480f829
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,15 @@ const headers = [
}
];

const tempSortOptions = [
{ label: 'Name', value: 'customGroupsSort asc', directionLabel: 'A-Z', sortKey: 'customGroupsSort', columnIndex: 1 },
{ label: 'Name', value: 'customGroupsSort desc', directionLabel: 'Z-A', sortKey: 'customGroupsSort', columnIndex: 1 },
]


const sortOptions = [
{ label: 'Endpoints', value: 'urlsCount asc', directionLabel: 'More', sortKey: 'urlsCount', columnIndex: 2 },
{ label: 'Endpoints', value: 'urlsCount desc', directionLabel: 'Less', sortKey: 'urlsCount' , columnIndex: 2},
{ label: 'Name', value: 'displayName asc', directionLabel: 'A-Z', sortKey: 'displayName' },
{ label: 'Name', value: 'displayName desc', directionLabel: 'Z-A', sortKey: 'displayName' },
{ label: 'Activity', value: 'deactivatedScore asc', directionLabel: 'Active', sortKey: 'deactivatedRiskScore' },
{ label: 'Activity', value: 'deactivatedScore desc', directionLabel: 'Inactive', sortKey: 'activatedRiskScore' },
{ label: 'Risk Score', value: 'score asc', directionLabel: 'High risk', sortKey: 'riskScore', columnIndex: 3 },
Expand Down Expand Up @@ -276,7 +279,8 @@ function ApiCollections() {
let res = {}
res.all = dataObj.prettify
res.hostname = dataObj.prettify.filter((c) => c.hostName !== null && c.hostName !== undefined && !c.deactivated)
res.groups = dataObj.prettify.filter((c) => c.type === "API_GROUP" && !c.deactivated)
const allGroups = dataObj.prettify.filter((c) => c.type === "API_GROUP" && !c.deactivated);
res.groups = allGroups;
res.custom = res.all.filter(x => !res.hostname.includes(x) && !x.deactivated && !res.groups.includes(x));
setData(res);
if (res.hostname.length === 0 && (tableSelectedTab === undefined || tableSelectedTab.length === 0)) {
Expand Down Expand Up @@ -377,7 +381,8 @@ function ApiCollections() {
tmp = {}
tmp.all = dataObj.prettify
tmp.hostname = dataObj.prettify.filter((c) => c.hostName !== null && c.hostName !== undefined && !c.deactivated)
tmp.groups = dataObj.prettify.filter((c) => c.type === "API_GROUP" && !c.deactivated)
const allGroupsForTmp = dataObj.prettify.filter((c) => c.type === "API_GROUP" && !c.deactivated);
tmp.groups = allGroupsForTmp;
tmp.custom = tmp.all.filter(x => !tmp.hostname.includes(x) && !x.deactivated && !tmp.groups.includes(x));
tmp.deactivated = deactivatedCollections
setData(tmp);
Expand Down Expand Up @@ -619,7 +624,7 @@ function ApiCollections() {
key={refreshData}
pageLimit={100}
data={data[selectedTab]}
sortOptions={sortOptions}
sortOptions={ selectedTab === 'groups' ? [...tempSortOptions, ...sortOptions] : sortOptions}
resourceName={resourceName}
filters={[]}
disambiguateLabel={disambiguateLabel}
Expand Down
17 changes: 17 additions & 0 deletions apps/dashboard/web/polaris_web/web/src/util/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,23 @@ sortFunc: (data, sortKey, sortOrder, treeView) => {
finalArr.reverse()
}
return finalArr
}else if(sortKey === 'customGroupsSort'){
let arr1 = []
let arr2 = [];
data.forEach((x) => {
if(x.automated){
arr2.push(x)
}else{
arr1.push(x)
}
})
arr1 = arr1.sort((a, b) => {
return (sortOrder) * (b['displayName'].localeCompare(a['displayName']))
})
arr2 = arr2.sort((a, b) => {
return (sortOrder) * (b['displayName'].localeCompare(a['displayName']))
})
return [...arr1, ...arr2]
}
data.sort((a, b) => {
if(typeof a[sortKey] ==='number')
Expand Down

0 comments on commit 480f829

Please sign in to comment.