Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-heppner-ibigroup committed Jul 10, 2023
1 parent 94a3bb6 commit c765371
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 57 deletions.
8 changes: 5 additions & 3 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: {
medium: { id: "cash" },
riderCategory: { id: "regular" },
name: "rideCost",
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
16 changes: 8 additions & 8 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
52 changes: 26 additions & 26 deletions packages/trip-details/src/TripDetails.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,57 +59,57 @@ const StyledTripDetails = styled(TripDetails)`

const otp2FareByLegLayout: FareTableLayout[] = [
{
headerKey: "regular",
cols: [
{
columnHeaderKey: "cash",
riderCategoryId: "orca:regular",
mediumId: "orca:cash"
mediumId: "orca:cash",
riderCategoryId: "orca:regular"
},
{
columnHeaderKey: "electronic",
riderCategoryId: "orca:regular",
mediumId: "orca:electronic"
mediumId: "orca:electronic",
riderCategoryId: "orca:regular"
},
{
columnHeaderKey: "special",
riderCategoryId: "orca:special",
mediumId: "orca:electronic"
mediumId: "orca:electronic",
riderCategoryId: "orca:special"
}
]
],
headerKey: "regular"
},
{
headerKey: "youth",
cols: [
{
columnHeaderKey: "cash",
riderCategoryId: "orca:youth",
mediumId: "orca:cash"
mediumId: "orca:cash",
riderCategoryId: "orca:youth"
},
{
columnHeaderKey: "electronic",
riderCategoryId: "orca:youth",
mediumId: "orca:electronic"
mediumId: "orca:electronic",
riderCategoryId: "orca:youth"
},
{
columnHeaderKey: "test",
riderCategoryId: "invalidkey",
mediumId: "invalidkey"
mediumId: "invalidkey",
riderCategoryId: "invalidkey"
}
]
],
headerKey: "youth"
},
{
headerKey: "senior",
cols: [
{
columnHeaderKey: "cash",
riderCategoryId: "orca:senior",
mediumId: "orca:cash"
mediumId: "orca:cash",
riderCategoryId: "orca:senior"
},
{
columnHeaderKey: "electronic",
riderCategoryId: "orca:senior",
mediumId: "orca:electronic"
mediumId: "orca:electronic",
riderCategoryId: "orca:senior"
}
]
}
Expand Down Expand Up @@ -193,11 +193,11 @@ function createTripDetailsTemplate(
): ComponentStory<typeof TripDetails> {
const TripDetailsTemplate = (
{
TimeActiveDetails,
defaultFareType,
DepartureDetails,
FareDetails,
fareDetailsLayout,
defaultFareType,
TimeActiveDetails,
itinerary
}: TripDetailsProps,
{ globals, parameters }: StoryContext
Expand Down Expand Up @@ -280,9 +280,9 @@ export const BikeTransitBikeItinerary = makeStory({
});

export const LegFareProductsItinerary = makeStory({
itinerary: otp2FareProducts,
defaultFareType: otp2defaultFareType,
fareDetailsLayout: otp2FareByLegLayout,
defaultFareType: otp2defaultFareType
itinerary: otp2FareProducts
});

export const WalkInterlinedTransitItinerary = makeStory(
Expand Down Expand Up @@ -346,14 +346,14 @@ export const TncTransitItinerary = makeStory(

export const TncTransitItineraryWithCustomMessages = makeStory(
{
TimeActiveDetails: CustomTimeActiveDetails,
defaultFareType: {
headerKey: "electronicRegular",
mediumId: "orca:electronic",
riderCategoryId: "orca:regular"
},
DepartureDetails: CustomDepartureDetails,
itinerary: tncTransitTncItinerary
itinerary: tncTransitTncItinerary,
TimeActiveDetails: CustomTimeActiveDetails
},
{
// For illustration purposes,
Expand Down
15 changes: 7 additions & 8 deletions packages/trip-details/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import coreUtils from "@opentripplanner/core-utils";
import { FareProductSelector } from "@opentripplanner/types";
import React, { ReactElement } from "react";
import { FormattedMessage, FormattedNumber } from "react-intl";
import { CalendarAlt } from "@styled-icons/fa-solid/CalendarAlt";
import { Heartbeat } from "@styled-icons/fa-solid/Heartbeat";
import { MoneyBillAlt } from "@styled-icons/fa-solid/MoneyBillAlt";
import { Leaf } from "@styled-icons/fa-solid/Leaf";
import { Route } from "@styled-icons/fa-solid/Route";

import { getItineraryCost } from "@opentripplanner/core-utils/lib/itinerary";
import { flatten } from "flat";
import * as S from "./styled";
import TripDetail from "./trip-detail";
import FareLegTable from "./fare-table";
import { boldText, renderFare } from "./utils";

import { FareType, TimeActiveDetailsProps, TripDetailsProps } from "./types";
import { TimeActiveDetailsProps, TripDetailsProps } from "./types";

// Load the default messages.
import defaultEnglishMessages from "../i18n/en-US.yml";
Expand Down Expand Up @@ -81,7 +80,7 @@ export function TripDetails({

const { companies, fareTypes } = itinerary.legs.reduce<{
companies: string;
fareTypes: FareType[];
fareTypes: FareProductSelector[];
}>(
(prev, leg) => {
if (leg.rideHailingEstimate) {
Expand Down Expand Up @@ -110,7 +109,7 @@ export function TripDetails({

let fare;
if (fareTypes.length > 0 && defaultFareType) {
const defaultFareTotal = getItineraryCost(
const defaultFareTotal = coreUtils.itinerary.getItineraryCost(
itinerary.legs,
defaultFareType.mediumId,
defaultFareType.riderCategoryId
Expand Down Expand Up @@ -160,12 +159,12 @@ export function TripDetails({
}
return (
<FormattedMessage
key={Object.values(fareType).join("-")}
defaultMessage={
defaultMessages["otpUi.TripDetails.transitFareEntry"]
}
description="Text showing the price of tickets on public transportation."
id="otpUi.TripDetails.transitFareEntry"
key={Object.values(fareType).join("-")}
values={{
name:
fareKeyNameMap[defaultFareType.headerKey] ||
Expand Down Expand Up @@ -284,9 +283,9 @@ export function TripDetails({
description={
FareDetails && (
<FareDetails
legs={itinerary.legs}
maxTNCFare={maxTNCFare}
minTNCFare={minTNCFare}
legs={itinerary.legs}
/>
)
}
Expand All @@ -300,9 +299,9 @@ export function TripDetails({
description={
FareDetails && (
<FareDetails
legs={itinerary.legs}
maxTNCFare={maxTNCFare}
minTNCFare={minTNCFare}
legs={itinerary.legs}
/>
)
}
Expand Down
15 changes: 5 additions & 10 deletions packages/trip-details/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Prettier does not recognize the import type syntax.
// eslint-disable-next-line prettier/prettier
import type { MassUnitOption, Itinerary, Money, Leg } from "@opentripplanner/types";
import type { FareProductSelector, Itinerary, Leg, Money, MassUnitOption, } from "@opentripplanner/types";
import type { ReactElement } from "react";

export interface TimeActiveDetailsProps {
Expand All @@ -19,18 +19,13 @@ export interface DepartureDetailsProps {
departureDate: Date;
}

export interface FareType {
riderCategoryId: string;
mediumId: string;
}

/**
* This is the interface used to define the layout for a particular fare table.
* The table with be rendered with the columns defined here,
* with each row being an individual transit leg from the itinerary.
*/
export interface FareTableLayout {
cols: (FareType & {
cols: (FareProductSelector & {
columnHeaderKey: string;
})[]
headerKey: string;
Expand All @@ -41,7 +36,7 @@ export interface FareLegTableProps {
}

// Total fare amount corresponding to a fare key
export type FareTotals = (FareType & { price: Money })[]
export type FareTotals = (FareProductSelector & { price: Money })[]

export interface TransitFareProps {
headerKey: string;
Expand All @@ -55,9 +50,9 @@ export interface TransitFareProps {
}

export interface FareDetailsProps {
legs: Leg[];
maxTNCFare: number;
minTNCFare: number;
legs: Leg[];
}


Expand All @@ -73,7 +68,7 @@ export interface TripDetailsProps {
/**
* Determines which transit fare should be displayed by default, should there be multiple transit fare types.
*/
defaultFareType?: { headerKey: string } & FareType;
defaultFareType?: { headerKey: string } & FareProductSelector;
/**
* Slot for a custom component to render the expandable section for departure.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/trip-details/src/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { ReactElement } from "react";
import React, { ReactElement, ReactNode } from "react";
import { FormattedNumber } from "react-intl";

/**
* Format text bold (used with FormattedMessage).
*/
export function boldText(contents: ReactElement | string): ReactElement {
export function boldText(contents: ReactNode): ReactElement {
return <strong>{contents}</strong>;
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3275,6 +3275,11 @@
resolved "https://registry.yarnpkg.com/@opentripplanner/types/-/types-6.0.0-alpha.4.tgz#dee3c06675e30c596159d182ed707e7710cd937c"
integrity sha512-FlYsHm/tk+x0ldrEG1X9Ph1R1k3way1oEdKX7XSnhu9lNTzL4lO0hfT1PLzNXMfBRar7TzK94PHNDibJsod8Kw==

"@opentripplanner/types@^6.0.0-alpha.9":
version "6.0.0-alpha.10"
resolved "https://registry.yarnpkg.com/@opentripplanner/types/-/types-6.0.0-alpha.10.tgz#1489c55f7741ef46df6882c682580ea96ca23d62"
integrity sha512-s0xBgA3WLqvda5itUYzv7PGyMV/dqITfnA2zpdwsbyzuNQeOYTk1tSQLWr+QH7mbUYJXAs5i8qzC/VNvDSZQqg==

"@peculiar/asn1-schema@^2.1.6", "@peculiar/asn1-schema@^2.3.0":
version "2.3.3"
resolved "https://registry.yarnpkg.com/@peculiar/asn1-schema/-/asn1-schema-2.3.3.tgz#21418e1f3819e0b353ceff0c2dad8ccb61acd777"
Expand Down

0 comments on commit c765371

Please sign in to comment.