From 614a7a2a294b4c733c8630766cbbb91339c6bcdb Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Wed, 28 Aug 2024 07:38:38 +0100 Subject: [PATCH] Improved asset download criteria --- src/dashboards/AssignmentCard.tsx | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/dashboards/AssignmentCard.tsx b/src/dashboards/AssignmentCard.tsx index 6466a335..d3243656 100644 --- a/src/dashboards/AssignmentCard.tsx +++ b/src/dashboards/AssignmentCard.tsx @@ -62,6 +62,30 @@ export default function AssignmentCard({ return resultModuleBandScores.length === 0 ? -1 : resultModuleBandScores.reduce((acc, curr) => acc + curr, 0) / results.length; }; + const uniqModules = uniqBy(exams, (x) => x.module); + + const shouldRenderPDF = () => { + if(released && allowDownload) { + // in order to be downloadable, the assignment has to be released + // the component should have the allowDownload prop + // and the assignment should not have the level module + return uniqModules.every(({ module }) => module !== 'level'); + } + + return false; + } + + const shouldRenderExcel = () => { + if(released && allowExcelDownload) { + // in order to be downloadable, the assignment has to be released + // the component should have the allowExcelDownload prop + // and the assignment should have the level module + return uniqModules.some(({ module }) => module === 'level'); + } + + return false; + } + return (

{name}

- {allowDownload && released && renderPdfIcon(id, "text-mti-gray-dim", "text-mti-gray-dim")} - {allowExcelDownload && released && renderExcelIcon(id, "text-mti-gray-dim", "text-mti-gray-dim")} + {shouldRenderPDF() && renderPdfIcon(id, "text-mti-gray-dim", "text-mti-gray-dim")} + {shouldRenderExcel() && renderExcelIcon(id, "text-mti-gray-dim", "text-mti-gray-dim")} {allowArchive && !archived && renderArchiveIcon("text-mti-gray-dim", "text-mti-gray-dim")} {allowUnarchive && archived && renderUnarchiveIcon("text-mti-gray-dim", "text-mti-gray-dim")} {!released && renderReleaseIcon("text-mti-gray-dim", "text-mti-gray-dim")} @@ -94,7 +118,7 @@ export default function AssignmentCard({ Assigner: {getUserName(users.find((x) => x.id === assigner))}
- {uniqBy(exams, (x) => x.module).map(({module}) => ( + {uniqModules.map(({module}) => (