Skip to content

Commit

Permalink
🐛 Hide non required questionnaires from view in view archetypes page
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Dec 14, 2023
1 parent 1a2f183 commit 477f823
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ const ViewArchetypesTable: React.FC<ViewArchetypesTableProps> = ({
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 (
<>
<QuestionnairesTable
Expand All @@ -34,15 +52,16 @@ const ViewArchetypesTable: React.FC<ViewArchetypesTableProps> = ({
isFetching={isFetchingQuestionnaires || isFetchingAssessmentsById}
tableName="Required questionnaires"
/>

<QuestionnairesTable
isReadonly
archetype={archetype}
questionnaires={archivedQuestionnaires}
assessments={assessments}
isFetching={isFetchingQuestionnaires || isFetchingAssessmentsById}
tableName="Archived questionnaires"
/>
{filteredArchivedAssessments.length === 0 ? null : (
<QuestionnairesTable
archetype={archetype}
isReadonly
questionnaires={filteredArchivedQuestionnaires}
assessments={filteredArchivedAssessments}
isFetching={isFetchingQuestionnaires || isFetchingAssessmentsById}
tableName="Archived questionnaires"
/>
)}
</>
);
};
Expand Down

0 comments on commit 477f823

Please sign in to comment.