@opentripplanner/trip-details 5.0.0-alpha.7 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.tsx CHANGED
@@ -1,4 +1,5 @@
1
1
  import coreUtils from "@opentripplanner/core-utils";
2
+ import { FareProductSelector } from "@opentripplanner/types";
2
3
  import React, { ReactElement } from "react";
3
4
  import { FormattedMessage, FormattedNumber } from "react-intl";
4
5
  import { CalendarAlt } from "@styled-icons/fa-solid/CalendarAlt";
@@ -6,15 +7,13 @@ import { Heartbeat } from "@styled-icons/fa-solid/Heartbeat";
6
7
  import { MoneyBillAlt } from "@styled-icons/fa-solid/MoneyBillAlt";
7
8
  import { Leaf } from "@styled-icons/fa-solid/Leaf";
8
9
  import { Route } from "@styled-icons/fa-solid/Route";
9
-
10
- import { getItineraryCost } from "@opentripplanner/core-utils/lib/itinerary";
11
10
  import { flatten } from "flat";
12
11
  import * as S from "./styled";
13
12
  import TripDetail from "./trip-detail";
14
13
  import FareLegTable from "./fare-table";
15
14
  import { boldText, renderFare } from "./utils";
16
15
 
17
- import { FareType, TimeActiveDetailsProps, TripDetailsProps } from "./types";
16
+ import { TimeActiveDetailsProps, TripDetailsProps } from "./types";
18
17
 
19
18
  // Load the default messages.
20
19
  import defaultEnglishMessages from "../i18n/en-US.yml";
@@ -79,19 +78,19 @@ export function TripDetails({
79
78
  const fareResult = coreUtils.itinerary.calculateTncFares(itinerary);
80
79
  const { currencyCode, maxTNCFare, minTNCFare } = fareResult;
81
80
 
82
- // Depending on if there are additional fares to display either render a <span> or a <details>.
83
81
  const { companies, fareTypes } = itinerary.legs.reduce<{
84
82
  companies: string;
85
- fareTypes: FareType[];
83
+ fareTypes: FareProductSelector[];
86
84
  }>(
87
85
  (prev, leg) => {
88
86
  if (leg.rideHailingEstimate) {
89
87
  prev.companies = leg.rideHailingEstimate.provider.id;
90
88
  }
89
+
91
90
  if (leg.fareProducts) {
92
91
  leg.fareProducts.forEach(fp => {
93
- const mediumId = fp.product?.medium?.id;
94
- const riderCategoryId = fp.product?.riderCategory?.id;
92
+ const mediumId = fp.product.medium?.id;
93
+ const riderCategoryId = fp.product.riderCategory?.id;
95
94
  if (
96
95
  !prev.fareTypes.find(
97
96
  ft =>
@@ -110,7 +109,7 @@ export function TripDetails({
110
109
 
111
110
  let fare;
112
111
  if (fareTypes.length > 0 && defaultFareType) {
113
- const defaultFareTotal = getItineraryCost(
112
+ const defaultFareTotal = coreUtils.itinerary.getItineraryCost(
114
113
  itinerary.legs,
115
114
  defaultFareType.mediumId,
116
115
  defaultFareType.riderCategoryId
@@ -127,7 +126,7 @@ export function TripDetails({
127
126
  />
128
127
  );
129
128
 
130
- fare = defaultFareTotal.amount && (
129
+ fare = defaultFareTotal?.amount && (
131
130
  <S.Fare>
132
131
  <TransitFareWrapper>
133
132
  <summary style={{ display: fareTypes.length > 1 ? "list-item" : "" }}>
@@ -160,12 +159,12 @@ export function TripDetails({
160
159
  }
161
160
  return (
162
161
  <FormattedMessage
163
- key={Object.values(fareType).join("-")}
164
162
  defaultMessage={
165
163
  defaultMessages["otpUi.TripDetails.transitFareEntry"]
166
164
  }
167
165
  description="Text showing the price of tickets on public transportation."
168
166
  id="otpUi.TripDetails.transitFareEntry"
167
+ key={Object.values(fareType).join("-")}
169
168
  values={{
170
169
  name:
171
170
  fareKeyNameMap[defaultFareType.headerKey] ||
@@ -284,9 +283,9 @@ export function TripDetails({
284
283
  description={
285
284
  FareDetails && (
286
285
  <FareDetails
286
+ legs={itinerary.legs}
287
287
  maxTNCFare={maxTNCFare}
288
288
  minTNCFare={minTNCFare}
289
- legs={itinerary.legs}
290
289
  />
291
290
  )
292
291
  }
@@ -300,9 +299,9 @@ export function TripDetails({
300
299
  description={
301
300
  FareDetails && (
302
301
  <FareDetails
302
+ legs={itinerary.legs}
303
303
  maxTNCFare={maxTNCFare}
304
304
  minTNCFare={minTNCFare}
305
- legs={itinerary.legs}
306
305
  />
307
306
  )
308
307
  }
package/src/types.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  // Prettier does not recognize the import type syntax.
2
2
  // eslint-disable-next-line prettier/prettier
3
- import type { MassUnitOption, Itinerary, Money, Leg } from "@opentripplanner/types";
4
- import type { ReactElement } from "react";
3
+ import type {
4
+ FareProductSelector,
5
+ Itinerary,
6
+ Leg,
7
+ MassUnitOption,
8
+ Money
9
+ } from "@opentripplanner/types";
5
10
 
6
11
  export interface TimeActiveDetailsProps {
7
12
  bikeMinutes: number;
@@ -19,45 +24,32 @@ export interface DepartureDetailsProps {
19
24
  departureDate: Date;
20
25
  }
21
26
 
22
- export interface FareType {
23
- riderCategoryId: string;
24
- mediumId: string;
25
- }
26
-
27
27
  /**
28
28
  * This is the interface used to define the layout for a particular fare table.
29
- * The table with be rendered with the columsn defined here,
29
+ * The table with be rendered with the columns defined here,
30
30
  * with each row being an individual transit leg from the itinerary.
31
31
  */
32
32
  export interface FareTableLayout {
33
- cols: (FareType & {
33
+ cols: (FareProductSelector & {
34
34
  columnHeaderKey: string;
35
35
  })[]
36
36
  headerKey: string;
37
37
  }
38
+ /**
39
+ * Interface containing the lgs and the layout of the fare table.
40
+ */
38
41
  export interface FareLegTableProps {
39
42
  layout?: FareTableLayout[];
40
43
  legs: Leg[];
41
44
  }
42
45
 
43
46
  // Total fare amount corresponding to a fare key
44
- export type FareTotals = (FareType & { price: Money })[]
45
-
46
- export interface TransitFareProps {
47
- headerKey: string;
48
- fareMediumId: string
49
- riderCategoryId: string
50
- fareNameFallback?: ReactElement;
51
- fareKeyNameMap: {
52
- [key: string]: string;
53
- };
54
- fareTotals: FareTotals;
55
- }
47
+ export type FareTotals = (FareProductSelector & { price: Money })[]
56
48
 
57
49
  export interface FareDetailsProps {
50
+ legs: Leg[];
58
51
  maxTNCFare: number;
59
52
  minTNCFare: number;
60
- legs: Leg[];
61
53
  }
62
54
 
63
55
 
@@ -73,7 +65,7 @@ export interface TripDetailsProps {
73
65
  /**
74
66
  * Determines which transit fare should be displayed by default, should there be multiple transit fare types.
75
67
  */
76
- defaultFareType?: { headerKey: string } & FareType;
68
+ defaultFareType?: { headerKey: string } & FareProductSelector;
77
69
  /**
78
70
  * Slot for a custom component to render the expandable section for departure.
79
71
  */
package/src/utils.tsx CHANGED
@@ -1,10 +1,10 @@
1
- import React, { ReactElement } from "react";
1
+ import React, { ReactElement, ReactNode } from "react";
2
2
  import { FormattedNumber } from "react-intl";
3
3
 
4
4
  /**
5
5
  * Format text bold (used with FormattedMessage).
6
6
  */
7
- export function boldText(contents: ReactElement | string): ReactElement {
7
+ export function boldText(contents: ReactNode): ReactElement {
8
8
  return <strong>{contents}</strong>;
9
9
  }
10
10