From 487b446531295fc0477fb0348822b6f03f3bb9f9 Mon Sep 17 00:00:00 2001 From: Michael Chadwick Date: Tue, 1 Oct 2024 15:47:40 -0700 Subject: [PATCH] session objectives now use multiple columns --- .../app/components/reports/subject/session.js | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/packages/frontend/app/components/reports/subject/session.js b/packages/frontend/app/components/reports/subject/session.js index 9f034e9d87..4728ab92e1 100644 --- a/packages/frontend/app/components/reports/subject/session.js +++ b/packages/frontend/app/components/reports/subject/session.js @@ -108,27 +108,39 @@ export default class ReportsSubjectSessionComponent extends Component { ]; const result = await this.graphql.find('sessions', filters, attributes.join(',')); const sortedResults = sortBy(result.data.sessions, 'title'); + + const objectives = sortedResults.map(({ sessionObjectives }) => { + return mapBy(sessionObjectives, 'title'); + }); + const maxObjectiveCount = objectives.reduce((longest, current) => { + return current.length > longest.length ? current : longest; + }, []).length; + const mappedResults = sortedResults.map(({ title, course, sessionObjectives, description }) => { - return [ + const results = [ title, course.title, this.academicYearCrossesCalendarYearBoundaries ? `${course.year} - ${course.year + 1}` : `${course.year}`, striptags(description), - striptags(mapBy(sessionObjectives, 'title').join()), ]; + sessionObjectives.forEach((objective) => { + results.push(striptags(objective.title)); + }); + return results; }); - return [ - [ - this.intl.t('general.session'), - this.intl.t('general.course'), - this.intl.t('general.academicYear'), - this.intl.t('general.description'), - this.intl.t('general.objectives'), - ], - ...mappedResults, + const columns = [ + this.intl.t('general.session'), + this.intl.t('general.course'), + this.intl.t('general.academicYear'), + this.intl.t('general.description'), ]; + [...Array(maxObjectiveCount + 1).keys()].slice(1).map((key) => { + columns.push(`${this.intl.t('general.objective')} ${key}`); + }); + + return [columns, ...mappedResults]; } }