-
Notifications
You must be signed in to change notification settings - Fork 57
feat(itinerary): add ability to sort itineraries by fare #1411
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
177cecc
53d0e2f
f1522f5
096a63a
c2ede03
83ecd7a
eee9938
6f316ec
52e6b1e
e384331
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 |
---|---|---|
|
@@ -33,6 +33,17 @@ export function getActiveSearch(state) { | |
return state.otp.searches[state.otp.activeSearchId] | ||
} | ||
|
||
function compareItineraryFare(a, b, direction = 'ASC') { | ||
const aMissing = a === undefined || a === null | ||
const bMissing = b === undefined || b === null | ||
// Always sort missing values (null/undefined) to the end of the array. | ||
if (aMissing && bMissing) return 0 | ||
if (aMissing) return 1 | ||
if (bMissing) return -1 | ||
// If both fares are defined, compare them according to direction | ||
return direction === 'ASC' ? a - b : b - a | ||
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. hahah so the old version didn't work? Good thing you wrote the test!! 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. Old version didn't handle the direction of undefined/null values. Good thinking on a unit test! |
||
} | ||
|
||
/** | ||
* Array sort function for itineraries (in batch routing context) that attempts | ||
* to sort based on the type/direction specified. | ||
|
@@ -50,6 +61,8 @@ export function sortItineraries(type, direction, a, b, config) { | |
return dirFactor * (a.duration - b.duration) | ||
case 'COST': | ||
return dirFactor * (a.totalFare - b.totalFare) | ||
case 'FARE': | ||
return compareItineraryFare(a.transitFare, b.transitFare, direction) | ||
default: | ||
if (type !== 'BEST') | ||
console.warn(`Sort (${type}) not supported. Defaulting to BEST.`) | ||
|
Unchanged files with check annotations Beta
import { Field, Form, Formik } from 'formik' | ||
import React, {Component} from 'react' | ||
import { | ||
Button, |
import { createAction } from 'redux-actions' | ||
if (typeof (fetch) === 'undefined') require('isomorphic-fetch') | ||
export const receivedZipcarLocationsError = createAction('ZIPCAR_LOCATIONS_ERROR') | ||
export const receivedZipcarLocationsResponse = createAction('ZIPCAR_LOCATIONS_RESPONSE') | ||
export const requestZipcarLocationsResponse = createAction('ZIPCAR_LOCATIONS_REQUEST') | ||
export function zipcarLocationsQuery (url) { | ||
return async function (dispatch, getState) { | ||
dispatch(requestZipcarLocationsResponse()) | ||
let json |
import { replace, push } from 'connected-react-router' | ||
import { setPathBeforeSignIn } from '../actions/user' | ||
* @param {Error} err | ||
* @param {AccessTokenRequestOptions} options | ||
*/ | ||
export function showAccessTokenError (err, options) { | ||
return function (dispatch, getState) { | ||
// TODO: improve this. | ||
console.error('Failed to retrieve access token: ', err) | ||
* when signing-in fails for some reason. | ||
* @param {Error} err | ||
*/ | ||
export function showLoginError (err) { | ||
return function (dispatch, getState) { | ||
// TODO: improve this. | ||
if (err) dispatch(push('/oops')) | ||
* @param {Object} appState The state stored when calling useAuth0().loginWithRedirect | ||
* or when instantiating a component that uses withAuhenticationRequired. | ||
*/ | ||
export function processSignIn (appState) { | ||
return function (dispatch, getState) { | ||
if (appState && appState.returnTo) { | ||
// Remove URL parameters that were added by auth0-react |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These look good, but can you also add a $0 fare to make sure that it doesn't get accidentally lumped in with null/undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed in 52e6b1e