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 : ( + + )} ); };