Skip to content

Commit

Permalink
Merge branch 'dev' into multiple-notification-channels
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup authored Sep 12, 2023
2 parents 344442f + 2aed935 commit a068d0c
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 182 deletions.
44 changes: 2 additions & 42 deletions lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { zoomToPlace } from './map'

const { generateCombinations, generateOtp2Query } = coreUtils.queryGen
const { getTripOptionsFromQuery, getUrlParams } = coreUtils.query
const { convertGraphQLResponseToLegacy } = coreUtils.itinerary
const { randId } = coreUtils.storage

const LIGHT_GRAY = '666666'
Expand Down Expand Up @@ -782,47 +783,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) {
Expand Down Expand Up @@ -962,7 +922,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
Expand Down
30 changes: 16 additions & 14 deletions lib/components/util/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Route } from '@opentripplanner/types'

// TYPESCRIPT TODO: move this to a larger shared types file, preferably within otp-ui
export interface StopData {
bikeRental: BikeRental
Expand All @@ -22,15 +24,6 @@ export interface BikeRental {
stations: any[]
}

export interface Route {
agencyId: string
agencyName: string
id: string
longName: string
mode: string
sortOrder: number
}

// FIXME: incomplete
export interface StopTime {
departureDelay: number
Expand All @@ -45,6 +38,11 @@ export interface Pattern {
desc: string
headsign: string
id: string
patternGeometry?: {
length: number
points: string
}
stops?: StopData[]
}

export interface Time {
Expand Down Expand Up @@ -80,14 +78,18 @@ export interface ViewedRouteState {
routeId: string
}

export interface RouteVehicle {
patternId: string
}

// Routes have many properties beside id, but none of these are guaranteed.
export interface ViewedRouteObject {
id: string
longName?: string
export interface ViewedRouteObject extends Route {
patterns?: Record<string, Pattern>
pending?: boolean
shortName?: string
textColor?: string
url?: string
vehicles?: RouteVehicle[]
}

export type SetViewedRouteHandler = (route?: ViewedRouteState) => void

export type SetViewedStopHandler = (payload: { stopId: string }) => void
6 changes: 1 addition & 5 deletions lib/components/viewers/pattern-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ const PatternViewer = ({
</h1>
</div>
</div>
<RouteDetails
operator={operator}
pattern={route?.patterns?.[patternId]}
route={route}
/>
<RouteDetails operator={operator} patternId={patternId} route={route} />
</div>
)
}
Expand Down
Loading

0 comments on commit a068d0c

Please sign in to comment.