From 3a5d280086b708bf8c12106f9ac0d32d5bdf2867 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Fri, 2 Aug 2024 17:46:46 -0400 Subject: [PATCH 1/4] chore(deps): Update core-utils version for bug fix --- package.json | 2 +- yarn.lock | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7e4c69365..48e9c2886 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@floating-ui/react": "^0.19.2", "@opentripplanner/base-map": "^3.2.0", "@opentripplanner/building-blocks": "^1.1.0", - "@opentripplanner/core-utils": "^11.4.2", + "@opentripplanner/core-utils": "^11.4.3", "@opentripplanner/endpoints-overlay": "^2.1.1", "@opentripplanner/from-to-location-picker": "^2.1.13", "@opentripplanner/geocoder": "^3.0.1", diff --git a/yarn.lock b/yarn.lock index 1c0bb7eb6..a1728d568 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2398,7 +2398,7 @@ resolved "https://registry.yarnpkg.com/@opentripplanner/building-blocks/-/building-blocks-1.1.0.tgz#ef9fe862ce0a3e92c9a6c2c2db749a9a02deebd5" integrity sha512-nx7pU1zIZzJcSkCFYyZ7gt+jd0gXj7bjx8rXn1msgF5uLWmtN/70dsmYNEApeA7haC076KOO3B/Jh44YfXG95g== -"@opentripplanner/core-utils@^11.2.3", "@opentripplanner/core-utils@^11.4.0", "@opentripplanner/core-utils@^11.4.2": +"@opentripplanner/core-utils@^11.2.3", "@opentripplanner/core-utils@^11.4.0": version "11.4.2" resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-11.4.2.tgz#cc6034fb80ccda44e50f7f0a1e80a7bad8387f84" integrity sha512-EVYVN73Cgf9IC+uya49843MFJnVkmv0nHAjsQwmPGSx/w5fY49X4fSpDprL7Bn+MTzk58U2udDsn6OzKmV0JdA== @@ -2416,6 +2416,24 @@ 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" + integrity sha512-GbvchRsLfEi9JygUx6ypU+Iqv2hELseC53yQyQ/XdnB1kcHzN71BtBbz+qpD5/jk8IuM92j1taRnGMeu5ni6yA== + dependencies: + "@conveyal/lonlat" "^1.4.1" + "@mapbox/polyline" "^1.1.0" + "@opentripplanner/geocoder" "^3.0.0" + "@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/endpoints-overlay@^2.1.1": version "2.1.1" resolved "https://registry.yarnpkg.com/@opentripplanner/endpoints-overlay/-/endpoints-overlay-2.1.1.tgz#e7029d95bd13436aacbc6f854c243d1fcf7e8570" From 0ea80dd5988e6488a93e868eac16407692af4f0a Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:43:42 -0400 Subject: [PATCH 2/4] fix(actions/user): Correctly parse trip request data with GraphQL parameters --- lib/actions/user.js | 60 ++++++++++++++++------- lib/components/form/user-settings-i18n.js | 10 +++- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/lib/actions/user.js b/lib/actions/user.js index 9ec2d9965..149d7cf9a 100644 --- a/lib/actions/user.js +++ b/lib/actions/user.js @@ -156,35 +156,57 @@ export function fetchAuth0Token(auth0, intl) { */ function convertRequestToSearch(config) { return function (tripRequest) { - const { dateCreated, id, requestParameters = {} } = tripRequest + const { + dateCreated, + id, + otp2QueryParams = {}, + requestParameters = {} // Deprecated OTP1 + } = tripRequest const { host, path } = config.api return { canDelete: false, id, - query: planParamsToQuery(requestParameters || {}), + query: planParamsToQuery(otp2QueryParams || requestParameters || {}), timestamp: dateCreated, url: `${host}${path}/plan?${qs.stringify(requestParameters)}` } } } +// TODO move to a utils file +function areRequestsSame(qp1, qp2) { + // Everything except modes. + // Exclude banned/preferred/unpreferred at this time. + return ( + qp1.bikeReluctance === qp2.bikeReluctance && + qp1.carReluctance === qp2.carReluctance && + qp1.date === qp2.date && + qp1.departArrive === qp2.departArrive && + qp1.from?.name === qp2.from?.name && + qp1.departArrive === qp2.departArrive && + qp1.time === qp2.time && + qp1.to?.name === qp2.to?.name && + qp1.walkReluctance === qp2.walkReluctance && + qp1.walkSpeed === qp2.walkSpeed && + qp1.wheelchair === qp2.wheelchair + ) +} + /** - * Removes duplicate requests saved from batch queries, - * so that only one request is displayed per batch. - * (Except for the mode, all query params in the same batch are the same.) + * Removes duplicate requests so that only one request is displayed per "batch". */ -function removeDuplicateRequestsFromBatch() { - const batches = {} - return function ({ query }) { - if (!batches[query.batchId]) { - batches[query.batchId] = true - - // Remove the mode for display purposes - query.mode = '' - return true - } - return false +function removeDuplicateRequests(filtered, tripRequest) { + // Compare one trip request to the next one. + if (filtered.length === 0) { + filtered.push(tripRequest) + } else if ( + !areRequestsSame(filtered[filtered.length - 1].query, tripRequest.query) + ) { + filtered.push(tripRequest) + } else { + filtered[filtered.length - 1].query.modes.push(...tripRequest.query.modes) } + return filtered } /** @@ -221,8 +243,10 @@ export function fetchTripRequests() { const { config } = getState().otp const convertedTrips = trips.data .map(convertRequestToSearch(config)) - .filter((tripReq) => !isEmpty(tripReq.query)) - .filter(removeDuplicateRequestsFromBatch()) + .filter( + (tripReq) => !isEmpty(tripReq.query) || !!tripReq.otp2QueryParams + ) + .reduce(removeDuplicateRequests, []) dispatch(setCurrentUserTripRequests(convertedTrips)) } diff --git a/lib/components/form/user-settings-i18n.js b/lib/components/form/user-settings-i18n.js index c1a639a00..246baea68 100644 --- a/lib/components/form/user-settings-i18n.js +++ b/lib/components/form/user-settings-i18n.js @@ -50,15 +50,21 @@ export function summarizeQuery(query, intl, locations = []) { ) } + const modes = + query.modes + ?.map( + ({ mode, qualifier }) => `${mode}${qualifier ? `_${qualifier}` : ''}` + ) + .join(',') || '' const from = findLocationType(intl, query.from, locations) || stripAllButNameOfAddress(query.from.name) const to = findLocationType(intl, query.to, locations) || stripAllButNameOfAddress(query.to.name) - const mode = hasTransit(query.mode) + const mode = hasTransit(modes) ? intl.formatMessage({ id: 'common.modes.transit' }) - : toSentenceCase(query.mode) + : toSentenceCase(modes) return intl.formatMessage( { id: 'components.UserSettings.recentSearchSummary' }, { from, mode, to } From 67c5fef6d0b92c59679c1eab3c34c3e7e0fed9d0 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Mon, 5 Aug 2024 13:22:11 -0400 Subject: [PATCH 3/4] refactor(actions/user): Remove OTP1-style requestParameters. --- lib/actions/user.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/actions/user.js b/lib/actions/user.js index 149d7cf9a..f3581be8d 100644 --- a/lib/actions/user.js +++ b/lib/actions/user.js @@ -156,19 +156,14 @@ export function fetchAuth0Token(auth0, intl) { */ function convertRequestToSearch(config) { return function (tripRequest) { - const { - dateCreated, - id, - otp2QueryParams = {}, - requestParameters = {} // Deprecated OTP1 - } = tripRequest + const { dateCreated, id, otp2QueryParams = {} } = tripRequest const { host, path } = config.api return { canDelete: false, id, - query: planParamsToQuery(otp2QueryParams || requestParameters || {}), + query: planParamsToQuery(otp2QueryParams || {}), timestamp: dateCreated, - url: `${host}${path}/plan?${qs.stringify(requestParameters)}` + url: `${host}${path}/plan?${qs.stringify(otp2QueryParams)}` } } } From 42e6753b64bbddcabf6d7defe31e0ac2f4824d56 Mon Sep 17 00:00:00 2001 From: binh-dam-ibigroup <56846598+binh-dam-ibigroup@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:33:23 -0400 Subject: [PATCH 4/4] refactor(actions/user): Replace manual field comparison with lodash.isequal. --- lib/actions/user.js | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/lib/actions/user.js b/lib/actions/user.js index f3581be8d..17b63d1f7 100644 --- a/lib/actions/user.js +++ b/lib/actions/user.js @@ -2,6 +2,7 @@ import { createAction } from 'redux-actions' import clone from 'clone' import coreUtils from '@opentripplanner/core-utils' import isEmpty from 'lodash.isempty' +import isEqual from 'lodash.isequal' import qs from 'qs' import toast from 'react-hot-toast' @@ -168,25 +169,6 @@ function convertRequestToSearch(config) { } } -// TODO move to a utils file -function areRequestsSame(qp1, qp2) { - // Everything except modes. - // Exclude banned/preferred/unpreferred at this time. - return ( - qp1.bikeReluctance === qp2.bikeReluctance && - qp1.carReluctance === qp2.carReluctance && - qp1.date === qp2.date && - qp1.departArrive === qp2.departArrive && - qp1.from?.name === qp2.from?.name && - qp1.departArrive === qp2.departArrive && - qp1.time === qp2.time && - qp1.to?.name === qp2.to?.name && - qp1.walkReluctance === qp2.walkReluctance && - qp1.walkSpeed === qp2.walkSpeed && - qp1.wheelchair === qp2.wheelchair - ) -} - /** * Removes duplicate requests so that only one request is displayed per "batch". */ @@ -194,9 +176,7 @@ function removeDuplicateRequests(filtered, tripRequest) { // Compare one trip request to the next one. if (filtered.length === 0) { filtered.push(tripRequest) - } else if ( - !areRequestsSame(filtered[filtered.length - 1].query, tripRequest.query) - ) { + } else if (!isEqual(filtered[filtered.length - 1].query, tripRequest.query)) { filtered.push(tripRequest) } else { filtered[filtered.length - 1].query.modes.push(...tripRequest.query.modes)