Skip to content

Commit d82dd3d

Browse files
Merge branch 'dev' into mtc-deploy-with-dev
2 parents b45e38e + a5e48da commit d82dd3d

File tree

10 files changed

+38
-43
lines changed

10 files changed

+38
-43
lines changed

lib/common/components/ManagerPage.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ export default class ManagerPage extends React.Component<Props> {
4242
render () {
4343
const {itemToLock, title} = this.props
4444
const homeIsActive = this.isActive('home') || this.isActive('feed') || this.isActive('project')
45-
const appTitle = getConfigProperty('application.title') || this.messages('datatools')
4645
const changelogUrl: ?string = getConfigProperty('application.changelog_url')
4746
const docsUrl: ?string = getConfigProperty('application.docs_url')
4847
const supportEmail: ?string = getConfigProperty('application.support_email')
4948
return (
5049
<div>
51-
<Title>{`${appTitle}${title ? ` - ${title}` : ''}`}</Title>
50+
<Title subTitle={title} />
5251
<CurrentStatusMessage />
5352
<ConfirmModal ref='confirmModal' />
5453
<InfoModal ref='infoModal' />

lib/common/components/Title.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
// @flow
22

3-
import {Component} from 'react'
3+
import { Component } from 'react'
4+
5+
import { getAppName } from '../../common/util/config'
46

57
type Props = {
6-
children: string
8+
subTitle?: ?string
79
}
810

9-
export default class Title extends Component<Props> {
10-
oldTitle = ''
11+
function makeTitle (subTitle?: ?string): string {
12+
return `${getAppName()}${subTitle ? ` - ${subTitle}` : ''}`
13+
}
1114

15+
export default class Title extends Component<Props> {
1216
componentWillMount () {
13-
this.oldTitle = document.title
14-
document.title = this.props.children
15-
}
16-
17-
componentWillUnmount () {
18-
document.title = this.oldTitle
17+
document.title = makeTitle(this.props.subTitle)
1918
}
2019

2120
componentWillReceiveProps (nextProps: Props) {
22-
if (nextProps.children !== this.props.children) {
23-
document.title = nextProps.children
21+
if (nextProps.subTitle !== this.props.subTitle) {
22+
document.title = makeTitle(this.props.subTitle)
2423
}
2524
}
2625

27-
shouldComponentUpdate (nextProps: Props) {
28-
// Never update the component when the title changes.
29-
return false
30-
}
31-
3226
render () {
3327
return null
3428
}

lib/common/util/config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
MessageFile,
1010
ModuleType
1111
} from '../../types'
12+
import { DEFAULT_TITLE } from '../constants'
1213

1314
const DEFAULT_CONFIG = {
1415
extensions: {},
@@ -77,6 +78,14 @@ export function isExtensionEnabled (extensionName: ExtensionType): boolean {
7778
)
7879
}
7980

81+
export function getAppName () {
82+
// A localized app title might exist in the ManagerPage i18n messages.
83+
// Use that as first fallback, then DEFAULT_TITLE if that one is not provided.
84+
const managerPageMessages = getComponentMessages('ManagerPage')
85+
const localizedDataToolsName = managerPageMessages('datatools')
86+
return getConfigProperty('application.title') || localizedDataToolsName || DEFAULT_TITLE
87+
}
88+
8089
function initializeConfig () {
8190
if (!process.env.SETTINGS) {
8291
throw new Error('SETTINGS environment variable not set')

lib/editor/components/GtfsEditor.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import * as userActions from '../../manager/actions/user'
1717
import ActiveEntityList from '../containers/ActiveEntityList'
1818
import ActiveTimetableEditor from '../containers/ActiveTimetableEditor'
1919
import ActiveFeedInfoPanel from '../containers/ActiveFeedInfoPanel'
20-
import {getConfigProperty} from '../../common/util/config'
2120
import {getEntityName, getTableById} from '../util/gtfs'
2221
import {getEditorEnabledState, GTFS_ICONS} from '../util/ui'
2322
import type {Props as ContainerProps} from '../containers/ActiveGtfsEditor'
@@ -245,10 +244,7 @@ export default class GtfsEditor extends Component<Props, State> {
245244

246245
getEditorTitle () {
247246
const {activeComponent, activeEntity} = this.props
248-
const appName = getConfigProperty('application.title')
249-
let title = ''
250-
if (appName) title += `${appName} - `
251-
title += 'GTFS Editor'
247+
let title = 'GTFS Editor'
252248
if (activeEntity) {
253249
title += ` - ${getEntityName(activeEntity)}`
254250
} else if (activeComponent) {
@@ -303,7 +299,7 @@ export default class GtfsEditor extends Component<Props, State> {
303299
: null
304300
return (
305301
<div className='GtfsEditor'>
306-
<Title>{this.getEditorTitle()}</Title>
302+
<Title subTitle={this.getEditorTitle()} />
307303
<ActiveEditorLockManager
308304
disableLock={!namespace}
309305
feedSourceId={feedSourceId}

lib/manager/components/UserHomePage.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import * as feedsActions from '../actions/feeds'
1010
import * as userActions from '../actions/user'
1111
import * as visibilityFilterActions from '../actions/visibilityFilter'
1212
import ManagerPage from '../../common/components/ManagerPage'
13-
import { AUTH0_DISABLED, DEFAULT_DESCRIPTION, DEFAULT_TITLE } from '../../common/constants'
14-
import {getConfigProperty, getComponentMessages} from '../../common/util/config'
13+
import { AUTH0_DISABLED, DEFAULT_DESCRIPTION } from '../../common/constants'
14+
import {getConfigProperty, getComponentMessages, getAppName} from '../../common/util/config'
1515
import {defaultSorter} from '../../common/util/util'
1616
import type {Props as ContainerProps} from '../containers/ActiveUserHomePage'
1717
import type {Project} from '../../types'
@@ -85,7 +85,7 @@ export default class UserHomePage extends Component<Props, State> {
8585
} = this.props
8686
const visibleProjects = projects.sort(defaultSorter)
8787
const activeProject = project
88-
const appTitle = getConfigProperty('application.title') || 'datatools'
88+
const appTitle = getAppName()
8989
return (
9090
<ManagerPage
9191
ref='page'
@@ -97,7 +97,7 @@ export default class UserHomePage extends Component<Props, State> {
9797
<Col md={8} xs={12}>
9898
{/* Top Welcome Box */}
9999
<Jumbotron style={{ padding: 30 }}>
100-
<h2>{this.messages('welcomeTo')} {appTitle || DEFAULT_TITLE}!</h2>
100+
<h2>{this.messages('welcomeTo')} {appTitle}!</h2>
101101
<p>{getConfigProperty('application.description') || DEFAULT_DESCRIPTION}</p>
102102
<ButtonToolbar>
103103
<Button

lib/manager/components/deployment/DeploymentViewer.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Loading from '../../../common/components/Loading'
2626
import EditableTextField from '../../../common/components/EditableTextField'
2727
import Title from '../../../common/components/Title'
2828
import WatchButton from '../../../common/containers/WatchButton'
29-
import {getComponentMessages, getConfigProperty} from '../../../common/util/config'
29+
import {getComponentMessages} from '../../../common/util/config'
3030
import {formatTimestamp, fromNow} from '../../../common/util/date-time'
3131
import {defaultTileLayerProps} from '../../../common/util/maps'
3232
import { versionsSorter } from '../../../common/util/util'
@@ -385,11 +385,9 @@ export default class DeploymentViewer extends Component<Props, State> {
385385
const oldDeployment = (target && project.deployments)
386386
? project.deployments.find(d => d.deployedTo === target && deployment.routerId === d.routerId)
387387
: null
388-
const appName = getConfigProperty('application.title')
389-
const title = `${appName ? appName + ' - ' : ''}${deployment.name}`
390388
return (
391389
<div>
392-
<Title>{title}</Title>
390+
<Title subTitle={deployment.name} />
393391
{target && (
394392
<DeploymentConfirmModal
395393
deployment={deployment}

lib/manager/containers/__tests__/__snapshots__/ActiveProjectViewer.js.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ exports[`lib > manager > ActiveProjectViewer should render with newly created pr
172172
title="mock-project"
173173
>
174174
<div>
175-
<Title />
175+
<Title
176+
subTitle="mock-project"
177+
/>
176178
<Connect(StatusMessage)>
177179
<StatusMessage
178180
dispatch={[Function]}

lib/public/components/PublicLandingPage.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { Button, Grid, Row, Col } from 'react-bootstrap'
55
import {Link} from 'react-router'
66
import {LinkContainer} from 'react-router-bootstrap'
77

8-
import { DEFAULT_DESCRIPTION, DEFAULT_LOGO, DEFAULT_TITLE } from '../../common/constants'
9-
import { getComponentMessages, getConfigProperty, isModuleEnabled } from '../../common/util/config'
8+
import { DEFAULT_DESCRIPTION, DEFAULT_LOGO } from '../../common/constants'
9+
import { getAppName, getComponentMessages, getConfigProperty, isModuleEnabled } from '../../common/util/config'
1010
import type {Props as ContainerProps} from '../containers/ActivePublicLandingPage'
1111
import type {ManagerUserState} from '../../types/reducers'
1212

@@ -20,7 +20,6 @@ export default class PublicLandingPage extends Component<Props> {
2020
messages = getComponentMessages('PublicLandingPage')
2121

2222
render () {
23-
const appTitle = getConfigProperty('application.title') || DEFAULT_TITLE
2423
const appDescription = getConfigProperty('application.description') || DEFAULT_DESCRIPTION
2524
const logoLarge = getConfigProperty('application.logo_large') || DEFAULT_LOGO
2625
return (
@@ -29,7 +28,7 @@ export default class PublicLandingPage extends Component<Props> {
2928
<Row>
3029
<Col style={{textAlign: 'center'}} smOffset={4} xs={12} sm={4}>
3130
<img alt={this.messages('appLogo')} src={logoLarge} style={{maxWidth: '256px'}} />
32-
<h1>{appTitle}</h1>
31+
<h1>{getAppName()}</h1>
3332
</Col>
3433
</Row>
3534
<Row>

lib/public/components/PublicPage.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import ConfirmModal from '../../common/components/ConfirmModal'
77
import SelectFileModal from '../../common/components/SelectFileModal'
88
import Title from '../../common/components/Title'
99
import ActivePublicHeader from '../containers/ActivePublicHeader'
10-
import { getConfigProperty } from '../../common/util/config'
1110

1211
type Props = {
1312
children?: Node
@@ -23,10 +22,9 @@ export default class PublicPage extends Component<Props> {
2322
}
2423

2524
render () {
26-
const appTitle = getConfigProperty('application.title') || 'Data Tools'
2725
return (
2826
<div>
29-
<Title>{appTitle}</Title>
27+
<Title />
3028
<ActivePublicHeader />
3129
{this.props.children}
3230
<CurrentStatusMessage />

lib/public/containers/ActivePublicHeader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { connect } from 'react-redux'
55

66
import PublicHeader from '../components/PublicHeader'
77
import * as userActions from '../../manager/actions/user'
8-
import { getConfigProperty } from '../../common/util/config'
8+
import { getAppName } from '../../common/util/config'
99
import type { AppState } from '../../types/reducers'
1010

1111
export type Props = {}
1212

1313
const mapStateToProps = (state: AppState, ownProps: Props) => {
1414
return {
15-
title: getConfigProperty('application.title'),
15+
title: getAppName(),
1616
username: state.user.profile ? state.user.profile.email : null,
1717
userPicture: state.user.profile ? state.user.profile.picture : null
1818
}

0 commit comments

Comments
 (0)