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 authored Dec 15, 2023
1 parent 8637733 commit fa6abfe
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 fa6abfe

Please sign in to comment.