Commit 639cded7 authored by Anton Akhmerov's avatar Anton Akhmerov
Browse files

Merge branch '521-fix-search-panel' into 'master'

Resolve "Fix search panel in Grade and Student views"

Closes #521

See merge request zesje/zesje!311
parents d95f1095 6abe360e
......@@ -67,7 +67,7 @@ class SearchBox extends React.Component {
event.target.select()
}
onSuggestionSelected = (event, { suggestion }) => {
this.props.setSelected(suggestion.id)
this.props.setSelected(suggestion)
}
// Autosuggest will call this function every time you need to update suggestions.
......
......@@ -47,7 +47,7 @@ class Grade extends React.Component {
submission: submission,
problem: problem,
...partialState
}, () => this.props.history.replace(`${this.props.parentURL}/grade/${submissionID}/${problemID}`))
}, () => this.props.history.replace(this.getURL(submissionID, problemID)))
// eslint-disable-next-line handle-callback-err
}).catch(err => {
this.setState({
......@@ -85,7 +85,7 @@ class Grade extends React.Component {
this.setState({
submission: submission,
problem: problem
}, () => this.props.history.replace(`${this.props.parentURL}/grade/${submission.id}/${problem.id}`))
}, () => this.props.history.replace(this.getURL(submission.id, problem.id)))
}).catch(err => {
if (err.status === 404) {
this.setState({
......@@ -154,6 +154,10 @@ class Grade extends React.Component {
}
}
getURL = (submissionID, problemID) => {
return `${this.props.parentURL}/grade/${submissionID}/${problemID}`
}
/**
* Navigates the current submission forwards or backwards, and either just to the next, or to the next ungraded.
* It then pushes the URL of the updated submission to history.
......@@ -170,7 +174,7 @@ class Grade extends React.Component {
'&ungraded=' + ungraded).then(sub =>
this.setState({
submission: sub
}, () => this.props.history.push(`${this.props.parentURL}/grade/${this.state.submission.id}/${this.state.problem.id}`))
}, () => this.props.history.push(this.getURL(this.state.submission.id, this.state.problem.id)))
)
}
/**
......@@ -248,11 +252,19 @@ class Grade extends React.Component {
}
/**
* Navigates the problem to the problem corresponding to the specified problem id by pushing a new URL to history.
* Navigates to the given problem by pushing a new URL to history without changing the submission.
* @param problemID - the id of the problem that we want to navigate to
*/
navigateProblem = (problemID) => {
this.props.history.push(`${this.props.parentURL}/grade/${this.props.submissionID}/${problemID}`)
this.props.history.push(this.getURL(this.props.submissionID, problemID))
}
/**
* Navigates to the given submission by pushing a new URL to history without changing the problem.
* @param submissionID - the id of the submission that we want to navigate to
*/
navigateSubmission = (submissionID) => {
this.props.history.push(this.getURL(submissionID, this.props.problemID))
}
/**
......@@ -421,7 +433,7 @@ class Grade extends React.Component {
<GradeNavigation
submission={submission}
submissions={submissions}
setSubmission={this.updateSubmission}
setSubmission={this.navigateSubmission}
prevUngraded={this.prevUngraded}
prev={this.prev}
next={this.next}
......
......@@ -78,6 +78,10 @@ class CheckStudents extends React.Component {
}
}
selectCopy = (copy) => {
this.setCopyIndex(this.state.copies.findIndex((c) => c.number === copy.number))
}
prev = () => {
this.setCopyIndex(this.state.index - 1)
}
......@@ -180,7 +184,7 @@ class CheckStudents extends React.Component {
'student.lastName',
'student.id'
]}
setSelected={this.setCopyIndex}
setSelected={this.selectCopy}
renderSelected={({number, student}) => {
if (student) {
return `#${number}: ${student.firstName} ${student.lastName} (${student.id})`
......
......@@ -67,9 +67,8 @@ class StudentControls extends React.Component {
'firstName',
'lastName'
]}
setSelected={studentID => {
const idx = this.state.students.findIndex(s => s.id === studentID)
this.props.setStudent(this.state.students[idx])
setSelected={student => {
this.props.setStudent(student)
}}
renderSelected={(student) => (
student !== null
......
......@@ -2,6 +2,10 @@ import React from 'react'
import SearchBox from '../../components/SearchBox.jsx'
class GradeNavigation extends React.Component {
setSubmission = (submission) => {
this.props.setSubmission(submission.id)
}
render () {
const submission = this.props.submission
const submissions = this.props.submissions
......@@ -26,7 +30,7 @@ class GradeNavigation extends React.Component {
data-tooltip='Press ctrl to hide shortcuts'>
<SearchBox
placeholder='Search for a submission'
setSelected={this.props.setSubmission}
setSelected={this.setSubmission}
selected={submission}
options={submissions}
suggestionKeys={(this.props.anonymous ? ['id'] : [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment