Skip to content

Commit

Permalink
Do not show nibrs details for violent/property crime at the agency le…
Browse files Browse the repository at this point in the history
…vel (#1146)

* Rename "ucr" to "participation"

Since all of this data, indeed the entire site, falls under the UCR
program, I am using "participation" to refer to the actions, reducers
and utils that are related to getting UCR participation information

* Do not show details for violent/property crime for an agency

* small fixes
  • Loading branch information
jeremiak authored and brendansudol committed Jul 11, 2017
1 parent d2bfc29 commit 4d51258
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/actions/composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import { updateFilters } from './filters'
import { fetchNibrs } from './nibrs'
import { fetchSummaries } from '../actions/summary'
import { fetchUcrParticipation } from '../actions/ucr'
import { fetchUcrParticipation } from '../actions/participation'
import history, { createNewLocation } from '../util/history'
import {
shouldFetchUcr,
shouldFetchSummaries,
shouldFetchNibrs,
} from '../util/ucr'
} from '../util/participation'

const fetchData = () => (dispatch, getState) => {
const { filters } = getState()
Expand Down
2 changes: 1 addition & 1 deletion src/actions/ucr.js → src/actions/participation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
UCR_PARTICIPATION_RECEIVED,
} from './constants'
import api from '../util/api'
import { reshapeData } from '../util/ucr'
import { reshapeData } from '../util/participation'

export const failedUcrParticipation = error => ({
type: UCR_PARTICIPATION_FAILED,
Expand Down
4 changes: 2 additions & 2 deletions src/components/About.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UsaMap from './UsaMap'

import DownloadDataBtn from './DownloadDataBtn'
import { showFeedback } from '../actions/feedback'
import ucr from '../util/ucr'
import participation from '../util/participation'
import { slugify } from '../util/text'
import usa, { data as usaData, nationalKey } from '../util/usa'

Expand Down Expand Up @@ -43,7 +43,7 @@ const stateColors = Object.keys(usaData)
.filter(k => slugify(usa(k)) !== nationalKey)
.map(k => {
const stateName = usa(k)
const ucrInfo = ucr(stateName)
const ucrInfo = participation(stateName)
const { 'state-program': stateProgram, nibrs, srs } = ucrInfo
const matches = legend.filter(l => l.check(stateProgram, nibrs, srs))

Expand Down
15 changes: 8 additions & 7 deletions src/components/AgencySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,21 @@ class AgencySearch extends Component {
data.forEach(d => (counties[d.primary_county || 'N/A'] = true))

const searchUpper = search.toUpperCase()
const dataFiltered = searchUpper === ''
? data
: data.filter(d => {
const words = `${d.ori} ${d.agency_name}`.toUpperCase()
return words.includes(searchUpper)
})
const dataFiltered =
searchUpper === ''
? data
: data.filter(d => {
const words = `${d.ori} ${d.agency_name}`.toUpperCase()
return words.includes(searchUpper)
})

return (
<div className="agency-search mt2">
<div className="relative">
<div className="relative">
<input
type="text"
className="col-12 field field-sm fs-14 bold bg-white border-blue rounded-none placeholder-blue placeholder-fw-100 truncate pr4"
className="col-12 pr5 field field-sm fs-14 bold bg-white border-blue rounded-none placeholder-blue placeholder-fw-100 truncate"
placeholder="Search for an agency"
value={search}
onChange={this.handleChange}
Expand Down
12 changes: 6 additions & 6 deletions src/components/ExplorerIntro.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ExplorerIntroState from './ExplorerIntroState'
import { oriToState } from '../util/ori'
import { nationalKey } from '../util/usa'

const ExplorerIntro = ({ agency, crime, place, ucr, until }) => {
const ExplorerIntro = ({ agency, crime, participation, place, until }) => {
if (agency) {
return (
<ExplorerIntroAgency
Expand All @@ -22,16 +22,16 @@ const ExplorerIntro = ({ agency, crime, place, ucr, until }) => {
)
}

if (ucr.loading) return null
if (participation.loading) return null

if (ucr.error) return <ErrorCard error={ucr.error} />
if (participation.error) return <ErrorCard error={participation.error} />

if (place === nationalKey) {
return (
<ExplorerIntroNational
crime={crime}
until={until}
ucr={ucr.data[nationalKey]}
participation={participation.data[nationalKey]}
/>
)
}
Expand All @@ -41,7 +41,7 @@ const ExplorerIntro = ({ agency, crime, place, ucr, until }) => {
crime={crime}
place={place}
until={until}
ucr={ucr.data[place]}
participation={participation.data[place]}
/>
)
}
Expand All @@ -50,7 +50,7 @@ ExplorerIntro.propTypes = {
agency: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]).isRequired,
crime: PropTypes.string.isRequired,
place: PropTypes.string.isRequired,
ucr: PropTypes.shape({
participation: PropTypes.shape({
data: PropTypes.object,
loading: PropTypes.boolean,
}).isRequired,
Expand Down
6 changes: 3 additions & 3 deletions src/components/ExplorerIntroNational.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import mapCrimeToGlossaryTerm from '../util/glossary'

const highlight = txt => <strong>{txt}</strong>

const ExplorerIntroNational = ({ crime, ucr, until }) => {
const ExplorerIntroNational = ({ crime, participation, until }) => {
const isArson = crime === 'arson'
const untilUcr = ucr.find(p => p.year === until)
const untilUcr = participation.find(p => p.year === until)
const crimeTerm = (
<Term id={mapCrimeToGlossaryTerm(crime)}>
{upperFirst(lowerCase(crime))}
Expand Down Expand Up @@ -82,7 +82,7 @@ const ExplorerIntroNational = ({ crime, ucr, until }) => {

ExplorerIntroNational.propTypes = {
crime: PropTypes.string,
ucr: PropTypes.array,
participation: PropTypes.array,
until: PropTypes.number,
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/ExplorerIntroState.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Term from './Term'
import { estimatedTerm, nibrsTerm, srsTerm } from './Terms'
import { formatNum } from '../util/formats'
import mapCrimeToGlossaryTerm from '../util/glossary'
import ucrParticipationLookup from '../util/ucr'
import ucrParticipationLookup from '../util/participation'

const highlight = txt => <strong>{txt}</strong>
const getReportTerms = ({ nibrs, srs, hybrid }) =>
Expand All @@ -18,10 +18,10 @@ const getReportTerms = ({ nibrs, srs, hybrid }) =>
{nibrs && nibrsTerm}
</span>

const ExplorerIntroState = ({ crime, place, ucr, until }) => {
const ExplorerIntroState = ({ crime, place, participation, until }) => {
const isArson = crime === 'arson'
const { nibrs, srs } = ucrParticipationLookup(place)
const untilUcr = ucr.find(p => p.year === until)
const untilUcr = participation.find(p => p.year === until)
const reportTerms = getReportTerms({ nibrs, srs, hybrid: nibrs && srs })
const crimeTerm = (
<Term id={mapCrimeToGlossaryTerm(crime)}>
Expand Down
6 changes: 3 additions & 3 deletions src/components/NibrsIntro.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const NibrsIntro = ({
crime,
isAgency,
nibrsFirstYear,
participation,
place,
placeDisplay,
totalCount,
ucr,
until,
}) => {
if (isAgency) {
Expand All @@ -28,7 +28,7 @@ const NibrsIntro = ({
)
}

const ucrData = ucr.data[place]
const ucrData = participation.data[place]
const untilUcr = ucrData.find(p => p.year === until)
const agencyCt = untilUcr.nibrs_participating_agencies

Expand All @@ -50,7 +50,7 @@ NibrsIntro.propTypes = {
place: PropTypes.string.isRequired,
placeDisplay: PropTypes.string.isRequired,
totalCount: PropTypes.number.isRequired,
ucr: PropTypes.object.isRequired,
participation: PropTypes.object.isRequired,
until: PropTypes.number.isRequired,
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/TrendSourceText.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react'

import Term from './Term'

import ucrParticipationLookup from '../util/ucr'
import ucrParticipationLookup from '../util/participation'

const estimatedTerm = (
<Term id="estimated data" size="sm">
Expand Down
10 changes: 5 additions & 5 deletions src/containers/ExplorerHeaderContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const ExplorerHeaderContainer = ({
coordinates,
crime,
isAgency,
participation,
place,
placeType,
ucr,
until,
}) => {
const isLoading = isAgency ? agencies.loading : ucr.loading
const isLoading = isAgency ? agencies.loading : participation.loading
const usState = isAgency ? oriToState(place) : place
const placeDisplay = isAgency ? agency.agency_name : startCase(usState)

Expand All @@ -42,7 +42,7 @@ const ExplorerHeaderContainer = ({
agency={agency}
crime={crime}
place={place}
ucr={ucr}
participation={participation}
until={until}
/>}
<UcrResourcesList
Expand All @@ -67,7 +67,7 @@ const ExplorerHeaderContainer = ({
)
}

const mapStateToProps = ({ agencies, filters, ucr }) => {
const mapStateToProps = ({ agencies, filters, participation }) => {
const { place, placeType } = getPlaceInfo(filters)
const { crime, until } = filters
const isAgency = placeType === 'agency'
Expand All @@ -81,9 +81,9 @@ const mapStateToProps = ({ agencies, filters, ucr }) => {
coordinates,
crime,
isAgency,
participation,
place,
placeType,
ucr,
until,
}
}
Expand Down
31 changes: 17 additions & 14 deletions src/containers/NibrsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { nibrsTerm } from '../components/Terms'
import parseNibrs from '../util/nibrs'
import { getAgency, oriToState } from '../util/ori'
import { getPlaceInfo } from '../util/place'
import ucrParticipation, { shouldFetchNibrs as shouldShowNibrs } from '../util/ucr'
import ucrParticipation, {
shouldFetchNibrs as shouldShowNibrs,
} from '../util/participation'

const initialNibrsYear = ({ place, placeType, since }) => {
const placeNorm = placeType === 'agency' ? oriToState(place) : place
Expand Down Expand Up @@ -41,25 +43,26 @@ const NibrsContainer = ({
crime,
isAgency,
nibrs,
participation,
place,
placeType,
since,
ucr,
until,
}) => {
if (isAgency && !agency) return null

const showNibrs = isAgency
? agency.nibrs_months_reported === 12
: shouldShowNibrs({ crime, place, placeType })

if (!showNibrs) return null
if (
(isAgency && (!agency || agency.nibrs_months_reported !== 12)) ||
!shouldShowNibrs({ crime, place, placeType })
) {
return null
}

const placeDisplay = isAgency ? agency.display : startCase(place)
const nibrsFirstYear = initialNibrsYear({ place, placeType, since })
const { data, error } = nibrs

const isLoading = isAgency ? nibrs.loading : nibrs.loading || ucr.loading
const isLoading = isAgency
? nibrs.loading
: nibrs.loading || participation.loading
const isReady = !isLoading && error === null && !!data

let totalCount = 0
Expand Down Expand Up @@ -107,7 +110,7 @@ const NibrsContainer = ({
place={place}
placeDisplay={placeDisplay}
totalCount={totalCount}
ucr={ucr}
participation={participation}
until={until}
/>}
</div>
Expand All @@ -130,14 +133,14 @@ NibrsContainer.propTypes = {
place: PropTypes.string.isRequired,
placeType: PropTypes.string.isRequired,
since: PropTypes.number.isRequired,
ucr: PropTypes.shape({
participation: PropTypes.shape({
data: PropTypes.object,
loading: PropTypes.bool,
}).isRequired,
until: PropTypes.number.isRequired,
}

const mapStateToProps = ({ agencies, filters, nibrs, ucr }) => {
const mapStateToProps = ({ agencies, filters, nibrs, participation }) => {
const { place, placeType } = getPlaceInfo(filters)
const isAgency = placeType === 'agency'
const agency = isAgency && !agencies.loading && getAgency(agencies, place)
Expand All @@ -149,7 +152,7 @@ const mapStateToProps = ({ agencies, filters, nibrs, ucr }) => {
place,
placeType,
nibrs,
ucr,
participation,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import feedback from './feedback'
import filters from './filters'
import glossary from './glossary'
import nibrs from './nibrs'
import participation from './participation'
import sidebar from './sidebar'
import summaries from './summary'
import ucr from './ucr'

export default combineReducers({
agencies,
feedback,
filters,
glossary,
nibrs,
participation,
sidebar,
summaries,
ucr,
})
File renamed without changes.
2 changes: 1 addition & 1 deletion src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const {

const initState = {
agencies: { data: {}, loading: true },
ucr: { data: {}, loading: true },
participation: { data: {}, loading: true },
summaries: { data: {}, loading: true },
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
fetchingUcrParticipation,
receivedUcrParticipation,
fetchUcrParticipation,
} from '../../src/actions/ucr'
} from '../../src/actions/participation'
import api from '../../src/util/api'

const createPromise = (res, err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
UCR_PARTICIPATION_FETCHING,
UCR_PARTICIPATION_RECEIVED,
} from '../../src/actions/constants'
import reducer from '../../src/reducers/ucr'
import reducer from '../../src/reducers/participation'

describe('ucr reducer', () => {
const error = {
Expand Down
2 changes: 1 addition & 1 deletion test/util/ucr.test.js → test/util/participation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dataSourcesReportedByState, {
shouldFetchUcr,
shouldFetchSummaries,
shouldFetchNibrs,
} from '../../src/util/ucr'
} from '../../src/util/participation'
import { nationalKey } from '../../src/util/usa'

describe('ucr utility', () => {
Expand Down

0 comments on commit 4d51258

Please sign in to comment.