Skip to content

Commit

Permalink
Merge pull request #990 from opentripplanner/alert-on-forbidden-combo
Browse files Browse the repository at this point in the history
Alert if user clicks Plan Trip with invalid mode selection
  • Loading branch information
binh-dam-ibigroup authored Sep 14, 2023
2 parents 6822dc0 + 86e63b6 commit d7f0c2b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions i18n/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ components:
modeSelectorLabel: Select a transit mode
BatchSettings:
destination: destination
invalidModeSelection: >-
Cannot plan a trip using the selected modes. Try including transit in your
mode selection.
origin: origin
planTripTooltip: Plan trip
validationMessage: "Please define the following fields to plan a trip: {issues}"
Expand Down
3 changes: 3 additions & 0 deletions i18n/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ components:
modeSelectorLabel: Sélectionnez un mode de transport
BatchSettings:
destination: destination
invalidModeSelection: >-
Impossible de planifier un trajet avec les modes sélectionnés. Réessayez
en ajoutant les transports publics.
origin: point de départ
planTripTooltip: Planifier le trajet
validationMessage: >-
Expand Down
5 changes: 5 additions & 0 deletions lib/actions/api-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const RoutingQueryCallResult = {
INVALID_MODE_SELECTION: 2,
INVALID_QUERY: 1,
SUCCESS: 0
}
7 changes: 6 additions & 1 deletion lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
updateOtpUrlParams
} from './api'
import { rememberPlace } from './user'
import { RoutingQueryCallResult } from './api-constants'
import { setItineraryView } from './ui'
import { zoomToPlace } from './map'

Expand Down Expand Up @@ -800,7 +801,7 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
// Don't permit a routing query if the query is invalid
if (!queryIsValid(state)) {
console.warn('Query is invalid. Aborting routing query', currentQuery)
return
return RoutingQueryCallResult.INVALID_QUERY
}

const {
Expand Down Expand Up @@ -968,6 +969,10 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
if (isNewSearch || params.ui_activeSearch !== searchId) {
dispatch(updateOtpUrlParams(state, searchId))
}

return combinations.length === 0
? RoutingQueryCallResult.INVALID_MODE_SELECTION
: RoutingQueryCallResult.SUCCESS
}
}

Expand Down
12 changes: 11 additions & 1 deletion lib/components/form/batch-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ComponentContext } from '../../util/contexts'
import { generateModeSettingValues } from '../../util/api'
import { getActiveSearch, hasValidLocation } from '../../util/state'
import { getFormattedMode } from '../../util/i18n'
import { RoutingQueryCallResult } from '../../actions/api-constants'
import { StyledIconWrapper } from '../util/styledIcon'

import {
Expand Down Expand Up @@ -165,7 +166,16 @@ function BatchSettings({

// Plan trip.
updateQueryTimeIfLeavingNow()
routingQuery()
const routingQueryResult = routingQuery()

// If mode combination is not valid (i.e. produced no query), alert the user.
if (routingQueryResult === RoutingQueryCallResult.INVALID_MODE_SELECTION) {
window.alert(
intl.formatMessage({
id: 'components.BatchSettings.invalidModeSelection'
})
)
}
}, [
currentQuery,
intl,
Expand Down

0 comments on commit d7f0c2b

Please sign in to comment.