From fb610b7322baec702b9d886af5872ebd19c6cef0 Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:09:24 -0500 Subject: [PATCH 01/13] feat(advanced-settings-panel): turn off mode if all submode settings are false --- .../form/advanced-settings-panel.tsx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/components/form/advanced-settings-panel.tsx b/lib/components/form/advanced-settings-panel.tsx index a76b3f85d..ad29c7b94 100644 --- a/lib/components/form/advanced-settings-panel.tsx +++ b/lib/components/form/advanced-settings-panel.tsx @@ -168,13 +168,34 @@ const AdvancedSettingsPanel = ({ ) const processedModeSettings = processSettings(modeSettingDefinitions) + + const checkAllSubsettingsFalse = (modeButton: ModeButtonDefinition) => { + if (modeButton.modeSettings && modeButton.modeSettings.length > 0) { + const transportModeSettings = modeButton.modeSettings.filter( + (setting: ModeSetting) => + // this checks if the setting is a transport mode + (setting.type === 'CHECKBOX' || setting.type === 'SUBMODE') && + setting.addTransportMode + ) + if (transportModeSettings.length === 0) return modeButton + + console.log('transportModeSettings::::::', transportModeSettings) + const allFalse = transportModeSettings.every((setting) => !setting.value) + return { ...modeButton, enabled: modeButton.enabled && !allFalse } + } + + return modeButton + } + const processedModeButtons = modeButtonOptions.map( pipe( addModeButtonIcon(ModeIcon), addSettingsToButton(processedModeSettings), - setModeButtonEnabled(enabledModeButtons) + setModeButtonEnabled(enabledModeButtons), + checkAllSubsettingsFalse ) ) + console.log('processedModeButtons::::::', processedModeButtons) return ( From e593dea94f1c370d551f8f426e186488bbb32a04 Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:05:47 -0500 Subject: [PATCH 02/13] fix(advanced-settings-panel): stop infinite loops on rerender --- .../form/advanced-settings-panel.tsx | 73 +++++++++++++------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/lib/components/form/advanced-settings-panel.tsx b/lib/components/form/advanced-settings-panel.tsx index ad29c7b94..79c4057a5 100644 --- a/lib/components/form/advanced-settings-panel.tsx +++ b/lib/components/form/advanced-settings-panel.tsx @@ -15,7 +15,7 @@ import { ModeSetting, ModeSettingValues } from '@opentripplanner/types' -import React, { RefObject, useContext, useState } from 'react' +import React, { RefObject, useContext, useEffect, useState } from 'react' import styled from 'styled-components' import * as formActions from '../../actions/form' @@ -168,35 +168,59 @@ const AdvancedSettingsPanel = ({ ) const processedModeSettings = processSettings(modeSettingDefinitions) + // console.log('processedModeSettings::::', processedModeSettings) - const checkAllSubsettingsFalse = (modeButton: ModeButtonDefinition) => { - if (modeButton.modeSettings && modeButton.modeSettings.length > 0) { - const transportModeSettings = modeButton.modeSettings.filter( - (setting: ModeSetting) => - // this checks if the setting is a transport mode - (setting.type === 'CHECKBOX' || setting.type === 'SUBMODE') && - setting.addTransportMode - ) - if (transportModeSettings.length === 0) return modeButton - - console.log('transportModeSettings::::::', transportModeSettings) - const allFalse = transportModeSettings.every((setting) => !setting.value) - return { ...modeButton, enabled: modeButton.enabled && !allFalse } - } - - return modeButton - } + const handleModeButtonToggle = setModeButton( + enabledModeButtons, + onSettingsUpdate(setQueryParam) + ) const processedModeButtons = modeButtonOptions.map( pipe( addModeButtonIcon(ModeIcon), addSettingsToButton(processedModeSettings), - setModeButtonEnabled(enabledModeButtons), - checkAllSubsettingsFalse + setModeButtonEnabled(enabledModeButtons) ) ) console.log('processedModeButtons::::::', processedModeButtons) + useEffect(() => { + console.log('processedModeButtons CHANGED!!! ::::::', processedModeButtons) + const checkTransportModeSubsettings = ( + modeButton: ModeButtonDefinition + ) => { + if ( + modeButton.enabled && + modeButton.modeSettings && + modeButton.modeSettings.length > 0 + ) { + const transportModeSettings = modeButton.modeSettings.filter( + (setting: ModeSetting) => + (setting.type === 'CHECKBOX' || setting.type === 'SUBMODE') && + setting.addTransportMode + ) + if (transportModeSettings.length === 0) return modeButton + + const allFalse = transportModeSettings.every( + (setting) => !setting.value + ) + if (allFalse) { + console.log( + 'subsettings are all false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + ) + modeButton.enabled = false + handleModeButtonToggle(modeButton.key, false) + return modeButton + } + return { ...modeButton, enabled: modeButton.enabled && !allFalse } + } + + return modeButton + } + + processedModeButtons.map(pipe(checkTransportModeSubsettings)) + }, [processedModeButtons, handleModeButtonToggle]) + return ( @@ -235,10 +259,7 @@ const AdvancedSettingsPanel = ({ label="test" modeButtons={processedModeButtons} onSettingsUpdate={onSettingsUpdate(setQueryParam)} - onToggleModeButton={setModeButton( - enabledModeButtons, - onSettingsUpdate(setQueryParam) - )} + onToggleModeButton={handleModeButtonToggle} /> { + /* console.log( + 'state.otp.modeSettingDefinitions::::', + state.otp.modeSettingDefinitions + ) */ const urlSearchParams = new URLSearchParams(state.router.location.search) const modeSettingValues = generateModeSettingValues( urlSearchParams, From 96d238105fd0db6bbd0ce72f2bc042487797f0d6 Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Thu, 29 Aug 2024 13:50:50 -0500 Subject: [PATCH 03/13] fix(advanced-settings-panel): start trying to use url search params to reset to default values --- .../form/advanced-settings-panel.tsx | 50 +++++++++++++------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/components/form/advanced-settings-panel.tsx b/lib/components/form/advanced-settings-panel.tsx index 79c4057a5..4985d8767 100644 --- a/lib/components/form/advanced-settings-panel.tsx +++ b/lib/components/form/advanced-settings-panel.tsx @@ -15,6 +15,7 @@ import { ModeSetting, ModeSettingValues } from '@opentripplanner/types' +import { QueryParamChangeEvent } from '@opentripplanner/trip-form/lib/types' import React, { RefObject, useContext, useEffect, useState } from 'react' import styled from 'styled-components' @@ -118,7 +119,8 @@ const AdvancedSettingsPanel = ({ modeButtonOptions, modeSettingDefinitions, modeSettingValues, - setQueryParam + setQueryParam, + urlSearchParams }: { closeAdvancedSettings: () => void enabledModeButtons: string[] @@ -127,7 +129,8 @@ const AdvancedSettingsPanel = ({ modeSettingDefinitions: ModeSetting[] modeSettingValues: ModeSettingValues onPlanTripClick: () => void - setQueryParam: (evt: any) => void + setQueryParam: (evt: QueryParamChangeEvent) => void + urlSearchParams: URLSearchParams }): JSX.Element => { const [closingBySave, setClosingBySave] = useState(false) const [closingByX, setClosingByX] = useState(false) @@ -189,11 +192,7 @@ const AdvancedSettingsPanel = ({ const checkTransportModeSubsettings = ( modeButton: ModeButtonDefinition ) => { - if ( - modeButton.enabled && - modeButton.modeSettings && - modeButton.modeSettings.length > 0 - ) { + if (modeButton.modeSettings && modeButton.modeSettings.length > 0) { const transportModeSettings = modeButton.modeSettings.filter( (setting: ModeSetting) => (setting.type === 'CHECKBOX' || setting.type === 'SUBMODE') && @@ -204,14 +203,31 @@ const AdvancedSettingsPanel = ({ const allFalse = transportModeSettings.every( (setting) => !setting.value ) - if (allFalse) { + // modeButton is enabled, but all of its subsettings are false + if (allFalse && enabledModeButtons.includes(modeButton.key)) { + console.log('button on -> off') + modeButton.enabled = false console.log( - 'subsettings are all false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + 'before delete urlSerchParams::::: ', + urlSearchParams.toString() + ) + urlSearchParams.forEach((value, key) => { + console.log('key:::::::::', key) + if (transportModeSettings.some((setting) => setting.key === key)) { + console.log('deleting key:::::::::', key) + urlSearchParams.delete(key) + } + }) + console.log( + 'after delete urlSerchParams::::: ', + urlSearchParams.toString() ) - modeButton.enabled = false handleModeButtonToggle(modeButton.key, false) + console.log('transportModeSettings:::::::::', transportModeSettings) + return modeButton } + return { ...modeButton, enabled: modeButton.enabled && !allFalse } } @@ -219,7 +235,12 @@ const AdvancedSettingsPanel = ({ } processedModeButtons.map(pipe(checkTransportModeSubsettings)) - }, [processedModeButtons, handleModeButtonToggle]) + }, [ + processedModeButtons, + handleModeButtonToggle, + enabledModeButtons, + urlSearchParams + ]) return ( @@ -284,10 +305,6 @@ const AdvancedSettingsPanel = ({ const queryParamConfig = { modeButtons: DelimitedArrayParam } const mapStateToProps = (state: AppReduxState) => { - /* console.log( - 'state.otp.modeSettingDefinitions::::', - state.otp.modeSettingDefinitions - ) */ const urlSearchParams = new URLSearchParams(state.router.location.search) const modeSettingValues = generateModeSettingValues( urlSearchParams, @@ -305,7 +322,8 @@ const mapStateToProps = (state: AppReduxState) => { [], modeButtonOptions: state.otp.config?.modes?.modeButtons || [], modeSettingDefinitions: state.otp?.modeSettingDefinitions || [], - modeSettingValues + modeSettingValues, + urlSearchParams } } From 2c8b84c0fc0eeb0c45d379662513f320f1d930c0 Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Thu, 29 Aug 2024 17:34:07 -0500 Subject: [PATCH 04/13] feat(form): create deleteQueryParams function --- lib/actions/form.js | 16 ++++++++++++ .../form/advanced-settings-panel.tsx | 25 +++++-------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/actions/form.js b/lib/actions/form.js index bfdc65fe7..4eecdb428 100644 --- a/lib/actions/form.js +++ b/lib/actions/form.js @@ -80,6 +80,22 @@ export function setQueryParam(payload, searchId) { } } +/** + * Deletes the specified query parameter from the current query and updates the + * application state accordingly. + */ +export function deleteQueryParams(params) { + return function (dispatch, getState) { + const state = getState() + const { currentQuery } = state.otp + const newQuery = Object.assign({}, currentQuery) + params.forEach((param) => { + delete newQuery[param] + }) + dispatch(settingQueryParam(newQuery)) + } +} + /** * An action that parses the active URL's query params (or whatever is passed in) * and updates the state with the OTP plan query params. A new search will be diff --git a/lib/components/form/advanced-settings-panel.tsx b/lib/components/form/advanced-settings-panel.tsx index 4985d8767..863aeb3c3 100644 --- a/lib/components/form/advanced-settings-panel.tsx +++ b/lib/components/form/advanced-settings-panel.tsx @@ -114,6 +114,7 @@ const DtSelectorContainer = styled.div` const AdvancedSettingsPanel = ({ closeAdvancedSettings, + deleteQueryParams, enabledModeButtons, innerRef, modeButtonOptions, @@ -123,6 +124,7 @@ const AdvancedSettingsPanel = ({ urlSearchParams }: { closeAdvancedSettings: () => void + deleteQueryParams: (params: string[]) => void enabledModeButtons: string[] innerRef: RefObject modeButtonOptions: ModeButtonDefinition[] @@ -205,25 +207,9 @@ const AdvancedSettingsPanel = ({ ) // modeButton is enabled, but all of its subsettings are false if (allFalse && enabledModeButtons.includes(modeButton.key)) { - console.log('button on -> off') - modeButton.enabled = false - console.log( - 'before delete urlSerchParams::::: ', - urlSearchParams.toString() - ) - urlSearchParams.forEach((value, key) => { - console.log('key:::::::::', key) - if (transportModeSettings.some((setting) => setting.key === key)) { - console.log('deleting key:::::::::', key) - urlSearchParams.delete(key) - } - }) - console.log( - 'after delete urlSerchParams::::: ', - urlSearchParams.toString() - ) + console.log('all keys:::::', Object.keys(transportModeSettings)) + deleteQueryParams(Object.keys(transportModeSettings)) handleModeButtonToggle(modeButton.key, false) - console.log('transportModeSettings:::::::::', transportModeSettings) return modeButton } @@ -239,7 +225,7 @@ const AdvancedSettingsPanel = ({ processedModeButtons, handleModeButtonToggle, enabledModeButtons, - urlSearchParams + deleteQueryParams ]) return ( @@ -328,6 +314,7 @@ const mapStateToProps = (state: AppReduxState) => { } const mapDispatchToProps = { + deleteQueryParams: formActions.deleteQueryParams, setQueryParam: formActions.setQueryParam, updateQueryTimeIfLeavingNow: formActions.updateQueryTimeIfLeavingNow } From 2e43af4267d4fda5a9933c614f88342883963242 Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:43:42 -0500 Subject: [PATCH 05/13] fix(advanced-trip-form): get correct param keys --- lib/components/form/advanced-settings-panel.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/components/form/advanced-settings-panel.tsx b/lib/components/form/advanced-settings-panel.tsx index 863aeb3c3..41382acbb 100644 --- a/lib/components/form/advanced-settings-panel.tsx +++ b/lib/components/form/advanced-settings-panel.tsx @@ -207,8 +207,11 @@ const AdvancedSettingsPanel = ({ ) // modeButton is enabled, but all of its subsettings are false if (allFalse && enabledModeButtons.includes(modeButton.key)) { - console.log('all keys:::::', Object.keys(transportModeSettings)) - deleteQueryParams(Object.keys(transportModeSettings)) + console.log( + 'all keys:::::', + transportModeSettings.map((setting) => setting.key) + ) + deleteQueryParams(transportModeSettings.map((setting) => setting.key)) handleModeButtonToggle(modeButton.key, false) return modeButton From 65f146eabbe09b120610abcf42c6f3b6f88ed329 Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:54:30 -0500 Subject: [PATCH 06/13] fix(util): disable mode button if all subsettings are false and reset values of all subsettings --- lib/actions/form.js | 16 ----- .../form/advanced-settings-panel.tsx | 60 +++--------------- lib/components/form/util.tsx | 61 ++++++++++++++++++- 3 files changed, 69 insertions(+), 68 deletions(-) diff --git a/lib/actions/form.js b/lib/actions/form.js index 4eecdb428..bfdc65fe7 100644 --- a/lib/actions/form.js +++ b/lib/actions/form.js @@ -80,22 +80,6 @@ export function setQueryParam(payload, searchId) { } } -/** - * Deletes the specified query parameter from the current query and updates the - * application state accordingly. - */ -export function deleteQueryParams(params) { - return function (dispatch, getState) { - const state = getState() - const { currentQuery } = state.otp - const newQuery = Object.assign({}, currentQuery) - params.forEach((param) => { - delete newQuery[param] - }) - dispatch(settingQueryParam(newQuery)) - } -} - /** * An action that parses the active URL's query params (or whatever is passed in) * and updates the state with the OTP plan query params. A new search will be diff --git a/lib/components/form/advanced-settings-panel.tsx b/lib/components/form/advanced-settings-panel.tsx index 41382acbb..ab83513be 100644 --- a/lib/components/form/advanced-settings-panel.tsx +++ b/lib/components/form/advanced-settings-panel.tsx @@ -29,6 +29,7 @@ import PageTitle from '../util/page-title' import { addCustomSettingLabels, addModeButtonIcon, + onAdvancedModeSubsettingsUpdate, onSettingsUpdate, pipe, populateSettingWithIcon, @@ -114,7 +115,6 @@ const DtSelectorContainer = styled.div` const AdvancedSettingsPanel = ({ closeAdvancedSettings, - deleteQueryParams, enabledModeButtons, innerRef, modeButtonOptions, @@ -124,7 +124,6 @@ const AdvancedSettingsPanel = ({ urlSearchParams }: { closeAdvancedSettings: () => void - deleteQueryParams: (params: string[]) => void enabledModeButtons: string[] innerRef: RefObject modeButtonOptions: ModeButtonDefinition[] @@ -173,12 +172,6 @@ const AdvancedSettingsPanel = ({ ) const processedModeSettings = processSettings(modeSettingDefinitions) - // console.log('processedModeSettings::::', processedModeSettings) - - const handleModeButtonToggle = setModeButton( - enabledModeButtons, - onSettingsUpdate(setQueryParam) - ) const processedModeButtons = modeButtonOptions.map( pipe( @@ -187,49 +180,11 @@ const AdvancedSettingsPanel = ({ setModeButtonEnabled(enabledModeButtons) ) ) - console.log('processedModeButtons::::::', processedModeButtons) - - useEffect(() => { - console.log('processedModeButtons CHANGED!!! ::::::', processedModeButtons) - const checkTransportModeSubsettings = ( - modeButton: ModeButtonDefinition - ) => { - if (modeButton.modeSettings && modeButton.modeSettings.length > 0) { - const transportModeSettings = modeButton.modeSettings.filter( - (setting: ModeSetting) => - (setting.type === 'CHECKBOX' || setting.type === 'SUBMODE') && - setting.addTransportMode - ) - if (transportModeSettings.length === 0) return modeButton - - const allFalse = transportModeSettings.every( - (setting) => !setting.value - ) - // modeButton is enabled, but all of its subsettings are false - if (allFalse && enabledModeButtons.includes(modeButton.key)) { - console.log( - 'all keys:::::', - transportModeSettings.map((setting) => setting.key) - ) - deleteQueryParams(transportModeSettings.map((setting) => setting.key)) - handleModeButtonToggle(modeButton.key, false) - - return modeButton - } - return { ...modeButton, enabled: modeButton.enabled && !allFalse } - } - - return modeButton - } - - processedModeButtons.map(pipe(checkTransportModeSubsettings)) - }, [ - processedModeButtons, - handleModeButtonToggle, + const handleModeButtonToggle = setModeButton( enabledModeButtons, - deleteQueryParams - ]) + onSettingsUpdate(setQueryParam) + ) return ( @@ -268,7 +223,11 @@ const AdvancedSettingsPanel = ({ fillModeIcons label="test" modeButtons={processedModeButtons} - onSettingsUpdate={onSettingsUpdate(setQueryParam)} + onSettingsUpdate={onAdvancedModeSubsettingsUpdate( + setQueryParam, + processedModeButtons, + handleModeButtonToggle + )} onToggleModeButton={handleModeButtonToggle} /> { } const mapDispatchToProps = { - deleteQueryParams: formActions.deleteQueryParams, setQueryParam: formActions.setQueryParam, updateQueryTimeIfLeavingNow: formActions.updateQueryTimeIfLeavingNow } diff --git a/lib/components/form/util.tsx b/lib/components/form/util.tsx index 23b5ab8fe..9cb6ad1d7 100644 --- a/lib/components/form/util.tsx +++ b/lib/components/form/util.tsx @@ -56,16 +56,75 @@ export const onSettingsUpdate = setQueryParam({ queryParamData: params, ...params }) } +const getModeButtonFromSubmode = ( + key: string, + modeButtons: ModeButtonDefinition[] +): ModeButtonDefinition | undefined => { + return modeButtons.find((button: ModeButtonDefinition) => { + if (button.modeSettings) { + return button.modeSettings.some((setting: ModeSetting) => { + // check if transport mode + if ( + (setting.type === 'CHECKBOX' || setting.type === 'SUBMODE') && + setting.addTransportMode + ) { + return setting.key === key + } + return false + }) + } + return false + }) +} + +export const onAdvancedModeSubsettingsUpdate = + ( + setQueryParam: (evt: any) => void, + processedModeButtons: ModeButtonDefinition[], + handleModeButtonToggle: (buttonId: string, newState: boolean) => void + ) => + (params: any) => { + // check if setting is a transport mode and get the mode button that contains it + const modeButton = getModeButtonFromSubmode( + Object.keys(params)[0], + processedModeButtons + ) + if (modeButton && modeButton.modeSettings && !Object.values(params)[0]) { + const transportModeSettings = modeButton.modeSettings.filter( + (setting: ModeSetting) => + (setting.type === 'CHECKBOX' || setting.type === 'SUBMODE') && + setting.addTransportMode + ) + // if we're disabling a transport mode, we need to check if the mode button needs to be disabled (all of its subsettings are false) + const allFalse = transportModeSettings.every((setting: ModeSetting) => { + if (setting.key === Object.keys(params)[0]) { + return !Object.values(params)[0] + } + return !setting.value + }) + if (allFalse) { + transportModeSettings.forEach((setting) => (params[setting.key] = true)) + handleModeButtonToggle(modeButton.key, false) + } + } + setQueryParam({ queryParamData: params, ...params }) + } + export const setModeButton = (enabledModeButtons: string[], updateHandler: (params: any) => void) => (buttonId: string, newState: boolean) => { + console.log('SET MODE BUTTON IS BEING CALLED. NEW STATE:::: ', newState) let newButtons + if (newState) { + // enable modeButton + // we need to add it to the list of enabled buttons newButtons = [...enabledModeButtons, buttonId] } else { + // disable modeButton + // we need to remove it from the list of enabled buttons newButtons = enabledModeButtons.filter((c) => c !== buttonId) } - // encodeQueryParams serializes the mode buttons for the URL // to get nice looking URL params and consistency updateHandler( From f24376bea7157f9512eda7e3b32bee4c3277e30f Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:21:56 -0500 Subject: [PATCH 07/13] update yarn lock --- yarn.lock | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/yarn.lock b/yarn.lock index 634ff87b2..a9dca0a61 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2416,6 +2416,24 @@ lodash.isequal "^4.5.0" qs "^6.9.1" +"@opentripplanner/core-utils@^11.4.1": + version "11.4.4" + resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-11.4.4.tgz#11c1be91a5e90afda4fc265831c761d3e044d933" + integrity sha512-WKhOuG7Q+Yxdm+P5MPmJyXndx+JUtGn44GTeilOnUqDdO8lTLTvqqt0hYeEWjA77jWP0u8tG7fAAsft8IZn2cg== + dependencies: + "@conveyal/lonlat" "^1.4.1" + "@mapbox/polyline" "^1.1.0" + "@opentripplanner/geocoder" "^3.0.2" + "@styled-icons/foundation" "^10.34.0" + "@turf/along" "^6.0.1" + chroma-js "^2.4.2" + date-fns "^2.28.0" + date-fns-tz "^1.2.2" + graphql "^16.6.0" + lodash.clonedeep "^4.5.0" + lodash.isequal "^4.5.0" + qs "^6.9.1" + "@opentripplanner/core-utils@^11.4.3": version "11.4.3" resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-11.4.3.tgz#4655f9a3bef1977e53abd81a4a0eae966f977c60" @@ -2465,6 +2483,17 @@ isomorphic-mapzen-search "^1.6.1" lodash.memoize "^4.1.2" +"@opentripplanner/geocoder@^3.0.2": + version "3.0.2" + resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-3.0.2.tgz#2c7618947d1d9b082bd39d037327c9cf23282782" + integrity sha512-pl7tCiodex0hXWKLH3WE+I+HzoSgOOWp9kR3xMcuRiE5g6k2JXNneoD/ZfSS1n6Oorxcjv3U2DbMSXT2j/39dQ== + dependencies: + "@conveyal/geocoder-arcgis-geojson" "^0.0.3" + "@conveyal/lonlat" "^1.4.1" + "@leeoniya/ufuzzy" "^1.0.14" + isomorphic-mapzen-search "^1.6.1" + lodash.memoize "^4.1.2" + "@opentripplanner/humanize-distance@^1.2.0": version "1.2.0" resolved "https://registry.yarnpkg.com/@opentripplanner/humanize-distance/-/humanize-distance-1.2.0.tgz#71cf5d5d1b756adef15300edbba0995ccd4b35ee" From f452700e9ebf0bbabab8e4800e8a70e891a9498c Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Tue, 10 Sep 2024 15:51:28 -0500 Subject: [PATCH 08/13] feat(advanced-settings-panel): add support for onAllSubmodesDisabled prop --- .../form/advanced-settings-panel.tsx | 12 ++--- lib/components/form/util.tsx | 54 ------------------- 2 files changed, 6 insertions(+), 60 deletions(-) diff --git a/lib/components/form/advanced-settings-panel.tsx b/lib/components/form/advanced-settings-panel.tsx index ab83513be..7f1500f23 100644 --- a/lib/components/form/advanced-settings-panel.tsx +++ b/lib/components/form/advanced-settings-panel.tsx @@ -29,7 +29,6 @@ import PageTitle from '../util/page-title' import { addCustomSettingLabels, addModeButtonIcon, - onAdvancedModeSubsettingsUpdate, onSettingsUpdate, pipe, populateSettingWithIcon, @@ -186,6 +185,10 @@ const AdvancedSettingsPanel = ({ onSettingsUpdate(setQueryParam) ) + const handleAllSubmodesDisabled = (modeButton: ModeButtonDefinition) => { + handleModeButtonToggle(modeButton.key, false) + } + return ( @@ -223,11 +226,8 @@ const AdvancedSettingsPanel = ({ fillModeIcons label="test" modeButtons={processedModeButtons} - onSettingsUpdate={onAdvancedModeSubsettingsUpdate( - setQueryParam, - processedModeButtons, - handleModeButtonToggle - )} + onAllSubmodesDisabled={handleAllSubmodesDisabled} + onSettingsUpdate={onSettingsUpdate(setQueryParam)} onToggleModeButton={handleModeButtonToggle} /> { - return modeButtons.find((button: ModeButtonDefinition) => { - if (button.modeSettings) { - return button.modeSettings.some((setting: ModeSetting) => { - // check if transport mode - if ( - (setting.type === 'CHECKBOX' || setting.type === 'SUBMODE') && - setting.addTransportMode - ) { - return setting.key === key - } - return false - }) - } - return false - }) -} - -export const onAdvancedModeSubsettingsUpdate = - ( - setQueryParam: (evt: any) => void, - processedModeButtons: ModeButtonDefinition[], - handleModeButtonToggle: (buttonId: string, newState: boolean) => void - ) => - (params: any) => { - // check if setting is a transport mode and get the mode button that contains it - const modeButton = getModeButtonFromSubmode( - Object.keys(params)[0], - processedModeButtons - ) - if (modeButton && modeButton.modeSettings && !Object.values(params)[0]) { - const transportModeSettings = modeButton.modeSettings.filter( - (setting: ModeSetting) => - (setting.type === 'CHECKBOX' || setting.type === 'SUBMODE') && - setting.addTransportMode - ) - // if we're disabling a transport mode, we need to check if the mode button needs to be disabled (all of its subsettings are false) - const allFalse = transportModeSettings.every((setting: ModeSetting) => { - if (setting.key === Object.keys(params)[0]) { - return !Object.values(params)[0] - } - return !setting.value - }) - if (allFalse) { - transportModeSettings.forEach((setting) => (params[setting.key] = true)) - handleModeButtonToggle(modeButton.key, false) - } - } - setQueryParam({ queryParamData: params, ...params }) - } - export const setModeButton = (enabledModeButtons: string[], updateHandler: (params: any) => void) => (buttonId: string, newState: boolean) => { From a39f049821640a9641ceb0c8761c420282ab4304 Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:04:51 -0500 Subject: [PATCH 09/13] chore(advanced-settings-panel): remove unused prop --- lib/components/form/advanced-settings-panel.tsx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/components/form/advanced-settings-panel.tsx b/lib/components/form/advanced-settings-panel.tsx index 7f1500f23..c5e99f656 100644 --- a/lib/components/form/advanced-settings-panel.tsx +++ b/lib/components/form/advanced-settings-panel.tsx @@ -119,8 +119,7 @@ const AdvancedSettingsPanel = ({ modeButtonOptions, modeSettingDefinitions, modeSettingValues, - setQueryParam, - urlSearchParams + setQueryParam }: { closeAdvancedSettings: () => void enabledModeButtons: string[] @@ -130,7 +129,6 @@ const AdvancedSettingsPanel = ({ modeSettingValues: ModeSettingValues onPlanTripClick: () => void setQueryParam: (evt: QueryParamChangeEvent) => void - urlSearchParams: URLSearchParams }): JSX.Element => { const [closingBySave, setClosingBySave] = useState(false) const [closingByX, setClosingByX] = useState(false) @@ -270,8 +268,7 @@ const mapStateToProps = (state: AppReduxState) => { [], modeButtonOptions: state.otp.config?.modes?.modeButtons || [], modeSettingDefinitions: state.otp?.modeSettingDefinitions || [], - modeSettingValues, - urlSearchParams + modeSettingValues } } From e0979791623fab83f85123be518416616ec65ba3 Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Wed, 11 Sep 2024 10:02:43 -0500 Subject: [PATCH 10/13] chore(form/util): clean up unnecessary logs and comments --- lib/components/form/util.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/components/form/util.tsx b/lib/components/form/util.tsx index a65c1e721..9dfd6366d 100644 --- a/lib/components/form/util.tsx +++ b/lib/components/form/util.tsx @@ -59,16 +59,10 @@ export const onSettingsUpdate = export const setModeButton = (enabledModeButtons: string[], updateHandler: (params: any) => void) => (buttonId: string, newState: boolean) => { - console.log('SET MODE BUTTON IS BEING CALLED. NEW STATE:::: ', newState) let newButtons - if (newState) { - // enable modeButton - // we need to add it to the list of enabled buttons newButtons = [...enabledModeButtons, buttonId] } else { - // disable modeButton - // we need to remove it from the list of enabled buttons newButtons = enabledModeButtons.filter((c) => c !== buttonId) } // encodeQueryParams serializes the mode buttons for the URL From 8a6bef9d872f91de2e783509e895fd3e0b150857 Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Mon, 7 Oct 2024 14:48:21 -0500 Subject: [PATCH 11/13] fix: address PR feedback --- .../form/advanced-settings-panel.tsx | 3 +- lib/components/form/util.tsx | 34 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/components/form/advanced-settings-panel.tsx b/lib/components/form/advanced-settings-panel.tsx index c5e99f656..730c53e2f 100644 --- a/lib/components/form/advanced-settings-panel.tsx +++ b/lib/components/form/advanced-settings-panel.tsx @@ -15,7 +15,6 @@ import { ModeSetting, ModeSettingValues } from '@opentripplanner/types' -import { QueryParamChangeEvent } from '@opentripplanner/trip-form/lib/types' import React, { RefObject, useContext, useEffect, useState } from 'react' import styled from 'styled-components' @@ -128,7 +127,7 @@ const AdvancedSettingsPanel = ({ modeSettingDefinitions: ModeSetting[] modeSettingValues: ModeSettingValues onPlanTripClick: () => void - setQueryParam: (evt: QueryParamChangeEvent) => void + setQueryParam: (evt: any) => void }): JSX.Element => { const [closingBySave, setClosingBySave] = useState(false) const [closingByX, setClosingByX] = useState(false) diff --git a/lib/components/form/util.tsx b/lib/components/form/util.tsx index 9dfd6366d..85dd3107d 100644 --- a/lib/components/form/util.tsx +++ b/lib/components/form/util.tsx @@ -5,6 +5,7 @@ import React from 'react' import { getFormattedMode } from '../../util/i18n' import { hasValidLocation } from '../../util/state' +import { QueryParamChangeHandler } from '../util/types' import { RoutingQueryCallResult } from '../../actions/api-constants' import { updateQueryTimeIfLeavingNow } from '../../actions/form' @@ -18,9 +19,9 @@ export const modesQueryParamConfig = { modeButtons: DelimitedArrayParam } export const populateSettingWithIcon = (ModeIcon: React.ComponentType<{ mode?: string; width?: number }>) => // eslint-disable-next-line react/display-name - (msd: ModeSetting): ModeSetting => ({ - ...msd, - icon: + (modeSetting: ModeSetting): ModeSetting => ({ + ...modeSetting, + icon: }) export const addModeButtonIcon = @@ -34,17 +35,17 @@ export const addModeButtonIcon = export const addCustomSettingLabels = (intl: IntlShape) => - (msd: ModeSetting): ModeSetting => { - let modeLabel + (modeSetting: ModeSetting): ModeSetting => { // If we're using route mode overrides, make sure we're using the custom mode name - if (msd.type === 'SUBMODE') { - modeLabel = msd.overrideMode || msd.addTransportMode.mode + if (modeSetting.type === 'SUBMODE') { + const modeLabel = + modeSetting.overrideMode || modeSetting.addTransportMode.mode return { - ...msd, + ...modeSetting, label: getFormattedMode(modeLabel, intl) } } - return msd + return modeSetting } /** @@ -52,19 +53,18 @@ export const addCustomSettingLabels = * @param params Params to store */ export const onSettingsUpdate = - (setQueryParam: (evt: any) => void) => (params: any) => { + (setQueryParam: QueryParamChangeHandler) => + (params: any): void => { setQueryParam({ queryParamData: params, ...params }) } export const setModeButton = (enabledModeButtons: string[], updateHandler: (params: any) => void) => - (buttonId: string, newState: boolean) => { - let newButtons - if (newState) { - newButtons = [...enabledModeButtons, buttonId] - } else { - newButtons = enabledModeButtons.filter((c) => c !== buttonId) - } + (buttonId: string, newState: boolean): void => { + const newButtons = newState + ? [...enabledModeButtons, buttonId] + : enabledModeButtons.filter((c) => c !== buttonId) + // encodeQueryParams serializes the mode buttons for the URL // to get nice looking URL params and consistency updateHandler( From 3f91771db0c58de957908aae08e05d83ea3c974b Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:12:14 -0500 Subject: [PATCH 12/13] chore: update ui package --- package.json | 2 +- yarn.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 7b69da5c0..6c0a5d74e 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "@opentripplanner/transit-vehicle-overlay": "5.0.0", "@opentripplanner/transitive-overlay": "4.0.0", "@opentripplanner/trip-details": "6.0.0", - "@opentripplanner/trip-form": "4.0.0", + "@opentripplanner/trip-form": "4.1.0", "@opentripplanner/trip-viewer-overlay": "3.0.0", "@opentripplanner/vehicle-rental-overlay": "3.0.0", "@styled-icons/fa-regular": "^10.34.0", diff --git a/yarn.lock b/yarn.lock index 1a65ef7a9..81fb842c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2408,7 +2408,7 @@ resolved "https://registry.yarnpkg.com/@opentripplanner/building-blocks/-/building-blocks-2.0.0.tgz#8282c01dff7db5c7e809f6ea91cb52df559a2f9d" integrity sha512-N07rDaZL8fp552eI9/0j1udKjc0uOpvO0Wv1P19Ge0a4roques463MJgWJ026fbopRCi3uwbc/gYTlh4/ske9A== -"@opentripplanner/building-blocks@^1.0.3", "@opentripplanner/building-blocks@^1.2.2": +"@opentripplanner/building-blocks@^1.2.2": version "1.2.3" resolved "https://registry.yarnpkg.com/@opentripplanner/building-blocks/-/building-blocks-1.2.3.tgz#404e8f9038867d66d55f51adf8855b1326c51ed5" integrity sha512-I0AxiZrTZu+e7+av4u0tHW2ijqpxH0AkLHrhf75BHf1Ep2FOGxaul/v+8UT18mNYiM5eHNstOX3XiXaDjtCUaw== @@ -2698,14 +2698,14 @@ flat "^5.0.2" react-animate-height "^3.0.4" -"@opentripplanner/trip-form@4.0.0": - version "4.0.0" - resolved "https://registry.yarnpkg.com/@opentripplanner/trip-form/-/trip-form-4.0.0.tgz#27b36a0504e46cfda1cdf50c971b5cea03de8ae2" - integrity sha512-Cg8SlAVN8M+qoWpz8jAkwuqllIPgrL2PVewTPuDPsIQ8i5B7xo5KKE3TPo7cQUM+jE6WEshpvv0FIdMF+NAlNg== +"@opentripplanner/trip-form@4.1.0": + version "4.1.0" + resolved "https://registry.yarnpkg.com/@opentripplanner/trip-form/-/trip-form-4.1.0.tgz#83bd7135d1c814f1ea0be4f6896dd2494c9ddba9" + integrity sha512-VOWoyAfnnmwNnsolYLk7vfXRQvF3rj2XW5pXJ+OKwplGTgOhxJGNMKjZxau4legRedauyf0MHBNRpD3M3vsqRg== dependencies: "@floating-ui/react" "^0.19.2" - "@opentripplanner/building-blocks" "^1.0.3" - "@opentripplanner/core-utils" "^11.4.4" + "@opentripplanner/building-blocks" "^2.0.0" + "@opentripplanner/core-utils" "^12.0.0" "@styled-icons/bootstrap" "^10.34.0" "@styled-icons/boxicons-regular" "^10.38.0" "@styled-icons/fa-regular" "^10.37.0" From 38de6c2de6e892109d691b164a91b363a2a44ae0 Mon Sep 17 00:00:00 2001 From: josh-willis-arcadis <168561922+josh-willis-arcadis@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:40:08 -0500 Subject: [PATCH 13/13] refactor(advanced-settings-panel): remove new line to clean up git blame --- lib/components/form/advanced-settings-panel.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/components/form/advanced-settings-panel.tsx b/lib/components/form/advanced-settings-panel.tsx index d3cd25c3d..d39e03ec9 100644 --- a/lib/components/form/advanced-settings-panel.tsx +++ b/lib/components/form/advanced-settings-panel.tsx @@ -169,7 +169,6 @@ const AdvancedSettingsPanel = ({ ) const processedModeSettings = processSettings(modeSettingDefinitions) - const processedModeButtons = modeButtonOptions.map( pipe( addModeButtonIcon(ModeIcon),