From e7b2aeebd7a27edab7c6a4595ebc15a8d5f88bab Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Fri, 1 Sep 2023 01:01:16 +0200 Subject: [PATCH 1/3] improvement(apiv2): use the OTP-UI conversion utility for legacy format --- lib/actions/apiV2.js | 49 ++++++-------------------------------------- 1 file changed, 6 insertions(+), 43 deletions(-) diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index 3b9eba694..ec8aec770 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -44,7 +44,11 @@ import { rememberPlace } from './user' import { setItineraryView } from './ui' import { zoomToPlace } from './map' -const { generateCombinations, generateOtp2Query } = coreUtils.queryGen +const { + convertGraphQLResponseToLegacy, + generateCombinations, + generateOtp2Query +} = coreUtils.queryGen const { getTripOptionsFromQuery, getUrlParams } = coreUtils.query const { randId } = coreUtils.storage @@ -782,47 +786,6 @@ const pickupDropoffTypeToOtp1 = (otp2Type) => { } } -/** - * Converts a leg from GraphQL format to legacy REST format. - * @param leg OTP2 GraphQL style leg - * @returns REST shaped leg - */ -const processLeg = (leg) => ({ - ...leg, - agencyBrandingUrl: leg.agency?.url, - agencyName: leg.agency?.name, - agencyUrl: leg.agency?.url, - alerts: aggregateAlerts( - leg.agency?.alerts, - leg.route?.alerts, - leg.to?.stop?.alerts, - leg.from?.stop?.alerts - ), - alightRule: pickupDropoffTypeToOtp1(leg.dropoffType), - boardRule: pickupDropoffTypeToOtp1(leg.pickupType), - dropOffBookingInfo: { - latestBookingTime: leg.dropOffBookingInfo - }, - from: { - ...leg.from, - stopCode: leg.from.stop?.code, - stopId: leg.from.stop?.gtfsId - }, - route: leg.route?.shortName, - routeColor: leg.route?.color, - routeId: leg.route?.id, - routeLongName: leg.route?.longName, - routeShortName: leg.route?.shortName, - routeTextColor: leg.route?.textColor, - to: { - ...leg.to, - stopCode: leg.to.stop?.code, - stopId: leg.to.stop?.gtfsId - }, - tripHeadsign: leg.trip?.tripHeadsign, - tripId: leg.trip?.gtfsId -}) - const queryParamConfig = { modeButtons: DelimitedArrayParam } export function routingQuery(searchId = null, updateSearchInReducer) { @@ -962,7 +925,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) { const withCollapsedShortNames = response.data?.plan?.itineraries?.map((itin) => ({ ...itin, - legs: itin.legs?.map(processLeg) + legs: itin.legs?.map(convertGraphQLResponseToLegacy) })) /* It is possible for a NO_TRANSIT_CONNECTION error to be From bc341dea9436c2d3353de4bf023242542ce7d205 Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Fri, 1 Sep 2023 12:46:26 +0200 Subject: [PATCH 2/3] fix incorrect import --- lib/actions/apiV2.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/actions/apiV2.js b/lib/actions/apiV2.js index ec8aec770..70f116d2a 100644 --- a/lib/actions/apiV2.js +++ b/lib/actions/apiV2.js @@ -44,12 +44,9 @@ import { rememberPlace } from './user' import { setItineraryView } from './ui' import { zoomToPlace } from './map' -const { - convertGraphQLResponseToLegacy, - generateCombinations, - generateOtp2Query -} = coreUtils.queryGen +const { generateCombinations, generateOtp2Query } = coreUtils.queryGen const { getTripOptionsFromQuery, getUrlParams } = coreUtils.query +const { convertGraphQLResponseToLegacy } = coreUtils.itinerary const { randId } = coreUtils.storage const LIGHT_GRAY = '666666' From 92ac6c941b335b824d90257f6222cffcfa2b09d2 Mon Sep 17 00:00:00 2001 From: Daniel Heppner Date: Sat, 2 Sep 2023 00:52:22 +0200 Subject: [PATCH 3/3] deps: update core-utils --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 770861132..5982b1c6f 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@bugsnag/plugin-react": "^7.17.0", "@floating-ui/react": "^0.19.2", "@opentripplanner/base-map": "^3.0.14", - "@opentripplanner/core-utils": "^11.0.0", + "@opentripplanner/core-utils": "^11.0.2", "@opentripplanner/endpoints-overlay": "^2.0.8", "@opentripplanner/from-to-location-picker": "^2.1.8", "@opentripplanner/geocoder": "^1.4.2", diff --git a/yarn.lock b/yarn.lock index 2d9cec407..d24a5c104 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2439,10 +2439,10 @@ lodash.isequal "^4.5.0" qs "^6.9.1" -"@opentripplanner/core-utils@^11.0.0": - version "11.0.0" - resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-11.0.0.tgz#dd40b7cd68d7d7bf4f56d87bf708d6bd4b7660ed" - integrity sha512-b+oPQWKpzXHeq9QdU0JmsplZX2QIRj4ARdIPJ++f5i/hpIxMnbKApwDHVkRdHz6kYCOQI7pcVNTunT7AGNvudg== +"@opentripplanner/core-utils@^11.0.2": + version "11.0.2" + resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-11.0.2.tgz#ebfa939c3b7b266e3bf47dcaddda88e093430a9d" + integrity sha512-3oQYvnhFHY88K61j2tUkU2fm8tDci5qaMVGEgqTzxpE5NmBTUdAWU1V7W9snJoRATzz3zy+K9qrtIhGjwbwlnA== dependencies: "@conveyal/lonlat" "^1.4.1" "@mapbox/polyline" "^1.1.0"