Skip to content

Commit 0936851

Browse files
committed
Add stop owner to search filters
1 parent 22ae7f3 commit 0936851

13 files changed

Lines changed: 137 additions & 17 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ function buildInfoSpotsFilter({
227227
};
228228
}
229229

230+
function buildStopOwnerFilter({
231+
stopOwner,
232+
}: StopSearchFilters): StopsDatabaseQuayNewestVersionBoolExp {
233+
if (stopOwner.includes(AllOptionEnum.All)) {
234+
return {};
235+
}
236+
237+
return { stop_owner: { _in: stopOwner } };
238+
}
239+
230240
export function buildSearchStopsGqlQueryVariables(
231241
filters: StopSearchFilters,
232242
...extraConditions: ReadonlyArray<StopsDatabaseQuayNewestVersionBoolExp>
@@ -246,6 +256,7 @@ export function buildSearchStopsGqlQueryVariables(
246256
const shelterFilter = buildShelterFilter(filters);
247257
const electricityFilter = buildElectricityFilter(filters);
248258
const infoSpotsFilter = buildInfoSpotsFilter(filters);
259+
const stopOwnerFilter = buildStopOwnerFilter(filters);
249260

250261
return {
251262
_and: [
@@ -259,6 +270,7 @@ export function buildSearchStopsGqlQueryVariables(
259270
shelterFilter,
260271
electricityFilter,
261272
infoSpotsFilter,
273+
stopOwnerFilter,
262274
...extraConditions,
263275
].filter((filter) => !isEmpty(filter)),
264276
};

ui/src/components/stop-registry/search/components/StopSearchBar/ExtraFilters/ExtraFilters.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { FC } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { twMerge } from 'tailwind-merge';
4-
import { Visible } from '../../../../../../layoutComponents';
4+
import { Row, Visible } from '../../../../../../layoutComponents';
55
import { ExpandedSearchButtons } from '../../../../../common';
66
import { stopSearchBarTestIds } from '../stopSearchBarTestIds';
7+
import { MetaFilters } from './MetaFilters';
78
import { StopPropertyFilters } from './StopPropertyFilters';
89

910
type ExtraFiltersProps = {
@@ -34,13 +35,14 @@ export const ExtraFilters: FC<ExtraFiltersProps> = ({
3435
>
3536
<h2>{t('search.advancedSearchTitle')}</h2>
3637

37-
<StopPropertyFilters
38-
className="border-b border-background pb-5 xl:w-2/3 xl:border-b-0 xl:border-r xl:pb-0 xl:pr-5"
39-
notForStops={notForStops}
40-
/>
38+
<Row className="flex flex-wrap xl:flex-nowrap">
39+
<StopPropertyFilters
40+
className="border-b border-background pb-5 xl:w-2/3 xl:border-b-0 xl:border-r xl:pb-0 xl:pr-5"
41+
notForStops={notForStops}
42+
/>
4143

42-
{/* Future extended filters: Nousijamäärä, Päivitystiedot, ... */}
43-
{/* <MetaFilters className="xl:w-1/3 xl:pt-5 xl:pl-5 pt-5 space-y-5" */}
44+
<MetaFilters className="xl:w-1/3" notForStops={notForStops} />
45+
</Row>
4446
</div>
4547

4648
<ExpandedSearchButtons
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { FC } from 'react';
2+
import { twMerge } from 'tailwind-merge';
3+
import { Row } from '../../../../../../layoutComponents';
4+
import { StopOwnerFilter } from './StopOwnerFilter';
5+
6+
type MetaFilterProps = {
7+
readonly className?: string;
8+
readonly notForStops: boolean;
9+
};
10+
11+
export const MetaFilters: FC<MetaFilterProps> = ({
12+
className,
13+
notForStops,
14+
}) => {
15+
return (
16+
<Row
17+
className={twMerge('self-start xl:border-b xl:pb-4 xl:pl-4', className)}
18+
>
19+
<StopOwnerFilter className="w-full" disabled={notForStops} />
20+
</Row>
21+
);
22+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { FC } from 'react';
2+
import { useController } from 'react-hook-form';
3+
import { mapStopOwnerToUiName } from '../../../../../../i18n/uiNameMappings';
4+
import { Column } from '../../../../../../layoutComponents';
5+
import { StopOwner } from '../../../../../../types/stop-registry';
6+
import { AllOptionEnum } from '../../../../../../utils';
7+
import { InputLabel, ValidationErrorList } from '../../../../../forms/common';
8+
import { StopSearchFilters } from '../../../types';
9+
import { stopSearchBarTestIds } from '../stopSearchBarTestIds';
10+
import { DisableableFilterProps } from '../Types/DisableableFilterProps';
11+
import { EnumFilter } from './EnumFilter';
12+
13+
const options: ReadonlyArray<StopOwner | AllOptionEnum> = [
14+
AllOptionEnum.All,
15+
...Object.values(StopOwner),
16+
];
17+
18+
const uiNameMapper = mapStopOwnerToUiName.extend({
19+
[AllOptionEnum.All]: (t) => t('all'),
20+
});
21+
22+
const defaultValue: ReadonlyArray<StopOwner | AllOptionEnum> = [
23+
AllOptionEnum.All,
24+
];
25+
26+
export const StopOwnerFilter: FC<DisableableFilterProps> = ({
27+
className,
28+
disabled,
29+
}) => {
30+
const {
31+
field: { onChange, onBlur, value },
32+
} = useController<StopSearchFilters, 'stopOwner'>({
33+
name: 'stopOwner',
34+
disabled,
35+
});
36+
37+
return (
38+
<Column className={className}>
39+
<InputLabel<StopSearchFilters>
40+
fieldPath="stopOwner"
41+
translationPrefix="stopRegistrySearch.fieldLabels"
42+
/>
43+
44+
<EnumFilter
45+
id="stopRegistrySearch.fieldLabels.stopOwner"
46+
defaultValue={defaultValue}
47+
disabled={disabled}
48+
options={options}
49+
onBlur={onBlur}
50+
onChange={onChange}
51+
testId={stopSearchBarTestIds.stopOwnerFilter}
52+
uiNameMapper={uiNameMapper}
53+
value={value}
54+
/>
55+
56+
<ValidationErrorList fieldPath="stopOwner" />
57+
</Column>
58+
);
59+
};

ui/src/components/stop-registry/search/components/StopSearchBar/stopSearchBarTestIds.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export const stopSearchBarTestIds = {
77
searchForDropdown: 'StopSearchBar::SearchForDropdown',
88
shelterFilter: 'StopSearchBar::shelterFilter',
99
stopStateFilter: 'StopSearchBar::stopStateFilter',
10+
stopOwnerFilter: 'StopSearchBar::stopOwnerFilter',
1011
prefix: 'StopSearchBar',
1112
};

ui/src/components/stop-registry/search/types/StopSearchFilters.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { Priority } from '../../../../types/enums';
99
import {
1010
JoreStopRegistryTransportModeType,
11+
StopOwner,
1112
StopPlaceState,
1213
} from '../../../../types/stop-registry';
1314
import { AllOptionEnum, NullOptionEnum, areEqual } from '../../../../utils';
@@ -52,6 +53,7 @@ export const stopSearchFiltersSchema = z.object({
5253
shelter: zEnumArrayWithAllAndNull(StopRegistryShelterType),
5354
electricity: zEnumArrayWithAllAndNull(StopRegistryShelterElectricity),
5455
infoSpots: z.array(z.union([infoSpotSize, allEnum, nullEnum])),
56+
stopOwner: zEnumArrayWithAll(StopOwner),
5557
});
5658

5759
export type InfoSpotSize = z.infer<typeof infoSpotSize>;
@@ -70,6 +72,7 @@ export const defaultFilters: StopSearchFilters = {
7072
shelter: [AllOptionEnum.All],
7173
electricity: [AllOptionEnum.All],
7274
infoSpots: [AllOptionEnum.All],
75+
stopOwner: [AllOptionEnum.All],
7376
};
7477

7578
export function pickMeaningfulFilters(filters: StopSearchFilters) {

ui/src/components/stop-registry/search/utils/useStopSearchRouterState.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const filterSerializers: UrlStateSerializers<StopSearchFilters> = {
8686
shelter: serializeArray,
8787
electricity: serializeArray,
8888
infoSpots: serializeInfoSpots,
89+
stopOwner: serializeArray,
8990
};
9091

9192
const serializers: UrlStateSerializers<StopSearchUrlFlatState> = {
@@ -183,6 +184,9 @@ const parseShelter = parseEnumArrayWithAllAndNullOptions(
183184
const parseElectricity = parseEnumArrayWithAllAndNullOptions(
184185
stopSearchFiltersSchema.shape.electricity,
185186
);
187+
const parseStopOwner = parseEnumArrayWithAllOption(
188+
stopSearchFiltersSchema.shape.stopOwner,
189+
);
186190

187191
function parseInfoSpots(value: string): StopSearchFilters['infoSpots'] {
188192
return splitString(value).map((size) => {
@@ -225,6 +229,7 @@ export const filterDeserializers: UrlStateDeserializers<StopSearchFilters> = {
225229
shelter: parseShelter,
226230
electricity: parseElectricity,
227231
infoSpots: parseInfoSpots,
232+
stopOwner: parseStopOwner,
228233
};
229234

230235
const deserializers: UrlStateDeserializers<StopSearchUrlFlatState> = {

ui/src/components/stop-registry/stops/stop-details/maintenance/StopOwnerViewCard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FC } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { mapStopOwnerToUiName } from '../../../../../i18n/uiNameMappings';
4+
import { StopOwner } from '../../../../../types/stop-registry';
45

56
const testIds = {
67
stopOwner: 'MaintenanceViewCard::stopOwner',
@@ -9,7 +10,7 @@ const testIds = {
910
};
1011

1112
type StopOwnerViewCardProps = {
12-
readonly stopOwner: string | null;
13+
readonly stopOwner: StopOwner | null;
1314
};
1415

1516
export const StopOwnerViewCard: FC<StopOwnerViewCardProps> = ({

ui/src/i18n/uiNameMappings.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
} from '../types/enums';
2727
import {
2828
JoreStopRegistryTransportModeType,
29+
StopOwner,
2930
StopPlaceSignType,
3031
StopPlaceState,
3132
} from '../types/stop-registry';
@@ -446,6 +447,18 @@ export const mapInfoSpotPurposeToUiName =
446447
t('stopDetails.infoSpots.purposes.other'),
447448
});
448449

449-
export const mapStopOwnerToUiName = (t: TFunction, value: string): string => {
450-
return t(`stopDetails.maintenance.stopOwnerOptions.${value}`);
451-
};
450+
export const mapStopOwnerToUiName = genTranslationMapper<StopOwner>({
451+
[StopOwner.Municipality]: (t) =>
452+
t('stopDetails.maintenance.stopOwnerOptions.municipality'),
453+
[StopOwner.Finavia]: (t) =>
454+
t('stopDetails.maintenance.stopOwnerOptions.finavia'),
455+
[StopOwner.Hkl]: (t) => t('stopDetails.maintenance.stopOwnerOptions.hkl'),
456+
[StopOwner.Hkr]: (t) => t('stopDetails.maintenance.stopOwnerOptions.hkr'),
457+
[StopOwner.Vr]: (t) => t('stopDetails.maintenance.stopOwnerOptions.vr'),
458+
[StopOwner.Ely]: (t) => t('stopDetails.maintenance.stopOwnerOptions.ely'),
459+
[StopOwner.FinnishTransportAgency]: (t) =>
460+
t('stopDetails.maintenance.stopOwnerOptions.finnishTransportAgency'),
461+
[StopOwner.PrivateRoad]: (t) =>
462+
t('stopDetails.maintenance.stopOwnerOptions.privateRoad'),
463+
[StopOwner.Other]: (t) => t('stopDetails.maintenance.stopOwnerOptions.other'),
464+
});

ui/src/locales/en-US/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,8 @@
795795
"stopState": "Stop state",
796796
"shelter": "Shelter",
797797
"electricity": "Electricity",
798-
"infoSpots": "Info spots"
798+
"infoSpots": "Info spots",
799+
"stopOwner": "Stop owner"
799800
},
800801

801802
"noOptions": {

0 commit comments

Comments
 (0)