-
Notifications
You must be signed in to change notification settings - Fork 58
Stop viewer/itinerary body status #294
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
5 commits
Select commit
Hold shift + click to select a range
f39ebc0
refactor(StatusLabel): Extract component, move non-render logic to ut…
binh-dam-ibigroup 4a8695a
refactor(BaseStatusLabel): Remove color override for 'scheduled' stat…
binh-dam-ibigroup 38630f2
refactor(realtime-status-label): encapsulate more of the status label…
landonreed 4124a51
Merge pull request #296 from opentripplanner/trip-status-label-ltr
binh-dam-ibigroup 508bc80
fix(RealtimeStatusLabel): Add spacer between delay text and status text.
binh-dam-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 |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { formatDuration } from '@opentripplanner/core-utils/lib/time' | ||
| import React from 'react' | ||
| import styled from 'styled-components' | ||
|
|
||
| import { getTripStatus, REALTIME_STATUS } from '../../util/viewer' | ||
|
|
||
| // If shown, keep the '5 min' portion of the status string on the same line. | ||
| export const DelayText = styled.span` | ||
| white-space: nowrap; | ||
| ` | ||
|
|
||
| export const MainContent = styled.div`` | ||
|
|
||
| const Container = styled.div` | ||
| ${props => props.withBackground | ||
| ? `background-color: ${props.color};` | ||
| : `color: ${props.color};` | ||
| } | ||
| ` | ||
|
|
||
| const TimeStruck = styled.div` | ||
| text-decoration: line-through; | ||
| ` | ||
|
|
||
| const TimeBlock = styled.div` | ||
| line-height: 1em; | ||
| margin-bottom: 4px; | ||
| ` | ||
|
|
||
| const STATUS = { | ||
| EARLY: { | ||
| color: '#337ab7', | ||
| label: 'early' | ||
| }, | ||
| LATE: { | ||
| color: '#d9534f', | ||
| label: 'late' | ||
| }, | ||
| ON_TIME: { | ||
| color: '#5cb85c', | ||
| label: 'on time' | ||
| }, | ||
| SCHEDULED: { | ||
| label: 'scheduled' | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This component renders a string such as '5 min late' or 'on time' | ||
| * while keeping the '5 min' portion on the same line. | ||
| * | ||
| * If the formatted time/original time values (e.g. 5:11 pm) are provided, they | ||
| * will be rendered above the status. Also, this can optionally be rendered with | ||
| * a background color for a label-like presentation. | ||
| */ | ||
| const RealtimeStatusLabel = ({ withBackground, className, delay, isRealtime, originalTime, time }) => { | ||
| const status = getTripStatus(isRealtime, delay) | ||
| const isEarlyOrLate = status === REALTIME_STATUS.EARLY || status === REALTIME_STATUS.LATE | ||
| // Use a default background color if the status object doesn't set a color | ||
| // (e.g. for 'Scheduled' status), but only in withBackground mode. | ||
| const color = STATUS[status].color || (withBackground && '#bbb') | ||
| // Render time if provided. | ||
| let renderedTime | ||
| if (time) { | ||
| // If transit vehicle is not on time, strike the original scheduled time | ||
| // and display the updated time underneath. | ||
| renderedTime = isEarlyOrLate | ||
| ? ( | ||
| <TimeBlock> | ||
| <TimeStruck>{originalTime}</TimeStruck> | ||
| <div>{time}</div> | ||
| </TimeBlock> | ||
| ) | ||
| : <div>{time}</div> | ||
| } | ||
| return ( | ||
| <Container | ||
| withBackground={withBackground} | ||
| className={className} | ||
| color={color} | ||
| > | ||
| {renderedTime} | ||
| <MainContent> | ||
| {isEarlyOrLate && | ||
| <DelayText> | ||
| {formatDuration(Math.abs(delay))} | ||
| {/* A spacer is needed between '5 min' and 'early/late'. */} | ||
| {' '} | ||
| </DelayText> | ||
| } | ||
| {STATUS[status].label} | ||
| </MainContent> | ||
| </Container> | ||
| ) | ||
| } | ||
|
|
||
| export default RealtimeStatusLabel |
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
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.
Consider basing this PR off of #305 and then refactor this function so that it uses the configurable on-time threshold.
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.
Actually, since #305 was introduced after the latest commit here, I think it might be unfair to request this. Therefore, I'm going to merge this and make #305 dependent on this.