forked from opentripplanner/otp-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Improve types to remove unsafe casts #31
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
miles-grant-ibigroup
merged 8 commits into
fares-overhaul
from
fares-overhaul-type-improvements
Jul 16, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8293bf0
fix: Improve types to remove unsafe casts
danielhep 554c7c0
fix: sort properties
danielhep 9a5badb
reinstate null check
danielhep 17c1e79
reinstate valid story
danielhep 0fbb861
make sure the fare product has a price at all
danielhep b9abbe5
feat: make price optional on FareProduct
danielhep 3bd7ce6
test: update snapshots
danielhep c7a3f2f
PR cleanup
danielhep 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 |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ import { FormattedMessage, useIntl } from "react-intl"; | |
| import styled from "styled-components"; | ||
| import { Transfer } from "@styled-icons/boxicons-regular/Transfer"; | ||
|
|
||
| import { ExtendedMoney } from "@opentripplanner/core-utils/lib/itinerary"; | ||
| import { renderFare } from "../utils"; | ||
| import { InvisibleA11yLabel } from "../styled"; | ||
|
|
||
|
|
@@ -144,14 +143,16 @@ const FaresV2Table = ({ | |
| const { | ||
| alternateFareProducts, | ||
| isDependent, | ||
| price, | ||
| appliedFareProduct, | ||
| productUseId | ||
| } = getLegCost( | ||
| leg, | ||
| descope(medium.id) || null, | ||
| descope(rider.id) || null, | ||
| Array.from(productUseIds) | ||
| ); | ||
| const legPrice = appliedFareProduct?.legPrice; | ||
|
|
||
| productUseIds.add(productUseId); | ||
|
|
||
| // Only consider alternateFareProducts if current product is dependent | ||
|
|
@@ -160,11 +161,9 @@ const FaresV2Table = ({ | |
|
|
||
| // Calculate pre-tranfer amount either via alternate fare or fare-id matching (price.originalAmount) | ||
| const originalAmount = | ||
| price?.originalAmount || | ||
| (dependentAlternateFareProducts?.[0]?.price?.amount || | ||
| (dependentAlternateFareProducts?.[0]?.price as ExtendedMoney) | ||
| ?.originalAmount) - price?.amount || | ||
| null; | ||
| dependentAlternateFareProducts?.[0]?.price.amount - | ||
| legPrice?.amount || | ||
| appliedFareProduct?.price.amount - legPrice?.amount; | ||
|
|
||
| const newCell = ( | ||
| <> | ||
|
|
@@ -182,7 +181,7 @@ const FaresV2Table = ({ | |
| </th> | ||
| )} | ||
| <td | ||
| style={{ textAlign: price ? "right" : "center" }} | ||
| style={{ textAlign: legPrice ? "right" : "center" }} | ||
| title={ | ||
| !Number.isNaN(originalAmount) && | ||
| originalAmount > 0 && | ||
|
|
@@ -195,7 +194,7 @@ const FaresV2Table = ({ | |
| }, | ||
| { | ||
| transferAmount: intl.formatNumber(originalAmount, { | ||
| currency: price?.currency?.code, | ||
| currency: legPrice?.currency?.code, | ||
| currencyDisplay: "narrowSymbol", | ||
| style: "currency" | ||
| }) | ||
|
|
@@ -206,8 +205,9 @@ const FaresV2Table = ({ | |
| {!Number.isNaN(originalAmount) && | ||
| originalAmount > 0 && | ||
| index > 0 && <TransferIcon size={16} />} | ||
| {price | ||
| ? renderFare(price?.currency?.code, price?.amount) | ||
| {/* Leg Price will always be defined if the fare product has a price */} | ||
| {legPrice | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a comment that legprice exists when original amount exists. There's probably a lot of cleanup possible overall but we can put it as a todo for now |
||
| ? renderFare(legPrice?.currency?.code, legPrice?.amount) | ||
| : FailDash} | ||
| </td> | ||
| </> | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.