mirror of
https://github.com/UniversityOfHelsinkiCS/oodikone.git
synced 2026-10-12 19:03:39 +03:00
[Course statistics] Improve typing
This commit is contained in:
+6
-1
@@ -69,7 +69,12 @@ export const ResultTab = ({
|
||||
.map(data => (
|
||||
<div key={data.name}>
|
||||
{settings.viewMode === 'STUDENTS' ? (
|
||||
<StudentsTable data={data} settings={settings} userHasAccessToAllStats={userHasAccessToAllStats} />
|
||||
<StudentsTable
|
||||
data={data}
|
||||
separate={settings.separate}
|
||||
showGrades={settings.showGrades}
|
||||
userHasAccessToAllStats={userHasAccessToAllStats}
|
||||
/>
|
||||
) : (
|
||||
<AttemptsTable data={data} settings={settings} userHasAccessToAllStats={userHasAccessToAllStats} />
|
||||
)}
|
||||
|
||||
+25
-14
@@ -3,16 +3,19 @@ import qs from 'query-string'
|
||||
import { useMemo } from 'react'
|
||||
import { useSelector } from 'react-redux'
|
||||
import { Link } from 'react-router'
|
||||
import { Header, Icon, Item } from 'semantic-ui-react'
|
||||
import { Icon, Item } from 'semantic-ui-react'
|
||||
|
||||
import { isDefaultServiceProvider } from '@/common'
|
||||
import { SortableTable, row } from '@/components/SortableTable'
|
||||
import { RootState } from '@/redux'
|
||||
import { getCourseAlternatives } from '@/selectors/courseStats'
|
||||
import { Name } from '@/shared/types'
|
||||
import { FormattedStats, ProgrammeStats } from '@/types/courseStat'
|
||||
import { defineCellColor, getSortableColumn, resolveGrades } from '../util'
|
||||
|
||||
const formatPercentage = passRate => (Number.isNaN(passRate) ? '–' : `${(passRate * 100).toFixed(2)} %`)
|
||||
|
||||
const getGradeColumns = grades => {
|
||||
const getGradeColumns = (grades: { key: string; title: string }[]) => {
|
||||
return grades.map(({ key, title }) =>
|
||||
getSortableColumn({
|
||||
key,
|
||||
@@ -23,11 +26,18 @@ const getGradeColumns = grades => {
|
||||
)
|
||||
}
|
||||
|
||||
const getColumns = (stats, showGrades, userHasAccessToAllStats, alternatives, separate, unifyCourses) => {
|
||||
const showPopulation = (yearcode, years) => {
|
||||
const getColumns = (
|
||||
stats: FormattedStats[],
|
||||
showGrades: boolean,
|
||||
userHasAccessToAllStats: boolean,
|
||||
alternatives: { code: string; name: Name }[],
|
||||
separate: boolean,
|
||||
unifyCourses: 'openStats' | 'regularStats' | 'unifyStats'
|
||||
) => {
|
||||
const showPopulation = (yearCode: number, years: string) => {
|
||||
const queryObject = {
|
||||
from: yearcode,
|
||||
to: yearcode,
|
||||
from: yearCode,
|
||||
to: yearCode,
|
||||
coursecodes: JSON.stringify(uniq(alternatives.map(course => course.code))),
|
||||
years,
|
||||
separate,
|
||||
@@ -36,6 +46,7 @@ const getColumns = (stats, showGrades, userHasAccessToAllStats, alternatives, se
|
||||
const searchString = qs.stringify(queryObject)
|
||||
return `/coursepopulation?${searchString}`
|
||||
}
|
||||
|
||||
const toskaColumns = [
|
||||
{
|
||||
key: 'TIME_PARENT',
|
||||
@@ -171,12 +182,17 @@ const getColumns = (stats, showGrades, userHasAccessToAllStats, alternatives, se
|
||||
|
||||
export const StudentsTable = ({
|
||||
data: { name, stats },
|
||||
settings: { separate, showGrades },
|
||||
separate,
|
||||
showGrades,
|
||||
userHasAccessToAllStats,
|
||||
headerVisible = false,
|
||||
}: {
|
||||
data: ProgrammeStats
|
||||
separate: boolean
|
||||
showGrades: boolean
|
||||
userHasAccessToAllStats: boolean
|
||||
}) => {
|
||||
const alternatives = useSelector(getCourseAlternatives)
|
||||
const unifyCourses = useSelector(state => state.courseSearch.openOrRegular)
|
||||
const unifyCourses = useSelector((state: RootState) => state.courseSearch.openOrRegular)
|
||||
|
||||
const columns = useMemo(
|
||||
() => getColumns(stats, showGrades, userHasAccessToAllStats, alternatives, separate, unifyCourses),
|
||||
@@ -192,11 +208,6 @@ export const StudentsTable = ({
|
||||
|
||||
return (
|
||||
<div>
|
||||
{headerVisible && (
|
||||
<Header as="h3" textAlign="center">
|
||||
{name}
|
||||
</Header>
|
||||
)}
|
||||
<SortableTable
|
||||
columns={columns}
|
||||
data={data}
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
import { flatten } from 'lodash'
|
||||
|
||||
import { calculatePercentage } from '@/common'
|
||||
import { FormattedStats } from '@/types/courseStat'
|
||||
|
||||
type Series = {
|
||||
name: string
|
||||
@@ -110,7 +111,7 @@ const getSortedGrades = (grades: string[]) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const resolveGrades = stats => {
|
||||
export const resolveGrades = (stats: FormattedStats[]) => {
|
||||
const allGrades = [
|
||||
'0',
|
||||
...flatten(
|
||||
|
||||
Reference in New Issue
Block a user