-
Notifications
You must be signed in to change notification settings - Fork 59
Vehicle rental overlay graphql migration #1440
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
Changes from all commits
3c4a12c
95a31c5
5f66024
814d420
915413f
e9bb584
d5f97ea
b3cf826
8511d5c
a57cd26
fbd6599
348cb88
0ee6823
2440192
3734792
0ba399b
99e7281
684dcc2
e14ac3f
4f9c2d3
a2743e7
41f6198
fc9e127
dd356ab
98da8e5
3c9e280
0207ff0
15fded0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { | |
| } from '@opentripplanner/trip-form' | ||
| import { createAction } from 'redux-actions' | ||
| import { decodeQueryParams, DelimitedArrayParam } from 'use-query-params' | ||
| import { FormFactor } from '@opentripplanner/types' | ||
| import clone from 'clone' | ||
| import coreUtils from '@opentripplanner/core-utils' | ||
|
|
||
|
|
@@ -184,60 +185,6 @@ const findTrip = (params) => | |
| } | ||
| ) | ||
|
|
||
| export const vehicleRentalQuery = ( | ||
| params, | ||
| responseAction, | ||
| errorAction, | ||
| options | ||
| ) => | ||
| // TODO: ErrorsByNetwork is missing | ||
| createGraphQLQueryAction( | ||
| `{ | ||
| rentalVehicles { | ||
| vehicleId | ||
| id | ||
| name | ||
| lat | ||
| lon | ||
| allowPickupNow | ||
| vehicleType { | ||
| formFactor | ||
| } | ||
| network | ||
| } | ||
| } | ||
| `, | ||
| {}, | ||
| responseAction, | ||
| errorAction, | ||
| { | ||
| noThrottle: true, | ||
| postprocess: (payload, dispatch) => { | ||
| if (payload.errors) { | ||
| return errorAction(payload.errors) | ||
| } | ||
| }, | ||
| // TODO: most of this rewrites the OTP2 response to match OTP1. | ||
| // we should re-write the rest of the UI to match OTP's behavior instead | ||
| rewritePayload: (payload) => { | ||
| return { | ||
| stations: payload?.data?.rentalVehicles?.map((vehicle) => { | ||
| return { | ||
| allowPickup: vehicle.allowPickupNow, | ||
| id: vehicle.vehicleId, | ||
| isFloatingBike: vehicle?.vehicleType?.formFactor === 'BICYCLE', | ||
| isFloatingVehicle: vehicle?.vehicleType?.formFactor === 'SCOOTER', | ||
| name: vehicle.name, | ||
| networks: [vehicle.network], | ||
| x: vehicle.lon, | ||
| y: vehicle.lat | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| // TODO: numberOfDepartures needs to come from config! | ||
| const stopTimeGraphQLQuery = ` | ||
| stopTimes: stoptimesForPatterns(numberOfDepartures: 3) { | ||
|
|
@@ -687,6 +634,127 @@ const getVehiclePositionsForRoute = (routeId) => | |
| ) | ||
| } | ||
|
|
||
| const vehicleRentalStationsQuery = ` | ||
| query VehicleRentalStations { | ||
| vehicleRentalStations { | ||
| id | ||
| name | ||
| lat | ||
| lon | ||
| allowDropoff | ||
| allowPickup | ||
| rentalNetwork { | ||
| networkId | ||
| } | ||
| availableVehicles { | ||
| total | ||
| byType { | ||
| vehicleType { | ||
| formFactor | ||
| } | ||
| } | ||
| } | ||
| availableSpaces { | ||
| total | ||
| byType { | ||
| vehicleType { | ||
| formFactor | ||
| } | ||
| } | ||
| } | ||
| realtime | ||
| } | ||
| }` | ||
|
|
||
| const vehicleRentalStationFilter = (formFactor) => (station) => | ||
| (station.availableVehicles && | ||
| station.availableVehicles.byType.some( | ||
| (av) => av.vehicleType.formFactor === formFactor | ||
| )) || | ||
| (station.availableSpaces && | ||
| station.availableSpaces.byType.some( | ||
| (as) => as.vehicleType.formFactor === formFactor | ||
| )) | ||
|
|
||
| const bikeRentalError = createAction('BIKE_RENTAL_ERROR') | ||
| const bikeRentalResponse = createAction('BIKE_RENTAL_RESPONSE') | ||
|
|
||
| export function findBikeRentalStations() { | ||
| return function (dispatch) { | ||
| dispatch( | ||
| createGraphQLQueryAction( | ||
| vehicleRentalStationsQuery, | ||
| {}, | ||
| bikeRentalResponse, | ||
| bikeRentalError, | ||
| { | ||
| rewritePayload: (payload) => | ||
| payload.data.vehicleRentalStations.filter( | ||
| vehicleRentalStationFilter('BICYCLE') | ||
| ) | ||
| } | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export const carRentalResponse = createAction('CAR_RENTAL_RESPONSE') | ||
| export const carRentalError = createAction('CAR_RENTAL_ERROR') | ||
|
|
||
| export function findCarRentalStations() { | ||
|
Comment on lines
+682
to
+704
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe for another PR: There is probably a way to make that query once and update the bike and rental states at the same time instead of filtering out the results. We could throttle the callbacks from the respective overlays too. |
||
| return function (dispatch) { | ||
| dispatch( | ||
| createGraphQLQueryAction( | ||
| vehicleRentalStationsQuery, | ||
| {}, | ||
| carRentalResponse, | ||
| carRentalError, | ||
| { | ||
| rewritePayload: (payload) => | ||
| payload.data.vehicleRentalStations.filter( | ||
| vehicleRentalStationFilter('CAR') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use constant
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interestingly, I think my other usages of
In the default map component, this means that we get type safety when using
Unfortunately, this |
||
| ) | ||
| } | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| const rentalVehiclesQuery = ` | ||
| query RentalVehicles { | ||
| rentalVehicles { | ||
| allowPickupNow | ||
| id | ||
| lat | ||
| lon | ||
| name | ||
| operative | ||
| rentalNetwork { | ||
| networkId | ||
| } | ||
| vehicleType { | ||
| formFactor | ||
| } | ||
| } | ||
| }` | ||
|
|
||
| const vehicleRentalResponse = createAction('VEHICLE_RENTAL_RESPONSE') | ||
| const vehicleRentalError = createAction('VEHICLE_RENTAL_ERROR') | ||
|
|
||
| export function findRentalVehicles() { | ||
| return function (dispatch) { | ||
| dispatch( | ||
| createGraphQLQueryAction( | ||
| rentalVehiclesQuery, | ||
| {}, | ||
| vehicleRentalResponse, | ||
| vehicleRentalError, | ||
| {} | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export const findRoute = (params) => | ||
| function (dispatch, getState) { | ||
| const { routeId } = params | ||
|
|
@@ -1369,15 +1437,17 @@ const retrieveServiceTimeRangeIfNeeded = () => | |
|
|
||
| export default { | ||
| fetchNearby, | ||
| findBikeRentalStations, | ||
| findCarRentalStations, | ||
| findFeeds, | ||
| findPatternsForRoute, | ||
| findRentalVehicles, | ||
| findRoute, | ||
| findRoutes, | ||
| findStopsWithinBBox, | ||
| findStopTimesForStop, | ||
| findTrip, | ||
| getVehiclePositionsForRoute, | ||
| retrieveServiceTimeRangeIfNeeded, | ||
| routingQuery, | ||
| vehicleRentalQuery | ||
| routingQuery | ||
| } | ||


Uh oh!
There was an error while loading. Please reload this page.