Skip to content

Commit

Permalink
[Close to graduation] Implement page with material-react-table
Browse files Browse the repository at this point in the history
  • Loading branch information
valtterikantanen committed Nov 27, 2024
1 parent 264aaa2 commit bf6d6af
Show file tree
Hide file tree
Showing 14 changed files with 856 additions and 23 deletions.
48 changes: 41 additions & 7 deletions services/backend/src/services/populations/closeToGraduation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { col, Op, where } from 'sequelize'
import { col, InferAttributes, Op, where } from 'sequelize'

import { Course, Credit, Student, Studyplan, SISStudyRight, SISStudyRightElement } from '../../models'
import {
Course,
Credit,
Organization,
ProgrammeModule,
Student,
Studyplan,
SISStudyRight,
SISStudyRightElement,
} from '../../models'
import { Name } from '../../shared/types'
import { CreditTypeCode, DegreeProgrammeType, EnrollmentType, ExtentCode, SemesterEnrollment } from '../../types'
import { redisClient } from '../redis'
Expand Down Expand Up @@ -40,6 +49,7 @@ type AccumulatorType = {
startedAt: Date
degreeProgrammeType: DegreeProgrammeType
}
faculty: Name
attainmentDates: AttainmentDates
numberOfAbsentSemesters: number
curriculumPeriod: string | null
Expand Down Expand Up @@ -88,7 +98,7 @@ const findThesisAndLatestAndEarliestAttainments = (
return { attainmentDates, thesisData }
}

const formatStudent = (student: Student) => {
const formatStudent = (student: InferAttributes<Student>, facultyMap: Record<string, Name>) => {
const {
studentnumber: studentNumber,
abbreviatedname: name,
Expand Down Expand Up @@ -147,6 +157,7 @@ const formatStudent = (student: Student) => {
startedAt: programmeStartDate,
degreeProgrammeType,
},
faculty: facultyMap[programmeCode],
attainmentDates,
numberOfAbsentSemesters,
curriculumPeriod: getCurriculumVersion(studyPlan.curriculum_period_id),
Expand All @@ -159,8 +170,8 @@ const formatStudent = (student: Student) => {
}, [])
}

export const findStudentsCloseToGraduation = async (studentNumbers?: string[]) =>
(
export const findStudentsCloseToGraduation = async (studentNumbers?: string[]) => {
const students = (
await Student.findAll({
attributes: [
'abbreviatedname',
Expand Down Expand Up @@ -261,8 +272,30 @@ export const findStudentsCloseToGraduation = async (studentNumbers?: string[]) =
],
order: [[{ model: Credit, as: 'credits' }, 'attainment_date', 'DESC']],
})
)
.flatMap(student => formatStudent(student.toJSON()))
).map(student => student.toJSON())

const programmeCodes = [...new Set(students.flatMap(student => student.studyplans.map(sp => sp.programme_code)))]
const programmesWithFaculties = await ProgrammeModule.findAll({
attributes: ['code'],
where: {
code: {
[Op.in]: programmeCodes,
},
},
include: {
model: Organization,
attributes: ['name'],
},
raw: true,
})

const facultyMap: Record<string, Name> = {}
for (const programme of programmesWithFaculties) {
facultyMap[programme.code] = programme['organization.name']
}

return students
.flatMap(student => formatStudent(student, facultyMap))
.reduce(
(acc, student) => {
if (student.programme.degreeProgrammeType === DegreeProgrammeType.BACHELOR) {
Expand All @@ -274,6 +307,7 @@ export const findStudentsCloseToGraduation = async (studentNumbers?: string[]) =
},
{ bachelor: [] as AccumulatorType[], masterAndLicentiate: [] as AccumulatorType[] }
)
}

export const getCloseToGraduationData = async (studentNumbers?: string[]) => {
if (!studentNumbers) {
Expand Down
217 changes: 217 additions & 0 deletions services/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions services/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
"@emotion/styled": "^11.13.0",
"@mui/icons-material": "^6.1.6",
"@mui/material": "^6.1.6",
"@mui/x-date-pickers": "^7.22.3",
"@reduxjs/toolkit": "^2.3.0",
"@sentry/browser": "^8.37.1",
"axios": "^0.28.1",
"highcharts": "^11.4.8",
"immer": "^10.1.1",
"lodash": "^4.17.21",
"material-react-table": "^3.0.1",
"moment": "^2.30.1",
"prop-types": "^15.8.1",
"query-string": "^9.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const getSemestersPresentFunctions = ({
}) => {
if (allSemesters?.length === 0 || !filteredStudents)
return {
getSemesterEnrollmentsContent: () => {},
getSemesterEnrollmentsContent: () => null,
getSemesterEnrollmentsVal: () => {},
getFirstSemester: () => {},
getLastSemester: () => {},
Expand Down
2 changes: 2 additions & 0 deletions services/frontend/src/components/Routes/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Updater } from '@/components/Updater'
import { Users } from '@/components/Users'
import { languageCenterViewEnabled } from '@/conf'
import { Changelog } from '@/pages/Changelog'
import { CloseToGraduation as NewCloseToGraduation } from '@/pages/CloseToGraduation'
import { Feedback } from '@/pages/Feedback'
import { FrontPage } from '@/pages/FrontPage'
import { University } from '@/pages/University'
Expand Down Expand Up @@ -130,6 +131,7 @@ export const Routes = () => (
/>
)}
<ProtectedRoute component={University} exact path={routes.university} />
<ProtectedRoute component={NewCloseToGraduation} exact path="/close-to-graduation/new" />
<ProtectedRoute
component={CloseToGraduation}
exact
Expand Down
Loading

0 comments on commit bf6d6af

Please sign in to comment.