-
Notifications
You must be signed in to change notification settings - Fork 59
Update issue reporting template #538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e07f3fd
refactor: run autoformatter
miles-grant-ibigroup 158482c
refactor(trip-tools): modernize report issue email template
miles-grant-ibigroup c9d973b
refactor(trip-tools): add prop types
miles-grant-ibigroup fd8ea13
refactor: add newlines to email template
miles-grant-ibigroup 04ea9e9
Revert "refactor: add newlines to email template"
binh-dam-ibigroup 96d72fa
improvement(i18n): Improve report email template.
binh-dam-ibigroup 170f3ce
Merge pull request #542 from opentripplanner/update-issue-reporting-t…
miles-grant-ibigroup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,88 +1,18 @@ | ||
| /* eslint-disable no-case-declarations */ | ||
| import { Button } from 'react-bootstrap' | ||
| import { connect } from 'react-redux' | ||
| import bowser from 'bowser' | ||
| import copyToClipboard from 'copy-to-clipboard' | ||
| import React, {Component} from 'react' | ||
| import { connect } from 'react-redux' | ||
| import { Button } from 'react-bootstrap' | ||
| import PropTypes from 'prop-types' | ||
| import React, { Component } from 'react' | ||
| // import { DropdownButton, MenuItem } from 'react-bootstrap' | ||
| import { FormattedMessage, injectIntl } from 'react-intl' | ||
|
|
||
| import Icon from '../util/icon' | ||
|
|
||
| class TripTools extends Component { | ||
| static defaultProps = { | ||
| buttonTypes: [ 'COPY_URL', 'PRINT', 'REPORT_ISSUE', 'START_OVER' ] | ||
| } | ||
|
|
||
| render () { | ||
| const { buttonTypes, reactRouterConfig, reportConfig } = this.props | ||
|
|
||
| const buttonComponents = [] | ||
| buttonTypes.forEach((type) => { | ||
| switch (type) { | ||
| case 'COPY_URL': | ||
| buttonComponents.push(<CopyUrlButton />) | ||
| break | ||
| case 'PRINT': | ||
| buttonComponents.push(<PrintButton />) | ||
| break | ||
| case 'REPORT_ISSUE': | ||
| if (!reportConfig || !reportConfig.mailto) break | ||
| buttonComponents.push(<ReportIssueButton {...reportConfig} />) | ||
| break | ||
| case 'START_OVER': | ||
| // Determine "home" URL | ||
| let startOverUrl = '/' | ||
| if (reactRouterConfig && reactRouterConfig.basename) { | ||
| startOverUrl += reactRouterConfig.basename | ||
| } | ||
| buttonComponents.push( | ||
| // FIXME: The Spanish string does not fit in button width. | ||
| <LinkButton | ||
| icon='undo' | ||
| text={<FormattedMessage id='common.forms.startOver' />} | ||
| url={startOverUrl} | ||
| /> | ||
| ) | ||
| break | ||
| } | ||
| }) | ||
|
|
||
| return ( | ||
| <div className='trip-tools'> | ||
| {buttonComponents.map((btn, i) => <div className='button-container' key={i}>{btn}</div>)} | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // Share/Save Dropdown Component -- not used currently | ||
|
|
||
| /* | ||
| class ShareSaveDropdownButton extends Component { | ||
| _onCopyToClipboardClick = () => { | ||
| copyToClipboard(window.location.href) | ||
| } | ||
|
|
||
| render () { | ||
| return ( | ||
| <DropdownButton | ||
| className='tool-button' | ||
| title={<span><i className='fa fa-share' /> Share/Save</span>} | ||
| id={'tool-share-dropdown'} | ||
| > | ||
| <MenuItem onClick={this._onCopyToClipboardClick}> | ||
| <i className='fa fa-clipboard' /> Copy Link to Clipboard | ||
| </MenuItem> | ||
| </DropdownButton> | ||
| ) | ||
| } | ||
| } | ||
| */ | ||
|
|
||
| // Copy URL Button | ||
|
|
||
| class CopyUrlButton extends Component { | ||
| constructor (props) { | ||
| constructor(props) { | ||
| super(props) | ||
| this.state = { showCopied: false } | ||
| } | ||
|
|
@@ -100,35 +30,32 @@ class CopyUrlButton extends Component { | |
| url = `${parts[0]}#/start/x/x/x/${routerId}${parts[1]}` | ||
| } else { | ||
| // Console logs are not internationalized. | ||
| console.warn('URL not formatted as expected, copied URL will not contain session routerId.', routerId) | ||
| console.warn( | ||
| 'URL not formatted as expected, copied URL will not contain session routerId.', | ||
| routerId | ||
| ) | ||
| } | ||
| } | ||
| copyToClipboard(url) | ||
| this.setState({ showCopied: true }) | ||
| window.setTimeout(this._resetState, 2000) | ||
| } | ||
|
|
||
| render () { | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <Button | ||
| className='tool-button' | ||
| onClick={this._onClick} | ||
| > | ||
| {this.state.showCopied | ||
| ? ( | ||
| <span> | ||
| <Icon type='check' withSpace /> | ||
| <FormattedMessage id='components.TripTools.linkCopied' /> | ||
| </span> | ||
| ) | ||
| : ( | ||
| <span> | ||
| <Icon type='clipboard' withSpace /> | ||
| <FormattedMessage id='components.TripTools.copyLink' /> | ||
| </span> | ||
| ) | ||
| } | ||
| <Button className="tool-button" onClick={this._onClick}> | ||
| {this.state.showCopied ? ( | ||
| <span> | ||
| <Icon type="check" withSpace /> | ||
| <FormattedMessage id="components.TripTools.linkCopied" /> | ||
| </span> | ||
| ) : ( | ||
| <span> | ||
| <Icon type="clipboard" withSpace /> | ||
| <FormattedMessage id="components.TripTools.copyLink" /> | ||
| </span> | ||
| )} | ||
| </Button> | ||
| </div> | ||
| ) | ||
|
|
@@ -144,15 +71,12 @@ class PrintButton extends Component { | |
| window.open(printUrl, '_blank') | ||
| } | ||
|
|
||
| render () { | ||
| render() { | ||
| return ( | ||
| <div> | ||
| <Button | ||
| className='tool-button' | ||
| onClick={this._onClick} | ||
| > | ||
| <Icon type='print' withSpace /> | ||
| <FormattedMessage id='common.forms.print' /> | ||
| <Button className="tool-button" onClick={this._onClick}> | ||
| <Icon type="print" withSpace /> | ||
| <FormattedMessage id="common.forms.print" /> | ||
| </Button> | ||
| </div> | ||
| ) | ||
|
|
@@ -164,37 +88,45 @@ class PrintButton extends Component { | |
| class ReportIssueButtonBase extends Component { | ||
| _onClick = () => { | ||
| const { intl, mailto, subject: configuredSubject } = this.props | ||
| const subject = configuredSubject || intl.formatMessage({id: 'components.TripTools.reportEmailSubject'}) | ||
| const subject = | ||
| configuredSubject || | ||
| intl.formatMessage({ id: 'components.TripTools.reportEmailSubject' }) | ||
| const bodyLines = [ | ||
| intl.formatMessage({id: 'components.TripTools.reportEmailTemplate'}), | ||
| intl.formatMessage({ id: 'components.TripTools.reportEmailTemplate' }), | ||
| '', | ||
| // Search data section is for support and is not translated. | ||
| 'SEARCH DATA:', | ||
| 'Address: ' + window.location.href, | ||
| 'Browser: ' + bowser.name + ' ' + bowser.version, | ||
| 'OS: ' + bowser.osname + ' ' + bowser.osversion, | ||
| '', | ||
| 'ADDITIONAL COMMENTS:', | ||
| '' | ||
| ] | ||
|
|
||
| window.open(`mailto:${mailto}?subject=${subject}&body=${encodeURIComponent(bodyLines.join('\n'))}`, '_self') | ||
| window.open( | ||
| `mailto:${mailto}?subject=${subject}&body=${encodeURIComponent( | ||
| bodyLines.join('\n') | ||
| )}`, | ||
| '_self' | ||
| ) | ||
| } | ||
|
|
||
| render () { | ||
| render() { | ||
| return ( | ||
| <Button | ||
| className='tool-button' | ||
| onClick={this._onClick} | ||
| > | ||
| <Icon type='flag' withSpace /> | ||
| <Button className="tool-button" onClick={this._onClick}> | ||
| <Icon type="flag" withSpace /> | ||
| {/* FIXME: Depending on translation, Spanish and French strings may not fit in button width. */} | ||
| <FormattedMessage id='components.TripTools.reportIssue' /> | ||
| <FormattedMessage id="components.TripTools.reportIssue" /> | ||
| </Button> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| ReportIssueButtonBase.propTypes = { | ||
| intl: PropTypes.object, | ||
| mailto: PropTypes.string, | ||
| subject: PropTypes.string | ||
| } | ||
|
|
||
| // The ReportIssueButton component above, with an intl prop | ||
| // for retrieving messages shown outside of React rendering. | ||
| const ReportIssueButton = injectIntl(ReportIssueButtonBase) | ||
|
|
@@ -206,14 +138,11 @@ class LinkButton extends Component { | |
| window.location.href = this.props.url | ||
| } | ||
|
|
||
| render () { | ||
| render() { | ||
| const { icon, text } = this.props | ||
| return ( | ||
| <div> | ||
| <Button | ||
| className='tool-button' | ||
| onClick={this._onClick} | ||
| > | ||
| <Button className="tool-button" onClick={this._onClick}> | ||
| {icon && <Icon type={icon} withSpace />} | ||
| {text} | ||
| </Button> | ||
|
|
@@ -222,9 +151,74 @@ class LinkButton extends Component { | |
| } | ||
| } | ||
|
|
||
| LinkButton.propTypes = { | ||
| icon: PropTypes.string, | ||
| text: PropTypes.string, | ||
| url: PropTypes.string | ||
| } | ||
|
|
||
| class TripTools extends Component { | ||
| static defaultProps = { | ||
| buttonTypes: ['COPY_URL', 'PRINT', 'REPORT_ISSUE', 'START_OVER'] | ||
| } | ||
|
|
||
| render() { | ||
| const { buttonTypes, reactRouterConfig, reportConfig } = this.props | ||
|
|
||
| const buttonComponents = [] | ||
| buttonTypes.forEach((type) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about a map to map buttonTypes to buttonComponents? |
||
| switch (type) { | ||
| case 'COPY_URL': | ||
| buttonComponents.push(<CopyUrlButton />) | ||
| break | ||
| case 'PRINT': | ||
| buttonComponents.push(<PrintButton />) | ||
| break | ||
| case 'REPORT_ISSUE': | ||
| if (!reportConfig || !reportConfig.mailto) break | ||
| buttonComponents.push(<ReportIssueButton {...reportConfig} />) | ||
| break | ||
| case 'START_OVER': | ||
| // Determine "home" URL | ||
| let startOverUrl = '/' | ||
| if (reactRouterConfig && reactRouterConfig.basename) { | ||
| startOverUrl += reactRouterConfig.basename | ||
| } | ||
| buttonComponents.push( | ||
| // FIXME: The Spanish string does not fit in button width. | ||
| <LinkButton | ||
| icon="undo" | ||
| text={<FormattedMessage id="common.forms.startOver" />} | ||
| url={startOverUrl} | ||
| /> | ||
| ) | ||
| break | ||
| default: | ||
| console.warn(`TripTools called with invalid button type ${type}!`) | ||
| } | ||
| }) | ||
|
|
||
| return ( | ||
| <div className="trip-tools"> | ||
| {buttonComponents.map((btn, i) => ( | ||
| <div className="button-container" key={i}> | ||
| {btn} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| TripTools.propTypes = { | ||
| buttonTypes: PropTypes.arrayOf(PropTypes.string), | ||
| reactRouterConfig: PropTypes.object, | ||
| reportConfig: PropTypes.object | ||
| } | ||
|
|
||
| // Connect main class to redux store | ||
|
|
||
| const mapStateToProps = (state, ownProps) => { | ||
| const mapStateToProps = (state) => { | ||
| return { | ||
| reactRouterConfig: state.otp.config.reactRouter, | ||
| reportConfig: state.otp.config.reportIssue | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like it would work well as a functional component.