From 1edbbb9d1e26b3de845ca1accce534aa1a8a0a25 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Tue, 29 Aug 2023 13:46:29 -0400 Subject: [PATCH 1/3] improvement(BatchSettings): Alert if user clicks Plan Trip when no OTP query will be issued. --- i18n/en-US.yml | 1 + i18n/fr.yml | 1 + lib/actions/api-constants.ts | 5 +++++ lib/actions/apiV2.js | 7 ++++++- lib/components/form/batch-settings.tsx | 12 +++++++++++- 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 lib/actions/api-constants.ts diff --git a/i18n/en-US.yml b/i18n/en-US.yml index 613156575..03d9611a4 100644 --- a/i18n/en-US.yml +++ b/i18n/en-US.yml @@ -227,6 +227,7 @@ components: modeSelectorLabel: Select a transit mode BatchSettings: destination: destination + invalidModeSelection: Cannot plan a trip using the selected modes. origin: origin planTripTooltip: Plan trip validationMessage: "Please define the following fields to plan a trip: {issues}" diff --git a/i18n/fr.yml b/i18n/fr.yml index 742db4275..326179282 100644 --- a/i18n/fr.yml +++ b/i18n/fr.yml @@ -238,6 +238,7 @@ components: modeSelectorLabel: Sélectionnez un mode de transport BatchSettings: destination: destination + invalidModeSelection: Impossible de planifier un trajet avec les modes sélectionnés. origin: point de départ planTripTooltip: Planifier le trajet validationMessage: >- diff --git a/lib/actions/api-constants.ts b/lib/actions/api-constants.ts new file mode 100644 index 000000000..b47743b9b --- /dev/null +++ b/lib/actions/api-constants.ts @@ -0,0 +1,5 @@ +export const RoutingQueryResult = { + INVALID_MODE_SELECTION: 2, + INVALID_QUERY: 1, + SUCCESS: 0 +} diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index 3b9eba694..5c82ec36a 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -41,6 +41,7 @@ import { updateOtpUrlParams } from './api' import { rememberPlace } from './user' +import { RoutingQueryResult } from './api-constants' import { setItineraryView } from './ui' import { zoomToPlace } from './map' @@ -840,7 +841,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) { // Don't permit a routing query if the query is invalid if (!queryIsValid(state)) { console.warn('Query is invalid. Aborting routing query', currentQuery) - return + return RoutingQueryResult.INVALID_QUERY } const { @@ -1007,6 +1008,10 @@ export function routingQuery(searchId = null, updateSearchInReducer) { if (isNewSearch || params.ui_activeSearch !== searchId) { dispatch(updateOtpUrlParams(state, searchId)) } + + return combinations.length === 0 + ? RoutingQueryResult.INVALID_MODE_SELECTION + : RoutingQueryResult.SUCCESS } } diff --git a/lib/components/form/batch-settings.tsx b/lib/components/form/batch-settings.tsx index 6cc65fce4..c005d05a1 100644 --- a/lib/components/form/batch-settings.tsx +++ b/lib/components/form/batch-settings.tsx @@ -26,6 +26,7 @@ import { ComponentContext } from '../../util/contexts' import { generateModeSettingValues } from '../../util/api' import { getActiveSearch, hasValidLocation } from '../../util/state' import { getFormattedMode } from '../../util/i18n' +import { RoutingQueryResult } from '../../actions/api-constants' import { StyledIconWrapper } from '../util/styledIcon' import { @@ -165,7 +166,16 @@ function BatchSettings({ // Plan trip. updateQueryTimeIfLeavingNow() - routingQuery() + const routingQueryResult = routingQuery() + + // If mode combination is not valid (i.e. produced no query), alert the user. + if (routingQueryResult === RoutingQueryResult.INVALID_MODE_SELECTION) { + window.alert( + intl.formatMessage({ + id: 'components.BatchSettings.invalidModeSelection' + }) + ) + } }, [ currentQuery, intl, From c72cbc70eeb78434188d524794b78dd25c406370 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:33:11 -0400 Subject: [PATCH 2/3] chore(i18n): Add transit suggestion after invalid mode combination. --- i18n/en-US.yml | 4 +++- i18n/fr.yml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/i18n/en-US.yml b/i18n/en-US.yml index 03d9611a4..1e94f00ad 100644 --- a/i18n/en-US.yml +++ b/i18n/en-US.yml @@ -227,7 +227,9 @@ components: modeSelectorLabel: Select a transit mode BatchSettings: destination: destination - invalidModeSelection: Cannot plan a trip using the selected modes. + invalidModeSelection: >- + Cannot plan a trip using the selected modes. Try including transit in your + mode selection. origin: origin planTripTooltip: Plan trip validationMessage: "Please define the following fields to plan a trip: {issues}" diff --git a/i18n/fr.yml b/i18n/fr.yml index 326179282..515b81b79 100644 --- a/i18n/fr.yml +++ b/i18n/fr.yml @@ -238,7 +238,9 @@ components: modeSelectorLabel: Sélectionnez un mode de transport BatchSettings: destination: destination - invalidModeSelection: Impossible de planifier un trajet avec les modes sélectionnés. + invalidModeSelection: >- + Impossible de planifier un trajet avec les modes sélectionnés. Réessayez + en ajoutant les transports publics. origin: point de départ planTripTooltip: Planifier le trajet validationMessage: >- From 8a0e6c906d37de4c0a8359da6fde1f7d77544b44 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:34:53 -0400 Subject: [PATCH 3/3] refactor(api-constants): Rename RoutingQueryResult => RoutingQueryCallResult per PR feedback --- lib/actions/api-constants.ts | 2 +- lib/actions/apiV2.js | 8 ++++---- lib/components/form/batch-settings.tsx | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/actions/api-constants.ts b/lib/actions/api-constants.ts index b47743b9b..bfa917885 100644 --- a/lib/actions/api-constants.ts +++ b/lib/actions/api-constants.ts @@ -1,4 +1,4 @@ -export const RoutingQueryResult = { +export const RoutingQueryCallResult = { INVALID_MODE_SELECTION: 2, INVALID_QUERY: 1, SUCCESS: 0 diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index 5c82ec36a..74d0e53d1 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -41,7 +41,7 @@ import { updateOtpUrlParams } from './api' import { rememberPlace } from './user' -import { RoutingQueryResult } from './api-constants' +import { RoutingQueryCallResult } from './api-constants' import { setItineraryView } from './ui' import { zoomToPlace } from './map' @@ -841,7 +841,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) { // Don't permit a routing query if the query is invalid if (!queryIsValid(state)) { console.warn('Query is invalid. Aborting routing query', currentQuery) - return RoutingQueryResult.INVALID_QUERY + return RoutingQueryCallResult.INVALID_QUERY } const { @@ -1010,8 +1010,8 @@ export function routingQuery(searchId = null, updateSearchInReducer) { } return combinations.length === 0 - ? RoutingQueryResult.INVALID_MODE_SELECTION - : RoutingQueryResult.SUCCESS + ? RoutingQueryCallResult.INVALID_MODE_SELECTION + : RoutingQueryCallResult.SUCCESS } } diff --git a/lib/components/form/batch-settings.tsx b/lib/components/form/batch-settings.tsx index c005d05a1..15e3f95e8 100644 --- a/lib/components/form/batch-settings.tsx +++ b/lib/components/form/batch-settings.tsx @@ -26,7 +26,7 @@ import { ComponentContext } from '../../util/contexts' import { generateModeSettingValues } from '../../util/api' import { getActiveSearch, hasValidLocation } from '../../util/state' import { getFormattedMode } from '../../util/i18n' -import { RoutingQueryResult } from '../../actions/api-constants' +import { RoutingQueryCallResult } from '../../actions/api-constants' import { StyledIconWrapper } from '../util/styledIcon' import { @@ -169,7 +169,7 @@ function BatchSettings({ const routingQueryResult = routingQuery() // If mode combination is not valid (i.e. produced no query), alert the user. - if (routingQueryResult === RoutingQueryResult.INVALID_MODE_SELECTION) { + if (routingQueryResult === RoutingQueryCallResult.INVALID_MODE_SELECTION) { window.alert( intl.formatMessage({ id: 'components.BatchSettings.invalidModeSelection'