diff --git a/lib/actions/user.js b/lib/actions/user.js index 9ec2d9965..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' @@ -156,35 +157,31 @@ export function fetchAuth0Token(auth0, intl) { */ function convertRequestToSearch(config) { return function (tripRequest) { - const { dateCreated, id, requestParameters = {} } = tripRequest + const { dateCreated, id, otp2QueryParams = {} } = tripRequest const { host, path } = config.api return { canDelete: false, id, - query: planParamsToQuery(requestParameters || {}), + query: planParamsToQuery(otp2QueryParams || {}), timestamp: dateCreated, - url: `${host}${path}/plan?${qs.stringify(requestParameters)}` + url: `${host}${path}/plan?${qs.stringify(otp2QueryParams)}` } } } /** - * 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 (!isEqual(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 +218,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 } 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"