diff --git a/__tests__/components/viewers/__snapshots__/nearby-view.js.snap b/__tests__/components/viewers/__snapshots__/nearby-view.js.snap index d9d1112fc..432329be4 100644 --- a/__tests__/components/viewers/__snapshots__/nearby-view.js.snap +++ b/__tests__/components/viewers/__snapshots__/nearby-view.js.snap @@ -7122,6 +7122,7 @@ exports[`components > viewers > nearby view renders proper scooter dates 1`] = ` /> } homeTimezone="America/Los_Angeles" + routeSortComparator={[Function]} stopData={ Object { "__typename": "Stop", @@ -14945,6 +14946,7 @@ exports[`components > viewers > nearby view renders proper scooter dates 1`] = ` /> } homeTimezone="America/Los_Angeles" + routeSortComparator={[Function]} stopData={ Object { "__typename": "Stop", @@ -23041,6 +23043,7 @@ exports[`components > viewers > nearby view renders proper scooter dates 1`] = ` /> } homeTimezone="America/Los_Angeles" + routeSortComparator={[Function]} stopData={ Object { "__typename": "Stop", @@ -33944,6 +33947,7 @@ exports[`components > viewers > nearby view renders proper scooter dates 1`] = ` /> } homeTimezone="America/Los_Angeles" + routeSortComparator={[Function]} stopData={ Object { "__typename": "Stop", @@ -40874,6 +40878,7 @@ exports[`components > viewers > nearby view renders proper scooter dates 1`] = ` /> } homeTimezone="America/Los_Angeles" + routeSortComparator={[Function]} stopData={ Object { "__typename": "Stop", @@ -47900,6 +47905,7 @@ exports[`components > viewers > nearby view renders proper scooter dates 1`] = ` /> } homeTimezone="America/Los_Angeles" + routeSortComparator={[Function]} stopData={ Object { "__typename": "Stop", @@ -59395,6 +59401,7 @@ exports[`components > viewers > nearby view renders proper scooter dates 1`] = ` /> } homeTimezone="America/Los_Angeles" + routeSortComparator={[Function]} stopData={ Object { "__typename": "Stop", diff --git a/example-config.yml b/example-config.yml index 43fbc99fd..b04b7d8cf 100644 --- a/example-config.yml +++ b/example-config.yml @@ -662,4 +662,6 @@ itinerary: ### Setting to hide stops with no depatures in the nearby view. # hideEmptyStops: true ### What radius should the nearby query get results within? (in meters) -# radius: 600 \ No newline at end of file +# radius: 600 +### Setting this to true will use the route viewer sort algorithm on routes +# useRouteViewSort: false \ No newline at end of file diff --git a/i18n/es.yml b/i18n/es.yml index 1f847bfd8..31c17586c 100644 --- a/i18n/es.yml +++ b/i18n/es.yml @@ -521,13 +521,13 @@ components: signInText: Inicia sesión para guardar el viaje signInTooltip: Por favor, inicia sesión para guardar el viaje. SavedTripEditor: + deleteSavedTrip: Borrar viaje guardado editSavedTrip: Editar el viaje guardado saveNewTrip: Guardar un nuevo viaje tripInformation: Información sobre el viaje tripNotFound: No se encontró el viaje tripNotFoundDescription: Lo sentimos, no se encontró el viaje solicitado. tripNotifications: Notificaciones de viaje - deleteSavedTrip: Borrar viaje guardado SavedTripList: alertTag: "{alerta, plural, one {Ver una alerta} other {Ver # alertas}}" fromTo: De {from} al {to} diff --git a/lib/components/viewers/nearby/stop.tsx b/lib/components/viewers/nearby/stop.tsx index 18b71905d..0fdc0a694 100644 --- a/lib/components/viewers/nearby/stop.tsx +++ b/lib/components/viewers/nearby/stop.tsx @@ -1,6 +1,7 @@ import { Calendar } from '@styled-icons/fa-solid' import { connect } from 'react-redux' import { FormattedMessage } from 'react-intl' +import { TransitOperator } from '@opentripplanner/types' import coreUtils from '@opentripplanner/core-utils' import React from 'react' @@ -23,6 +24,7 @@ type Props = { fromToSlot: JSX.Element homeTimezone: string nearbyViewConfig?: NearbyViewConfig + routeSortComparator: (a: PatternStopTime, b: PatternStopTime) => number stopData: StopData } @@ -30,6 +32,7 @@ const Stop = ({ fromToSlot, homeTimezone, nearbyViewConfig, + routeSortComparator, stopData }: Props): JSX.Element => { const patternRows = (stopData.stoptimesForPatterns || []) @@ -52,10 +55,7 @@ const Stop = ({ } return acc }, []) - .sort( - (a: PatternStopTime, b: PatternStopTime) => - fullTimestamp(a.stoptimes?.[0]) - fullTimestamp(b.stoptimes?.[0]) - ) + .sort(routeSortComparator) .map((st: any, index: number) => { const sortedStopTimes = st.stoptimes.sort( (a: StopTime, b: StopTime) => fullTimestamp(a) - fullTimestamp(b) @@ -103,9 +103,26 @@ const Stop = ({ const mapStateToProps = (state: AppReduxState) => { const { config } = state.otp + const nearbyViewConfig = config?.nearbyView + const transitOperators = config?.transitOperators || [] + + // Default sort: departure time + let routeSortComparator = (a: PatternStopTime, b: PatternStopTime) => + fullTimestamp(a.stoptimes?.[0]) - fullTimestamp(b.stoptimes?.[0]) + + if (nearbyViewConfig?.useRouteViewSort) { + routeSortComparator = (a: PatternStopTime, b: PatternStopTime) => + coreUtils.route.makeRouteComparator(transitOperators)( + // @ts-expect-error core-utils types are wrong! + a.pattern.route, + b.pattern.route + ) + } + return { homeTimezone: config.homeTimezone, - nearbyViewConfig: config?.nearbyView + nearbyViewConfig, + routeSortComparator } } diff --git a/lib/util/config-types.ts b/lib/util/config-types.ts index 343686e5e..d3f10a090 100644 --- a/lib/util/config-types.ts +++ b/lib/util/config-types.ts @@ -68,7 +68,11 @@ interface ApiKeyConfig { export type BugsnagConfig = ApiKeyConfig export type MapillaryConfig = ApiKeyConfig -export type NearbyViewConfig = { hideEmptyStops?: boolean; radius?: number } +export type NearbyViewConfig = { + hideEmptyStops?: boolean + radius?: number + useRouteViewSort?: boolean +} /** TODO: Language settings */ export type LanguageConfig = Record