Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GraphQL Trip Requests #1253

Merged
merged 5 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions lib/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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))
}
Expand Down
10 changes: 8 additions & 2 deletions lib/components/form/user-settings-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 19 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand All @@ -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"
Expand Down
Loading