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 2 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
12 changes: 9 additions & 3 deletions src/components/AgencySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,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 +129,8 @@ class AgencySearch extends Component {
)}
groupKey="primary_county"
groupValues={Object.keys(counties).sort()}
onClick={this.handleSearchClick}
onResultsClick={this.handleResultsClick}
onStateClick={this.handleStateClick}
/>
</OnEscape>}
</div>
Expand Down
35 changes: 32 additions & 3 deletions src/components/AgencySearchResults.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import startCase from 'lodash.startcase'
import PropTypes from 'prop-types'
import React from 'react'

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

const prevent = e => e.preventDefault()

/* eslint-disable camelcase */
Expand All @@ -26,7 +29,13 @@ const AgencySearchResultItem = ({ agency, onClick }) => {
}
/* eslint-enable camelcase */

const AgencySearchResults = ({ data, groupKey, groupValues, onClick }) => {
const AgencySearchResults = ({
data,
groupKey,
groupValues,
onResultsClick,
onStateClick,
}) => {
const noFederal = data.filter(d => d.agency_type_name !== 'Federal')
const dataGrouped = groupValues.map(key => ({
key,
Expand All @@ -37,6 +46,8 @@ const AgencySearchResults = ({ data, groupKey, groupValues, onClick }) => {
data: noFederal.filter(d => d[groupKey] === null),
})

const usState = oriToState(noFederal[0].ori)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should pass usState down as a prop rather than parse and lookup from ORIs (since it's available in the LocationFilter component)


return (
<div
className="mb2 p2 absolute col-12 border-box bg-white border overflow-auto"
Expand All @@ -52,11 +63,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 +93,8 @@ 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,
}

export default AgencySearchResults