Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add US state button to bottom of agency search results #1028

Merged
merged 3 commits into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/components/AgencySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { Component } from 'react'

import AgencySearchResults from './AgencySearchResults'
import OnEscape from './OnEscape'
import { oriToState } from '../util/ori'

class AgencySearch extends Component {
constructor(props) {
Expand Down Expand Up @@ -50,14 +51,19 @@ class AgencySearch extends Component {
return e
}

handleSearchClick = d => e => {
handleResultsClick = d => e => {
e.preventDefault()
this.setState({ search: d.agency_name, hasSelection: true })
this.props.onChange({ place: d.ori, placeType: 'agency' })
}

handleStateClick = usState => {
this.setState({ showResults: false })
this.props.onChange({ place: usState, placeType: 'state' })
}

clearInput = () => {
this.setState({ search: '', hasSelection: false })
this.setState({ search: '', hasSelection: false, showResults: true })
}

toggleResults = () => {
Expand Down Expand Up @@ -124,7 +130,9 @@ class AgencySearch extends Component {
)}
groupKey="primary_county"
groupValues={Object.keys(counties).sort()}
onClick={this.handleSearchClick}
onResultsClick={this.handleResultsClick}
onStateClick={this.handleStateClick}
usState={oriToState(data[0].ori)}
/>
</OnEscape>}
</div>
Expand Down
33 changes: 30 additions & 3 deletions src/components/AgencySearchResults.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import startCase from 'lodash.startcase'
import PropTypes from 'prop-types'
import React from 'react'

Expand Down Expand Up @@ -26,7 +27,14 @@ const AgencySearchResultItem = ({ agency, onClick }) => {
}
/* eslint-enable camelcase */

const AgencySearchResults = ({ data, groupKey, groupValues, onClick }) => {
const AgencySearchResults = ({
data,
groupKey,
groupValues,
onResultsClick,
onStateClick,
usState,
}) => {
const noFederal = data.filter(d => d.agency_type_name !== 'Federal')
const dataGrouped = groupValues.map(key => ({
key,
Expand All @@ -52,11 +60,28 @@ const AgencySearchResults = ({ data, groupKey, groupValues, onClick }) => {
.slice(0, 100)
.sort((a, b) => a.agency_name < b.agency_name)
.map((d, i) =>
<AgencySearchResultItem agency={d} key={i} onClick={onClick} />,
<AgencySearchResultItem
agency={d}
key={i}
onClick={onResultsClick}
/>,
)}
</ul>
</div>,
)}
<hr className="my2" />
<div>
<p className="italic serif fs-12">
Agencies that have submitted a full year{"'"}s worth of data in 2014
are listed in dark blue.
</p>
<button
className="btn btn-primary regular py-tiny px1 fs-14"
onClick={() => onStateClick(usState)}
>
View {startCase(usState)}
</button>
</div>
</div>
)
}
Expand All @@ -65,7 +90,9 @@ AgencySearchResults.propTypes = {
data: PropTypes.arrayOf(PropTypes.object).isRequired,
groupKey: PropTypes.string.isRequired,
groupValues: PropTypes.arrayOf(PropTypes.string).isRequired,
onClick: PropTypes.func.isRequired,
onResultsClick: PropTypes.func.isRequired,
onStateClick: PropTypes.func.isRequired,
usState: PropTypes.string.isRequired,
}

export default AgencySearchResults