Skip to content

Commit

Permalink
Merge branch 'dev' into route-viewer-a11y-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup authored Aug 28, 2023
2 parents a883aaf + 6734acf commit e5af8d4
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Object {
"startTime": "07:00",
"time": "19:34",
"to": null,
"walkSpeed": 1.34,
"watts": 250,
"wheelchair": false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Object {
"routingType": "ITINERARY",
"showIntermediateStops": true,
"startTime": "07:00",
"walkSpeed": 1.34,
"watts": 250,
"wheelchair": false,
},
Expand Down
13 changes: 13 additions & 0 deletions example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,19 @@ itinerary:
showLegDurations: false
# Allows calorie counts to be hidden
displayCalories: true
# The sort option to use by default
# Available sort options: 'BEST', 'DURATION', 'ARRIVALTIME', 'WALKTIME', 'COST', 'DEPARTURETIME'
# defaultSort: "BEST" # Default
# The sort options to display in the sort options list
# If unset, will display all.
# Available sort options: 'BEST', 'DURATION', 'ARRIVALTIME', 'WALKTIME', 'COST', 'DEPARTURETIME'
# sortModes:
# - 'BEST'
# - 'DURATION'
# - 'ARRIVALTIME'
# - 'WALKTIME'
# - 'COST'
# - 'DEPARTURETIME'

# The transitOperators key is a list of transit operators that can be used to
# order transit agencies when sorting by route. Also, this can optionally
Expand Down
2 changes: 1 addition & 1 deletion lib/components/narrative/metro/default-route-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const DefaultRouteRenderer = ({
leg,
style
}: RouteRendererProps): JSX.Element => {
const routeTitle = leg.routeShortName || leg.route || leg.routeLongName
const routeTitle = leg.routeShortName || leg.routeLongName
return (
<Block
color={leg.routeColor || '333333'}
Expand Down
6 changes: 4 additions & 2 deletions lib/components/narrative/narrative-itineraries-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { useCallback } from 'react'
import styled from 'styled-components'

import { IconWithText, StyledIconWrapper } from '../util/styledIcon'
import { sortOptions } from '../util/sortOptions'
import { sortOptions, SortOptionsType } from '../util/sortOptions'
import { SortResultsDropdown } from '../util/dropdown'
import { UnstyledButton } from '../util/unstyled-button'
import InvisibleA11yLabel from '../util/invisible-a11y-label'
Expand All @@ -36,6 +36,7 @@ const ItinerariesHeaderContainer = styled.div<{ showHeaderText: boolean }>`

export default function NarrativeItinerariesHeader({
customBatchUiBackground,
enabledSortModes,
errors,
itineraries,
itinerary,
Expand All @@ -52,6 +53,7 @@ export default function NarrativeItinerariesHeader({
sort
}: {
customBatchUiBackground?: boolean
enabledSortModes: SortOptionsType[]
errors: unknown[]
itineraries: unknown[]
itinerary: Itinerary
Expand Down Expand Up @@ -97,7 +99,7 @@ export default function NarrativeItinerariesHeader({
? searching
: intl.formatList([itinerariesFound, numIssues], { type: 'conjunction' })

const sortOptionsArr = sortOptions(intl)
const sortOptionsArr = sortOptions(intl, enabledSortModes)
const sortText = sortOptionsArr.find((x) => x.value === sort.type)?.text

const handleSortClick = useCallback(
Expand Down
7 changes: 6 additions & 1 deletion lib/components/narrative/narrative-itineraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class NarrativeItineraries extends Component {
activeStep: PropTypes.object,
containerStyle: PropTypes.object,
customBatchUiBackground: PropTypes.bool,
enabledSortModes: PropTypes.object,
errorMessages: PropTypes.object,
errors: PropTypes.array,
itineraries: PropTypes.array,
Expand Down Expand Up @@ -391,6 +392,7 @@ class NarrativeItineraries extends Component {
activeItinerary,
activeSearch,
customBatchUiBackground,
enabledSortModes,
errorMessages,
errors,
errorsOtp2,
Expand Down Expand Up @@ -453,6 +455,7 @@ class NarrativeItineraries extends Component {
/>
<NarrativeItinerariesHeader
customBatchUiBackground={customBatchUiBackground}
enabledSortModes={enabledSortModes}
errors={errors}
itineraries={mergedItineraries}
itinerary={itinerary}
Expand Down Expand Up @@ -577,7 +580,8 @@ const mapStateToProps = (state) => {
groupByMode: groupItineraries,
groupTransitModes,
mergeItineraries,
showHeaderText
showHeaderText,
sortModes
} = state.otp.config?.itinerary || false
// Default to true for backwards compatibility
const renderSkeletons = !state.otp.config.itinerary?.hideSkeletons
Expand Down Expand Up @@ -610,6 +614,7 @@ const mapStateToProps = (state) => {
activeStep: activeSearch && activeSearch.activeStep,
co2Config: co2,
customBatchUiBackground,
enabledSortModes: sortModes,
errorMessages,
errors: getResponsesWithErrors(state),
// TODO: Destroy otp1 errors and rename this
Expand Down
26 changes: 23 additions & 3 deletions lib/components/util/sortOptions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import { IntlShape } from 'react-intl'

export type SortOptionsType =
| 'BEST'
| 'DURATION'
| 'ARRIVALTIME'
| 'DEPARTURETIME'
| 'WALKTIME'
| 'COST'

type SortOptionEntry = { text: string; value: SortOptionsType }

export const sortOptions = (
intl: IntlShape
intl: IntlShape,
enabledOptions: SortOptionsType[] = [
'BEST',
'DURATION',
'ARRIVALTIME',
'WALKTIME',
'COST',
'DEPARTURETIME'
]
): {
text: string
value: string
}[] => {
const sortOptionsArray = [
const sortOptionsArray: SortOptionEntry[] = [
{
text: intl.formatMessage({
id: 'components.NarrativeItinerariesHeader.selectBest'
Expand Down Expand Up @@ -45,5 +63,7 @@ export const sortOptions = (
}
]

return sortOptionsArray
return sortOptionsArray.filter((sortOption) =>
enabledOptions.includes(sortOption.value)
)
}
4 changes: 2 additions & 2 deletions lib/reducers/create-otp-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function getInitialState(userDefinedConfig) {
}

let initialModeSettings = defaultModeSettings
if (!initialModeSettings.length) {
if (!initialModeSettings?.length) {
initialModeSettings = []
}

Expand Down Expand Up @@ -162,7 +162,7 @@ export function getInitialState(userDefinedConfig) {
sort: {
direction: 'ASC',
// Only apply custom sort if batch routing is enabled.
type: 'BEST'
type: config.itinerary?.defaultSort || 'BEST'
}
},
initialUrl: window.location.href,
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,29 @@
"@bugsnag/js": "^7.17.0",
"@bugsnag/plugin-react": "^7.17.0",
"@floating-ui/react": "^0.19.2",
"@opentripplanner/base-map": "^3.0.13",
"@opentripplanner/core-utils": "^9.0.3",
"@opentripplanner/endpoints-overlay": "^2.0.7",
"@opentripplanner/from-to-location-picker": "^2.1.7",
"@opentripplanner/base-map": "^3.0.14",
"@opentripplanner/core-utils": "^11.0.0",
"@opentripplanner/endpoints-overlay": "^2.0.8",
"@opentripplanner/from-to-location-picker": "^2.1.8",
"@opentripplanner/geocoder": "^1.4.2",
"@opentripplanner/humanize-distance": "^1.2.0",
"@opentripplanner/icons": "^2.0.3",
"@opentripplanner/itinerary-body": "^5.0.3",
"@opentripplanner/icons": "^2.0.5",
"@opentripplanner/itinerary-body": "^5.0.5",
"@opentripplanner/location-field": "^2.0.7",
"@opentripplanner/location-icon": "^1.4.1",
"@opentripplanner/map-popup": "^2.0.4",
"@opentripplanner/map-popup": "^2.0.5",
"@opentripplanner/otp2-tile-overlay": "^1.0.5",
"@opentripplanner/park-and-ride-overlay": "^2.0.5",
"@opentripplanner/printable-itinerary": "2.0.10-alpha.4",
"@opentripplanner/route-viewer-overlay": "^2.0.12",
"@opentripplanner/stop-viewer-overlay": "^2.0.5",
"@opentripplanner/stops-overlay": "^5.1.0",
"@opentripplanner/transit-vehicle-overlay": "^4.0.4",
"@opentripplanner/transitive-overlay": "^3.0.13",
"@opentripplanner/park-and-ride-overlay": "^2.0.6",
"@opentripplanner/route-viewer-overlay": "^2.0.13",
"@opentripplanner/stop-viewer-overlay": "^2.0.6",
"@opentripplanner/stops-overlay": "^5.1.1",
"@opentripplanner/transit-vehicle-overlay": "^4.0.5",
"@opentripplanner/transitive-overlay": "^3.0.14",
"@opentripplanner/trip-details": "^5.0.2",
"@opentripplanner/trip-form": "^3.1.1",
"@opentripplanner/trip-viewer-overlay": "^2.0.5",
"@opentripplanner/vehicle-rental-overlay": "^2.1.1",
"@opentripplanner/trip-form": "^3.3.1",
"@opentripplanner/trip-viewer-overlay": "^2.0.6",
"@opentripplanner/vehicle-rental-overlay": "^2.1.2",
"@styled-icons/fa-regular": "^10.34.0",
"@styled-icons/fa-solid": "^10.34.0",
"blob-stream": "^0.1.3",
Expand Down Expand Up @@ -132,7 +132,7 @@
"@craco/craco": "^6.3.0",
"@jackwilsdon/craco-use-babelrc": "^1.0.0",
"@opentripplanner/scripts": "^1.2.0",
"@opentripplanner/types": "^6.0.0",
"@opentripplanner/types": "^6.1.0",
"@percy/cli": "^1.20.3",
"@percy/puppeteer": "^2.0.2",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
Expand Down
Loading

0 comments on commit e5af8d4

Please sign in to comment.