Skip to content

Commit

Permalink
Merge pull request #1117 from UniversityOfHelsinkiCS/trunk
Browse files Browse the repository at this point in the history
fix own garbage
  • Loading branch information
esakemp authored Jul 15, 2019
2 parents cb617bb + 7138e46 commit b34d04b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class PopulationSearchForm extends Component {

fetchPopulationFromUrlParams() {
const query = this.parseQueryFromUrl()
if (query.fetch || query.studyRights.programme !== this.state.query.studyRights.programme) {
if (query.fetch && query !== this.state.query) {
this.setState({ query })
this.fetchPopulation(query)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import { getActiveLanguage, getTranslate } from 'react-localize-redux'
import { func, bool, shape, string } from 'prop-types'
import { func, bool, shape } from 'prop-types'
import { Header, Segment, Divider, Button } from 'semantic-ui-react'
import qs from 'query-string'

Expand All @@ -19,21 +19,11 @@ class PopulationStatistics extends PureComponent {
populationFound: bool.isRequired,
loading: bool.isRequired,
location: shape({}).isRequired,
language: string.isRequired,
query: shape({}).isRequired,
history: shape({}).isRequired,
studyrights: shape({}).isRequired
}

constructor() {
super()
this.state = {
show: false
}
history: shape({}).isRequired
}

handleClick = () => {
this.setState({ show: !this.state.show })
const { query, history } = this.props
const { startYear, endYear, studyRights, semesters, months } = query
const queryObject = { startYear, endYear, studyRights: JSON.stringify(studyRights), semesters, months, fetch: false }
Expand All @@ -55,41 +45,38 @@ class PopulationStatistics extends PureComponent {
</Header>
<PopulationSearchForm />
<Divider />
{location.search !== '' || this.state.show ? (<PopulationSearchHistory />) : null}
{location.search !== '' ? (<PopulationSearchHistory />) : null}
<SegmentDimmer translate={translate} isLoading={loading} />
</Segment>
)
}

render() {
this.setState({ show: false })
const { translate, location, populationFound, studyrights, query, language } = this.props
const programmeInStore = studyrights.programmes ? studyrights.programmes.find(programme => programme.code === query.studyRights.programme) : []
const { translate, location, populationFound } = this.props
return (
<div className="segmentContainer">
<Header className="segmentTitle" size="large">{translate('populationStatistics.header')}</Header>
<Segment className="contentSegment">
{this.renderPopulationSearch()}
{location.search !== '' || this.state.show ? (<PopulationDetails />) : null}
{location.search !== '' ? (<PopulationDetails />) : null}
{populationFound && location.search === '' ? (
<Segment>
<Header>Search history</Header>
<Button onClick={this.handleClick}>{programmeInStore.name[language]}</Button>
<Header>Your previous search</Header>
<PopulationSearchHistory />
<Button onClick={this.handleClick}>open this population</Button>
</Segment>) : null}
</Segment>
</div>
)
}
}

const mapStateToProps = ({ locale, populations, settings }) => ({
const mapStateToProps = ({ locale, populations }) => ({
translate: getTranslate(locale),
currentLanguage: getActiveLanguage(locale).value,
loading: populations.pending,
populationFound: populations.data.students !== undefined,
query: populations.query,
studyrights: populations.data.studyrights ? populations.data.studyrights : [],
language: settings.language
query: populations.query ? populations.query : {}
})

export default connect(mapStateToProps)(PopulationStatistics)
2 changes: 1 addition & 1 deletion services/oodikone2-frontend/src/redux/students.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const reducer = (state = { data: [] }, action) => {
case 'SELECT_STUDENTS_SUCCESS':
return { ...state, selected: action.response }
case 'RESET_STUDENT_SUCCESS':
return { ...state, data: [] }
return { ...state, data: [], lastSearch: '' }
case 'REMOVE_SELECTED_SUCCESS':
return { ...state, selected: null }
default:
Expand Down

0 comments on commit b34d04b

Please sign in to comment.