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}) => (