Skip to content

April OTP-UI package updates #1373

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 4 commits into from
Apr 4, 2025
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
14 changes: 12 additions & 2 deletions lib/components/narrative/default/default-itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const {
isTransitLeg
} = coreUtils.itinerary

const { ensureAtLeastOneMinute } = coreUtils.time

// Styled components
const LegIconWrapper = styled.div`
display: inline-block;
Expand Down Expand Up @@ -88,7 +90,11 @@ const ITINERARY_ATTRIBUTES = [
alias: 'best',
id: 'duration',
order: 0,
render: (itinerary) => <FormattedDuration duration={itinerary.duration} />
render: (itinerary) => (
<FormattedDuration
duration={ensureAtLeastOneMinute(itinerary.duration)}
/>
)
},
{
alias: 'departureTime',
Expand Down Expand Up @@ -173,7 +179,11 @@ const ITINERARY_ATTRIBUTES = [
// FIXME: For CAR mode, walk time considers driving time.
<>
<FormattedDuration
duration={itinerary.walkTime}
duration={
itinerary.walkTime > 0
? ensureAtLeastOneMinute(itinerary.walkTime)
: itinerary.walkTime
}
Comment on lines +183 to +186
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this condition also appear on line 95?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking was it would be nearly impossible to have a leg/itinerary with an exact duration of 0 so it felt like an unnecessary check. However for itineraries that might not have any walk legs, we don't want to accidentally add a default walk time of 1min to an itinerary with absolutely no walking.

Although maybe when you're taking transit it's equally as unlikely to have itineraries with 0 walking, so we should just apply the check across the board to be safe?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Leg with duration 0 is very common! That's how we identify transfer legs

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'd prefer applying the check inside core-utils. Are we ok to block this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First of all, it's not how we identify transfer legs, we identify them by checking if leg.to.stopId === leg.from.stopId
Second of all, we don't show the leg duration on transfer legs:
image
So I don't understand why this would be a reason to block the PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry I wasn't clear. The reason to block is to avoid having to check for explicitly 0 leg durations in multiple places

Copy link
Contributor Author

@amy-corson-ibigroup amy-corson-ibigroup Apr 2, 2025

Choose a reason for hiding this comment

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

I do not think we should have to check for explicitly 0 leg durations in multiple places. It makes sense to have this check here, because we could feasibly get an itinerary with a 0 walkDuration and we would not want to replace that with a 1min. For example, you plan a trip that starts at one bus stop and ends at another bus stop.

Are there examples where we would need to show a 0min duration for a leg in the itinerary? A leg is going to take you from point A to point B and that's going to take time. The point of the util is to avoid implying that it's going to take 0 time.

Copy link
Contributor Author

@amy-corson-ibigroup amy-corson-ibigroup Apr 2, 2025

Choose a reason for hiding this comment

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

And just to be clear so I'm not contradicting myself, I know I said

so we should just apply the check across the board to be safe?

But thinking about it further, I don't think there's a reason to.

includeSeconds={false}
/>
<LegIconWrapper noSpace>
Expand Down
21 changes: 17 additions & 4 deletions lib/components/narrative/metro/metro-itinerary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IntlShape
} from 'react-intl'
import { Leaf } from '@styled-icons/fa-solid/Leaf'
import coreUtils from '@opentripplanner/core-utils'
import React from 'react'
import styled, { keyframes } from 'styled-components'

Expand Down Expand Up @@ -41,6 +42,8 @@ import DepartureTimesList, {
import MetroItineraryRoutes from './metro-itinerary-routes'
import RouteBlock from './route-block'

const { ensureAtLeastOneMinute } = coreUtils.time

// Styled components
const ItineraryWrapper = styled.div.attrs((props) => {
return { 'aria-label': props['aria-label'] }
Expand Down Expand Up @@ -232,7 +235,11 @@ class MetroItinerary extends NarrativeItinerary {
aria-hidden
footer={
showLegDurations &&
mainLeg?.duration && <FormattedDuration duration={mainLeg.duration} />
mainLeg?.duration && (
<FormattedDuration
duration={ensureAtLeastOneMinute(mainLeg.duration)}
/>
)
}
hideLongName
leg={mainLeg}
Expand Down Expand Up @@ -384,7 +391,7 @@ class MetroItinerary extends NarrativeItinerary {
>
<PrimaryInfo>
<FormattedDuration
duration={itinerary.duration}
duration={ensureAtLeastOneMinute(itinerary.duration)}
includeSeconds={false}
/>
</PrimaryInfo>
Expand All @@ -409,7 +416,13 @@ class MetroItinerary extends NarrativeItinerary {
values={{
time: (
<FormattedDuration
duration={itinerary.walkTime}
duration={
/* If the walk time is truly zero, show 0. But if the walk time is just less
than a minute, round up to the nearest minute to avoid showing no walk time. */
itinerary.walkTime > 0
? ensureAtLeastOneMinute(itinerary.walkTime)
: itinerary.walkTime
Comment on lines +422 to +424
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is like taking a deep breath next to an exhaust pipe

Copy link
Collaborator

Choose a reason for hiding this comment

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

could we add a comment that explains that we need it to be exactly 0 in some cases, but any value between 1 - 59 is problematic!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should that condition also appear on lines 240 and 394, and 486?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in c664f9b

}
includeSeconds={false}
/>
)
Expand Down Expand Up @@ -470,7 +483,7 @@ class MetroItinerary extends NarrativeItinerary {
<ItineraryGridSmall className="other-itin">
<PrimaryInfo as="span">
<FormattedDuration
duration={itinerary.duration}
duration={ensureAtLeastOneMinute(itinerary.duration)}
includeSeconds={false}
/>
</PrimaryInfo>
Expand Down
5 changes: 4 additions & 1 deletion lib/components/user/monitored-trip/trip-duration-summary.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FormattedMessage, FormattedTime } from 'react-intl'
import coreUtils from '@opentripplanner/core-utils'
import React from 'react'
import styled from 'styled-components'

Expand All @@ -10,6 +11,8 @@ const Divider = styled.span`
margin: 0 7px;
`

const { ensureAtLeastOneMinute } = coreUtils.time

const TripSummary = ({ monitoredTrip }: MonitoredTripProps): JSX.Element => {
const { itinerary } = monitoredTrip
const { duration, endTime, startTime } = itinerary
Expand All @@ -27,7 +30,7 @@ const TripSummary = ({ monitoredTrip }: MonitoredTripProps): JSX.Element => {
<InvisibleA11yLabel>, </InvisibleA11yLabel>
<Divider>•</Divider>
<span aria-hidden>
<FormattedDuration duration={duration} />
<FormattedDuration duration={ensureAtLeastOneMinute(duration)} />
</span>
</span>
)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
"@floating-ui/react": "^0.19.2",
"@opentripplanner/base-map": "4.0.0",
"@opentripplanner/building-blocks": "2.1.0",
"@opentripplanner/core-utils": "12.0.2",
"@opentripplanner/core-utils": "12.2.0",
"@opentripplanner/endpoints-overlay": "3.1.1",
"@opentripplanner/from-to-location-picker": "3.0.1",
"@opentripplanner/geocoder": "^3.0.3",
"@opentripplanner/geocoder": "^3.0.4",
"@opentripplanner/humanize-distance": "^1.2.0",
"@opentripplanner/icons": "3.0.2",
"@opentripplanner/itinerary-body": "6.1.3",
"@opentripplanner/itinerary-body": "6.2.0",
"@opentripplanner/location-field": "3.1.3",
"@opentripplanner/location-icon": "^1.4.1",
"@opentripplanner/map-popup": "5.1.2",
Expand Down
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2415,10 +2415,10 @@
resolved "https://registry.yarnpkg.com/@opentripplanner/building-blocks/-/building-blocks-1.2.3.tgz#404e8f9038867d66d55f51adf8855b1326c51ed5"
integrity sha512-I0AxiZrTZu+e7+av4u0tHW2ijqpxH0AkLHrhf75BHf1Ep2FOGxaul/v+8UT18mNYiM5eHNstOX3XiXaDjtCUaw==

"@opentripplanner/core-utils@12.0.2":
version "12.0.2"
resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-12.0.2.tgz#2869b3ac3672d636d427de04e4ce8efc1a0de435"
integrity sha512-Czga518J+rQIDjXRKG+taZ75xN8GPOB5MiILHo5B/v9Z6VXz5lypDe8vDGv66pbmf8Mj62zl5Tm3AAkB/lPdIA==
"@opentripplanner/core-utils@12.2.0", "@opentripplanner/core-utils@^12.1.0":
version "12.2.0"
resolved "https://registry.yarnpkg.com/@opentripplanner/core-utils/-/core-utils-12.2.0.tgz#0e1210a4e5565f5a1720e7ff30da54130e5d45c8"
integrity sha512-w9/H6WODI+ooe0tFctPlB9fpwnXCYOgVs7PKI9jKbNBaa39o7Z3Z+bcm9FTpNhE9K0VRcZGf99p9mk2xjbQZjA==
dependencies:
"@conveyal/lonlat" "^1.4.1"
"@mapbox/polyline" "^1.1.0"
Expand Down Expand Up @@ -2516,10 +2516,10 @@
isomorphic-mapzen-search "^1.6.1"
lodash.memoize "^4.1.2"

"@opentripplanner/geocoder@^3.0.3":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-3.0.3.tgz#a31be41aef51d10f415343fa4564c4959c99422f"
integrity sha512-0I+HgqLpqwBI65hUKCWhDhRJHS7GKwo1JjvDVVCS4f0d2mjlQW3gnoHodxP7WGqiUJHhtoTtRrF8xPZeDCZ0/w==
"@opentripplanner/geocoder@^3.0.4":
version "3.0.4"
resolved "https://registry.yarnpkg.com/@opentripplanner/geocoder/-/geocoder-3.0.4.tgz#99f4a6ac66cf850f5e2defffd0d04bf3ca2b98f7"
integrity sha512-MDNKlDQacmddYHZnNm7TPNWXrPXspxWnmYFa2IL4V1t2KVdQ1Z3U6yurEsIsw9TaD00sa0KlbNo9M0h9lXqWCg==
dependencies:
"@conveyal/geocoder-arcgis-geojson" "^0.0.3"
"@conveyal/lonlat" "^1.4.1"
Expand Down Expand Up @@ -2548,12 +2548,12 @@
"@opentripplanner/core-utils" "^12.0.0"
prop-types "^15.7.2"

"@opentripplanner/itinerary-body@6.1.3":
version "6.1.3"
resolved "https://registry.yarnpkg.com/@opentripplanner/itinerary-body/-/itinerary-body-6.1.3.tgz#0d60f1bfe29f74dacf03a9abfd5d23b4bc10c04e"
integrity sha512-glwxm0NyPjDnHBR4W7AmsIvrU7bW52xs2e9Qy1Q6jP7ghnK8Vq3u44vrEw8ZlZllkIqe9kVhEXrSXUu5NPfRRA==
"@opentripplanner/itinerary-body@6.2.0":
version "6.2.0"
resolved "https://registry.yarnpkg.com/@opentripplanner/itinerary-body/-/itinerary-body-6.2.0.tgz#f00ff6076083bff71952177e9d52a98ccc69a098"
integrity sha512-ktf9XbXMOEdZxlEGXGaukhseV9XEGMqIcuUM0CsjEKMUT8L55E6VO4ZP1lzItG4+7wrBgWEaxMOSBCWkM/1DNA==
dependencies:
"@opentripplanner/core-utils" "^12.0.0"
"@opentripplanner/core-utils" "^12.1.0"
"@opentripplanner/humanize-distance" "^1.2.0"
"@opentripplanner/icons" "^3.0.0"
"@opentripplanner/location-icon" "^1.4.1"
Expand Down
Loading