Skip to content

Commit

Permalink
🐛 Adjust risk values displayed based on questionnaire filter (konveyo…
Browse files Browse the repository at this point in the history
…r#1711)

Resolves https://issues.redhat.com/browse/MTA-2093
- Uses the assessment risk when a specific questionnaire is selected in
the landscape filter rather than the application risk.

---------

Signed-off-by: Ian Bolton <[email protected]>
  • Loading branch information
ibolton336 authored Feb 29, 2024
1 parent d346801 commit ccb8dfd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ interface IAggregateRiskData {

const aggregateRiskData = (
assessments: AssessmentWithArchetypeApplications[],
applications: Application[]
applications: Application[],
questionnaire: Questionnaire | null
): IAggregateRiskData => {
let low = 0;
let medium = 0;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -119,8 +124,8 @@ export const ApplicationLandscape: React.FC<IApplicationLandscapeProps> = ({
);

const landscapeData = useMemo(
() => aggregateRiskData(filteredAssessments, applications),
[filteredAssessments, applications]
() => aggregateRiskData(filteredAssessments, applications, questionnaire),
[filteredAssessments, applications, questionnaire]
);

return (
Expand Down
42 changes: 21 additions & 21 deletions client/src/app/queries/assessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import { AxiosError } from "axios";
import {
Assessment,
AssessmentWithArchetypeApplications,
AssessmentWithSectionOrder,
InitialAssessment,
} from "@app/api/models";
Expand Down Expand Up @@ -222,40 +221,41 @@ 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(
(query) => query.isLoading
);

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,
Expand Down

0 comments on commit ccb8dfd

Please sign in to comment.