Bugfix sorting
This commit is contained in:
parent
068db211d5
commit
259e9967b6
|
@ -23,7 +23,7 @@ export default class MunicipalityList extends React.Component<any, State> {
|
||||||
super()
|
super()
|
||||||
const stateTemplate = {
|
const stateTemplate = {
|
||||||
filterText: '',
|
filterText: '',
|
||||||
filterByResource: false,
|
filterByResource: false
|
||||||
}
|
}
|
||||||
this.state = Object.assign(
|
this.state = Object.assign(
|
||||||
stateTemplate,
|
stateTemplate,
|
||||||
|
@ -38,7 +38,7 @@ export default class MunicipalityList extends React.Component<any, State> {
|
||||||
distance: 10,
|
distance: 10,
|
||||||
shouldSort: true,
|
shouldSort: true,
|
||||||
tokenize: true,
|
tokenize: true,
|
||||||
matchAllTokens: true,
|
matchAllTokens: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -48,11 +48,12 @@ export default class MunicipalityList extends React.Component<any, State> {
|
||||||
const hasLogo = (muni: Municipality) => !!muni.orgnummer
|
const hasLogo = (muni: Municipality) => !!muni.orgnummer
|
||||||
|
|
||||||
// copy array and sort by name
|
// copy array and sort by name
|
||||||
let municipalities = this.state.filterText.length > 0 ?
|
let municipalities =
|
||||||
this.state.municipalities.search(this.state.filterText) :
|
this.state.filterText.length > 0
|
||||||
municipalitiesData
|
? this.state.municipalities.search(this.state.filterText)
|
||||||
|
: municipalitiesData
|
||||||
|
|
||||||
municipalities = municipalities
|
municipalities = municipalities
|
||||||
.slice()
|
.slice()
|
||||||
.reduce((acc: Array<Municipality>, elem: Municipality) => {
|
.reduce((acc: Array<Municipality>, elem: Municipality) => {
|
||||||
if (this.state.filterByResource && !hasLogo(elem)) {
|
if (this.state.filterByResource && !hasLogo(elem)) {
|
||||||
|
@ -61,8 +62,14 @@ export default class MunicipalityList extends React.Component<any, State> {
|
||||||
acc.push(elem)
|
acc.push(elem)
|
||||||
return acc
|
return acc
|
||||||
}, [] as Municipality[])
|
}, [] as Municipality[])
|
||||||
.sort((municipalityA: Municipality, municipalityB: Municipality) => {
|
.sort((a: Municipality, b: Municipality) => {
|
||||||
return municipalityA.name.localeCompare(municipalityB.name)
|
if (a.name < b.name) {
|
||||||
|
return -1
|
||||||
|
} else if (a.name > b.name) {
|
||||||
|
return 1
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in a new issue