Skip to content

Commit 0dbb277

Browse files
Merge pull request #612 from opentripplanner/print-correct-itinerary
fix(printable-itinerary): always print selected itinerary
2 parents 1b3d630 + f29ae2a commit 0dbb277

File tree

5 files changed

+62
-36
lines changed

5 files changed

+62
-36
lines changed

Diff for: i18n/en-US.yml

+2
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ common:
649649
forms:
650650
back: Back
651651
cancel: Cancel
652+
clear: Clear
653+
close: Close
652654
error: error!
653655
defaultValue: "{value} (default)"
654656
delete: Delete

Diff for: i18n/fr.yml

+2
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ common:
628628
forms:
629629
back: Retour
630630
cancel: Annuler
631+
clear: Effacer
632+
close: Fermer
631633
error: erreur !
632634
defaultValue: "{value} (défaut)"
633635
delete: Supprimer

Diff for: lib/actions/form.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function setQueryParam(payload, searchId) {
9595
* query made during a call taker session, to prevent
9696
* a search from being added to the current call)
9797
*/
98-
export function parseUrlQueryString(params = getUrlParams(), source) {
98+
export function parseUrlQueryString(params = getUrlParams(), source = null) {
9999
return function (dispatch, getState) {
100100
const state = getState()
101101
if (state.otp.ui.mainPanelContent !== null) return state

Diff for: lib/components/app/print-layout.js renamed to lib/components/app/print-layout.tsx

+56-34
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
1-
import PrintableItinerary from '@opentripplanner/printable-itinerary'
2-
import PropTypes from 'prop-types'
3-
import React, { Component } from 'react'
41
import { Button } from 'react-bootstrap'
5-
import { FormattedMessage } from 'react-intl'
62
import { connect } from 'react-redux'
3+
import { FormattedMessage } from 'react-intl'
4+
import { Itinerary } from '@opentripplanner/types'
5+
// @ts-expect-error not typescripted yet
6+
import PrintableItinerary from '@opentripplanner/printable-itinerary'
7+
import React, { Component } from 'react'
78

9+
import {
10+
addPrintViewClassToRootHtml,
11+
clearClassFromRootHtml
12+
} from '../../util/print'
13+
import { ComponentContext } from '../../util/contexts'
14+
import { getActiveItinerary } from '../../util/state'
815
import { parseUrlQueryString } from '../../actions/form'
916
import { routingQuery } from '../../actions/api'
1017
import DefaultMap from '../map/default-map'
11-
import TripDetails from '../narrative/connected-trip-details'
12-
import { ComponentContext } from '../../util/contexts'
1318
import Icon from '../util/icon'
1419
import SpanWithSpace from '../util/span-with-space'
15-
import { addPrintViewClassToRootHtml, clearClassFromRootHtml } from '../../util/print'
16-
import { getActiveItinerary } from '../../util/state'
20+
import TripDetails from '../narrative/connected-trip-details'
1721

18-
class PrintLayout extends Component {
19-
static propTypes = {
20-
itinerary: PropTypes.object,
21-
parseUrlQueryString: PropTypes.func
22-
}
22+
type Props = {
23+
// TODO: Typescript config type
24+
config: any
25+
// TODO: typescript state.js
26+
itinerary: any
27+
location?: { search?: string }
28+
parseUrlQueryString: (params?: any, source?: string) => any
29+
}
30+
type State = {
31+
mapVisible?: boolean
32+
}
2333

34+
class PrintLayout extends Component<Props, State> {
2435
static contextType = ComponentContext
2536

26-
constructor (props) {
37+
constructor(props: Props) {
2738
super(props)
2839
this.state = {
2940
mapVisible: true
@@ -38,53 +49,63 @@ class PrintLayout extends Component {
3849
window.print()
3950
}
4051

41-
componentDidMount () {
42-
const { location, parseUrlQueryString } = this.props
52+
_close = () => {
53+
window.location.replace(String(window.location).replace('print/', ''))
54+
}
55+
56+
componentDidMount() {
57+
const { itinerary, location, parseUrlQueryString } = this.props
4358
// Add print-view class to html tag to ensure that iOS scroll fix only applies
4459
// to non-print views.
4560
addPrintViewClassToRootHtml()
4661
// Parse the URL query parameters, if present
47-
if (location && location.search) {
62+
if (!itinerary && location && location.search) {
4863
parseUrlQueryString()
4964
}
5065
}
5166

52-
componentWillUnmount () {
67+
componentWillUnmount() {
5368
clearClassFromRootHtml()
5469
}
5570

56-
render () {
71+
render() {
5772
const { config, itinerary } = this.props
5873
const { LegIcon } = this.context
5974

6075
return (
61-
<div className='otp print-layout'>
76+
<div className="otp print-layout">
6277
{/* The header bar, including the Toggle Map and Print buttons */}
63-
<div className='header'>
78+
<div className="header">
6479
<div style={{ float: 'right' }}>
6580
<SpanWithSpace margin={0.25}>
66-
<Button bsSize='small' onClick={this._toggleMap}>
67-
<Icon type='map' withSpace />
68-
<FormattedMessage id='components.PrintLayout.toggleMap' />
81+
<Button bsSize="small" onClick={this._toggleMap}>
82+
<Icon type="map" withSpace />
83+
<FormattedMessage id="components.PrintLayout.toggleMap" />
84+
</Button>
85+
</SpanWithSpace>
86+
<SpanWithSpace margin={0.25}>
87+
<Button bsSize="small" onClick={this._print}>
88+
<Icon type="print" withSpace />
89+
<FormattedMessage id="common.forms.print" />
6990
</Button>
7091
</SpanWithSpace>
71-
<Button bsSize='small' onClick={this._print}>
72-
<Icon type='print' withSpace />
73-
<FormattedMessage id='common.forms.print' />
92+
<Button bsSize="small" onClick={this._close}>
93+
<Icon type="close" withSpace />
94+
<FormattedMessage id="common.forms.close" />
7495
</Button>
7596
</div>
76-
<FormattedMessage id='components.PrintLayout.itinerary' />
97+
<FormattedMessage id="components.PrintLayout.itinerary" />
7798
</div>
7899

79100
{/* The map, if visible */}
80-
{this.state.mapVisible &&
81-
<div className='map-container'>
101+
{this.state.mapVisible && (
102+
<div className="map-container">
82103
<DefaultMap />
83104
</div>
84-
}
105+
)}
85106

86107
{/* The main itinerary body */}
87-
{itinerary &&
108+
{itinerary && (
88109
<>
89110
<PrintableItinerary
90111
config={config}
@@ -93,15 +114,16 @@ class PrintLayout extends Component {
93114
/>
94115
<TripDetails itinerary={itinerary} />
95116
</>
96-
}
117+
)}
97118
</div>
98119
)
99120
}
100121
}
101122

102123
// connect to the redux store
103124

104-
const mapStateToProps = (state, ownProps) => {
125+
// TODO: Typescript state
126+
const mapStateToProps = (state: any) => {
105127
return {
106128
config: state.otp.config,
107129
itinerary: getActiveItinerary(state)

Diff for: lib/components/narrative/trip-tools.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class PrintButton extends Component {
6868
_onClick = () => {
6969
// Note: this is designed to work only with hash routing.
7070
const printUrl = window.location.href.replace('#', '#/print')
71-
window.open(printUrl, '_blank')
71+
window.location = printUrl
7272
}
7373

7474
render() {

0 commit comments

Comments
 (0)