11import CheckIcon from '@mui/icons-material/Check'
22import CropSquareIcon from '@mui/icons-material/CropSquare'
33import Box from '@mui/material/Box'
4- import Divider from '@mui/material/Divider'
54import Tooltip from '@mui/material/Tooltip'
65import Typography from '@mui/material/Typography'
76import { ColumnDef , createColumnHelper , TableOptions } from '@tanstack/react-table'
@@ -12,56 +11,51 @@ import { StudentInfoItem } from '@/components/material/StudentInfoItem'
1211import { useStudentNameVisibility } from '@/components/material/StudentNameVisibilityToggle'
1312import { OodiTable } from '@/components/OodiTable'
1413import { 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-
3219export 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 } ,
0 commit comments