Skip to content
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

Display delay info on route view #753

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
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
29 changes: 21 additions & 8 deletions app/component/DepartureTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ import Icon from './Icon';
import LocalTime from './LocalTime';

function DepartureTime(props, context) {
const isLate =
props.realtimeDeparture - props.scheduledDeparture >=
context.config.itinerary.delayThreshold;
const departureTime =
props.canceled || !isLate
? props.scheduledDeparture
: props.realtimeDeparture;

let shownTime;
const timeDiffInMinutes = Math.floor(
(props.departureTime - props.currentTime) / 60,
(departureTime - props.currentTime) / 60,
);
if (timeDiffInMinutes <= -1) {
shownTime = undefined;
Expand Down Expand Up @@ -45,6 +53,7 @@ function DepartureTime(props, context) {
{
realtime: props.realtime,
canceled: props.canceled,
late: isLate,
},
props.className,
)}
Expand All @@ -63,6 +72,7 @@ function DepartureTime(props, context) {
canceled: props.canceled,
first: !props.isNextDeparture,
next: props.isNextDeparture,
late: isLate,
},
props.className,
)}
Expand All @@ -72,8 +82,13 @@ function DepartureTime(props, context) {
id: 'next',
defaultMessage: 'Next',
})} `}
<LocalTime forceUtc={props.useUTC} time={props.departureTime} />
<LocalTime forceUtc={props.useUTC} time={departureTime} />
</span>
{props.realtime && isLate && (
<span key="time" className="time original-time">
<LocalTime forceUtc={props.useUTC} time={props.scheduledDeparture} />
</span>
)}
{props.canceled && props.showCancelationIcon && (
<Icon className="caution" img="icon-icon_caution" />
)}
Expand All @@ -92,7 +107,8 @@ DepartureTime.propTypes = {
className: PropTypes.string,
canceled: PropTypes.bool,
currentTime: PropTypes.number.isRequired,
departureTime: PropTypes.number.isRequired,
scheduledDeparture: PropTypes.number.isRequired,
realtimeDeparture: PropTypes.number.isRequired,
realtime: PropTypes.bool,
style: PropTypes.object,
useUTC: PropTypes.bool,
Expand Down Expand Up @@ -123,11 +139,8 @@ export default DepartureTime;
export const mapStopTime = (stoptime, pattern) => ({
stop: stoptime.stop,
canceled: stoptime.realtimeState === 'CANCELED',
departureTime:
stoptime.serviceDay +
(stoptime.realtimeState === 'CANCELED' || stoptime.realtimeDeparture === -1
? stoptime.scheduledDeparture
: stoptime.realtimeDeparture),
scheduledDeparture: stoptime.serviceDay + stoptime.scheduledDeparture,
realtimeDeparture: stoptime.serviceDay + stoptime.realtimeDeparture,
realtime: stoptime.realtimeDeparture !== -1 && stoptime.realtime,
pattern: pattern && pattern.pattern,
trip: stoptime.trip,
Expand Down
4 changes: 4 additions & 0 deletions app/component/route.scss
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ $margin-left-right: 21.3px;
letter-spacing: -0.03em;
}
}
.original-time {
text-decoration: line-through;
color: $gray;
}
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions test/unit/component/DepartureTime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ describe('<DepartureTime />', () => {
const props = {
canceled: true,
currentTime: 0,
departureTime: 180,
scheduledDeparture: 180,
realtimeDeparture: 180,
showCancelationIcon: true,
};
const wrapper = shallowWithIntl(<DepartureTime {...props} />, {
context: { config: { minutesToDepartureLimit: 2 } },
context: {
config: {
minutesToDepartureLimit: 2,
itinerary: { delayThreshold: 180 },
},
},
});
expect(wrapper.find('.caution')).to.have.lengthOf(1);
});
Expand Down