Skip to content

Commit

Permalink
Merge branch 'main' into optimize-polling
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 authored Feb 29, 2024
2 parents 957abe7 + ccb8dfd commit 2a21a38
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export const MultiselectFilterControl = <TItem,>({
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
Expand Down
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 2a21a38

Please sign in to comment.