Skip to content

Commit

Permalink
fix(RouteViewer): Show user friendly pattern name in title bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Mar 6, 2023
1 parent 06e8ed4 commit 4a00fc2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/components/app/responsive-webapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ResponsiveWebapp extends Component {
setMapCenter,
title
} = this.props
document.title = title
// document.title = title
const urlParams = coreUtils.query.getUrlParams()
const newSearchId = urlParams.ui_activeSearch
// Determine if trip is being replanned by checking the active search ID
Expand Down
32 changes: 28 additions & 4 deletions lib/components/viewers/route-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import React, { Component } from 'react'
import * as apiActions from '../../actions/api'
import * as uiActions from '../../actions/ui'
import { ComponentContext } from '../../util/contexts'
import {
extractHeadsignFromPattern,
getModeFromRoute,
getRouteColorBasedOnSettings
} from '../../util/viewer'
import {
getAgenciesFromRoutes,
getModesForActiveAgencyFilter,
getSortedFilteredRoutes
} from '../../util/state'
import { getFormattedMode } from '../../util/i18n'
import {
getModeFromRoute,
getRouteColorBasedOnSettings
} from '../../util/viewer'
import { StyledIconWrapper } from '../util/styledIcon'

import { RouteName, RouteRow } from './RouteRow'
Expand Down Expand Up @@ -70,14 +71,36 @@ class RouteViewer extends Component {
patternId: null
})

getTitle = () => {
const { appTitle, intl, viewedRoute, viewedRouteObject } = this.props
const { patternId } = viewedRoute
const pattern = viewedRouteObject?.patterns?.[patternId]
return (
intl.formatMessage(
{ id: 'util.state.titleBarRouteId' },
{ routeId: viewedRoute?.routeId }
) +
' | ' +
(patternId &&
`Direction ${
pattern &&
extractHeadsignFromPattern(pattern, viewedRouteObject.shortName)
}`) +
' | ' +
appTitle
)
}

componentDidMount() {
document.title = this.getTitle()
this.props.findRoutesIfNeeded()
}

/** Used to scroll to actively viewed route on load */
componentDidUpdate() {
const { routes } = this.props
const { initialRender } = this.state
document.title = this.getTitle()

// Wait until more than the one route is present.
// This ensures that there is something to scroll past!
Expand Down Expand Up @@ -321,6 +344,7 @@ class RouteViewer extends Component {
const mapStateToProps = (state) => {
return {
agencies: getAgenciesFromRoutes(state),
appTitle: state.otp.config.title, // or the default one
filter: state.otp.ui.routeViewer.filter,
modes: getModesForActiveAgencyFilter(state),
routes: getSortedFilteredRoutes(state),
Expand Down
4 changes: 1 addition & 3 deletions lib/util/itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import coreUtils from '@opentripplanner/core-utils'

import { WEEKDAYS, WEEKEND_DAYS } from './monitored-trip'

export function isBatchRoutingEnabled(otpConfig) {
return Boolean(otpConfig.routingTypes.find((t) => t.key === 'BATCH'))
}
// TODO: Delete all 'BATCH' config entries

/**
* Determines whether the specified Itinerary can be monitored.
Expand Down
10 changes: 2 additions & 8 deletions lib/util/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,16 +836,10 @@ export function getTitle(state, intl) {
const { localUser, loggedInUser } = state.user
const user = loggedInUser || localUser
const title = config.title || DEFAULT_TITLE
const { mainPanelContent, viewedRoute, viewedStop } = ui

const { mainPanelContent, viewedStop } = ui
let status
switch (mainPanelContent) {
case MainPanelContent.ROUTE_VIEWER:
case MainPanelContent.PATTERN_VIEWER:
status = intl.formatMessage(
{ id: 'util.state.titleBarRouteId' },
{ routeId: viewedRoute?.routeId }
)
break
case MainPanelContent.STOP_VIEWER:
status = intl.formatMessage(
{ id: 'util.state.titleBarStopId' },
Expand Down

0 comments on commit 4a00fc2

Please sign in to comment.