Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extend travel mode filter selection to use selected_as_default property #293

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ yarn-error.log*
.env*.local
.env*.atb
.env*.fram
.env*.nfk

# vercel
.vercel
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@apollo/client": "^3.9.7",
"@atb-as/config-specs": "^3.16.0",
"@atb-as/config-specs": "^3.23.0",
"@atb-as/theme": "^8.1.0",
"@github/combobox-nav": "^2.3.1",
"@isaacs/ttlcache": "^1.4.1",
Expand Down
7 changes: 7 additions & 0 deletions src/modules/transport-mode/filter/__tests__/filter.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const filter: TransportModeFilterOptionType[] = [
transportMode: 'trolleybus',
},
],
selectedAsDefault: true,
},
{
id: 'rail',
Expand Down Expand Up @@ -79,6 +80,7 @@ export const filter: TransportModeFilterOptionType[] = [
transportSubModes: ['railReplacementBus'],
},
],
selectedAsDefault: false,
},
{
id: 'expressboat',
Expand Down Expand Up @@ -112,6 +114,7 @@ export const filter: TransportModeFilterOptionType[] = [
],
},
],
selectedAsDefault: true,
},
{
id: 'ferry',
Expand Down Expand Up @@ -143,6 +146,7 @@ export const filter: TransportModeFilterOptionType[] = [
],
},
],
selectedAsDefault: true,
},
{
id: 'airportbus',
Expand All @@ -169,6 +173,7 @@ export const filter: TransportModeFilterOptionType[] = [
transportSubModes: ['airportLinkBus'],
},
],
selectedAsDefault: true,
},
{
id: 'air',
Expand All @@ -194,6 +199,7 @@ export const filter: TransportModeFilterOptionType[] = [
transportMode: 'air',
},
],
selectedAsDefault: false,
},
{
id: 'other',
Expand Down Expand Up @@ -248,5 +254,6 @@ export const filter: TransportModeFilterOptionType[] = [
transportMode: 'lift',
},
],
selectedAsDefault: true,
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, expect, it } from 'vitest';
import { setTransportModeFilters } from '../utils';
import { TravelSearchFiltersType } from '@atb-as/config-specs';

describe('setTransportModeFilters', () => {
it('should only return transport mode filters where `selectedAsDefault` is true.', () => {
const tmfInput = [
{ id: 'bus', selectedAsDefault: true },
{ id: 'air', selectedAsDefault: false },
] as TravelSearchFiltersType['transportModes'];

const transportModeFilters = setTransportModeFilters(tmfInput);
expect(transportModeFilters).toEqual(['bus']);
});

it('should not return transport mode filters where `selectedAsDefault` is undefined.', () => {
const tmfInput = [
{ id: 'bus', selectedAsDefault: true },
{ id: 'air' },
{ id: 'rail', selectedAsDefault: undefined },
] as TravelSearchFiltersType['transportModes'];

const transportModeFilters = setTransportModeFilters(tmfInput);
expect(transportModeFilters).toEqual(['bus']);
});
});
25 changes: 4 additions & 21 deletions src/page-modules/assistant/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ import { PageText, useTranslation } from '@atb/translations';
import { FocusScope } from '@react-aria/focus';
import { AnimatePresence, motion } from 'framer-motion';
import { useRouter } from 'next/router';
import {
FormEventHandler,
PropsWithChildren,
useEffect,
useState,
} from 'react';
import { FormEventHandler, PropsWithChildren, useState } from 'react';
import style from './assistant.module.css';
import { FromToTripQuery } from './types';
import { createTripQuery } from './utils';
import { createTripQuery, setTransportModeFilters } from './utils';
import { TabLink } from '@atb/components/tab-link';
import { logSpecificEvent } from '@atb/modules/firebase';
import { getOrgData } from '@atb/modules/org-data';
Expand Down Expand Up @@ -122,20 +117,8 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) {
const { urls, orgId } = getOrgData();
const { isDarkMode } = useTheme();

/*
* Temporary solution until firebase configuration is in place.
*/
useEffect(() => {
if (tripQuery.transportModeFilter === null)
onTransportFilterChanged(
transportModeFilter
?.filter(
(filter) =>
!filter.modes.some((mode) => mode.transportMode === 'air'),
)
.map((filter) => filter.id) ?? null,
);
}, [transportModeFilter]); //eslint-disable-line react-hooks/exhaustive-deps
if (tripQuery.transportModeFilter === null)
onTransportFilterChanged(setTransportModeFilters(transportModeFilter));

return (
<div>
Expand Down
11 changes: 11 additions & 0 deletions src/page-modules/assistant/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { SearchMode } from '@atb/modules/search-time';
import { searchTimeToQueryString } from '@atb/modules/search-time';
import { GeocoderFeature } from '@atb/page-modules/departures';
import { FromToTripQuery, TripData, TripQuery, TripQuerySchema } from './types';
import { TravelSearchFiltersType } from '@atb-as/config-specs';

export function filterOutDuplicates(
arrayToFilter: TripData['tripPatterns'],
Expand Down Expand Up @@ -122,3 +123,13 @@ export function tripQueryToQueryString(input: TripQuery): string {
)
.join('&');
}

export function setTransportModeFilters(
transportModes: TravelSearchFiltersType['transportModes'],
) {
return (
transportModes
?.filter((filter) => filter.selectedAsDefault)
.map((filter) => filter.id) ?? null
);
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
dependencies:
node-fetch "^2.6.1"

"@atb-as/config-specs@^3.16.0":
version "3.16.0"
resolved "https://registry.yarnpkg.com/@atb-as/config-specs/-/config-specs-3.16.0.tgz#c0693176ad894283a99eca421c9d158436e9f9bb"
integrity sha512-+xmB4zKpAWumMjmbwu2Mpyzm5gkejZC2+f+dc1hFQrQnyCcv+6BOIfKfqUs52ziJqzeK2l4YSUlaqqB8lkrrkQ==
"@atb-as/config-specs@^3.23.0":
version "3.23.0"
resolved "https://registry.yarnpkg.com/@atb-as/config-specs/-/config-specs-3.23.0.tgz#f915ac43df1d7d59d7e964feb27106c4940647ed"
integrity sha512-p3n8E38r2mXggZE6HuTD/Nz/3KOnRnxux5mwqw2xeuClYuP6HnxaC6k7FUo1sAouHZTqA64C+C2Ld0hWMI2dlQ==
dependencies:
ajv "^8.12.0"
ajv-formats "^2.1.1"
Expand Down
Loading