Skip to content

Commit

Permalink
Add an extra department for undefined cases in useGetPortsAsTreeOptio…
Browse files Browse the repository at this point in the history
…ns()
  • Loading branch information
ivangabriele committed Mar 26, 2024
1 parent e2892ec commit e38b7d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ values ('AD', null, null, 'ADALV', 'Andorra la Vella', 42.5, 1.016666666

-- https://service.unece.org/trade/locode/fr.htm
('FR', 'NAMO', '29', 'FRBES', 'Brest', 48.24, 4.29, null, true),
('FR', 'MEMN', '29', 'FRMRS', 'Marseille', 43.18, 5.24, null, true),
('FR', 'MEMN', '29', 'FRNCE', 'Nice', 43.42, 7.16, null, true),
('FR', 'MEMN', '13', 'FRMRS', 'Marseille', 43.18, 5.24, null, true),
('FR', 'MEMN', '06', 'FRNCE', 'Nice', 43.42, 7.16, null, true),
('FR', 'NAMO', '35', 'FRSML', 'Saint-Malo', 48.39, 2.01, null, true),
('FR', 'NAMO', '56', 'FRVNE', 'Vannes', 47.39, 2.46, null, true);
7 changes: 4 additions & 3 deletions frontend/src/hooks/useGetPortsAsTreeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ export function useGetPortsAsTreeOptions() {
return undefined
}

// TODO If `region` is null, the port won't appear. Check if that's the expected behavior.
const sortedUniquePortDepartments = uniq(ports.map(port => port.region).filter(isDefined)).sort()
const sortedUniquePortDepartments = uniq(ports.map(port => port.region).filter(isDefined))
.sort()
.concat('Hors Départements')

return sortedUniquePortDepartments.map(department => ({
children: ports
.filter(port => port.region === department)
.filter(port => (department === 'Hors Départements' ? !port.region : port.region === department))
.map(port => ({
label: port.name,
value: port.locode
Expand Down

0 comments on commit e38b7d8

Please sign in to comment.