Skip to content

Commit

Permalink
applied sorting logic to sort filters by predefined order from left t…
Browse files Browse the repository at this point in the history
…o right, ensuring filters are desplayed in a consistent and logical order, making it easier to understand
  • Loading branch information
lwersiy committed Dec 12, 2024
1 parent 3e772fd commit 9439c85
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion frontend/src/pages/Search/FilterTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ type FlatFilters = {
type: 'all' | 'none' | 'any';
}[];

const filterOrder = [
'Region',
'Organization',
'IP',
'Domain',
'Root Domain(s)',
'Port',
'CVE',
'Severity'
];

const sortFiltersByOrder = (filters: FlatFilters) => {
return filters.sort((a, b) => {
return filterOrder.indexOf(a.label) - filterOrder.indexOf(b.label);
});
};

export const FilterTags: React.FC<Props> = ({ filters, removeFilter }) => {
const { userLevel } = useUserLevel();

Expand All @@ -134,7 +151,7 @@ export const FilterTags: React.FC<Props> = ({ filters, removeFilter }) => {
}, [userLevel]);

const filtersByColumn: FlatFilters = useMemo(() => {
return filters.reduce((acc, nextFilter) => {
const processedFilters = filters.reduce((acc, nextFilter) => {
const fieldAccessors = FIELD_TO_LABEL_MAP[nextFilter.field] ?? null;
const value = fieldAccessors
? ellipsisPastIndex(
Expand All @@ -156,6 +173,7 @@ export const FilterTags: React.FC<Props> = ({ filters, removeFilter }) => {
}
];
}, []);
return sortFiltersByOrder(processedFilters);
}, [filters]);

return (
Expand Down

0 comments on commit 9439c85

Please sign in to comment.