Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 99 additions & 41 deletions lib/components/form/date-time-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,132 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Button, ButtonGroup } from 'react-bootstrap'
import styled from 'styled-components'
import { getTimeFormat, getDateFormat } from '@opentripplanner/core-utils/lib/time'
import { DateTimeSelector } from '@opentripplanner/trip-form'
import * as TripFormClasses from '@opentripplanner/trip-form/lib/styled'

import DateTimeSelector from './date-time-selector'
import { setQueryParam } from '../../actions/form'

// Define default routingType labels and components
const rtDefaults = [
{
key: 'ITINERARY',
text: 'Itinerary',
component: <DateTimeSelector />
}, {
key: 'PROFILE',
text: 'Profile',
component: <DateTimeSelector profile />
// Styles for the DateTimeSelector.
// TODO: Find a way to bring OTP CSS classes in here.
// See for instance:
// https://github.com/theKashey/styled-components-mixins
// https://github.com/kingpowerclick/styled-bootstrap-mixins

const StyledDateTimeSelector = styled(DateTimeSelector)`
margin: 0 -15px 20px;
${TripFormClasses.DateTimeSelector.DateTimeRow} {
margin-top: 20px;
}

input {
-webkit-appearance: textfield;
-moz-appearance: textfield;
appearance: textfield;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
box-shadow: none;
color: #555;
font-family: inherit;
font-size: 16px;
height: 34px;
padding: 6px 12px;
text-align: center;
&.focused {
outline: 0;
border-color: #66afe9;
font-weight: 400;
box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125);
}
}
]

button {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 4px;
color: #333;
cursor: pointer;
font-family: inherit;
font-weight: 400;
font-size: 14px;
line-height: 1.42857143;
outline-offset:-2px;
padding: 6px 12px;
text-align: center;
touch-action: manipulation;
user-select: none;
white-space: nowrap;

&.active {
background-color: #e6e6e6;
border-color: #adadad;
box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125);
font-weight: 400;
}
&:hover {
background-color: #e6e6e6;
border-color: #adadad;
}
&.active {
background-color: #e6e6e6;
border-color: #adadad;
box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125);
font-weight: 400;
&:hover {
background-color: #d4d4d4;
border-color: #8c8c8c;
}
}
}
`

class DateTimeModal extends Component {
static propTypes = {
routingType: PropTypes.string,
setQueryParam: PropTypes.func
}

render () {
const { config, routingType, setQueryParam } = this.props
const { date, dateFormatLegacy, departArrive, setQueryParam, time, timeFormatLegacy } = this.props

return (
<div className='date-time-modal'>
{/* The routing-type selection button row. Only show if more than one configured */}
{config.routingTypes.length > 1 && (
<div className='button-row'>
<ButtonGroup justified>
{config.routingTypes.map(rtConfig => {
return (
<ButtonGroup key={rtConfig.key}>
<Button
className={rtConfig.key === routingType ? 'selected' : ''}
onClick={() => {
setQueryParam({ routingType: rtConfig.key })
}}
>
{rtConfig.text || rtDefaults.find(d => d.key === rtConfig.key).text}
</Button>
</ButtonGroup>
)
})}
</ButtonGroup>
</div>
)}

{/* The main panel for the selected routing type */}
<div className='main-panel'>
{rtDefaults.find(d => d.key === routingType).component}
<StyledDateTimeSelector
className='date-time-selector'
date={date}
departArrive={departArrive}
onQueryParamChange={setQueryParam}
time={time}
// These props below are for Safari on MacOS, and legacy browsers
// that don't support `<input type="time|date">`.
// These props are not relevant in modern browsers,
// where `<input type="time|date">` already
// formats the time|date according to the OS settings.
dateFormatLegacy={dateFormatLegacy}
timeFormatLegacy={timeFormatLegacy}
Copy link
Member

@landonreed landonreed Mar 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why we're using props called *Legacy? This kind of splitting of code paths within the components doesn't seem necessary -- we should not be considering the otp-react-redux project "legacy" software. I don't think I had a chance to review opentripplanner/otp-ui#32, otherwise, I wouldn't have supported the splitting of the handlers like this.

EDIT: OK, I'm seeing below that this is intended to support legacy browsers? This and the DateTimeSelector probably need more comments to document this. We may want to modify the prop names to something a little more clear. Without the comment in mapStateToProps, I would have had little idea what was going on here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on adding more documentation to DateTimeSelector in OTP-ui. There is a tiny bit here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my adjusted the comments that are relevant to OTP-RR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added additional docs on the OTP-UI side, see opentripplanner/otp-ui#98

/>
</div>
</div>
)
}
}

const mapStateToProps = (state, ownProps) => {
const {departArrive, date, time, routingType} = state.otp.currentQuery
const { departArrive, date, time } = state.otp.currentQuery
return {
config: state.otp.config,
departArrive,
date,
time,
routingType
// These props below are for legacy browsers (see render method above).
timeFormatLegacy: getTimeFormat(state.otp.config),
dateFormatLegacy: getDateFormat(state.otp.config)
}
}

Expand Down
Loading