Skip to content

Commit a8e7575

Browse files
joonas-asanteri0200
authored andcommitted
[Class statistics] Re-introduce summary rows in modules tab
1 parent c350ada commit a8e7575

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

services/frontend/src/components/PopulationStudents/StudentTable/ModulesTab/ModulesTable.tsx

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import CheckIcon from '@mui/icons-material/Check'
22
import CropSquareIcon from '@mui/icons-material/CropSquare'
33
import Box from '@mui/material/Box'
4-
import Divider from '@mui/material/Divider'
54
import Tooltip from '@mui/material/Tooltip'
65
import Typography from '@mui/material/Typography'
76
import { ColumnDef, createColumnHelper, TableOptions } from '@tanstack/react-table'
@@ -12,56 +11,51 @@ import { StudentInfoItem } from '@/components/material/StudentInfoItem'
1211
import { useStudentNameVisibility } from '@/components/material/StudentNameVisibilityToggle'
1312
import { OodiTable } from '@/components/OodiTable'
1413
import { OodiTableExcelExport } from '@/components/OodiTable/excelExport'
15-
import type { FormattedModules, FormattedStudent } from '@/components/PopulationStudents/StudentTable/ModulesTab'
14+
import type { FormattedModules, ModuleTabStudent } from '@/components/PopulationStudents/StudentTable/ModulesTab'
1615

17-
const getModuleIfExists = (student: FormattedStudent, moduleCode: string) =>
16+
const getModuleIfExists = (student: ModuleTabStudent, moduleCode: string) =>
1817
student.studyModulesInHOPS.find(studyModule => studyModule.code === moduleCode) ?? null
1918

20-
const DividedTableCell = ({ top, bottom }: { top?: string | number; bottom?: string | number }) => (
21-
<Box sx={{ alignItems: 'end', display: 'flex', flexDirection: 'column' }}>
22-
{top !== undefined && (
23-
<Typography sx={{ color: 'text.primary', padding: '8px', fontSize: '0.875rem' }}>{top}</Typography>
24-
)}
25-
<Divider aria-hidden="true" flexItem sx={{ position: 'absolute', left: 0, right: 0, top: '50%' }} />
26-
{bottom !== undefined && (
27-
<Typography sx={{ color: 'text.primary', padding: '8px', fontSize: '0.875rem' }}>{bottom}</Typography>
28-
)}
29-
</Box>
30-
)
31-
3219
export const ModulesTab = ({
3320
formattedModules,
3421
formattedStudents,
3522
}: {
3623
formattedModules: FormattedModules
37-
formattedStudents: FormattedStudent[]
24+
formattedStudents: ModuleTabStudent[]
3825
}) => {
3926
const { getTextIn } = useLanguage()
4027
const { visible: namesVisible } = useStudentNameVisibility()
41-
const ooditableColumnHelper = createColumnHelper<FormattedStudent>()
28+
const ooditableColumnHelper = createColumnHelper<ModuleTabStudent>()
4229

4330
const ooditableStaticColumns = useMemo(
4431
() => [
45-
ooditableColumnHelper.accessor('lastName', { header: 'Last name' }),
46-
ooditableColumnHelper.accessor('firstNames', { header: 'First names' }),
4732
ooditableColumnHelper.accessor('studentNumber', {
4833
header: _ => <Typography fontWeight="bold">Student number</Typography>,
4934
cell: cell => <StudentInfoItem sisPersonId={cell.row.original.sisPersonID} studentNumber={cell.getValue()} />,
50-
footer: () => <DividedTableCell bottom="Completed" top="Planned" />,
5135
filterFn: (row, columnId, filterValue) => {
5236
const value: string = row.getValue(columnId)
5337
if (!filterValue) return true
5438

5539
return value.toLowerCase().startsWith(filterValue.toLowerCase())
5640
},
41+
aggregationRows: [
42+
{ id: 'planned', value: 'Planned' },
43+
{ id: 'completed', value: 'Completed' },
44+
],
45+
}),
46+
ooditableColumnHelper.accessor('lastName', {
47+
header: 'Last name',
48+
}),
49+
ooditableColumnHelper.accessor('firstNames', {
50+
header: 'First names',
5751
}),
5852
],
5953
[]
6054
)
6155

6256
const ooditableDynamicColumns = useMemo(() => {
6357
if (!formattedModules) return []
64-
return Object.keys(formattedModules).flatMap(code => [
58+
return Object.keys(formattedModules).map(code =>
6559
ooditableColumnHelper.accessor(code as 'studyModulesInHOPS.code', {
6660
header: _ => (
6761
<Tooltip title={`${code}${getTextIn(formattedModules[code])}`}>
@@ -97,8 +91,8 @@ export const ModulesTab = ({
9791
</Box>
9892
)
9993
},
100-
footer: ({ table }) => {
101-
const { planned, completed } = table.getFilteredRowModel().rows.reduce(
94+
aggregationRows: ({ table }) => {
95+
const { completed, planned } = table.getFilteredRowModel().rows.reduce(
10296
(acc, row) => {
10397
const studyModule = getModuleIfExists(row.original, code)
10498
if (studyModule) {
@@ -114,7 +108,10 @@ export const ModulesTab = ({
114108
{ planned: 0, completed: 0 }
115109
)
116110

117-
return <DividedTableCell bottom={completed} top={planned} />
111+
return [
112+
{ id: 'planned', value: planned },
113+
{ id: 'completed', value: completed },
114+
]
118115
},
119116
sortingFn: (rowA, rowB, _) => {
120117
/*
@@ -131,11 +128,11 @@ export const ModulesTab = ({
131128

132129
return valueA - valueB
133130
},
134-
}),
135-
])
131+
})
132+
)
136133
}, [formattedModules, getTextIn])
137134

138-
const ooditableColumns: ColumnDef<FormattedStudent, any>[] = useMemo(
135+
const ooditableColumns: ColumnDef<ModuleTabStudent, any>[] = useMemo(
139136
() => [...ooditableStaticColumns, ...ooditableDynamicColumns],
140137
[ooditableStaticColumns, ooditableDynamicColumns]
141138
)
@@ -168,7 +165,7 @@ export const ModulesTab = ({
168165
),
169166
}))
170167

171-
const ooditableOptions: Partial<TableOptions<FormattedStudent>> = {
168+
const ooditableOptions: Partial<TableOptions<ModuleTabStudent>> = {
172169
initialState: {
173170
columnPinning: { left: ['studentNumber'] },
174171
},

services/frontend/src/components/PopulationStudents/StudentTable/ModulesTab/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createLocaleComparator } from '@/util/comparator'
44
import { formatISODate } from '@/util/timeAndDate'
55
import { ModulesTab } from './ModulesTable'
66

7-
export type FormattedStudent = {
7+
export type ModuleTabStudent = {
88
firstNames: string
99
lastName: string
1010
studentNumber: string
@@ -46,7 +46,7 @@ const getModulesFromRelevantStudyPlan = (student: any, degreeProgrammeCodes: str
4646
return []
4747
}
4848

49-
const formatStudent = (student: any, degreeProgrammeCodes: string[]): FormattedStudent => {
49+
const formatStudent = (student: any, degreeProgrammeCodes: string[]): ModuleTabStudent => {
5050
return {
5151
firstNames: student.firstnames,
5252
lastName: student.lastname,

0 commit comments

Comments
 (0)