From 0dc2a84c20e48c7ab7561ea2b37b09d498c6dbf5 Mon Sep 17 00:00:00 2001 From: miles-grant-ibigroup Date: Tue, 24 Oct 2023 14:25:41 -0400 Subject: [PATCH] add option to disable countdown unless realtime data present --- .../viewers/__snapshots__/stop-viewer.js.snap | 4406 +++++++++-------- example-config.yml | 2 + lib/components/viewers/stop-time-cell.tsx | 25 +- lib/util/config-types.ts | 1 + 4 files changed, 2502 insertions(+), 1932 deletions(-) diff --git a/__tests__/components/viewers/__snapshots__/stop-viewer.js.snap b/__tests__/components/viewers/__snapshots__/stop-viewer.js.snap index 4cf2c86dd..11a00e14f 100644 --- a/__tests__/components/viewers/__snapshots__/stop-viewer.js.snap +++ b/__tests__/components/viewers/__snapshots__/stop-viewer.js.snap @@ -1496,7 +1496,7 @@ exports[`components > viewers > stop viewer should render countdown times after className="next-trip-preview" >
  • - viewers > stop viewer should render countdown times after } } > -
    - +
    - viewers > stop viewer should render countdown times after } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render countdown times after iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - + + + + + + + + - - common.time.tripDurationFormat - - - -
    - + + common.time.tripDurationFormat + + + +
    +
    +
  • - viewers > stop viewer should render countdown times after } } > -
    - +
    - viewers > stop viewer should render countdown times after } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render countdown times after iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.wednesday - - - - - - + common.daysOfWeek.wednesday + + + + + + - - 1:52 AM - - - -
    - + + 1:52 AM + + + +
    +
    +
  • - viewers > stop viewer should render countdown times after } } > -
    - +
    - viewers > stop viewer should render countdown times after } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render countdown times after iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.wednesday - - - - - - + common.daysOfWeek.wednesday + + + + + + - - 2:53 AM - - - -
    - + + 2:53 AM + + + +
    +
    +
  • @@ -3981,7 +4056,7 @@ exports[`components > viewers > stop viewer should render countdown times for st className="next-trip-preview" >
  • - viewers > stop viewer should render countdown times for st } } > -
    - +
    - viewers > stop viewer should render countdown times for st } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render countdown times for st iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - + + + + + + + + - - common.time.tripDurationFormat - - - -
    - + + common.time.tripDurationFormat + + + +
    +
    +
  • @@ -6117,7 +6217,7 @@ exports[`components > viewers > stop viewer should render times after midnight w className="next-trip-preview" >
  • - viewers > stop viewer should render times after midnight w } } > -
    - +
    - viewers > stop viewer should render times after midnight w } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render times after midnight w iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.wednesday - - - - - - + common.daysOfWeek.wednesday + + + + + + - - 12:51 AM - - - -
    - + + 12:51 AM + + + +
    +
    +
  • - viewers > stop viewer should render times after midnight w } } > -
    - +
    - viewers > stop viewer should render times after midnight w } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render times after midnight w iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.wednesday - - - - - - + common.daysOfWeek.wednesday + + + + + + - - 1:52 AM - - - -
    - + + 1:52 AM + + + +
    +
    +
  • - viewers > stop viewer should render times after midnight w } } > -
    - +
    - viewers > stop viewer should render times after midnight w } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render times after midnight w iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.wednesday - - - - - - + common.daysOfWeek.wednesday + + + + + + - - 2:53 AM - - - -
    - + + 2:53 AM + + + +
    +
    +
  • @@ -9736,7 +9911,7 @@ exports[`components > viewers > stop viewer should render with OTP transit index className="next-trip-preview" >
  • - viewers > stop viewer should render with OTP transit index } } > -
    - +
    - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.monday - - - - - - + common.daysOfWeek.monday + + + + + + - - 6:00 PM - - - -
    - + + 6:00 PM + + + +
    +
    +
  • - viewers > stop viewer should render with OTP transit index } } > -
    - +
    - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.monday - - - - - - + common.daysOfWeek.monday + + + + + + - - 6:15 PM - - - -
    - + + 6:15 PM + + + +
    +
    +
  • - viewers > stop viewer should render with OTP transit index } } > -
    - +
    - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.monday - - - - - - + common.daysOfWeek.monday + + + + + + - - 6:31 PM - - - -
    - + + 6:31 PM + + + +
    +
    +
  • @@ -10334,7 +10584,7 @@ exports[`components > viewers > stop viewer should render with OTP transit index className="next-trip-preview" >
  • - viewers > stop viewer should render with OTP transit index } } > -
    - +
    - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.tuesday - - - - - - + common.daysOfWeek.tuesday + + + + + + - - 2:28 PM - - - -
    - + + 2:28 PM + + + +
    +
    +
  • - viewers > stop viewer should render with OTP transit index } } > -
    - +
    - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.tuesday - - - - - - + common.daysOfWeek.tuesday + + + + + + - - 3:02 PM - - - -
    - + + 3:02 PM + + + +
    +
    +
  • - viewers > stop viewer should render with OTP transit index } } > -
    - +
    - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.tuesday - - - - - - + common.daysOfWeek.tuesday + + + + + + - - 3:12 PM - - - -
    - + + 3:12 PM + + + +
    +
    +
  • @@ -10882,7 +11207,7 @@ exports[`components > viewers > stop viewer should render with OTP transit index className="next-trip-preview" >
  • - viewers > stop viewer should render with OTP transit index } } > -
    - +
    - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.tuesday - - - - - - + common.daysOfWeek.tuesday + + + + + + - - 3:22 PM - - - -
    - + + 3:22 PM + + + +
    +
    +
  • @@ -11162,7 +11512,7 @@ exports[`components > viewers > stop viewer should render with OTP transit index className="next-trip-preview" >
  • - viewers > stop viewer should render with OTP transit index } } > -
    - +
    - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.tuesday - - - - - - + common.daysOfWeek.tuesday + + + + + + - - 4:11 PM - - - -
    - + + 4:11 PM + + + +
    +
    +
  • - viewers > stop viewer should render with OTP transit index } } > -
    - +
    - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.tuesday - - - - - - + common.daysOfWeek.tuesday + + + + + + - - 5:09 PM - - - -
    - + + 5:09 PM + + + +
    +
    +
  • @@ -11581,7 +11981,7 @@ exports[`components > viewers > stop viewer should render with OTP transit index className="next-trip-preview" >
  • - viewers > stop viewer should render with OTP transit index } } > -
    - +
    - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.wednesday - - - - - - + common.daysOfWeek.wednesday + + + + + + - - 3:22 PM - - - -
    - + + 3:22 PM + + + +
    +
    +
  • @@ -11843,7 +12268,7 @@ exports[`components > viewers > stop viewer should render with OTP transit index className="next-trip-preview" >
  • - viewers > stop viewer should render with OTP transit index "timepoint": true, "tripId": "TriMet:9231858", } - } - > -
    + - - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.wednesday - - - - - - + common.daysOfWeek.wednesday + + + + + + - - 4:11 PM - - - -
    -
    + + 4:11 PM + + + + + +
  • @@ -12119,7 +12569,7 @@ exports[`components > viewers > stop viewer should render with OTP transit index className="next-trip-preview" >
  • - viewers > stop viewer should render with OTP transit index } } > -
    - +
    - viewers > stop viewer should render with OTP transit index } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with OTP transit index iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.thursday - - - - - - + common.daysOfWeek.thursday + + + + + + - - 3:22 PM - - - -
    - + + 3:22 PM + + + +
    +
    +
  • @@ -16471,7 +16946,7 @@ exports[`components > viewers > stop viewer should render with TriMet transit in className="next-trip-preview" >
  • - viewers > stop viewer should render with TriMet transit in } } > -
    - +
    - viewers > stop viewer should render with TriMet transit in } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with TriMet transit in iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.monday - - - - - - + common.daysOfWeek.monday + + + + + + - - 5:45 PM - - - -
    - + + 5:45 PM + + + +
    +
    +
  • - viewers > stop viewer should render with TriMet transit in } } > -
    - +
    - viewers > stop viewer should render with TriMet transit in } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with TriMet transit in iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.monday - - - - - - + common.daysOfWeek.monday + + + + + + - - 6:00 PM - - - -
    - + + 6:00 PM + + + +
    +
    +
  • - viewers > stop viewer should render with TriMet transit in } } > -
    - +
    - viewers > stop viewer should render with TriMet transit in } title="components.StopTimeCell.scheduled" > - - - + + viewers > stop viewer should render with TriMet transit in iconVerticalAlign="middle" iconViewBox="0 0 512 512" > - - - - - - - - - - + + + + + + + + + + - - common.daysOfWeek.monday - - - - - - + common.daysOfWeek.monday + + + + + + - - 6:15 PM - - - -
    - + + 6:15 PM + + + +
    +
    +
  • diff --git a/example-config.yml b/example-config.yml index 2bae9c943..b23c86936 100644 --- a/example-config.yml +++ b/example-config.yml @@ -352,6 +352,8 @@ itinerary: # This flag disables the dot between legs in the metro itnerary summary, replacing it with # a gray background disableMetroSeperatorDot: false + # If enabled, always shows departures as times ("10pm" instead of "3 min") unless realtime data is present + onlyShowCountdownForRealtime: true # Shows the duration of a leg below the leg in the metro itinerary summary showLegDurations: false # The sort option to use by default diff --git a/lib/components/viewers/stop-time-cell.tsx b/lib/components/viewers/stop-time-cell.tsx index 27b63a649..d1867c3c2 100644 --- a/lib/components/viewers/stop-time-cell.tsx +++ b/lib/components/viewers/stop-time-cell.tsx @@ -1,13 +1,14 @@ import { Clock } from '@styled-icons/fa-regular/Clock' +import { connect } from 'react-redux' import { format, getTimezoneOffset, utcToZonedTime } from 'date-fns-tz' import { FormattedMessage, useIntl } from 'react-intl' import { Rss } from '@styled-icons/fa-solid/Rss' -import addDays from 'date-fns/addDays' import coreUtils from '@opentripplanner/core-utils' import isSameDay from 'date-fns/isSameDay' import React from 'react' import styled from 'styled-components' +import { AppReduxState } from '../../util/state-types' import { getSecondsUntilDeparture, getTripStatus } from '../../util/viewer' import { StyledIconWrapperTextAlign } from '../util/styledIcon' import FormattedDayOfWeek from '../util/formatted-day-of-week' @@ -15,10 +16,10 @@ import FormattedDuration from '../util/formatted-duration' import getRealtimeStatusLabel, { status } from '../util/get-realtime-status-label' +import InvisibleA11yLabel from '../util/invisible-a11y-label' import type { Time } from '../util/types' import DepartureTime from './departure-time' -import InvisibleA11yLabel from '../util/invisible-a11y-label' const { getUserTimezone } = coreUtils.time const ONE_HOUR_IN_SECONDS = 3600 @@ -31,6 +32,8 @@ const PulsingRss = styled(Rss)` type Props = { /** If configured, the timezone of the area */ homeTimezone?: string + /** Optionally hide countdown unless realtime data is present */ + onlyShowCountdownForRealtime?: boolean /** A stopTime object as received from a transit index API */ stopTime: Time } @@ -39,8 +42,10 @@ type Props = { * Renders a stop time as either schedule or countdown, with an optional status icon. * Stop time that apply to a different day have an additional text showing the day of departure. */ +// eslint-disable-next-line complexity const StopTimeCell = ({ homeTimezone = getUserTimezone(), + onlyShowCountdownForRealtime, stopTime }: Props): JSX.Element => { const intl = useIntl() @@ -109,7 +114,10 @@ const StopTimeCell = ({ status: getTripStatus(realtime, stopTime.departureDelay, 30) as status })} > - {showCountdown ? ( + {/* Not the cleanest boolean, but makes it very clear what we're doing + in all cases. */} + {(onlyShowCountdownForRealtime === true && realtime) || + (onlyShowCountdownForRealtime === false && showCountdown) ? ( // Show countdown string (e.g., 3 min or Due) isDue ? ( @@ -140,4 +148,13 @@ const StopTimeCell = ({ ) } -export default StopTimeCell +const mapStateToProps = (state: AppReduxState) => { + return { + onlyShowCountdownForRealtime: + state.otp.config?.itinerary?.onlyShowCountdownForRealtime || false + } +} + +const mapDispatchToProps = {} + +export default connect(mapStateToProps, mapDispatchToProps)(StopTimeCell) diff --git a/lib/util/config-types.ts b/lib/util/config-types.ts index 734c39ed6..ee34ffa57 100644 --- a/lib/util/config-types.ts +++ b/lib/util/config-types.ts @@ -239,6 +239,7 @@ export interface ItineraryConfig { groupTransitModes?: boolean hideSkeletons?: boolean mergeItineraries?: boolean + onlyShowCountdownForRealtime?: boolean renderRouteNamesInBlocks?: boolean showFirstResultByDefault?: boolean showHeaderText?: boolean