From feb84bcbcc29fe1efb8bde01c7ea35938a093aab Mon Sep 17 00:00:00 2001 From: Jonas Brunvoll Larsson Date: Wed, 28 Feb 2024 12:15:38 +0100 Subject: [PATCH 1/8] Adding temporary solution to disable fligth as default filter. --- src/page-modules/assistant/layout.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/page-modules/assistant/layout.tsx b/src/page-modules/assistant/layout.tsx index 91cdfc1c..b2c0435d 100644 --- a/src/page-modules/assistant/layout.tsx +++ b/src/page-modules/assistant/layout.tsx @@ -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'; @@ -54,6 +59,13 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { getTransportModeFilter, ); + useEffect(() => { + tripQuery.transportModeFilter = + transportModeFilter + ?.filter((mode) => mode.icon.transportMode !== 'air') + .map((mode) => mode.id) ?? null; + }, [transportModeFilter]); + const setValuesWithLoading = async ( override: Partial, replace = false, From 2c9a3af0321ffc4fc05867761576283919b15453 Mon Sep 17 00:00:00 2001 From: Jonas Brunvoll Larsson Date: Wed, 28 Feb 2024 12:26:49 +0100 Subject: [PATCH 2/8] Renaming --- src/page-modules/assistant/layout.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/page-modules/assistant/layout.tsx b/src/page-modules/assistant/layout.tsx index b2c0435d..49efb845 100644 --- a/src/page-modules/assistant/layout.tsx +++ b/src/page-modules/assistant/layout.tsx @@ -62,8 +62,8 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { useEffect(() => { tripQuery.transportModeFilter = transportModeFilter - ?.filter((mode) => mode.icon.transportMode !== 'air') - .map((mode) => mode.id) ?? null; + ?.filter((filter) => filter.icon.transportMode !== 'air') + .map((filter) => filter.id) ?? null; }, [transportModeFilter]); const setValuesWithLoading = async ( From 4f14a5d6161431fc00ef5313ec8ca8a3a281bea5 Mon Sep 17 00:00:00 2001 From: Jonas Brunvoll Larsson Date: Wed, 28 Feb 2024 12:54:55 +0100 Subject: [PATCH 3/8] Add default filter hook. --- src/page-modules/assistant/layout.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/page-modules/assistant/layout.tsx b/src/page-modules/assistant/layout.tsx index 49efb845..84113985 100644 --- a/src/page-modules/assistant/layout.tsx +++ b/src/page-modules/assistant/layout.tsx @@ -50,6 +50,7 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { const [isPerformingSearchNavigation, setIsPerformingSearchNavigation] = useState(false); const [geolocationError, setGeolocationError] = useState(null); + const [defaultFilters, setDefaultFilters] = useState(null); // Loading the transport mode filter data here instead of in the component // avoids the data loading when the filter is mounted which causes the @@ -60,10 +61,11 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { ); useEffect(() => { - tripQuery.transportModeFilter = + setDefaultFilters( transportModeFilter ?.filter((filter) => filter.icon.transportMode !== 'air') - .map((filter) => filter.id) ?? null; + .map((filter) => filter.id) ?? null, + ); }, [transportModeFilter]); const setValuesWithLoading = async ( @@ -219,7 +221,7 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { >
From 991dc3e833e24fdb967259add86c2af5601254fe Mon Sep 17 00:00:00 2001 From: Jonas Brunvoll Larsson Date: Wed, 28 Feb 2024 13:21:51 +0100 Subject: [PATCH 4/8] Remove changes from last commit. --- src/page-modules/assistant/layout.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/page-modules/assistant/layout.tsx b/src/page-modules/assistant/layout.tsx index 84113985..49efb845 100644 --- a/src/page-modules/assistant/layout.tsx +++ b/src/page-modules/assistant/layout.tsx @@ -50,7 +50,6 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { const [isPerformingSearchNavigation, setIsPerformingSearchNavigation] = useState(false); const [geolocationError, setGeolocationError] = useState(null); - const [defaultFilters, setDefaultFilters] = useState(null); // Loading the transport mode filter data here instead of in the component // avoids the data loading when the filter is mounted which causes the @@ -61,11 +60,10 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { ); useEffect(() => { - setDefaultFilters( + tripQuery.transportModeFilter = transportModeFilter ?.filter((filter) => filter.icon.transportMode !== 'air') - .map((filter) => filter.id) ?? null, - ); + .map((filter) => filter.id) ?? null; }, [transportModeFilter]); const setValuesWithLoading = async ( @@ -221,7 +219,7 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { >
From e7e779c6e2d9384980e16e05c7021a58a3d0310a Mon Sep 17 00:00:00 2001 From: Jonas Brunvoll Larsson Date: Wed, 28 Feb 2024 13:35:37 +0100 Subject: [PATCH 5/8] Change filter conditions. --- src/page-modules/assistant/layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/page-modules/assistant/layout.tsx b/src/page-modules/assistant/layout.tsx index 49efb845..9d6c40f6 100644 --- a/src/page-modules/assistant/layout.tsx +++ b/src/page-modules/assistant/layout.tsx @@ -62,7 +62,7 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { useEffect(() => { tripQuery.transportModeFilter = transportModeFilter - ?.filter((filter) => filter.icon.transportMode !== 'air') + ?.filter((filter) => filter.id !== 'air') .map((filter) => filter.id) ?? null; }, [transportModeFilter]); From b7ae521cf3d498fbac044ad2dbf93840485c54ec Mon Sep 17 00:00:00 2001 From: Jonas Brunvoll Larsson Date: Wed, 28 Feb 2024 14:09:35 +0100 Subject: [PATCH 6/8] Logic to keep filter state modified to other than default when refreshing. --- src/page-modules/assistant/layout.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/page-modules/assistant/layout.tsx b/src/page-modules/assistant/layout.tsx index 9d6c40f6..804aac58 100644 --- a/src/page-modules/assistant/layout.tsx +++ b/src/page-modules/assistant/layout.tsx @@ -50,6 +50,7 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { const [isPerformingSearchNavigation, setIsPerformingSearchNavigation] = useState(false); const [geolocationError, setGeolocationError] = useState(null); + const [defaultFilters, setDefaultFilters] = useState(null); // Loading the transport mode filter data here instead of in the component // avoids the data loading when the filter is mounted which causes the @@ -60,10 +61,11 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { ); useEffect(() => { - tripQuery.transportModeFilter = + setDefaultFilters( transportModeFilter ?.filter((filter) => filter.id !== 'air') - .map((filter) => filter.id) ?? null; + .map((filter) => filter.id) ?? null, + ); }, [transportModeFilter]); const setValuesWithLoading = async ( @@ -219,7 +221,11 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { >
From 2dec3a0de733d707520f6b406dfd81ce2d0f7c2d Mon Sep 17 00:00:00 2001 From: Jonas Brunvoll Larsson Date: Wed, 28 Feb 2024 14:27:41 +0100 Subject: [PATCH 7/8] Remove hook and use onTransportFilterChanged. --- src/page-modules/assistant/layout.tsx | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/page-modules/assistant/layout.tsx b/src/page-modules/assistant/layout.tsx index 804aac58..973a4e87 100644 --- a/src/page-modules/assistant/layout.tsx +++ b/src/page-modules/assistant/layout.tsx @@ -50,7 +50,6 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { const [isPerformingSearchNavigation, setIsPerformingSearchNavigation] = useState(false); const [geolocationError, setGeolocationError] = useState(null); - const [defaultFilters, setDefaultFilters] = useState(null); // Loading the transport mode filter data here instead of in the component // avoids the data loading when the filter is mounted which causes the @@ -61,11 +60,12 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { ); useEffect(() => { - setDefaultFilters( - transportModeFilter - ?.filter((filter) => filter.id !== 'air') - .map((filter) => filter.id) ?? null, - ); + if (tripQuery.transportModeFilter === null) + onTransportFilterChanged( + transportModeFilter + ?.filter((filter) => filter.id !== 'air') + .map((filter) => filter.id) ?? null, + ); }, [transportModeFilter]); const setValuesWithLoading = async ( @@ -221,11 +221,7 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { >
From f06409f848c5e37f473aa6538cf19908d6b583bc Mon Sep 17 00:00:00 2001 From: Jonas Brunvoll Larsson Date: Wed, 28 Feb 2024 15:34:54 +0100 Subject: [PATCH 8/8] Updatet logic and test. --- .../filter/__tests__/filter.test.tsx | 10 ++++++- src/modules/transport-mode/filter/filter.tsx | 4 ++- src/page-modules/assistant/layout.tsx | 26 ++++++++++++------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/modules/transport-mode/filter/__tests__/filter.test.tsx b/src/modules/transport-mode/filter/__tests__/filter.test.tsx index 35d83609..894102d7 100644 --- a/src/modules/transport-mode/filter/__tests__/filter.test.tsx +++ b/src/modules/transport-mode/filter/__tests__/filter.test.tsx @@ -122,7 +122,15 @@ describe('transport mode filter', () => { const initial: string[] = []; - const expected = null; + const expected = [ + 'bus', + 'rail', + 'expressboat', + 'ferry', + 'airportbus', + 'air', + 'other', + ]; render( { - onChangeWrapper(event.target.checked ? null : []); + onChangeWrapper( + event.target.checked ? data?.map((option) => option.id) : [], + ); }} /> diff --git a/src/page-modules/assistant/layout.tsx b/src/page-modules/assistant/layout.tsx index 973a4e87..0dd850d5 100644 --- a/src/page-modules/assistant/layout.tsx +++ b/src/page-modules/assistant/layout.tsx @@ -59,15 +59,6 @@ function AssistantLayout({ children, tripQuery }: AssistantLayoutProps) { getTransportModeFilter, ); - useEffect(() => { - if (tripQuery.transportModeFilter === null) - onTransportFilterChanged( - transportModeFilter - ?.filter((filter) => filter.id !== 'air') - .map((filter) => filter.id) ?? null, - ); - }, [transportModeFilter]); - const setValuesWithLoading = async ( override: Partial, replace = false, @@ -131,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 =