Skip to content

Commit

Permalink
🐛 only render archetypes with associated apps in filter (#1609)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 authored Dec 13, 2023
1 parent 0f42c7e commit e98511e
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions client/src/app/pages/issues/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AnalysisIssue,
AnalysisIssueReport,
AnalysisRuleReport,
Archetype,
} from "@app/api/models";
import {
FilterCategory,
Expand Down Expand Up @@ -62,16 +63,30 @@ export const useSharedAffectedApplicationFilterCategories = <
t("actions.filterBy", {
what: t("terms.archetype").toLowerCase(),
}) + "...",
selectOptions: archetypes.map(({ name }) => ({ key: name, value: name })),
getServerFilterValue: (selectedOptions) =>
selectedOptions
?.map((option) => archetypes.find((item) => item.name === option))
selectOptions: archetypes.map(({ name }) => ({
key: name,
value: name,
})),

getServerFilterValue: (selectedOptions) => {
const findArchetypeByName = (name: string) => {
return archetypes.find((item) => item.name === name);
};

const getApplicationIds = (archetype: Archetype) => {
return archetype.applications?.map((app) => String(app.id));
};

if (!selectedOptions) return ["-1"];

const archetypeIds = selectedOptions
.map((option) => findArchetypeByName(option))
.filter(Boolean)
.flatMap(
({ applications }) =>
applications?.map(({ id }) => String(id)) ?? []
)
.filter(Boolean),
.flatMap((archetype) => getApplicationIds(archetype))
.filter(Boolean);

return archetypeIds.length === 0 ? ["-1"] : archetypeIds;
},
},
{
key: "businessService.name",
Expand Down

0 comments on commit e98511e

Please sign in to comment.