Skip to content

Commit d60536b

Browse files
committed
StopSearch: Make municipality filter more robust
Instead of using hard coded mapping of municiplaity name to database ID, perform the search with a join to actual DB entity witht a proper name.
1 parent abd7162 commit d60536b

File tree

3 files changed

+15
-32
lines changed

3 files changed

+15
-32
lines changed

ui/src/components/stop-registry/search/by-stop/filtersToQueryVariables.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import isEmpty from 'lodash/isEmpty';
22
import { StopsDatabaseQuayNewestVersionBoolExp } from '../../../../generated/graphql';
3-
import {
4-
StopRegistryMunicipality,
5-
knownPriorityValues,
6-
} from '../../../../types/enums';
3+
import { knownPriorityValues } from '../../../../types/enums';
74
import {
85
AllOptionEnum,
96
NullOptionEnum,
@@ -63,15 +60,8 @@ function buildSearchStopsMunicipalityFilter({
6360

6461
return {
6562
stop_place: {
66-
topographic_place_id: {
67-
_in: municipalities.map(
68-
(name) =>
69-
(
70-
StopRegistryMunicipality as unknown as Readonly<
71-
Record<StringMunicipality, number>
72-
>
73-
)[name as StringMunicipality],
74-
),
63+
topographic_place: {
64+
name_value: { _in: municipalities },
7565
},
7666
},
7767
};
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { StopRegistryMunicipality } from '../../../../types/enums';
2-
import { numberEnumKeys } from '../../../../utils';
1+
export const knownMunicipalities = [
2+
'Helsinki',
3+
'Vantaa',
4+
'Espoo',
5+
'Kauniainen',
6+
'Siuntio',
7+
'Kirkkonummi',
8+
'Sipoo',
9+
'Kerava',
10+
'Tuusula',
11+
] as const;
312

4-
export const knownMunicipalities = Object.freeze(
5-
numberEnumKeys(StopRegistryMunicipality),
6-
);
7-
8-
export type StringMunicipality = keyof typeof StopRegistryMunicipality;
13+
export type StringMunicipality = (typeof knownMunicipalities)[number];

ui/src/types/enums.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,6 @@ export enum DayType {
7272
SU = 9, // Sunday
7373
}
7474

75-
export enum StopRegistryMunicipality {
76-
Helsinki = 3,
77-
Vantaa = 4,
78-
Espoo = 5,
79-
Kauniainen = 6,
80-
Siuntio = 7,
81-
Kirkkonummi = 8,
82-
Sipoo = 9,
83-
Kerava = 10,
84-
Tuusula = 11,
85-
}
86-
8775
export const knownMunicipalityPrefixes = {
8876
Helsinki: 'H',
8977
Vantaa: 'V',

0 commit comments

Comments
 (0)