@opentripplanner/trip-details 4.0.2-alpha.1 → 5.0.0-alpha.1
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/esm/fare-table.js +47 -65
- package/esm/fare-table.js.map +1 -1
- package/esm/index.js +90 -89
- package/esm/index.js.map +1 -1
- package/esm/types.js +0 -11
- package/esm/types.js.map +1 -1
- package/esm/utils.js +1 -50
- package/esm/utils.js.map +1 -1
- package/lib/fare-table.d.ts +5 -0
- package/lib/fare-table.d.ts.map +1 -0
- package/lib/fare-table.js +43 -57
- package/lib/fare-table.js.map +1 -1
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +74 -73
- package/lib/index.js.map +1 -1
- package/lib/styled.d.ts +19 -0
- package/lib/styled.d.ts.map +1 -0
- package/lib/trip-detail.d.ts +9 -0
- package/lib/trip-detail.d.ts.map +1 -0
- package/lib/types.d.ts +100 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +0 -18
- package/lib/types.js.map +1 -1
- package/lib/utils.d.ts +13 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +0 -57
- package/lib/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/TripDetails.story.tsx +37 -88
- package/src/fare-table.tsx +57 -85
- package/src/index.tsx +93 -89
- package/src/types.ts +29 -29
- package/src/utils.tsx +2 -73
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from "@storybook/react";
|
|
10
10
|
import styled from "styled-components";
|
|
11
11
|
// The below eslint-disable is due to https://github.com/storybookjs/storybook/issues/13408
|
|
12
|
+
import { convertGraphQLResponseToLegacy } from "@opentripplanner/core-utils/lib/itinerary";
|
|
12
13
|
// eslint-disable-next-line import/no-named-as-default
|
|
13
14
|
import TripDetails, { FareLegTable } from ".";
|
|
14
15
|
import * as TripDetailsClasses from "./styled";
|
|
@@ -17,7 +18,6 @@ import {
|
|
|
17
18
|
DepartureDetailsProps,
|
|
18
19
|
FareDetailsProps,
|
|
19
20
|
FareTableLayout,
|
|
20
|
-
FareTableText,
|
|
21
21
|
TripDetailsProps
|
|
22
22
|
} from "./types";
|
|
23
23
|
|
|
@@ -37,10 +37,10 @@ const walkInterlinedTransitItinerary = require("@opentripplanner/itinerary-body/
|
|
|
37
37
|
const walkOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-only.json");
|
|
38
38
|
const walkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk.json");
|
|
39
39
|
const walkTransitWalkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk-transit-walk.json");
|
|
40
|
-
const
|
|
40
|
+
const fareProductsItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/leg-fare-products.json");
|
|
41
41
|
const flexItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/flex-itinerary.json");
|
|
42
42
|
const otp2ScooterItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/otp2-scooter.json");
|
|
43
|
-
const otp2FareProducts = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/
|
|
43
|
+
const otp2FareProducts = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/leg-fare-products.json");
|
|
44
44
|
|
|
45
45
|
const flattenedEnglishMessages = flatten(customEnglishMessages);
|
|
46
46
|
const flattenedFrenchMessages = flatten(customFrenchMessages);
|
|
@@ -59,97 +59,52 @@ const StyledTripDetails = styled(TripDetails)`
|
|
|
59
59
|
|
|
60
60
|
const otp2FareByLegLayout: FareTableLayout[] = [
|
|
61
61
|
{
|
|
62
|
-
|
|
62
|
+
headerKey: "regular",
|
|
63
63
|
cols: [
|
|
64
64
|
{
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
columnHeaderKey: "cash",
|
|
66
|
+
riderCategoryId: "orca:regular",
|
|
67
|
+
mediumId: "orca:cash"
|
|
68
68
|
},
|
|
69
69
|
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
columnHeaderKey: "electronic",
|
|
71
|
+
riderCategoryId: "orca:regular",
|
|
72
|
+
mediumId: "orca:electronic"
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
columnHeaderKey: "special",
|
|
76
|
+
riderCategoryId: "orca:special",
|
|
77
|
+
mediumId: "orca:electronic"
|
|
78
78
|
}
|
|
79
79
|
]
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
|
-
|
|
82
|
+
headerKey: "youth",
|
|
83
83
|
cols: [
|
|
84
84
|
{
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
columnHeaderKey: "cash",
|
|
86
|
+
riderCategoryId: "orca:youth",
|
|
87
|
+
mediumId: "orca:cash"
|
|
88
88
|
},
|
|
89
89
|
{
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
columnHeaderKey: "electronic",
|
|
91
|
+
riderCategoryId: "orca:youth",
|
|
92
|
+
mediumId: "orca:electronic"
|
|
93
93
|
}
|
|
94
94
|
]
|
|
95
95
|
},
|
|
96
96
|
{
|
|
97
|
-
|
|
97
|
+
headerKey: "senior",
|
|
98
98
|
cols: [
|
|
99
99
|
{
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
columnHeaderKey: "cash",
|
|
101
|
+
riderCategoryId: "orca:senior",
|
|
102
|
+
mediumId: "orca:cash"
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
];
|
|
112
|
-
const fareByLegLayout: FareTableLayout[] = [
|
|
113
|
-
{
|
|
114
|
-
header: "regular" as FareTableText,
|
|
115
|
-
cols: [
|
|
116
|
-
{
|
|
117
|
-
header: "cash" as FareTableText,
|
|
118
|
-
key: "regular"
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
header: "electronic" as FareTableText,
|
|
122
|
-
key: "electronicRegular"
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
header: "special" as FareTableText,
|
|
126
|
-
key: "electronicSpecial"
|
|
127
|
-
}
|
|
128
|
-
]
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
header: "youth" as FareTableText,
|
|
132
|
-
cols: [
|
|
133
|
-
{
|
|
134
|
-
header: "cash" as FareTableText,
|
|
135
|
-
key: "youth"
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
header: "electronic" as FareTableText,
|
|
139
|
-
key: "electronicYouth"
|
|
140
|
-
}
|
|
141
|
-
]
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
header: "senior" as FareTableText,
|
|
145
|
-
cols: [
|
|
146
|
-
{
|
|
147
|
-
header: "cash" as FareTableText,
|
|
148
|
-
key: "cash"
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
header: "electronic" as FareTableText,
|
|
152
|
-
key: "electronic"
|
|
105
|
+
columnHeaderKey: "electronic",
|
|
106
|
+
riderCategoryId: "orca:senior",
|
|
107
|
+
mediumId: "orca:electronic"
|
|
153
108
|
}
|
|
154
109
|
]
|
|
155
110
|
}
|
|
@@ -313,8 +268,8 @@ export const BikeTransitBikeItinerary = makeStory({
|
|
|
313
268
|
|
|
314
269
|
export const WalkInterlinedTransitItinerary = makeStory(
|
|
315
270
|
{
|
|
316
|
-
defaultFareKey: "electronicRegular",
|
|
317
|
-
fareDetailsLayout: fareByLegLayout,
|
|
271
|
+
// defaultFareKey: "electronicRegular",
|
|
272
|
+
// fareDetailsLayout: fareByLegLayout,
|
|
318
273
|
itinerary: walkInterlinedTransitItinerary
|
|
319
274
|
},
|
|
320
275
|
{
|
|
@@ -373,7 +328,11 @@ export const TncTransitItinerary = makeStory(
|
|
|
373
328
|
export const TncTransitItineraryWithCustomMessages = makeStory(
|
|
374
329
|
{
|
|
375
330
|
TimeActiveDetails: CustomTimeActiveDetails,
|
|
376
|
-
|
|
331
|
+
defaultFareType: {
|
|
332
|
+
headerKey: "electronicRegular",
|
|
333
|
+
mediumId: "orca:electronic",
|
|
334
|
+
riderCategoryId: "orca:regular"
|
|
335
|
+
},
|
|
377
336
|
DepartureDetails: CustomDepartureDetails,
|
|
378
337
|
itinerary: tncTransitTncItinerary
|
|
379
338
|
},
|
|
@@ -392,22 +351,12 @@ export const TncTransitItineraryWithCustomMessages = makeStory(
|
|
|
392
351
|
);
|
|
393
352
|
|
|
394
353
|
export const FareComponentsItinerary = makeStory({
|
|
395
|
-
itinerary:
|
|
354
|
+
itinerary: fareProductsItinerary
|
|
396
355
|
});
|
|
397
356
|
|
|
398
357
|
export const OTP2FlexItinerary = makeStory({ itinerary: flexItinerary });
|
|
399
358
|
|
|
400
|
-
export const FareLegTableStory = (): ReactElement => {
|
|
401
|
-
return (
|
|
402
|
-
<FareLegTable
|
|
403
|
-
layout={fareByLegLayout}
|
|
404
|
-
itinerary={walkInterlinedTransitItinerary}
|
|
405
|
-
/>
|
|
406
|
-
);
|
|
407
|
-
};
|
|
408
|
-
|
|
409
359
|
export const FareLegTableStoryLegProducts = (): ReactElement => {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
);
|
|
360
|
+
const otp1legs = otp2FareProducts.legs.map(convertGraphQLResponseToLegacy);
|
|
361
|
+
return <FareLegTable layout={otp2FareByLegLayout} legs={otp1legs} />;
|
|
413
362
|
};
|
package/src/fare-table.tsx
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { Leg
|
|
1
|
+
import { Leg } from "@opentripplanner/types";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import styled from "styled-components";
|
|
4
4
|
import { Transfer } from "@styled-icons/boxicons-regular/Transfer";
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
getItineraryCost,
|
|
8
|
-
getLegCost
|
|
9
|
-
getLegsWithFares
|
|
8
|
+
getLegCost
|
|
10
9
|
} from "@opentripplanner/core-utils/lib/itinerary";
|
|
11
10
|
import { useIntl } from "react-intl";
|
|
12
11
|
import { flatten } from "flat";
|
|
13
|
-
import { boldText,
|
|
12
|
+
import { boldText, renderFare } from "./utils";
|
|
14
13
|
|
|
15
14
|
import { FareLegTableProps, FareTableLayout } from "./types";
|
|
16
15
|
|
|
@@ -23,14 +22,8 @@ import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
|
23
22
|
// - the yaml loader for jest returns messages with flattened ids.
|
|
24
23
|
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
25
24
|
|
|
26
|
-
type LegAndFare = Leg & {
|
|
27
|
-
fares: Record<string, { price: Money; isTransfer?: boolean }>;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
25
|
interface FareTypeTableProps extends FareTableLayout {
|
|
31
|
-
|
|
32
|
-
legs: LegAndFare[];
|
|
33
|
-
hasLegProducts?: boolean;
|
|
26
|
+
legs: Leg[];
|
|
34
27
|
}
|
|
35
28
|
|
|
36
29
|
const TableHeader = styled.thead`
|
|
@@ -73,63 +66,73 @@ const TransferIcon = styled(Transfer)`
|
|
|
73
66
|
padding-left: 4px;
|
|
74
67
|
`;
|
|
75
68
|
|
|
69
|
+
const useGetHeaderString = (headerKey: string): string => {
|
|
70
|
+
const intl = useIntl();
|
|
71
|
+
return intl.formatMessage({
|
|
72
|
+
id: `otpUi.TripDetails.FareTable.${headerKey}`,
|
|
73
|
+
description: `Fare leg table header for key ${headerKey}`,
|
|
74
|
+
defaultMessage:
|
|
75
|
+
defaultEnglishMessages[`otpUi.TripDetails.FareTable.${headerKey}`]
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
76
79
|
const FareTypeTable = ({
|
|
77
80
|
cols,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
legs,
|
|
81
|
-
hasLegProducts
|
|
81
|
+
headerKey,
|
|
82
|
+
legs
|
|
82
83
|
}: FareTypeTableProps): JSX.Element => {
|
|
83
|
-
const colsToRender = cols.filter(col =>
|
|
84
|
-
hasLegProducts
|
|
85
|
-
? getItineraryCost(legs, col.riderCategory, col.fareContainer)
|
|
86
|
-
: fareTotals[col.key]
|
|
87
|
-
);
|
|
88
|
-
|
|
89
84
|
const intl = useIntl();
|
|
85
|
+
// FIXME: Is there a nicer way to do this?
|
|
86
|
+
const colsToRender = cols
|
|
87
|
+
.filter(col => getItineraryCost(legs, col.riderCategoryId, col.mediumId))
|
|
88
|
+
.map(col => ({
|
|
89
|
+
...col,
|
|
90
|
+
total: getItineraryCost(legs, col.riderCategoryId, col.mediumId)
|
|
91
|
+
}));
|
|
90
92
|
|
|
93
|
+
const headerString = useGetHeaderString(headerKey);
|
|
94
|
+
|
|
95
|
+
const filteredLegs = legs.filter(leg => leg.fareProducts?.length > 0);
|
|
91
96
|
if (colsToRender.length) {
|
|
92
97
|
return (
|
|
93
98
|
<Table>
|
|
94
99
|
<TableHeader>
|
|
95
100
|
<th className="main" scope="col">
|
|
96
|
-
{boldText(
|
|
101
|
+
{boldText(headerString)}
|
|
97
102
|
</th>
|
|
98
103
|
{colsToRender.map(col => {
|
|
99
|
-
const fare =
|
|
100
|
-
? getItineraryCost(legs, col.riderCategory, col.fareContainer)
|
|
101
|
-
: fareTotals[col.key];
|
|
104
|
+
const fare = col.total;
|
|
102
105
|
return (
|
|
103
106
|
<th
|
|
104
107
|
scope="col"
|
|
105
|
-
key={
|
|
108
|
+
key={
|
|
109
|
+
col.columnHeaderKey ||
|
|
110
|
+
`${col.mediumId}-${col.riderCategoryId}`
|
|
111
|
+
}
|
|
106
112
|
>
|
|
107
|
-
{boldText(
|
|
113
|
+
{boldText(useGetHeaderString(col.columnHeaderKey))}
|
|
108
114
|
<br />
|
|
109
115
|
{renderFare(
|
|
110
|
-
fare?.currency?.
|
|
111
|
-
(fare?.
|
|
116
|
+
fare?.currency?.code,
|
|
117
|
+
(fare?.amount || 0) / 10 ** fare?.currency?.digits
|
|
112
118
|
)}
|
|
113
119
|
</th>
|
|
114
120
|
);
|
|
115
121
|
})}
|
|
116
122
|
</TableHeader>
|
|
117
|
-
{
|
|
123
|
+
{filteredLegs.map((leg, index) => (
|
|
118
124
|
<tr key={index}>
|
|
119
125
|
<td className="no-zebra">
|
|
120
126
|
{leg.routeShortName || leg.route || leg.routeLongName}
|
|
121
127
|
</td>
|
|
122
128
|
{colsToRender.map(col => {
|
|
123
|
-
const fare =
|
|
124
|
-
? getLegCost(leg, col.riderCategory, col.fareContainer)
|
|
125
|
-
: leg.fares[col.key];
|
|
126
|
-
|
|
129
|
+
const fare = getLegCost(leg, col.mediumId, col.riderCategoryId);
|
|
127
130
|
return (
|
|
128
131
|
<td
|
|
129
|
-
key={col.
|
|
132
|
+
key={col.columnHeaderKey}
|
|
130
133
|
title={
|
|
131
134
|
"transferAmount" in fare &&
|
|
132
|
-
fare?.transferAmount &&
|
|
135
|
+
fare?.transferAmount?.amount > 0 &&
|
|
133
136
|
intl.formatMessage(
|
|
134
137
|
{
|
|
135
138
|
defaultMessage:
|
|
@@ -142,9 +145,10 @@ const FareTypeTable = ({
|
|
|
142
145
|
},
|
|
143
146
|
{
|
|
144
147
|
transferAmount: intl.formatNumber(
|
|
145
|
-
fare
|
|
148
|
+
fare?.transferAmount?.amount /
|
|
149
|
+
10 ** fare?.transferAmount?.currency.digits,
|
|
146
150
|
{
|
|
147
|
-
currency: fare?.price?.currency?.
|
|
151
|
+
currency: fare?.price?.currency?.code,
|
|
148
152
|
currencyDisplay: "narrowSymbol",
|
|
149
153
|
style: "currency"
|
|
150
154
|
}
|
|
@@ -153,15 +157,16 @@ const FareTypeTable = ({
|
|
|
153
157
|
)
|
|
154
158
|
}
|
|
155
159
|
>
|
|
156
|
-
{
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
{"transferAmount" in fare &&
|
|
161
|
+
fare?.transferAmount?.amount > 0 && (
|
|
162
|
+
<>
|
|
163
|
+
<TransferIcon size={16} />{" "}
|
|
164
|
+
</>
|
|
165
|
+
)}
|
|
162
166
|
{renderFare(
|
|
163
|
-
fare?.price?.currency?.
|
|
164
|
-
(fare?.price?.
|
|
167
|
+
fare?.price?.currency?.code,
|
|
168
|
+
(fare?.price?.amount || 0) /
|
|
169
|
+
10 ** fare?.price?.currency?.digits
|
|
165
170
|
)}
|
|
166
171
|
</td>
|
|
167
172
|
);
|
|
@@ -174,53 +179,20 @@ const FareTypeTable = ({
|
|
|
174
179
|
return null;
|
|
175
180
|
};
|
|
176
181
|
|
|
177
|
-
const
|
|
178
|
-
layout
|
|
179
|
-
itinerary
|
|
180
|
-
}: FareLegTableProps): JSX.Element => {
|
|
181
|
-
const hasLegProducts = !!itinerary?.fare?.legProducts;
|
|
182
|
-
const fareKeys = Object.keys(itinerary?.fare?.details);
|
|
183
|
-
|
|
184
|
-
let legsWithFares;
|
|
185
|
-
|
|
186
|
-
if (!hasLegProducts) {
|
|
187
|
-
// OTP1 Logic
|
|
188
|
-
legsWithFares = itinerary.legs
|
|
189
|
-
.map((leg, index) => {
|
|
190
|
-
const fares = fareKeys.reduce((prev, key) => {
|
|
191
|
-
const fareForKey = itinerary.fare.details[key]?.find(
|
|
192
|
-
detail => detail.legIndex === index
|
|
193
|
-
);
|
|
194
|
-
if (fareForKey) {
|
|
195
|
-
prev[key] = fareForKey;
|
|
196
|
-
}
|
|
197
|
-
return prev;
|
|
198
|
-
}, {});
|
|
199
|
-
return {
|
|
200
|
-
...leg,
|
|
201
|
-
fares
|
|
202
|
-
};
|
|
203
|
-
})
|
|
204
|
-
.filter(leg => leg.transitLeg);
|
|
205
|
-
} else {
|
|
206
|
-
// OTP2 Logic using core-utils function
|
|
207
|
-
legsWithFares = getLegsWithFares(itinerary).filter(leg => leg.transitLeg);
|
|
208
|
-
}
|
|
209
|
-
|
|
182
|
+
const FareLegTable = ({ layout, legs }: FareLegTableProps): JSX.Element => {
|
|
183
|
+
// the layout argument contains an object for every table to be displayed
|
|
210
184
|
return (
|
|
211
185
|
<div>
|
|
212
186
|
{layout.map(config => (
|
|
213
187
|
<FareTypeTable
|
|
214
188
|
cols={config.cols}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
legs={legsWithFares}
|
|
219
|
-
hasLegProducts={hasLegProducts}
|
|
189
|
+
headerKey={config.headerKey}
|
|
190
|
+
key={config.headerKey}
|
|
191
|
+
legs={legs}
|
|
220
192
|
/>
|
|
221
193
|
))}
|
|
222
194
|
</div>
|
|
223
195
|
);
|
|
224
196
|
};
|
|
225
197
|
|
|
226
|
-
export default
|
|
198
|
+
export default FareLegTable;
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import flatten from "flat";
|
|
2
1
|
import coreUtils from "@opentripplanner/core-utils";
|
|
3
2
|
import React, { ReactElement } from "react";
|
|
4
3
|
import { FormattedMessage, FormattedNumber } from "react-intl";
|
|
@@ -8,16 +7,14 @@ import { MoneyBillAlt } from "@styled-icons/fa-solid/MoneyBillAlt";
|
|
|
8
7
|
import { Leaf } from "@styled-icons/fa-solid/Leaf";
|
|
9
8
|
import { Route } from "@styled-icons/fa-solid/Route";
|
|
10
9
|
|
|
10
|
+
import { getItineraryCost } from "@opentripplanner/core-utils/lib/itinerary";
|
|
11
|
+
import { flatten } from "flat";
|
|
11
12
|
import * as S from "./styled";
|
|
12
13
|
import TripDetail from "./trip-detail";
|
|
13
14
|
import FareLegTable from "./fare-table";
|
|
14
15
|
import { boldText, renderFare } from "./utils";
|
|
15
16
|
|
|
16
|
-
import {
|
|
17
|
-
TimeActiveDetailsProps,
|
|
18
|
-
TransitFareProps,
|
|
19
|
-
TripDetailsProps
|
|
20
|
-
} from "./types";
|
|
17
|
+
import { FareType, TimeActiveDetailsProps, TripDetailsProps } from "./types";
|
|
21
18
|
|
|
22
19
|
// Load the default messages.
|
|
23
20
|
import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
@@ -63,54 +60,17 @@ function DefaultTimeActiveDetails({
|
|
|
63
60
|
);
|
|
64
61
|
}
|
|
65
62
|
|
|
66
|
-
/**
|
|
67
|
-
* Helper component that renders a transit fare entry.
|
|
68
|
-
*/
|
|
69
|
-
const TransitFare = ({
|
|
70
|
-
fareKey,
|
|
71
|
-
fareNameFallback,
|
|
72
|
-
fareKeyNameMap,
|
|
73
|
-
transitFares
|
|
74
|
-
}: TransitFareProps): ReactElement => {
|
|
75
|
-
const currentFare = transitFares[fareKey];
|
|
76
|
-
|
|
77
|
-
// TODO: Is this needed? Every implementation of TransitFare does a check for currentFare's existence, although not the cents field
|
|
78
|
-
if (typeof currentFare?.cents !== "number") {
|
|
79
|
-
return (
|
|
80
|
-
<FormattedMessage
|
|
81
|
-
defaultMessage={defaultMessages["otpUi.TripDetails.transitFareUnknown"]}
|
|
82
|
-
description="Text showing that no fare information is present."
|
|
83
|
-
id="otpUi.TripDetails.transitFareUnknown"
|
|
84
|
-
/>
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<span>
|
|
90
|
-
<FormattedMessage
|
|
91
|
-
defaultMessage={defaultMessages["otpUi.TripDetails.transitFareEntry"]}
|
|
92
|
-
description="Text showing the price of tickets on public transportation."
|
|
93
|
-
id="otpUi.TripDetails.transitFareEntry"
|
|
94
|
-
values={{
|
|
95
|
-
name: fareKeyNameMap[fareKey] || fareNameFallback || fareKey,
|
|
96
|
-
strong: boldText,
|
|
97
|
-
value: renderFare(
|
|
98
|
-
currentFare?.currency?.currencyCode || "USD",
|
|
99
|
-
currentFare.cents / 100
|
|
100
|
-
)
|
|
101
|
-
}}
|
|
102
|
-
/>
|
|
103
|
-
</span>
|
|
104
|
-
);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
63
|
/**
|
|
108
64
|
* Renders trip details such as departure instructions, fare amount, and minutes active.
|
|
109
65
|
*/
|
|
110
66
|
export function TripDetails({
|
|
111
67
|
className = "",
|
|
112
68
|
co2Config,
|
|
113
|
-
|
|
69
|
+
defaultFareType = {
|
|
70
|
+
headerKey: "cash-regular",
|
|
71
|
+
mediumId: "cash",
|
|
72
|
+
riderCategoryId: "regular"
|
|
73
|
+
},
|
|
114
74
|
DepartureDetails = null,
|
|
115
75
|
displayTimeActive = true,
|
|
116
76
|
FareDetails = null,
|
|
@@ -122,63 +82,107 @@ export function TripDetails({
|
|
|
122
82
|
// process the transit fare
|
|
123
83
|
const fareResult = coreUtils.itinerary.calculateTncFares(itinerary);
|
|
124
84
|
const { currencyCode, maxTNCFare, minTNCFare } = fareResult;
|
|
125
|
-
const transitFares = itinerary?.fare?.fare;
|
|
126
|
-
|
|
127
|
-
let companies = "";
|
|
128
|
-
itinerary.legs.forEach(leg => {
|
|
129
|
-
if (leg.rideHailingEstimate) {
|
|
130
|
-
companies = leg.rideHailingEstimate.provider.id;
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
let fare;
|
|
134
|
-
|
|
135
|
-
const fareKeys = transitFares && Object.keys(transitFares).sort();
|
|
136
85
|
|
|
137
|
-
if
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
86
|
+
// Depending on if there are additional fares to display either render a <span> or a <details>.
|
|
87
|
+
const { companies, fareTypes } = itinerary.legs.reduce<{
|
|
88
|
+
companies: string;
|
|
89
|
+
fareTypes: FareType[];
|
|
90
|
+
}>(
|
|
91
|
+
(prev, leg) => {
|
|
92
|
+
if (leg.rideHailingEstimate) {
|
|
93
|
+
prev.companies = leg.rideHailingEstimate.provider.id;
|
|
94
|
+
}
|
|
95
|
+
if (leg.fareProducts) {
|
|
96
|
+
leg.fareProducts.forEach(fp => {
|
|
97
|
+
const mediumId = fp.product.medium.id;
|
|
98
|
+
const riderCategoryId = fp.product.riderCategory.id;
|
|
99
|
+
if (
|
|
100
|
+
prev.fareTypes.find(
|
|
101
|
+
ft =>
|
|
102
|
+
!(
|
|
103
|
+
ft.mediumId === mediumId &&
|
|
104
|
+
ft.riderCategoryId === riderCategoryId
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
) {
|
|
108
|
+
prev.fareTypes.push({ mediumId, riderCategoryId });
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return prev;
|
|
113
|
+
},
|
|
114
|
+
{ companies: "", fareTypes: [] }
|
|
115
|
+
);
|
|
142
116
|
|
|
117
|
+
let fare;
|
|
118
|
+
if (fareTypes.length > 0) {
|
|
119
|
+
const defaultFareTotal = getItineraryCost(
|
|
120
|
+
itinerary.legs,
|
|
121
|
+
defaultFareType.riderCategoryId,
|
|
122
|
+
defaultFareType.mediumId
|
|
123
|
+
);
|
|
143
124
|
// Depending on if there are additional fares to display either render a <span> or a <details>
|
|
144
125
|
const TransitFareWrapper =
|
|
145
|
-
|
|
126
|
+
fareTypes.length > 1 ? S.TransitFare : S.TransitFareSingle;
|
|
146
127
|
|
|
147
|
-
|
|
128
|
+
const fareNameFallback = (
|
|
129
|
+
<FormattedMessage
|
|
130
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.transitFare"]}
|
|
131
|
+
description="Text showing the price of tickets on public transportation."
|
|
132
|
+
id="otpUi.TripDetails.transitFare"
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
fare = defaultFareTotal.amount && (
|
|
148
137
|
<S.Fare>
|
|
149
138
|
<TransitFareWrapper>
|
|
150
|
-
<summary style={{ display:
|
|
151
|
-
<
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
defaultMessage={
|
|
155
|
-
defaultMessages["otpUi.TripDetails.transitFare"]
|
|
156
|
-
}
|
|
157
|
-
description="Text showing the price of tickets on public transportation."
|
|
158
|
-
id="otpUi.TripDetails.transitFare"
|
|
159
|
-
/>
|
|
139
|
+
<summary style={{ display: fareTypes.length > 1 ? "list-item" : "" }}>
|
|
140
|
+
<FormattedMessage
|
|
141
|
+
defaultMessage={
|
|
142
|
+
defaultMessages["otpUi.TripDetails.transitFareEntry"]
|
|
160
143
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
144
|
+
description="Text showing the price of tickets on public transportation."
|
|
145
|
+
id="otpUi.TripDetails.transitFareEntry"
|
|
146
|
+
values={{
|
|
147
|
+
name:
|
|
148
|
+
fareKeyNameMap[defaultFareType.headerKey] || fareNameFallback,
|
|
149
|
+
strong: boldText,
|
|
150
|
+
value: renderFare(
|
|
151
|
+
defaultFareTotal.currency?.code || "USD",
|
|
152
|
+
defaultFareTotal?.amount / defaultFareTotal?.currency?.digits
|
|
153
|
+
)
|
|
154
|
+
}}
|
|
164
155
|
/>
|
|
165
156
|
</summary>
|
|
166
157
|
{fareDetailsLayout ? (
|
|
167
158
|
// Show full ƒare details by leg
|
|
168
|
-
<FareLegTable layout={fareDetailsLayout}
|
|
159
|
+
<FareLegTable layout={fareDetailsLayout} legs={itinerary.legs} />
|
|
169
160
|
) : (
|
|
170
161
|
// Just show the fares for each payment type
|
|
171
|
-
|
|
162
|
+
fareTypes.map(fareType => {
|
|
172
163
|
// Don't show the default fare twice!
|
|
173
|
-
if (
|
|
164
|
+
if (fareType) {
|
|
174
165
|
return null;
|
|
175
166
|
}
|
|
176
167
|
return (
|
|
177
|
-
<
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
168
|
+
<FormattedMessage
|
|
169
|
+
key={Object.values(fareType).join("-")}
|
|
170
|
+
defaultMessage={
|
|
171
|
+
defaultMessages["otpUi.TripDetails.transitFareEntry"]
|
|
172
|
+
}
|
|
173
|
+
description="Text showing the price of tickets on public transportation."
|
|
174
|
+
id="otpUi.TripDetails.transitFareEntry"
|
|
175
|
+
values={{
|
|
176
|
+
name:
|
|
177
|
+
fareKeyNameMap[defaultFareType.headerKey] ||
|
|
178
|
+
fareNameFallback,
|
|
179
|
+
strong: boldText,
|
|
180
|
+
value: renderFare(
|
|
181
|
+
defaultFareTotal.currency?.code || "USD",
|
|
182
|
+
defaultFareTotal?.amount /
|
|
183
|
+
defaultFareTotal?.currency?.digits
|
|
184
|
+
)
|
|
185
|
+
}}
|
|
182
186
|
/>
|
|
183
187
|
);
|
|
184
188
|
})
|
|
@@ -288,7 +292,7 @@ export function TripDetails({
|
|
|
288
292
|
<FareDetails
|
|
289
293
|
maxTNCFare={maxTNCFare}
|
|
290
294
|
minTNCFare={minTNCFare}
|
|
291
|
-
|
|
295
|
+
legs={itinerary.legs}
|
|
292
296
|
/>
|
|
293
297
|
)
|
|
294
298
|
}
|
|
@@ -304,7 +308,7 @@ export function TripDetails({
|
|
|
304
308
|
<FareDetails
|
|
305
309
|
maxTNCFare={maxTNCFare}
|
|
306
310
|
minTNCFare={minTNCFare}
|
|
307
|
-
|
|
311
|
+
legs={itinerary.legs}
|
|
308
312
|
/>
|
|
309
313
|
)
|
|
310
314
|
}
|