Skip to content

Commit

Permalink
Merge pull request #1747 from BaseAdresseNationale/jugurtha/ordre-des…
Browse files Browse the repository at this point in the history
…-suffixes-sur-lexplorateur

Add list of suffixes ordered non-alphabetically
  • Loading branch information
jbouhadoun authored Jun 4, 2024
2 parents 8238467 + 4cd0cb8 commit eb53a9f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions components/base-adresse-nationale/voie/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types'
import Link from 'next/link'
import colors from '@/styles/colors'

import {getNumeroComplet} from '@/lib/ban'
import {getNumeroComplet, orderBySuffixe} from '@/lib/ban'

import Tag from '@/components/tag'

Expand Down Expand Up @@ -56,7 +56,7 @@ function Voie({type, nomVoie, nomVoieAlt, commune, numeros, parcelles, displayBB
<div className='numeros-list'>
<AddressesList
title='Numéros de la voie'
addresses={numeros}
addresses={orderBySuffixe(numeros)}
placeholder='Rechercher un numéro'
getLabel={getNumeroComplet}
addressComponent={numero => (
Expand Down
38 changes: 38 additions & 0 deletions lib/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,41 @@ export function isCertifiable({sources, certifie, parcelles}) {
parcelles?.length > 0
)
}

export function orderBySuffixe(numeros) {
const suffixes = [
'bis',
'ter',
'quater',
'quinquies',
'sexies',
'septies',
'octies',
'nonies',
'decies'
]

return numeros.sort((a, b) => {
const numeroA = a.numero
const numeroB = b.numero

if (numeroA !== numeroB) {
return numeroA - numeroB
}

const suffixA = a.suffixe ? a.suffixe.toLowerCase() : null
const suffixB = b.suffixe ? b.suffixe.toLowerCase() : null

if (suffixA === null) {
return -1
}

if (suffixB === null) {
return 1
}

const indexA = suffixes.includes(suffixA) ? suffixes.indexOf(suffixA) : Number.MAX_SAFE_INTEGER
const indexB = suffixes.includes(suffixB) ? suffixes.indexOf(suffixB) : Number.MAX_SAFE_INTEGER
return indexA - indexB
})
}

0 comments on commit eb53a9f

Please sign in to comment.