From 77c455d733cf9d5a9ee4f6d88295d92ab975d8b7 Mon Sep 17 00:00:00 2001 From: amy-corson-ibigroup <115499534+amy-corson-ibigroup@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:22:06 -0600 Subject: [PATCH 01/11] feat(routingQuery): Add banned routes to routing query --- lib/actions/apiV2.js | 8 +++++++- lib/components/form/batch-settings.tsx | 14 ++++++++++---- lib/reducers/create-otp-reducer.js | 10 ++++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index 5bca59ad8..03fbade87 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -1,5 +1,6 @@ import { aggregateModes, + getBannedRoutesFromSubmodes, populateSettingWithValue } from '@opentripplanner/trip-form' import { createAction } from 'redux-actions' @@ -909,7 +910,6 @@ export function routingQuery(searchId = null, updateSearchInReducer) { const modeSettings = modeSettingDefinitions?.map( populateSettingWithValue(modeSettingValues) ) - // Get the raw query param strings to save for the rider's search history const rawModeButtonQP = urlSearchParams.get('modeButtons') const queryParamData = { @@ -917,9 +917,15 @@ export function routingQuery(searchId = null, updateSearchInReducer) { ...modeSettingValues } + const excludedRoutes = getBannedRoutesFromSubmodes( + modeSettings, + config.routeModeOverrides + ).toString() + const baseQuery = { arriveBy, banned: { + routes: excludedRoutes || undefined, trips: bannedTrips }, date, diff --git a/lib/components/form/batch-settings.tsx b/lib/components/form/batch-settings.tsx index 15e3f95e8..962588ca8 100644 --- a/lib/components/form/batch-settings.tsx +++ b/lib/components/form/batch-settings.tsx @@ -115,13 +115,19 @@ function BatchSettings({ ) const addCustomSettingLabels = useCallback( - (msd: ModeSetting) => - msd.type === 'SUBMODE' + (msd: ModeSetting) => { + let modeLabel + // If we're using route mode overrides, make sure we're using the custom mode name + if (msd.type === 'SUBMODE') { + modeLabel = msd.modeOverride || msd.addTransportMode.mode + } + return msd.type === 'SUBMODE' ? { ...msd, - label: getFormattedMode(msd.addTransportMode.mode, intl) + label: getFormattedMode(modeLabel, intl) } - : msd, + : msd + }, [intl] ) diff --git a/lib/reducers/create-otp-reducer.js b/lib/reducers/create-otp-reducer.js index 472598ab7..aed8c54ad 100644 --- a/lib/reducers/create-otp-reducer.js +++ b/lib/reducers/create-otp-reducer.js @@ -137,13 +137,19 @@ export function getInitialState(userDefinedConfig) { } const transitModeSettings = config?.modes?.transitModes.map((transitMode) => { - const { mode } = transitMode + const { gtfsMode, mode } = transitMode + /** + * If we're using custom route mode overrides, we pass both the + * custom mode name (mode) and the gtfs mode to the modeSetting. + */ + const modeSetting = gtfsMode || mode return { - addTransportMode: { mode }, + addTransportMode: { mode: modeSetting }, applicableMode: 'TRANSIT', default: true, iconName: mode.toLowerCase(), key: mode.toLowerCase(), + modeOverride: gtfsMode && mode, type: 'SUBMODE' } }) From 668b074cede931b31bc34045c198ac081f8acdb6 Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Wed, 24 Jan 2024 15:31:32 -0800 Subject: [PATCH 02/11] implement changes for overridemode support --- lib/actions/apiV2.js | 1 + lib/components/form/batch-settings.tsx | 13 ++++++------- lib/reducers/create-otp-reducer.js | 18 ++++++++---------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index 03fbade87..cdb1e445d 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -921,6 +921,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) { modeSettings, config.routeModeOverrides ).toString() + console.log(excludedRoutes) const baseQuery = { arriveBy, diff --git a/lib/components/form/batch-settings.tsx b/lib/components/form/batch-settings.tsx index 962588ca8..2ed424732 100644 --- a/lib/components/form/batch-settings.tsx +++ b/lib/components/form/batch-settings.tsx @@ -119,14 +119,13 @@ function BatchSettings({ let modeLabel // If we're using route mode overrides, make sure we're using the custom mode name if (msd.type === 'SUBMODE') { - modeLabel = msd.modeOverride || msd.addTransportMode.mode + modeLabel = msd.overrideMode || msd.addTransportMode.mode + return { + ...msd, + label: getFormattedMode(modeLabel, intl) + } } - return msd.type === 'SUBMODE' - ? { - ...msd, - label: getFormattedMode(modeLabel, intl) - } - : msd + return msd }, [intl] ) diff --git a/lib/reducers/create-otp-reducer.js b/lib/reducers/create-otp-reducer.js index aed8c54ad..7f69d8dfd 100644 --- a/lib/reducers/create-otp-reducer.js +++ b/lib/reducers/create-otp-reducer.js @@ -137,19 +137,17 @@ export function getInitialState(userDefinedConfig) { } const transitModeSettings = config?.modes?.transitModes.map((transitMode) => { - const { gtfsMode, mode } = transitMode - /** - * If we're using custom route mode overrides, we pass both the - * custom mode name (mode) and the gtfs mode to the modeSetting. - */ - const modeSetting = gtfsMode || mode + const { mode, overrideMode } = transitMode + const displayedMode = overrideMode || mode return { - addTransportMode: { mode: modeSetting }, + // This is the mode that gets added to the actual query to OTP + addTransportMode: { mode }, applicableMode: 'TRANSIT', default: true, - iconName: mode.toLowerCase(), - key: mode.toLowerCase(), - modeOverride: gtfsMode && mode, + iconName: displayedMode.toLowerCase(), + key: displayedMode.toLowerCase(), + // This overrideMode is used in case we need to filter routes out based on their overrideMode + overrideMode, type: 'SUBMODE' } }) From d47c9d6a9133bb1344d670a1704c12ba3940fb7b Mon Sep 17 00:00:00 2001 From: amy-corson-ibigroup <115499534+amy-corson-ibigroup@users.noreply.github.com> Date: Mon, 29 Jan 2024 14:19:15 -0600 Subject: [PATCH 03/11] replace toString with join --- lib/actions/apiV2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index cdb1e445d..e1fed2368 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -920,7 +920,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) { const excludedRoutes = getBannedRoutesFromSubmodes( modeSettings, config.routeModeOverrides - ).toString() + ).join(',') console.log(excludedRoutes) const baseQuery = { From b51769c80034da095adb02512657ef6d091ee3e5 Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Tue, 30 Jan 2024 13:16:22 -0800 Subject: [PATCH 04/11] fix sticky highlighted location --- lib/components/viewers/nearby/nearby-view.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/components/viewers/nearby/nearby-view.tsx b/lib/components/viewers/nearby/nearby-view.tsx index cdef99974..717fac30c 100644 --- a/lib/components/viewers/nearby/nearby-view.tsx +++ b/lib/components/viewers/nearby/nearby-view.tsx @@ -115,6 +115,13 @@ function NearbyView({ setLocation(payload) } + // Make sure the highlighted location is cleaned up when leaving nearby + useEffect(() => { + return function cleanup() { + setHighlightedLocation(null) + } + }) + useEffect(() => { const listener = (e: any) => { if (e.geolocateSource) { From 3cf1d70102be2f7fdae2316673c9ee6f344b5cfe Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Tue, 30 Jan 2024 15:17:06 -0800 Subject: [PATCH 05/11] fix crash on no OTP server --- lib/components/viewers/nearby/nearby-view.tsx | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/components/viewers/nearby/nearby-view.tsx b/lib/components/viewers/nearby/nearby-view.tsx index 717fac30c..66466f2ee 100644 --- a/lib/components/viewers/nearby/nearby-view.tsx +++ b/lib/components/viewers/nearby/nearby-view.tsx @@ -183,26 +183,29 @@ function NearbyView({ setHighlightedLocation(null) }, [setHighlightedLocation]) - const nearbyItemList = nearby?.map((n: any) => ( -
  • - {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */} -
    onMouseEnter(n.place)} - onMouseEnter={() => onMouseEnter(n.place)} - onMouseLeave={onMouseLeave} - /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */ - tabIndex={0} + const nearbyItemList = + nearby?.map && + nearby?.map((n: any) => ( +
  • - {getNearbyItem(n.place, onClickSetLocation)} - -
  • - )) + {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */} +
    onMouseEnter(n.place)} + onMouseEnter={() => onMouseEnter(n.place)} + onMouseLeave={onMouseLeave} + /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */ + tabIndex={0} + > + {getNearbyItem(n.place, onClickSetLocation)} +
    + + )) + useEffect(() => { setLoading(false) }, [nearby]) From abdcfc4bd23715ba610b5b583a0af2c52bc3d86b Mon Sep 17 00:00:00 2001 From: amy-corson-ibigroup <115499534+amy-corson-ibigroup@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:05:24 -0600 Subject: [PATCH 06/11] fix(DropdownOptions): Pass onChange to Field only when it exists --- .../user/common/dropdown-options.tsx | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/components/user/common/dropdown-options.tsx b/lib/components/user/common/dropdown-options.tsx index 42ef7524f..be110d936 100644 --- a/lib/components/user/common/dropdown-options.tsx +++ b/lib/components/user/common/dropdown-options.tsx @@ -22,22 +22,29 @@ export const Select = ({ label, name, onChange -}: SelectProps): JSX.Element => ( - // is kept outside of