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

Fare Table comaptibility with OTP2 FareProduct API #612

Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b7cfc5a
feat(core-utils): adds function for converting GQL response to REST
daniel-heppner-ibigroup Jun 9, 2023
bb3b334
fix(core-utils): convert fare functions to consume GQL data
daniel-heppner-ibigroup Jun 9, 2023
c456013
feat(itinerary-body): removes REST style fare data
daniel-heppner-ibigroup Jun 9, 2023
96eae08
test(itinerary-body): add new mock
daniel-heppner-ibigroup Jun 9, 2023
e941d67
test(core-utils): add new mock
daniel-heppner-ibigroup Jun 9, 2023
97d46a8
feat(trip-details): convert FareTable to use Fare Product data
daniel-heppner-ibigroup Jun 9, 2023
2a95a93
test: add test for getlegfare
daniel-heppner-ibigroup Jun 12, 2023
d102510
feat(types): Remove old fare info, add GraphQL style FareProducts to …
daniel-heppner-ibigroup Jun 12, 2023
8848676
Merge branch 'gql-transition/fare-product-types' into otp2-fare-produ…
daniel-heppner-ibigroup Jun 12, 2023
c7b7cad
refactor(itinerary-body): re-add showRouteFares
daniel-heppner-ibigroup Jun 13, 2023
0ca75a4
fix(core-utils): adds new FareProducts API to query
daniel-heppner-ibigroup Jun 13, 2023
7a5652f
refactor(itinerary-body): update legprodct mock
daniel-heppner-ibigroup Jun 13, 2023
1113b6b
undo some regressions
daniel-heppner-ibigroup Jun 15, 2023
1575424
Merge branch 'gql-transition/add-fareproducts-to-query' into fare-pro…
daniel-heppner-ibigroup Jun 15, 2023
93f257f
Merge branch 'gql-transition/fare-product-types' into fare-products-t…
daniel-heppner-ibigroup Jun 15, 2023
f842f87
Merge branch 'fare-products-table' into otp2-fare-products-table
daniel-heppner-ibigroup Jun 15, 2023
ce6c90a
Merge branch 'master' into otp2-fare-products-table
daniel-heppner-ibigroup Jun 19, 2023
6ee769c
fix(core-utils): correct bug with argument order
daniel-heppner-ibigroup Jun 19, 2023
0a1ba98
fix(trip-details): bug fixes
daniel-heppner-ibigroup Jun 19, 2023
a9befc9
fix(trip-details): fix fare product table bug
daniel-heppner-ibigroup Jun 20, 2023
4c1ed6e
fix(i18n): add correct translations
daniel-heppner-ibigroup Jun 20, 2023
a5232ec
fix(trip-details): fix crash
daniel-heppner-ibigroup Jun 20, 2023
ff007f3
fix(core-utils): hide undefined fare legs instead of returning 0
daniel-heppner-ibigroup Jul 3, 2023
0122ca5
refactor(trip-details): add story with invalidkey
daniel-heppner-ibigroup Jul 3, 2023
d5f1340
deps(trip-details): use latest core-utils
daniel-heppner-ibigroup Jul 3, 2023
118d5fe
Merge branch 'master' into otp2-fare-products-table
daniel-heppner-ibigroup Jul 3, 2023
fa21a13
fix spelling
daniel-heppner-ibigroup Jul 3, 2023
099920c
fix types issue
daniel-heppner-ibigroup Jul 3, 2023
077dbdb
i18n: clean up files
daniel-heppner-ibigroup Jul 3, 2023
c4753fa
fix crash
daniel-heppner-ibigroup Jul 3, 2023
8596ad9
i18n: remove unused key
daniel-heppner-ibigroup Jul 3, 2023
0e7efb2
refactor: fix i18n issues by restoring itinerary body code
daniel-heppner-ibigroup Jul 3, 2023
596fcf8
fix(types): add type for specifying fare product ids
daniel-heppner-ibigroup Jul 3, 2023
1b0757a
chore: update snapshots
daniel-heppner-ibigroup Jul 3, 2023
587cc08
Merge branch 'master' into otp2-fare-products-table
daniel-heppner-ibigroup Jul 3, 2023
365c6f9
deps: update types versions
daniel-heppner-ibigroup Jul 3, 2023
b8e2ae9
refactor(types): generate commit
daniel-heppner-ibigroup Jul 3, 2023
33cad91
refactor(types): pr comments
daniel-heppner-ibigroup Jul 10, 2023
94a3bb6
i18n: improve french text
daniel-heppner-ibigroup Jul 10, 2023
c765371
address pr comments
daniel-heppner-ibigroup Jul 10, 2023
0b2f9db
remove old story
daniel-heppner-ibigroup Jul 11, 2023
48bdcc4
fix(itinerary-body): remove unused prop and add new defaultFareSelect…
daniel-heppner-ibigroup Jul 11, 2023
63eb193
test: fix itinerary test
daniel-heppner-ibigroup Jul 11, 2023
eccaf39
fix(trip-details): remove unused types
daniel-heppner-ibigroup Jul 11, 2023
73c71fa
refactor: remove unused stories
daniel-heppner-ibigroup Jul 11, 2023
aa85e51
chore: update snapshots
daniel-heppner-ibigroup Jul 11, 2023
f4601e7
chore: sort props
daniel-heppner-ibigroup Jul 12, 2023
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
30,713 changes: 6,813 additions & 23,900 deletions __snapshots__/storybook.test.ts.snap

Large diffs are not rendered by default.

This file was deleted.

13 changes: 9 additions & 4 deletions packages/core-utils/src/__tests__/itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,20 @@ describe("util > itinerary", () => {
const leg = {
fareProducts: [
{
id: "testId",
product: {
daniel-heppner-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
medium: { id: "cash" },
riderCategory: { id: "regular" },
name: "rideCost",
daniel-heppner-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
price: { amount: 200, currency: "USD" }
price: { amount: 200, currency: "USD" },
riderCategory: { id: "regular" }
}
},
{
id: "testId",
product: {
medium: { id: "cash" },
name: "transfer",
price: { amount: 50, currency: "USD" },
medium: { id: "cash" },
riderCategory: { id: "regular" }
}
}
Expand Down Expand Up @@ -141,7 +143,10 @@ describe("util > itinerary", () => {
"orca:regular"
);
expect(result.amount).toEqual(5.75);
expect(result.currency).toMatchSnapshot();
expect(result.currency).toEqual({
code: "USD",
digits: 2
});
});
it("should return undefined when the keys are invalid", () => {
const result = getItineraryCost(
Expand Down
2 changes: 2 additions & 0 deletions packages/itinerary-body/src/ItineraryBody/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const ItineraryBody = ({
alwaysCollapseAlerts = false,
className,
config,
defaultFareSelector,
diagramVisible,
frameLeg = noop,
itinerary,
Expand Down Expand Up @@ -61,6 +62,7 @@ const ItineraryBody = ({
// eslint-disable-next-line react/no-array-index-key
key={i + (isDestination ? 1 : 0)}
config={config}
defaultFareSelector={defaultFareSelector}
diagramVisible={diagramVisible}
followsTransit={followsTransit}
frameLeg={frameLeg}
Expand Down
2 changes: 2 additions & 0 deletions packages/itinerary-body/src/ItineraryBody/place-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default function PlaceRow({
TimeColumnContent = DefaultTimeColumnContent,
toRouteAbbreviation,
TransitLegSubheader,
defaultFareSelector,
daniel-heppner-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
TransitLegSummary
}: PlaceRowProps): ReactElement {
// NOTE: Previously there was a check for itineraries that changed vehicles
Expand Down Expand Up @@ -146,6 +147,7 @@ export default function PlaceRow({
timeZone={config.homeTimezone}
TransitLegSubheader={TransitLegSubheader}
TransitLegSummary={TransitLegSummary}
defaultFareSelector={defaultFareSelector}
transitOperator={coreUtils.route.getTransitOperatorFromLeg(
leg,
config.transitOperators
Expand Down
62 changes: 31 additions & 31 deletions packages/itinerary-body/src/TransitLegBody/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
injectIntl,
IntlShape
} from "react-intl";
import { getLegCost } from "@opentripplanner/core-utils/lib/itinerary";

import { Duration } from "../defaults";

import * as S from "../styled";
Expand All @@ -35,11 +35,12 @@ interface Props {
AlertBodyIcon?: FunctionComponent;
AlertToggleIcon?: FunctionComponent;
alwaysCollapseAlerts: boolean;
defaultFareSelector?: FareProductSelector;
intl: IntlShape;
leg: Leg;
legDestination: string;
LegIcon: LegIconComponent;
legIndex: number;
legDestination: string;
RouteDescription: FunctionComponent<RouteDescriptionProps>;
setActiveLeg: SetActiveLegFunction;
setViewedTrip: SetViewedTripFunction;
Expand All @@ -49,7 +50,6 @@ interface Props {
TransitLegSubheader?: FunctionComponent<TransitLegSubheaderProps>;
TransitLegSummary: FunctionComponent<TransitLegSummaryProps>;
transitOperator?: TransitOperator;
defaultFareSelector?: FareProductSelector;
}

interface State {
Expand Down Expand Up @@ -126,22 +126,22 @@ class TransitLegBody extends Component<Props, State> {

render(): ReactElement {
const {
AlertToggleIcon = S.DefaultAlertToggleIcon,
AlertBodyIcon,
AlertToggleIcon = S.DefaultAlertToggleIcon,
alwaysCollapseAlerts,
defaultFareSelector,
intl,
leg,
LegIcon,
legDestination,
LegIcon,
RouteDescription,
setViewedTrip,
showAgencyInfo,
showViewTripButton,
timeZone,
TransitLegSubheader,
TransitLegSummary,
transitOperator,
defaultFareSelector
transitOperator
} = this.props;
const { agencyBrandingUrl, agencyName, agencyUrl, alerts } = leg;
const { alertsExpanded, stopsExpanded } = this.state;
Expand Down Expand Up @@ -171,7 +171,7 @@ class TransitLegBody extends Component<Props, State> {

const legCost =
defaultFareSelector &&
getLegCost(
coreUtils.itinerary.getLegCost(
leg,
defaultFareSelector.mediumId,
defaultFareSelector.riderCategoryId
Expand Down Expand Up @@ -341,31 +341,31 @@ class TransitLegBody extends Component<Props, State> {
>
<S.TransitLegExpandedBody>
<IntermediateStops stops={leg.intermediateStops} />
{legCost?.price && (
<S.TransitLegFare>
<FormattedMessage
defaultMessage={
defaultMessages["otpUi.TransitLegBody.fare"]
}
description="Describes the fare for a leg"
id="otpUi.TransitLegBody.fare"
values={{
fare: (
<FormattedNumber
currency={legCost.price.currency.code}
currencyDisplay="narrowSymbol"
// This isn't a "real" style prop
// eslint-disable-next-line react/style-prop-object
style="currency"
value={legCost.price.amount}
/>
)
}}
/>
</S.TransitLegFare>
)}
</S.TransitLegExpandedBody>
</AnimateHeight>
{legCost && (
<S.TransitLegFare>
<FormattedMessage
defaultMessage={
defaultMessages["otpUi.TransitLegBody.fare"]
}
description="Describes the fare for a leg"
id="otpUi.TransitLegBody.fare"
values={{
fare: (
<FormattedNumber
currency={legCost.price.currency.code}
currencyDisplay="narrowSymbol"
// This isn't a "real" style prop
// eslint-disable-next-line react/style-prop-object
style="currency"
value={legCost.price.amount}
/>
)
}}
/>
</S.TransitLegFare>
)}
{/* Average wait details, if present */}
{leg.averageWait && (
<span>
Expand Down
24 changes: 15 additions & 9 deletions packages/itinerary-body/src/stories/OtpRrItineraryBody.story.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Itinerary } from "@opentripplanner/types";
import { FareProductSelector, Itinerary } from "@opentripplanner/types";
import React, { ReactElement } from "react";

import ItineraryBody from "..";
Expand Down Expand Up @@ -47,20 +47,21 @@ if (!isRunningJest()) {

interface StoryWrapperProps {
itinerary: Itinerary;
showRouteFares: boolean;
TimeColumnContent: FunctionComponent<TimeColumnContentProps>;
alwaysCollapseAlerts: boolean;
TimeColumnContent?: FunctionComponent<TimeColumnContentProps>;
defaultFareSelector?: FareProductSelector;
daniel-heppner-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
alwaysCollapseAlerts?: boolean;
}

function OtpRRItineraryBodyWrapper({
alwaysCollapseAlerts,
defaultFareSelector,
itinerary,
showRouteFares,
TimeColumnContent,
alwaysCollapseAlerts
TimeColumnContent
}: StoryWrapperProps): ReactElement {
return (
<ItineraryBodyDefaultsWrapper
alwaysCollapseAlerts={alwaysCollapseAlerts}
defaultFareSelector={defaultFareSelector}
itinerary={itinerary}
LegIcon={LegIconWithA11y}
LineColumnContent={OtpRRLineColumnContent}
Expand All @@ -69,7 +70,6 @@ function OtpRRItineraryBodyWrapper({
showAgencyInfo
showLegIcon
showMapButtonColumn={false}
showRouteFares={showRouteFares}
showViewTripButton
styledItinerary="otp-rr"
TimeColumnContent={TimeColumnContent}
Expand Down Expand Up @@ -148,7 +148,13 @@ export const OTP2FlexItinerary = (): ReactElement => (
);

export const IndividualLegFareComponents = (): ReactElement => (
<OtpRRItineraryBodyWrapper itinerary={fareProductsItinerary} showRouteFares />
<OtpRRItineraryBodyWrapper
itinerary={fareProductsItinerary}
defaultFareSelector={{
daniel-heppner-ibigroup marked this conversation as resolved.
Show resolved Hide resolved
mediumId: "orca:cash",
riderCategoryId: "orca:regular"
}}
/>
);

export const CustomTimeColumn = (): ReactElement => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ export const OTP2FlexItinerary = (): ReactElement => (
);

export const IndividualLegFareComponents = (): ReactElement => (
<ItineraryBodyDefaultsWrapper
itinerary={fareProductsItinerary}
showRouteFares
/>
<ItineraryBodyDefaultsWrapper itinerary={fareProductsItinerary} />
);

export const CustomAlertIconsItinerary = (): ReactElement => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default class ItineraryBodyDefaultsWrapper extends Component<
render(): ReactElement {
const {
alwaysCollapseAlerts,
defaultFareSelector,
itinerary,
LegIcon = TriMetLegIcon,
LineColumnContent,
Expand All @@ -50,7 +51,6 @@ export default class ItineraryBodyDefaultsWrapper extends Component<
showAgencyInfo,
showLegIcon,
showMapButtonColumn = true,
showRouteFares,
showViewTripButton,
styledItinerary,
TimeColumnContent,
Expand Down Expand Up @@ -78,6 +78,7 @@ export default class ItineraryBodyDefaultsWrapper extends Component<
AlertToggleIcon={AlertToggleIcon}
alwaysCollapseAlerts={alwaysCollapseAlerts}
config={config}
defaultFareSelector={defaultFareSelector}
diagramVisible={diagramVisible}
frameLeg={action("frameLeg")}
itinerary={itinerary}
Expand All @@ -94,7 +95,6 @@ export default class ItineraryBodyDefaultsWrapper extends Component<
showElevationProfile
showLegIcon={showLegIcon}
showMapButtonColumn={showMapButtonColumn}
showRouteFares={showRouteFares}
showViewTripButton={showViewTripButton}
TimeColumnContent={TimeColumnContent}
toRouteAbbreviation={toRouteAbbreviation}
Expand Down
9 changes: 7 additions & 2 deletions packages/itinerary-body/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FunctionComponent } from "react";

import {
Config,
FareProductSelector,
GradationMap,
Itinerary,
Leg,
Expand Down Expand Up @@ -108,6 +109,12 @@ interface ItineraryBodySharedProps {
className?: string;
/** Contains OTP configuration details. */
config: Config;
/**
* Allows selection of a fare product type for display in the itinerary body.
* When fare leg information is available, it will be shown per-leg.
* Example: regular, cash or regular, electronic.
*/
defaultFareSelector?: FareProductSelector;
/**
* Should be either null or a legType. Indicates that a particular leg diagram
* has been selected and is active.
Expand Down Expand Up @@ -183,8 +190,6 @@ interface ItineraryBodySharedProps {
showLegIcon?: boolean;
/** If true, will show the right column with the map button */
showMapButtonColumn?: boolean;
/** If true, will show fare information in transit leg bodies */
showRouteFares?: boolean;
/** If true, shows the view trip button in transit leg bodies */
showViewTripButton?: boolean;
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/trip-details/__mocks__/custom-french-messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ otpUi:
FareTable:
cash: Espèces
electronic: ORCA
regular: Ordinaire
regular: Plein tarif
senior: Senior
special: LIFT
youth: Jeune
2 changes: 1 addition & 1 deletion packages/trip-details/i18n/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ otpUi:
FareTable:
cash: Espèces
electronic: Électronique
regular: Normal
regular: Plein tarif
senior: Séniors
special: Spécial
youth: Jeunes
Expand Down
Loading