Skip to content

Commit

Permalink
Merge pull request #1256 from UniversityOfHelsinkiCS/trunk
Browse files Browse the repository at this point in the history
jami and fix
  • Loading branch information
esakemp authored Aug 13, 2019
2 parents b974d08 + 92c5f57 commit 91bc8e8
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const mapStateToProps = ({ coursePopulation, localize, singleCourseStats, popula
selectedStudents = difference(samples.map(s => s.studentNumber), selectedStudents)
}
}

console.log(singleCourseStats)
return ({
studentData: coursePopulation.students,
courses: coursePopulation.courses,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React, { useState } from 'react'
import { connect } from 'react-redux'
import { Segment, Icon, Button, Form, Input, Popup } from 'semantic-ui-react'
import { func, shape, string } from 'prop-types'

import { removePopulationFilter, setPopulationFilter } from '../../redux/populationFilters'
import { courseCreditFilter } from '../../populationFilters'

const CourseCreditFilter = ({ coursecode, courseData, filter, setPopulationFilterAction, removePopulationFilterAction }) => {
const [credits, setCredits] = useState(0)
const handleFilter = () => {
setPopulationFilterAction(courseCreditFilter({ credits, coursecode, coursename: courseData.name }))
}

const handleChange = (e, { value }) => {
setCredits(value)
}
const clearFilter = () => {
removePopulationFilterAction(filter.id)
}

if (filter.notSet) {
return (
<Segment>
<Form>
<Popup
trigger={<Icon style={{ float: 'right' }} name="info" />}
/>
<Form.Group inline>
<Form.Field>
<label>Select students that </label>
</Form.Field>
<Form.Field>
<Input
type="number"
onChange={handleChange}
value={credits}
/>
</Form.Field>
<Form.Field>
<label>credits from course {courseData.name}</label>
</Form.Field>
<Form.Field>
<Button
onClick={handleFilter}
disabled={credits === 0}
>
set filter
</Button>
</Form.Field>
</Form.Group>
</Form>
</Segment>
)
}
return (
<Segment>
Students that have {filter.params.credits} credits from course {filter.params.coursename}
<span style={{ float: 'right' }}>
<Icon name="remove" onClick={clearFilter} />
</span>
</Segment>
)
}

CourseCreditFilter.propTypes = {
setPopulationFilterAction: func.isRequired,
removePopulationFilterAction: func.isRequired,
filter: shape({}).isRequired,
courseData: shape({}).isRequired,
coursecode: string.isRequired
}

const mapStateToProps = ({ singleCourseStats }) => ({
courseData: singleCourseStats.stats
})

export default connect(mapStateToProps, {
setPopulationFilterAction: setPopulationFilter,
removePopulationFilterAction: removePopulationFilter
})(CourseCreditFilter)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { gradeFilter } from '../../populationFilters'
const GradeFilter = ({ coursecode, courseData, filter, setPopulationFilterAction, removePopulationFilterAction }) => {
const [grade, setGrade] = useState(0)
const handleFilter = () => {
setPopulationFilterAction(gradeFilter({ grade, coursecode, coursename: courseData[coursecode].name }))
setPopulationFilterAction(gradeFilter({ grade, coursecode, coursename: courseData.name }))
}

const handleChange = (e, { value }) => {
Expand Down Expand Up @@ -42,7 +42,7 @@ const GradeFilter = ({ coursecode, courseData, filter, setPopulationFilterAction
/>
</Form.Field>
<Form.Field>
<label>from course {courseData[coursecode].name}</label>
<label>from course {courseData.name}</label>
</Form.Field>
<Form.Field>
<Button
Expand Down Expand Up @@ -75,8 +75,8 @@ GradeFilter.propTypes = {
coursecode: string.isRequired
}

const mapStateToProps = ({ courseStats }) => ({
courseData: courseStats.data
const mapStateToProps = ({ singleCourseStats }) => ({
courseData: singleCourseStats.stats
})

export default connect(mapStateToProps, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import InfoBox from '../InfoBox'
import infotooltips from '../../common/InfoToolTips'
import GradeFilter from './GradeFilter'
import ProgrammeFilter from './ProgrammeFilter'
import CourseCreditFilter from './CourseCreditFilter'
import {
clearPopulationFilters, setComplementFilter
} from '../../redux/populationFilters'

const componentFor = {
GradeFilter,
CourseCreditFilter,
ProgrammeFilter,
CreditsAtLeast,
CreditsLessThan,
Expand Down
17 changes: 17 additions & 0 deletions services/oodikone2-frontend/src/populationFilters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,23 @@ export const gradeFilter = (params) => {
})
}

export const courseCreditFilter = (params) => {
const { coursecode, credits, coursename } = params
return ({
id: uuidv4(),
type: 'GradeFilter',
params: {
coursecode,
credits,
coursename
},
filter: (student) => {
const course = student.courses.find(c => c.course.code === coursecode)
return Number(course.credits) === Number(credits)
}
})
}

export const programmeFilter = (params) => {
const { programme, programmeName } = params
return ({
Expand Down

0 comments on commit 91bc8e8

Please sign in to comment.