diff --git a/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx b/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx index f88511099e..1d2297ee7b 100644 --- a/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx +++ b/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx @@ -49,6 +49,12 @@ export const MultiselectFilterControl = ({ FilterSelectOptionProps[] >(Array.isArray(category.selectOptions) ? category.selectOptions : []); + React.useEffect(() => { + setSelectOptions( + Array.isArray(category.selectOptions) ? category.selectOptions : [] + ); + }, [category.selectOptions]); + const hasGroupings = !Array.isArray(selectOptions); const flatOptions: FilterSelectOptionProps[] = !hasGroupings diff --git a/client/src/app/pages/reports/components/application-landscape/application-landscape.tsx b/client/src/app/pages/reports/components/application-landscape/application-landscape.tsx index 6637c350e8..cdc88f04e7 100644 --- a/client/src/app/pages/reports/components/application-landscape/application-landscape.tsx +++ b/client/src/app/pages/reports/components/application-landscape/application-landscape.tsx @@ -29,7 +29,8 @@ interface IAggregateRiskData { const aggregateRiskData = ( assessments: AssessmentWithArchetypeApplications[], - applications: Application[] + applications: Application[], + questionnaire: Questionnaire | null ): IAggregateRiskData => { let low = 0; let medium = 0; @@ -61,8 +62,12 @@ const aggregateRiskData = ( const fullApp = findFullApplication(appRef); if (fullApp && fullApp.risk && !processedAppIds.has(fullApp.id)) { processedAppIds.add(fullApp.id); + let risk = fullApp.risk; + if (questionnaire?.id === assessment.questionnaire.id) { + risk = assessment.risk; + } - switch (fullApp.risk) { + switch (risk) { case "green": low++; break; @@ -119,8 +124,8 @@ export const ApplicationLandscape: React.FC = ({ ); const landscapeData = useMemo( - () => aggregateRiskData(filteredAssessments, applications), - [filteredAssessments, applications] + () => aggregateRiskData(filteredAssessments, applications, questionnaire), + [filteredAssessments, applications, questionnaire] ); return ( diff --git a/client/src/app/queries/assessments.ts b/client/src/app/queries/assessments.ts index 8b6cfab07b..44508dc353 100644 --- a/client/src/app/queries/assessments.ts +++ b/client/src/app/queries/assessments.ts @@ -18,7 +18,6 @@ import { import { AxiosError } from "axios"; import { Assessment, - AssessmentWithArchetypeApplications, AssessmentWithSectionOrder, InitialAssessment, } from "@app/api/models"; @@ -222,18 +221,21 @@ const removeSectionOrderFromQuestions = ( export const useFetchAssessmentsWithArchetypeApplications = () => { const { assessments, isFetching: assessmentsLoading } = useFetchAssessments(); + const archetypeQueries = useMemo(() => { + const uniqueArchetypeIds = new Set( + assessments.map((assessment) => assessment?.archetype?.id).filter(Boolean) + ); + return Array.from(uniqueArchetypeIds).map((archetypeId) => ({ + queryKey: ["archetype", archetypeId], + queryFn: async () => { + const data = await getArchetypeById(archetypeId); + return { archetypeId, applications: data.applications }; + }, + })); + }, [assessments]); + const archetypesUsedInAnAssessmentQueries = useQueries({ - queries: - [ - ...new Set( - assessments - .map((assessment) => assessment?.archetype?.id) - .filter(Boolean) - ), - ].map((archetypeId) => ({ - queryKey: ["archetype", archetypeId], - queryFn: () => getArchetypeById(archetypeId), - })) || [], + queries: archetypeQueries, }); const isArchetypesLoading = archetypesUsedInAnAssessmentQueries.some( @@ -241,21 +243,19 @@ export const useFetchAssessmentsWithArchetypeApplications = () => { ); const archetypeApplicationsMap = new Map(); - archetypesUsedInAnAssessmentQueries.forEach((query, index) => { - if (query.data && assessments[index].archetype?.id) { - archetypeApplicationsMap.set( - assessments[index]?.archetype?.id, - query.data.applications - ); + archetypesUsedInAnAssessmentQueries.forEach(({ data }) => { + if (data) { + archetypeApplicationsMap.set(data.archetypeId, data.applications); } }); - const assessmentsWithArchetypeApplications: AssessmentWithArchetypeApplications[] = - assessments.map((assessment) => ({ + const assessmentsWithArchetypeApplications = assessments.map( + (assessment) => ({ ...assessment, archetypeApplications: archetypeApplicationsMap.get(assessment?.archetype?.id) ?? [], - })); + }) + ); return { assessmentsWithArchetypeApplications,