Skip to content

Commit c9455d2

Browse files
committed
[Frontend] Make population course amount limiter consistent with debounced state
1 parent a343b24 commit c9455d2

File tree

4 files changed

+41
-56
lines changed

4 files changed

+41
-56
lines changed

services/frontend/src/components/CoursePopulation/index.tsx

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import Stack from '@mui/material/Stack'
2-
import TextField from '@mui/material/TextField'
3-
import Typography from '@mui/material/Typography'
41
import { useEffect, useMemo, useState } from 'react'
52
import { useLocation } from 'react-router'
63

@@ -30,15 +27,16 @@ import { PageLoading } from '@/components/Loading'
3027
import { PopulationCourseStatsFlat } from '@/components/PopulationCourseStats/PopulationCourseStatsFlat'
3128
import { PopulationStudents } from '@/components/PopulationStudents'
3229
import { useFormat as formatGeneralTab } from '@/components/PopulationStudents/StudentTable/GeneralTab/format/index'
30+
import { useDebouncedState } from '@/hooks/debouncedState'
3331
import { useTitle } from '@/hooks/title'
3432
import { useGetPopulationStatisticsByCourseQuery } from '@/redux/populations'
3533
import { useGetSemestersQuery } from '@/redux/semesters'
3634
import { useGetSingleCourseStatsQuery } from '@/redux/singleCourseStats'
3735
import { parseQueryParams } from '@/util/queryparams'
36+
import { StudentAmountLimiter } from '../common/StudentAmountLimiter'
3837
import { CoursePopulationCreditGainTable } from './CoursePopulationCreditGainTable'
3938
import { CoursePopulationGradeDist } from './CoursePopulationGradeDist'
4039
import { CoursePopulationLanguageDist } from './CoursePopulationLanguageDist'
41-
4240
import { useColumns as columnsGeneralTab } from './studentColumns'
4341

4442
export const CoursePopulation = () => {
@@ -234,7 +232,7 @@ export const CoursePopulation = () => {
234232
}
235233

236234
const CustomPopulationCoursesWrapper = ({ filteredCourses, filteredStudents }) => {
237-
const [studentAmountLimit, setStudentAmountLimit] = useState(0)
235+
const [studentAmountLimit, setStudentAmountLimit] = useDebouncedState(0, 1000)
238236

239237
useEffect(() => setStudentAmountLimit(Math.round(filteredStudents.length * 0.3)), [filteredStudents.length])
240238

@@ -245,20 +243,10 @@ const CustomPopulationCoursesWrapper = ({ filteredCourses, filteredStudents }) =
245243
return (
246244
<>
247245
<InfoBox content={populationStatisticsToolTips.coursesOfPopulation} />
248-
{/* FIXME:TODO: This is ripped off from CourseTableModeSelector */}
249-
<Stack direction="row" sx={{ alignItems: 'center', mt: '0.5em' }}>
250-
<Typography fontWeight={500}>Select all courses with at least</Typography>
251-
<TextField
252-
onChange={({ target }) => onStudentAmountLimitChange(target.value)}
253-
size="small"
254-
sx={{ maxWidth: '6em' }}
255-
type="number"
256-
value={studentAmountLimit}
257-
/>
258-
<Typography fontWeight={500} sx={{ ml: '1em' }}>
259-
total students
260-
</Typography>
261-
</Stack>
246+
<StudentAmountLimiter
247+
onStudentAmountLimitChange={onStudentAmountLimitChange}
248+
studentAmountLimit={studentAmountLimit}
249+
/>
262250
<PopulationCourseStatsFlat filteredCourses={filteredCourses} studentAmountLimit={studentAmountLimit} />
263251
</>
264252
)

services/frontend/src/components/CustomPopulation/CustomPopulationContent.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import Box from '@mui/material/Box'
44

55
import Button from '@mui/material/Button'
66
import Chip from '@mui/material/Chip'
7-
import Stack from '@mui/material/Stack'
8-
import TextField from '@mui/material/TextField'
97
import Tooltip from '@mui/material/Tooltip'
108
import Typography from '@mui/material/Typography'
11-
import { useEffect, useState } from 'react'
9+
import { useEffect } from 'react'
1210

1311
import { populationStatisticsToolTips } from '@/common/InfoToolTips'
1412
import { PanelView } from '@/components/common/PanelView'
@@ -20,11 +18,12 @@ import { PopulationStudents } from '@/components/PopulationStudents'
2018
import { useFormat as formatGeneralTab } from '@/components/PopulationStudents/StudentTable/GeneralTab/format/index'
2119
import { ProgressBar } from '@/components/ProgressBar'
2220
import { RightsNotification } from '@/components/RightsNotification'
21+
import { useDebouncedState } from '@/hooks/debouncedState'
2322
import { useProgress } from '@/hooks/progress'
2423
import { useFilteredAndFormattedStudyProgrammes } from '@/redux/studyProgramme'
2524
import { FormattedCourse, FormattedStudent } from '@oodikone/shared/types'
26-
2725
import { PageTitle } from '../common/PageTitle'
26+
import { StudentAmountLimiter } from '../common/StudentAmountLimiter'
2827
import { CustomPopulationProgrammeDist } from './CustomPopulationProgrammeDist'
2928
import { useColumns as columnsGeneralTab } from './studentColumns'
3029
import { UnihowDataExport } from './UnihowDataExport'
@@ -49,7 +48,7 @@ export const CustomPopulationContent = ({
4948
resetState: () => void
5049
}) => {
5150
const studyProgrammes = useFilteredAndFormattedStudyProgrammes()
52-
const [studentAmountLimit, setStudentAmountLimit] = useState(0)
51+
const [studentAmountLimit, setStudentAmountLimit] = useDebouncedState(0, 1000)
5352

5453
useEffect(() => {
5554
setStudentAmountLimit(Math.round(filteredStudents.length ? filteredStudents.length * 0.3 : 0))
@@ -95,20 +94,10 @@ export const CustomPopulationContent = ({
9594
content: (
9695
<>
9796
<InfoBox content={populationStatisticsToolTips.coursesOfPopulation} />
98-
{/* FIXME:TODO: This is ripped off from CourseTableModeSelector */}
99-
<Stack direction="row" sx={{ alignItems: 'center', mt: '0.5em' }}>
100-
<Typography fontWeight={500}>Select all courses with at least</Typography>
101-
<TextField
102-
onChange={({ target }) => onStudentAmountLimitChange(target.value)}
103-
size="small"
104-
sx={{ maxWidth: '6em' }}
105-
type="number"
106-
value={studentAmountLimit}
107-
/>
108-
<Typography fontWeight={500} sx={{ ml: '1em' }}>
109-
total students
110-
</Typography>
111-
</Stack>
97+
<StudentAmountLimiter
98+
onStudentAmountLimitChange={onStudentAmountLimitChange}
99+
studentAmountLimit={studentAmountLimit}
100+
/>
112101
<PopulationCourseStatsFlat filteredCourses={filteredCourses} studentAmountLimit={studentAmountLimit} />
113102
</>
114103
),

services/frontend/src/components/StudyGuidanceGroups/StudyGuidanceGroupPopulationCourses.jsx

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import Paper from '@mui/material/Paper'
2-
import Stack from '@mui/material/Stack'
3-
import TextField from '@mui/material/TextField'
4-
import Typography from '@mui/material/Typography'
52
import { useState } from 'react'
63

74
import { PopulationCourseStats } from '@/components/PopulationCourseStats'
85
import { PopulationCourseStatsFlat } from '@/components/PopulationCourseStats/PopulationCourseStatsFlat'
96
import { CourseTableModeSelector } from '@/components/PopulationDetails/CourseTableModeSelector'
7+
import { useDebouncedState } from '@/hooks/debouncedState'
8+
import { StudentAmountLimiter } from '../common/StudentAmountLimiter'
109

1110
export const StudyGuidanceGroupPopulationCourses = ({
1211
filteredCourses,
@@ -17,7 +16,7 @@ export const StudyGuidanceGroupPopulationCourses = ({
1716
curriculumList,
1817
setCurriculum,
1918
}) => {
20-
const [studentAmountLimit, setStudentAmountLimit] = useState(0)
19+
const [studentAmountLimit, setStudentAmountLimit] = useDebouncedState(0, 1000)
2120
const curriculumsAvailable = studyProgramme && year
2221
const [courseTableMode, setCourseTableMode] = useState(curriculumsAvailable ? 'curriculum' : 'all')
2322
const onStudentAmountLimitChange = value => {
@@ -38,20 +37,10 @@ export const StudyGuidanceGroupPopulationCourses = ({
3837
studentAmountLimit={studentAmountLimit}
3938
/>
4039
) : (
41-
// FIXME:TODO: This is ripped off from CourseTableModeSelector
42-
<Stack direction="row" sx={{ alignItems: 'center', mt: '0.5em' }}>
43-
<Typography fontWeight={500}>Select all courses with at least</Typography>
44-
<TextField
45-
onChange={({ target }) => onStudentAmountLimitChange(target.value)}
46-
size="small"
47-
sx={{ maxWidth: '6em' }}
48-
type="number"
49-
value={studentAmountLimit}
50-
/>
51-
<Typography fontWeight={500} sx={{ ml: '1em' }}>
52-
total students
53-
</Typography>
54-
</Stack>
40+
<StudentAmountLimiter
41+
onStudentAmountLimitChange={onStudentAmountLimitChange}
42+
studentAmountLimit={studentAmountLimit}
43+
/>
5544
)}
5645
{courseTableMode === 'curriculum' ? (
5746
<PopulationCourseStats curriculum={curriculum} filteredCourses={filteredCourses} />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Stack from '@mui/material/Stack'
2+
import TextField from '@mui/material/TextField'
3+
import Typography from '@mui/material/Typography'
4+
5+
export const StudentAmountLimiter = ({ onStudentAmountLimitChange, studentAmountLimit }) => (
6+
<Stack direction="row" sx={{ alignItems: 'center', mt: '0.5em' }}>
7+
<Typography fontWeight={500}>Select all courses with at least</Typography>
8+
<TextField
9+
onChange={({ target }) => onStudentAmountLimitChange(target.value)}
10+
size="small"
11+
sx={{ maxWidth: '6em' }}
12+
type="number"
13+
value={studentAmountLimit}
14+
/>
15+
<Typography fontWeight={500} sx={{ ml: '1em' }}>
16+
total students
17+
</Typography>
18+
</Stack>
19+
)

0 commit comments

Comments
 (0)