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

Optional Lateness Display #1028

Merged
merged 8 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ itinerary:
# This flag disables the dot between legs in the metro itnerary summary, replacing it with
# a gray background
disableMetroSeperatorDot: false
# Show the number of minutes of delay or early beneath a time in the itinerary body
showLateness: true
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
# Shows the duration of a leg below the leg in the metro itinerary summary
showLegDurations: false
# The sort option to use by default
Expand Down
71 changes: 38 additions & 33 deletions lib/components/viewers/realtime-status-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Typescript TODO: Waiting on viewer.js being typed
import { connect } from 'react-redux'
import { FormattedMessage, FormattedTime } from 'react-intl'
import { InvisibleAdditionalDetails } from '@opentripplanner/itinerary-body/lib/styled'
import React from 'react'
import styled from 'styled-components'

import { getTripStatus, REALTIME_STATUS } from '../../util/viewer'
import { InvisibleAdditionalDetails } from '@opentripplanner/itinerary-body/lib/styled'
import FormattedDuration from '../util/formatted-duration'
import FormattedRealtimeStatusLabel from '../util/formatted-realtime-status-label'

Expand Down Expand Up @@ -66,6 +66,7 @@ const RealtimeStatusLabel = ({
isRealtime,
onTimeThresholdSeconds,
originalTime,
showLateness,
time,
withBackground
}: {
Expand All @@ -74,6 +75,7 @@ const RealtimeStatusLabel = ({
isRealtime?: boolean
onTimeThresholdSeconds?: number
originalTime?: number
showLateness?: boolean
time?: number
withBackground?: boolean
}): JSX.Element => {
Expand Down Expand Up @@ -117,45 +119,48 @@ const RealtimeStatusLabel = ({
withBackground={withBackground}
>
{renderedTime}
<MainContent>
<FormattedRealtimeStatusLabel
minutes={
isEarlyOrLate ? (
<DelayText>
<FormattedDuration
duration={Math.abs(delay)}
includeSeconds={false}
/>
</DelayText>
) : (
<>{null}</>
)
}
// @ts-ignore getTripStatus is not typed yet
status={STATUS[status].label}
/>
{isEarlyOrLate && (
<InvisibleAdditionalDetails>
<FormattedMessage
id="components.MetroUI.originallyScheduledTime"
values={{
originalTime: (
<FormattedTime timeStyle="short" value={originalTime} />
)
}}
/>
</InvisibleAdditionalDetails>
)}
</MainContent>
{showLateness && (
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
<MainContent>
<FormattedRealtimeStatusLabel
minutes={
isEarlyOrLate ? (
<DelayText>
<FormattedDuration
duration={Math.abs(delay)}
includeSeconds={false}
/>
</DelayText>
) : (
<>{null}</>
)
}
// @ts-ignore getTripStatus is not typed yet
status={STATUS[status].label}
/>
{isEarlyOrLate && (
<InvisibleAdditionalDetails>
<FormattedMessage
id="components.MetroUI.originallyScheduledTime"
values={{
originalTime: (
<FormattedTime timeStyle="short" value={originalTime} />
)
}}
/>
</InvisibleAdditionalDetails>
)}
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
</MainContent>
)}
</Container>
)
}

const mapStateToProps = (state: {
miles-grant-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
// Typescript TODO: type state
otp: { config: { onTimeThresholdSeconds: any } }
otp: { config: { onTimeThresholdSeconds: any; showLateness: boolean } }
}) => ({
onTimeThresholdSeconds: state.otp.config.onTimeThresholdSeconds
onTimeThresholdSeconds: state.otp.config.onTimeThresholdSeconds,
showLateness: state.otp.config.showLateness
})

export default connect(mapStateToProps)(RealtimeStatusLabel)