From fa6abfe8d979494fd6ed2063ce9e3210946b15e1 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Thu, 14 Dec 2023 20:03:10 -0500 Subject: [PATCH] :bug: Hide non required questionnaires from view in view archetypes page (#1621) https://issues.redhat.com/browse/MTA-1895 Signed-off-by: ibolton336 --- .../components/view-archetypes-table.tsx | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/client/src/app/pages/assessment/components/view-archetypes/components/view-archetypes-table.tsx b/client/src/app/pages/assessment/components/view-archetypes/components/view-archetypes-table.tsx index c6b741f9e5..c8235eed27 100644 --- a/client/src/app/pages/assessment/components/view-archetypes/components/view-archetypes-table.tsx +++ b/client/src/app/pages/assessment/components/view-archetypes/components/view-archetypes-table.tsx @@ -24,6 +24,24 @@ const ViewArchetypesTable: React.FC = ({ const archivedQuestionnaires = questionnaires.filter( (questionnaire) => !questionnaire.required ); + + const nonRequiredQuestionnaireIds = questionnaires + .filter((q) => !q.required) + .map((q) => q.id); + + const relevantAssessmentIds = (archetype?.assessments || []).map((a) => a.id); + + const filteredArchivedAssessments = assessments.filter( + (assessment) => + nonRequiredQuestionnaireIds.includes(assessment.questionnaire.id) && + relevantAssessmentIds.includes(assessment.id) + ); + const filteredArchivedQuestionnaires = archivedQuestionnaires.filter( + (questionnaire) => + filteredArchivedAssessments.some( + (assessment) => assessment.questionnaire.id === questionnaire.id + ) + ); return ( <> = ({ isFetching={isFetchingQuestionnaires || isFetchingAssessmentsById} tableName="Required questionnaires" /> - - + {filteredArchivedAssessments.length === 0 ? null : ( + + )} ); };