Skip to content

Commit

Permalink
feat: disable travel planner flight filter by default (#242)
Browse files Browse the repository at this point in the history
* Adding temporary solution to disable fligth as default filter.

* Renaming

* Add default filter hook.

* Remove changes from last commit.

* Change filter conditions.

* Logic to keep filter state modified to other than default when refreshing.

* Remove hook and use onTransportFilterChanged.

* Updatet logic and test.
  • Loading branch information
jonasbrunvoll authored Feb 28, 2024
1 parent 67f37c5 commit 196dd79
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/modules/transport-mode/filter/__tests__/filter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,15 @@ describe('transport mode filter', () => {

const initial: string[] = [];

const expected = null;
const expected = [
'bus',
'rail',
'expressboat',
'ferry',
'airportbus',
'air',
'other',
];

render(
<TransportModeFilter
Expand Down
4 changes: 3 additions & 1 deletion src/modules/transport-mode/filter/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export default function TransportModeFilter({
!localFilterState || localFilterState.length === data.length
}
onChange={(event) => {
onChangeWrapper(event.target.checked ? null : []);
onChangeWrapper(
event.target.checked ? data?.map((option) => option.id) : [],
);
}}
/>

Expand Down
24 changes: 22 additions & 2 deletions src/page-modules/assistant/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ 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, useState } from 'react';
import {
FormEventHandler,
PropsWithChildren,
useEffect,
useState,
} from 'react';
import style from './assistant.module.css';
import { FromToTripQuery } from './types';
import { createTripQuery } from './utils';
Expand Down Expand Up @@ -117,8 +122,23 @@ 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]);

/**
* Temprorary solution to disable line filter for some orgs until
* Temporary solution to disable line filter for some orgs until
* we have a working solution for all orgs.
*/
const disableLineFilter =
Expand Down

0 comments on commit 196dd79

Please sign in to comment.