From 95b6ebc0200d2b0fbf894242f5b7bb53961ff00d Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Mon, 4 Mar 2024 16:44:55 -0500 Subject: [PATCH 1/2] :sparkles: Optimize polling to only occur when a task is active (#1715) Addresses part of https://issues.redhat.com/browse/MTA-2359 Signed-off-by: Ian Bolton --- .../applications/applications-table/applications-table.tsx | 7 +++++-- client/src/app/queries/tasks.ts | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/client/src/app/pages/applications/applications-table/applications-table.tsx b/client/src/app/pages/applications/applications-table/applications-table.tsx index 26c9b4d4dc..4f44be86ea 100644 --- a/client/src/app/pages/applications/applications-table/applications-table.tsx +++ b/client/src/app/pages/applications/applications-table/applications-table.tsx @@ -147,7 +147,10 @@ export const ApplicationsTable: React.FC = () => { const getTask = (application: Application) => tasks.find((task: Task) => task.application?.id === application.id); - const { tasks } = useFetchTasks({ addon: "analyzer" }, isAnalyzeModalOpen); + const { tasks, hasActiveTasks } = useFetchTasks( + { addon: "analyzer" }, + isAnalyzeModalOpen + ); const isTaskCancellable = (application: Application) => { const task = getTask(application); @@ -209,7 +212,7 @@ export const ApplicationsTable: React.FC = () => { isFetching: isFetchingApplications, error: applicationsFetchError, refetch: fetchApplications, - } = useFetchApplications(); + } = useFetchApplications(!hasActiveTasks); const { assessments, isFetching: isFetchingAssesments } = useFetchAssessments(); diff --git a/client/src/app/queries/tasks.ts b/client/src/app/queries/tasks.ts index 23d107a911..c2532f1ace 100644 --- a/client/src/app/queries/tasks.ts +++ b/client/src/app/queries/tasks.ts @@ -42,12 +42,14 @@ export const useFetchTasks = ( }, onError: (err) => console.log(err), }); + const hasActiveTasks = data && data.length > 0; return { tasks: data || [], isFetching: isLoading, fetchError: error, refetch, + hasActiveTasks, }; }; From 55fa63118ede47d0b4f668e308f3f7ab0dc65482 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Mon, 4 Mar 2024 16:45:30 -0500 Subject: [PATCH 2/2] :bug: Consider only inherited archetypes when computing status (#1733) [App 'Assessment' status shows Completed and Inheritance indicator icon even when not associated with archetypes](https://issues.redhat.com/browse/MTA-2354) Signed-off-by: Ian Bolton --- .../application-assessment-status.tsx | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/client/src/app/pages/applications/components/application-assessment-status/application-assessment-status.tsx b/client/src/app/pages/applications/components/application-assessment-status/application-assessment-status.tsx index b6fba08f30..a6a0df6ab7 100644 --- a/client/src/app/pages/applications/components/application-assessment-status/application-assessment-status.tsx +++ b/client/src/app/pages/applications/components/application-assessment-status/application-assessment-status.tsx @@ -15,16 +15,22 @@ export const ApplicationAssessmentStatus: React.FC< > = ({ application, assessments, archetypes, isLoading }) => { const { t } = useTranslation(); - const filteredAssessments = assessments?.filter( + const applicationAssessments = assessments?.filter( (assessment: Assessment) => assessment.application?.id === application.id ); + const inheritedArchetypes = archetypes?.filter( + (archetype: Archetype) => + archetype.applications?.map((app) => app.id).includes(application.id) + ); const assessmentStatusInfo = React.useMemo(() => { - const assessmentsWithArchetypes = archetypes.map((archetype) => ({ - archetype, - assessments: assessments.filter( - (assessment) => assessment.archetype?.id === archetype.id - ), - })); + const assessmentsWithArchetypes = inheritedArchetypes.map( + (inheritedArchetype) => ({ + inheritedArchetype, + assessments: assessments.filter( + (assessment) => assessment.archetype?.id === inheritedArchetype.id + ), + }) + ); const someArchetypesAssessed = assessmentsWithArchetypes.some( ({ assessments }) => assessments.length > 0 @@ -32,12 +38,12 @@ export const ApplicationAssessmentStatus: React.FC< const allArchetypesAssessed = assessmentsWithArchetypes.length > 0 && - assessmentsWithArchetypes.every(({ archetype, assessments }) => { + assessmentsWithArchetypes.every(({ inheritedArchetype, assessments }) => { const requiredAssessments = assessments.filter( (assessment) => assessment.required ); return ( - archetype.assessed && + inheritedArchetype.assessed && assessments.length > 0 && requiredAssessments.length > 0 && requiredAssessments.every( @@ -56,18 +62,19 @@ export const ApplicationAssessmentStatus: React.FC< ); const assessedArchetypesWithARequiredAssessment = - assessmentsWithArchetypes.filter(({ assessments, archetype }) => + assessmentsWithArchetypes.filter(({ assessments, inheritedArchetype }) => assessments.some( (assessment) => assessment.required && assessment.status === "complete" && - archetype.assessed + inheritedArchetype.assessed ) ); const assessedArchetypeCount = - archetypes?.filter( - (archetype) => - archetype?.assessments?.length ?? (0 > 0 && archetype.assessed) + inheritedArchetypes?.filter( + (inheritedArchetype) => + inheritedArchetype?.assessments?.length ?? + (0 > 0 && inheritedArchetype.assessed) ).length || 0; return { @@ -78,7 +85,7 @@ export const ApplicationAssessmentStatus: React.FC< assessedArchetypesWithARequiredAssessment, assessedArchetypeCount, }; - }, [archetypes, assessments]); + }, [inheritedArchetypes, assessments]); if (isLoading) { return ; @@ -89,6 +96,7 @@ export const ApplicationAssessmentStatus: React.FC< const isDirectlyAssessed = application.assessed && (application.assessments?.length ?? 0) > 0; + const { allArchetypesAssessed, assessedArchetypesWithARequiredAssessment, @@ -104,7 +112,9 @@ export const ApplicationAssessmentStatus: React.FC< statusPreset = "InProgressInheritedAssessments"; tooltipCount = assessedArchetypesWithARequiredAssessment.length; } else if ( - filteredAssessments?.some((assessment) => assessment.status === "started") + applicationAssessments?.some( + (assessment) => assessment.status === "started" + ) ) { statusPreset = "InProgress"; }