Skip to content

Commit

Permalink
Merge branch 'dev' into itin-style-regression-repair
Browse files Browse the repository at this point in the history
  • Loading branch information
miles-grant-ibigroup authored Sep 5, 2023
2 parents 5f59466 + e316c30 commit 0a5337b
Show file tree
Hide file tree
Showing 28 changed files with 576 additions and 423 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
3 changes: 3 additions & 0 deletions __tests__/util/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ describe('util > ui', () => {
describe('getItineraryView', () => {
it('returns a list mode by default or ui_activeItinerary is -1', () => {
expect(getItineraryView({})).toBe(ItineraryView.LIST)
expect(getItineraryView({ ui_activeItinerary: null })).toBe(
ItineraryView.LIST
)
expect(getItineraryView({ ui_activeItinerary: -1 })).toBe(
ItineraryView.LIST
)
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
6 changes: 6 additions & 0 deletions i18n/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ actions:
setPaymentError: "Error setting payment info:"
setRequestStatusError: "Error setting request status:"
location:
deniedAccessAlert: >
Access to your location is blocked.
To use your current location, enable location permissions from your
browser, and reload the page.
geolocationNotSupportedError: Geolocation not supported by your browser
unknownPositionError: Unknown error getting position
userDeniedPermission: User denied permission
map:
currentLocation: (Current Location)
user:
Expand Down
8 changes: 7 additions & 1 deletion i18n/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ actions:
setPaymentError: "Erreur sur les coordonnées de paiement :"
setRequestStatusError: "Erreur sur l'état de la requête :"
location:
deniedAccessAlert: >
L'accès à votre position est refusé.
Pour utiliser votre emplacement actuel, permettez-en l'accès depuis votre
navigateur, et ouvrez de nouveau cette page.
geolocationNotSupportedError: La géolocalisation n'est pas prise en charge par votre navigateur.
unknownPositionError: Erreur inconnue lors de la détection de votre emplacement.
userDeniedPermission: Refusé par l'utilisateur
map:
currentLocation: (Emplacement actuel)
user:
Expand Down Expand Up @@ -178,7 +184,7 @@ components:
AdvancedOptions:
bannedRoutes: Choisissez les lignes à éviter…
bikeTolerance: Tolérance au vélo
preferredRoutes: Choisissez les lignes preferées
preferredRoutes: Choisissez les lignes préferées
walkTolerance: Tolérance à la marche
AfterSignInScreen:
mainTitle: Redirection...
Expand Down
27 changes: 24 additions & 3 deletions lib/actions/location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { createAction } from 'redux-actions'
import { Dispatch } from 'redux'
import { IntlShape } from 'react-intl'
import { isMobile } from '@opentripplanner/core-utils/lib/ui'

import { setLocationToCurrent } from './map'

Expand Down Expand Up @@ -47,9 +48,29 @@ export function getCurrentPosition(
// On error
(error) => {
console.log('error getting current position', error)
// FIXME, analyze error code to produce better error message.
// See https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPositionError
dispatch(receivedPositionError({ error }))
// On desktop, after user clicks "Use location" from the location fields,
// show an alert and explain if location is blocked.
// TODO: Consider moving the handling of unavailable location to the location-field component.
if (!isMobile() && error.code === 1) {
window.alert(
intl.formatMessage({
id: 'actions.location.deniedAccessAlert'
})
)
}
const newError = { ...error }
if (error.code === 1) {
// i18n for user-denied location message (error.code = 1 on secure origins).
if (
window.location.protocol === 'https:' ||
window.location.host.startsWith('localhost:')
) {
newError.message = intl.formatMessage({
id: 'actions.location.userDeniedPermission'
})
}
}
dispatch(receivedPositionError({ error: newError }))
},
// Options
{ enableHighAccuracy: true }
Expand Down
20 changes: 15 additions & 5 deletions lib/actions/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
loadLocaleData
} from '../util/i18n'
import { getModesForActiveAgencyFilter, getUiUrlParams } from '../util/state'
import { getPathFromParts, ItineraryView } from '../util/ui'
import {
getPathFromParts,
isDefinedAndNotEqual,
ItineraryView
} from '../util/ui'

import {
clearActiveSearch,
Expand Down Expand Up @@ -114,12 +118,16 @@ export function setViewedTrip(payload) {
export function setMainPanelContent(payload) {
return function (dispatch, getState) {
const { otp, router } = getState()
if (otp.ui.mainPanelContent === payload) {
if (
otp.ui.mainPanelContent === payload &&
(payload || router.location.pathname === '/')
) {
// Do nothing if the panel is already set (but do something if changing to main panel
// and the router path is not at the root (/#/?ui_activeSearch=...).
// This will guard against over-enthusiastic routing and overwriting current/nested states.
console.warn(
`Attempt to route from ${otp.ui.mainPanelContent} to ${payload}. Doing nothing`
)
// Do nothing if the panel is already set. This will guard against over
// enthusiastic routing and overwriting current/nested states.
return
}
dispatch(setPanel(payload))
Expand Down Expand Up @@ -269,7 +277,9 @@ export function handleBackButtonPress(e) {
// previous search ID.
if (activeSearchId !== previousSearchId) {
dispatch(setActiveSearch(previousSearchId))
} else if (uiUrlParams.ui_activeItinerary !== previousItinIndex) {
} else if (
isDefinedAndNotEqual(uiUrlParams.ui_activeItinerary, previousItinIndex)
) {
// Active itinerary index has changed.
dispatch(setActiveItinerary({ index: previousItinIndex }))
}
Expand Down
3 changes: 1 addition & 2 deletions lib/components/app/responsive-webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,8 @@ class ResponsiveWebapp extends Component {
}

if (isMobile()) {
// If on mobile browser, check position on load
// Test location availability on load
getCurrentPosition(intl)

// Also, watch for changes in position on mobile
navigator.geolocation.watchPosition(
// On success
Expand Down
28 changes: 6 additions & 22 deletions lib/components/app/view-switcher.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Button } from 'react-bootstrap'
import { connect } from 'react-redux'
import { FormattedMessage, useIntl } from 'react-intl'
import { useHistory } from 'react-router'
import React from 'react'

import * as uiActions from '../../actions/ui'
import { MainPanelContent } from '../../actions/ui-constants'
import { setMainPanelContent } from '../../actions/ui'

type Props = {
accountsActive: boolean
Expand All @@ -23,23 +22,18 @@ const ViewSwitcher = ({
setMainPanelContent,
sticky
}: Props) => {
const history = useHistory()
const intl = useIntl()

const _showRouteViewer = () => {
setMainPanelContent(MainPanelContent.ROUTE_VIEWER)
}

const _showTripPlanner = () => {
if (accountsActive) {
// Go up to root while preserving query parameters
history.push('..' + history.location.search)
} else {
setMainPanelContent(null)
}
// setMainPanelContent(null) already includes navigation to '/'.
setMainPanelContent(null)
}

const tripPlannerActive = activePanel === null
const tripPlannerActive = activePanel === null && !accountsActive
const routeViewerActive = activePanel === MainPanelContent.ROUTE_VIEWER

return (
Expand Down Expand Up @@ -84,25 +78,15 @@ const ViewSwitcher = ({
// connect to the redux store

const mapStateToProps = (state: any) => {
const { mainPanelContent } = state.otp.ui

// Reverse the ID to string mapping
const activePanelPair = Object.entries(MainPanelContent).find(
(keyValuePair) => keyValuePair[1] === mainPanelContent
)
// activePanel is array of form [string, ID]
// The trip planner has id null
const activePanel = (activePanelPair && activePanelPair[1]) || null

return {
// TODO: more reliable way of detecting these things, such as terms of storage page
accountsActive: state.router.location.pathname.includes('/account'),
activePanel
activePanel: state.otp.ui.mainPanelContent
}
}

const mapDispatchToProps = {
setMainPanelContent
setMainPanelContent: uiActions.setMainPanelContent
}

export default connect(mapStateToProps, mapDispatchToProps)(ViewSwitcher)
28 changes: 17 additions & 11 deletions lib/components/form/call-taker/advanced-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
// FIXME: Remove the following eslint rule exception.
/* eslint-disable jsx-a11y/label-has-for */
import * as TripFormClasses from '@opentripplanner/trip-form/lib/styled'
import {
DropdownSelector,
SliderSelector,
SubmodeSelector
} from '@opentripplanner/trip-form'
import { FormattedMessage, injectIntl } from 'react-intl'
import { hasBike } from '@opentripplanner/core-utils/lib/itinerary'
import { SliderSelector, SubmodeSelector } from '@opentripplanner/trip-form'
import isEmpty from 'lodash.isempty'
import React, { Component, lazy, Suspense } from 'react'
import styled from 'styled-components'
Expand Down Expand Up @@ -155,9 +159,9 @@ class AdvancedOptions extends Component {
})
}

_setWaklTolerance = ({ walkTolerance }) => {
_setWalkTolerance = ({ walkReluctance }) => {
this.props.setUrlSearch({
walkTolerance
walkReluctance
})
}

Expand Down Expand Up @@ -224,17 +228,19 @@ class AdvancedOptions extends Component {
justifyContent: 'space-between'
}}
>
<SliderSelector
<DropdownSelector
label={intl.formatMessage({
id: 'components.AdvancedOptions.walkTolerance'
})}
max={5}
min={0}
name="walkTolerance"
onChange={this._setWaklTolerance}
step={1}
style={{ display: 'block', marginRight: '10px', width: '150px' }}
value={this.props.modeSettingValues.walkTolerance}
name="walkReluctance"
onChange={this._setWalkTolerance}
options={[
{ text: 'Avoid Walking', value: 15 },
{ text: 'Normal Walking', value: 3 },
{ text: 'Prefer walking', value: 1 }
]}
style={{ display: 'block' }}
value={this.props.modeSettingValues.walkReluctance}
/>

{hasBike(currentModes?.map((m) => m.mode).join(',') || '') ? (
Expand Down
2 changes: 1 addition & 1 deletion lib/components/narrative/metro/attribute-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getFirstTransitLegStop = (
itinerary.legs?.find((leg: Leg) => leg?.from?.vertexType === 'TRANSIT')?.from
?.name

export const getFlexAttirbutes = (
export const getFlexAttributes = (
itinerary: Itinerary
): {
isCallAhead: boolean
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
18 changes: 6 additions & 12 deletions lib/components/narrative/metro/metro-itinerary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import ItineraryBody from '../line-itin/connected-itinerary-body'
import NarrativeItinerary from '../narrative-itinerary'
import SimpleRealtimeAnnotation from '../simple-realtime-annotation'

import { getFirstTransitLegStop, getFlexAttirbutes } from './attribute-utils'
import { getFlexAttributes } from './attribute-utils'
import DepartureTimesList, {
SetActiveItineraryHandler
} from './departure-times-list'
Expand Down Expand Up @@ -202,23 +202,17 @@ class MetroItinerary extends NarrativeItinerary {
static ModesAndRoutes = MetroItineraryRoutes

_onMouseEnter = () => {
const { active, index, setVisibleItinerary, visibleItinerary } = this.props
const { active, index, setVisibleItinerary, visible } = this.props
// Set this itinerary as visible if not already visible.
const visibleNotSet =
visibleItinerary === null || visibleItinerary === undefined
const isVisible =
visibleItinerary === index || (active === index && visibleNotSet)
const isVisible = visible || active
if (typeof setVisibleItinerary === 'function' && !isVisible) {
setVisibleItinerary({ index })
}
}

_onMouseLeave = () => {
const { index, setVisibleItinerary, visibleItinerary } = this.props
if (
typeof setVisibleItinerary === 'function' &&
visibleItinerary === index
) {
const { setVisibleItinerary, visible } = this.props
if (typeof setVisibleItinerary === 'function' && visible) {
setVisibleItinerary({ index: null })
}
}
Expand Down Expand Up @@ -266,7 +260,7 @@ class MetroItinerary extends NarrativeItinerary {
const { SvgIcon } = this.context

const { isCallAhead, isContinuousDropoff, isFlexItinerary, phone } =
getFlexAttirbutes(itinerary)
getFlexAttributes(itinerary)

const { fareCurrency, transitFare } = getFare(itinerary, defaultFareType)

Expand Down
Loading

0 comments on commit 0a5337b

Please sign in to comment.