Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Fix lei select disabling. Sort MSA/MD and county dropdowns #208

Merged
merged 1 commit into from
Nov 22, 2019
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
6 changes: 6 additions & 0 deletions src/geo/InstitutionSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class InstitutionSelect extends React.Component {
}
}

componentDidUpdate(prevProps){
if(prevProps.nationwide && !this.props.nationwide)
this.setState({ disableItems: true })
}

onMethodChange = opt => {
opt.value && this.props.onChange([])
this.setState({ disableItems: opt.value })
Expand Down Expand Up @@ -74,6 +79,7 @@ const LeiMethodSelect = ({ onChange, value, options }) => (
simpleValue
value={value}
options={options}
isDisabled={options.length < 2}
/>
)

Expand Down
28 changes: 22 additions & 6 deletions src/geo/selectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,19 @@ function createMSAOption(id){
const stateLabel = MSATOSTATE[id].map(v => STATEOBJ[v]).join(' - ')
return {
value: '' + id,
label: `${id} - ${msaToName[id]} - ${stateLabel}`
label: `${id} - ${msaToName[id]} - ${stateLabel}`,
state: stateLabel,
other: msaToName[id]
}
}

function createCountyOption(id){
const stateLabel = fipsToState[id.slice(0, 2)]
return {
value: id,
label: `${id} - ${COUNTIES[id]} - ${stateLabel}`
label: `${id} - ${COUNTIES[id]} - ${stateLabel}`,
state: stateLabel,
other: COUNTIES[id]
}
}

Expand Down Expand Up @@ -134,16 +138,28 @@ function createItemOptions(props) {
itemOptions.msamds.push(createMSAOption(msa))
})

itemOptions.counties = Object.keys(COUNTIES).map(createCountyOption)
itemOptions.msamds = itemOptions.msamds.sort(sortByStateThenOther)
itemOptions.counties = Object.keys(COUNTIES).map(createCountyOption).sort(sortByStateThenOther)
itemOptions.leis = Object.keys(LEIS).map(createLEIOption).sort(sortByLabel)

return itemOptions
}

function sortByLabel(a,b){
const [aLabel, bLabel] = [a,b].map(i => i.label.toLowerCase())
if(aLabel > bLabel) return 1
if(aLabel === bLabel) return 0
const labels = [a,b].map(i => i.label)
return compareStrings(...labels)
}

function sortByStateThenOther(a,b){
const statesDiffer = compareStrings(a.state, b.state)
if(statesDiffer) return statesDiffer
return compareStrings(a.other, b.other)
}

function compareStrings(a,b){
const [aLower, bLower] = [a,b].map(i => i.toLowerCase())
if(!aLower || aLower > bLower) return 1
if(aLower === bLower) return 0
return -1
}

Expand Down