@opentripplanner/trip-details 2.1.0-alpha.1 → 2.1.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/__mocks__/{custom-messages.yml → custom-english-messages.yml} +7 -0
- package/__mocks__/custom-french-messages.yml +10 -0
- package/esm/fare-table.js +153 -0
- package/esm/fare-table.js.map +1 -0
- package/esm/index.js +26 -46
- package/esm/index.js.map +1 -1
- package/esm/types.js +11 -0
- package/esm/types.js.map +1 -1
- package/esm/utils.js +29 -0
- package/esm/utils.js.map +1 -0
- package/i18n/en-US.yml +7 -0
- package/i18n/fr.yml +7 -0
- package/lib/fare-table.d.ts +4 -0
- package/lib/fare-table.d.ts.map +1 -0
- package/lib/fare-table.js +160 -0
- package/lib/fare-table.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +32 -52
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +32 -11
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +18 -0
- 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 +41 -0
- package/lib/utils.js.map +1 -0
- package/package.json +4 -4
- package/src/TripDetails.story.tsx +61 -38
- package/src/fare-table.tsx +222 -0
- package/src/index.tsx +38 -60
- package/src/types.ts +34 -11
- package/src/utils.tsx +30 -0
- package/tsconfig.tsbuildinfo +177 -24
- package/esm/fare-detail.js +0 -111
- package/esm/fare-detail.js.map +0 -1
- package/lib/fare-detail.d.ts +0 -3
- package/lib/fare-detail.d.ts.map +0 -1
- package/lib/fare-detail.js +0 -115
- package/lib/fare-detail.js.map +0 -1
- package/src/fare-detail.tsx +0 -157
package/lib/utils.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.boldText = boldText;
|
|
9
|
+
exports.renderFare = renderFare;
|
|
10
|
+
|
|
11
|
+
var _react = _interopRequireDefault(require("react"));
|
|
12
|
+
|
|
13
|
+
var _reactIntl = require("react-intl");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Format text bold (used with FormattedMessage).
|
|
17
|
+
*/
|
|
18
|
+
function boldText(contents) {
|
|
19
|
+
return /*#__PURE__*/_react.default.createElement("strong", null, contents);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Render formatted fare.
|
|
23
|
+
* @param currencyCode The ISO currency code to use (USD, GBP, EUR).
|
|
24
|
+
* @param fare The fare value, in currency units, to be shown.
|
|
25
|
+
* @returns The formatted fare value according to the selected locale.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
function renderFare(currencyCode, fare) {
|
|
30
|
+
return /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedNumber, {
|
|
31
|
+
currency: currencyCode // For dollars in locales such as 'fr',
|
|
32
|
+
// this will limit the display to just the dollar sign
|
|
33
|
+
// (otherwise it will render e.g. '2,50 $US' instead of '2,50 $').
|
|
34
|
+
,
|
|
35
|
+
currencyDisplay: "narrowSymbol",
|
|
36
|
+
value: fare // eslint-disable-next-line react/style-prop-object
|
|
37
|
+
,
|
|
38
|
+
style: "currency"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.tsx"],"names":["boldText","contents","renderFare","currencyCode","fare"],"mappings":";;;;;;;;;;AAAA;;AACA;;AAEA;AACA;AACA;AACO,SAASA,QAAT,CAAkBC,QAAlB,EAAwD;AAC7D,sBAAO,6CAASA,QAAT,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,UAAT,CAAoBC,YAApB,EAA0CC,IAA1C,EAAsE;AAC3E,sBACE,6BAAC,0BAAD;AACE,IAAA,QAAQ,EAAED,YADZ,CAEE;AACA;AACA;AAJF;AAKE,IAAA,eAAe,EAAC,cALlB;AAME,IAAA,KAAK,EAAEC,IANT,CAOE;AAPF;AAQE,IAAA,KAAK,EAAC;AARR,IADF;AAYD","sourcesContent":["import React, { ReactElement } from \"react\";\nimport { FormattedNumber } from \"react-intl\";\n\n/**\n * Format text bold (used with FormattedMessage).\n */\nexport function boldText(contents: ReactElement): ReactElement {\n return <strong>{contents}</strong>;\n}\n\n/**\n * Render formatted fare.\n * @param currencyCode The ISO currency code to use (USD, GBP, EUR).\n * @param fare The fare value, in currency units, to be shown.\n * @returns The formatted fare value according to the selected locale.\n */\nexport function renderFare(currencyCode: string, fare: number): ReactElement {\n return (\n <FormattedNumber\n currency={currencyCode}\n // For dollars in locales such as 'fr',\n // this will limit the display to just the dollar sign\n // (otherwise it will render e.g. '2,50 $US' instead of '2,50 $').\n currencyDisplay=\"narrowSymbol\"\n value={fare}\n // eslint-disable-next-line react/style-prop-object\n style=\"currency\"\n />\n );\n}\n"],"file":"utils.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentripplanner/trip-details",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "A component for displaying details about a trip planning itinerary",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"private": false,
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@opentripplanner/core-utils": "^
|
|
14
|
+
"@opentripplanner/core-utils": "^5.0.1",
|
|
15
15
|
"@styled-icons/fa-solid": "^10.34.0",
|
|
16
16
|
"flat": "^5.0.2",
|
|
17
17
|
"velocity-react": "^1.4.3"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@opentripplanner/types": "^
|
|
20
|
+
"@opentripplanner/types": "^2.0.0",
|
|
21
21
|
"@types/flat": "^5.0.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
},
|
|
31
31
|
"gitHead": "0af1b7cda60bd4252b219dcf893e01c2acb2ed5d",
|
|
32
32
|
"scripts": {
|
|
33
|
-
"tsc": "tsc
|
|
33
|
+
"tsc": "tsc"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -14,11 +14,14 @@ import * as TripDetailsClasses from "./styled";
|
|
|
14
14
|
import {
|
|
15
15
|
CaloriesDetailsProps,
|
|
16
16
|
DepartureDetailsProps,
|
|
17
|
+
FareDetailsProps,
|
|
18
|
+
FareTableLayout,
|
|
19
|
+
FareTableText,
|
|
17
20
|
TripDetailsProps
|
|
18
21
|
} from "./types";
|
|
19
22
|
|
|
20
|
-
import
|
|
21
|
-
import
|
|
23
|
+
import customEnglishMessages from "../__mocks__/custom-english-messages.yml";
|
|
24
|
+
import customFrenchMessages from "../__mocks__/custom-french-messages.yml";
|
|
22
25
|
|
|
23
26
|
// import mock itinaries. These are all trip plan outputs from OTP.
|
|
24
27
|
const bikeOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-only.json");
|
|
@@ -34,6 +37,10 @@ const walkOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__
|
|
|
34
37
|
const walkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk.json");
|
|
35
38
|
const walkTransitWalkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk-transit-walk.json");
|
|
36
39
|
const fareComponentsItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/fare-components.json");
|
|
40
|
+
const otp2ScooterItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/otp2-scooter.json");
|
|
41
|
+
|
|
42
|
+
const flattenedEnglishMessages = flatten(customEnglishMessages);
|
|
43
|
+
const flattenedFrenchMessages = flatten(customFrenchMessages);
|
|
37
44
|
|
|
38
45
|
// Change currency code on one of the itineraries for illustration.
|
|
39
46
|
// (other currency fields in the itinerary object are not used for display).
|
|
@@ -47,47 +54,47 @@ const StyledTripDetails = styled(TripDetails)`
|
|
|
47
54
|
}
|
|
48
55
|
`;
|
|
49
56
|
|
|
50
|
-
const fareByLegLayout = [
|
|
57
|
+
const fareByLegLayout: FareTableLayout[] = [
|
|
51
58
|
{
|
|
52
|
-
header: "
|
|
59
|
+
header: "regular" as FareTableText,
|
|
53
60
|
cols: [
|
|
54
61
|
{
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
header: "cash" as FareTableText,
|
|
63
|
+
key: "regular"
|
|
57
64
|
},
|
|
58
65
|
{
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
header: "electronic" as FareTableText,
|
|
67
|
+
key: "electronicRegular"
|
|
61
68
|
},
|
|
62
69
|
{
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
header: "special" as FareTableText,
|
|
71
|
+
key: "electronicSpecial"
|
|
65
72
|
}
|
|
66
73
|
]
|
|
67
74
|
},
|
|
68
75
|
{
|
|
69
|
-
header: "
|
|
76
|
+
header: "youth" as FareTableText,
|
|
70
77
|
cols: [
|
|
71
78
|
{
|
|
72
|
-
|
|
73
|
-
|
|
79
|
+
header: "cash" as FareTableText,
|
|
80
|
+
key: "youth"
|
|
74
81
|
},
|
|
75
82
|
{
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
header: "electronic" as FareTableText,
|
|
84
|
+
key: "electronicYouth"
|
|
78
85
|
}
|
|
79
86
|
]
|
|
80
87
|
},
|
|
81
88
|
{
|
|
82
|
-
header: "
|
|
89
|
+
header: "senior" as FareTableText,
|
|
83
90
|
cols: [
|
|
84
91
|
{
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
header: "cash" as FareTableText,
|
|
93
|
+
key: "cash"
|
|
87
94
|
},
|
|
88
95
|
{
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
header: "electronic" as FareTableText,
|
|
97
|
+
key: "electronic"
|
|
91
98
|
}
|
|
92
99
|
]
|
|
93
100
|
}
|
|
@@ -121,6 +128,15 @@ const frenchFareKeyMap = {
|
|
|
121
128
|
electronicSenior: "Tarif Orca séniors"
|
|
122
129
|
};
|
|
123
130
|
|
|
131
|
+
const CustomFareDetails = ({
|
|
132
|
+
transitFares
|
|
133
|
+
}: FareDetailsProps): ReactElement => (
|
|
134
|
+
<>
|
|
135
|
+
Custom details about fares (transitFares: {JSON.stringify(transitFares)}){" "}
|
|
136
|
+
(cents), can be constructed dynamically using any markup.
|
|
137
|
+
</>
|
|
138
|
+
);
|
|
139
|
+
|
|
124
140
|
// Custom slots for expandable detail sections.
|
|
125
141
|
const CustomDepartureDetails = ({
|
|
126
142
|
departureDate
|
|
@@ -155,8 +171,9 @@ function createTripDetailsTemplate(
|
|
|
155
171
|
{
|
|
156
172
|
CaloriesDetails,
|
|
157
173
|
DepartureDetails,
|
|
158
|
-
|
|
159
|
-
fareDetailsLayout
|
|
174
|
+
FareDetails,
|
|
175
|
+
fareDetailsLayout,
|
|
176
|
+
itinerary
|
|
160
177
|
}: TripDetailsProps,
|
|
161
178
|
{ globals, parameters }: StoryContext
|
|
162
179
|
): ReactElement => {
|
|
@@ -171,9 +188,10 @@ function createTripDetailsTemplate(
|
|
|
171
188
|
<Component
|
|
172
189
|
CaloriesDetails={CaloriesDetails}
|
|
173
190
|
DepartureDetails={DepartureDetails}
|
|
191
|
+
FareDetails={FareDetails}
|
|
192
|
+
fareDetailsLayout={fareDetailsLayout}
|
|
174
193
|
fareKeyNameMap={fareKeyNameMap}
|
|
175
194
|
itinerary={itinerary}
|
|
176
|
-
fareDetailsLayout={fareDetailsLayout}
|
|
177
195
|
/>
|
|
178
196
|
);
|
|
179
197
|
};
|
|
@@ -237,11 +255,19 @@ export const BikeTransitBikeItinerary = makeStory({
|
|
|
237
255
|
export const WalkInterlinedTransitItinerary = makeStory(
|
|
238
256
|
{
|
|
239
257
|
defaultFareKey: "electronicRegular",
|
|
240
|
-
|
|
241
|
-
|
|
258
|
+
fareDetailsLayout: fareByLegLayout,
|
|
259
|
+
itinerary: walkInterlinedTransitItinerary
|
|
242
260
|
},
|
|
243
261
|
{
|
|
244
|
-
useCustomFareKeyMap: true
|
|
262
|
+
useCustomFareKeyMap: true,
|
|
263
|
+
// For illustration purposes,
|
|
264
|
+
// override a subset of localized strings with custom messages.
|
|
265
|
+
reactIntl: {
|
|
266
|
+
messages: {
|
|
267
|
+
"en-US": flattenedEnglishMessages,
|
|
268
|
+
fr: flattenedFrenchMessages
|
|
269
|
+
}
|
|
270
|
+
}
|
|
245
271
|
}
|
|
246
272
|
);
|
|
247
273
|
|
|
@@ -269,8 +295,15 @@ export const EScooterRentalTransitItinerary = makeStory({
|
|
|
269
295
|
itinerary: eScooterRentalTransiteScooterRentalItinerary
|
|
270
296
|
});
|
|
271
297
|
|
|
298
|
+
// The render of this itinerary is uninteresting, but the test
|
|
299
|
+
// is if we can parse an OTP2 itinerary without crashing
|
|
300
|
+
export const OTP2EScooterRentalTransitItinerary = makeStory({
|
|
301
|
+
itinerary: otp2ScooterItinerary
|
|
302
|
+
});
|
|
303
|
+
|
|
272
304
|
export const TncTransitItinerary = makeStory(
|
|
273
305
|
{
|
|
306
|
+
FareDetails: CustomFareDetails,
|
|
274
307
|
itinerary: tncTransitTncItinerary
|
|
275
308
|
},
|
|
276
309
|
{
|
|
@@ -278,7 +311,6 @@ export const TncTransitItinerary = makeStory(
|
|
|
278
311
|
}
|
|
279
312
|
);
|
|
280
313
|
|
|
281
|
-
const flattenedMessages = flatten(customMessages);
|
|
282
314
|
export const TncTransitItineraryWithCustomMessages = makeStory(
|
|
283
315
|
{
|
|
284
316
|
CaloriesDetails: CustomCaloriesDetails,
|
|
@@ -291,8 +323,8 @@ export const TncTransitItineraryWithCustomMessages = makeStory(
|
|
|
291
323
|
// override a subset of localized strings with custom messages.
|
|
292
324
|
reactIntl: {
|
|
293
325
|
messages: {
|
|
294
|
-
"en-US":
|
|
295
|
-
fr:
|
|
326
|
+
"en-US": flattenedEnglishMessages,
|
|
327
|
+
fr: flattenedFrenchMessages
|
|
296
328
|
}
|
|
297
329
|
},
|
|
298
330
|
useCustomFareKeyMap: true
|
|
@@ -303,12 +335,3 @@ export const TncTransitItineraryWithCustomMessages = makeStory(
|
|
|
303
335
|
export const FlexItinerary = makeStory({
|
|
304
336
|
itinerary: fareComponentsItinerary
|
|
305
337
|
});
|
|
306
|
-
|
|
307
|
-
const exampleItinerary = walkInterlinedTransitItinerary;
|
|
308
|
-
export const FareDetailsComponent = () => (
|
|
309
|
-
<FareDetails
|
|
310
|
-
transitFares={exampleItinerary.fare}
|
|
311
|
-
legs={exampleItinerary.legs}
|
|
312
|
-
layout={fareByLegLayout}
|
|
313
|
-
/>
|
|
314
|
-
);
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Leg, Money } from "@opentripplanner/types";
|
|
2
|
+
import flatten from "flat";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import styled from "styled-components";
|
|
5
|
+
import { FormattedMessage } from "react-intl";
|
|
6
|
+
import { Transfer } from "@styled-icons/boxicons-regular/Transfer";
|
|
7
|
+
|
|
8
|
+
import { boldText, renderFare } from "./utils";
|
|
9
|
+
|
|
10
|
+
import { FareLegTableProps, FareTableLayout, FareTableText } from "./types";
|
|
11
|
+
|
|
12
|
+
// Load the default messages.
|
|
13
|
+
import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
14
|
+
|
|
15
|
+
// HACK: We should flatten the messages loaded above because
|
|
16
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
17
|
+
// - the yaml loader for webpack returns a nested object,
|
|
18
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
19
|
+
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
20
|
+
|
|
21
|
+
type LegAndFare = Leg & {
|
|
22
|
+
fares: Record<string, { price: Money; isTransfer?: boolean }>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
interface FareTypeTableProps extends FareTableLayout {
|
|
26
|
+
fareTotals: Record<string, Money>;
|
|
27
|
+
legs: LegAndFare[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const TableHeader = styled.thead`
|
|
31
|
+
th {
|
|
32
|
+
font-weight: normal;
|
|
33
|
+
min-width: 5ch;
|
|
34
|
+
padding: 0.75em 1.5em;
|
|
35
|
+
text-align: center;
|
|
36
|
+
}
|
|
37
|
+
th:nth-of-type(2n + 1) {
|
|
38
|
+
background: #cccccc22;
|
|
39
|
+
}
|
|
40
|
+
th.main {
|
|
41
|
+
background: #333333;
|
|
42
|
+
color: #ffffffcc;
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
const Table = styled.table`
|
|
47
|
+
border-collapse: collapse;
|
|
48
|
+
display: block;
|
|
49
|
+
margin-bottom: 16px;
|
|
50
|
+
padding: 0;
|
|
51
|
+
|
|
52
|
+
td {
|
|
53
|
+
text-align: right;
|
|
54
|
+
}
|
|
55
|
+
td:nth-of-type(2n + 1) {
|
|
56
|
+
background: #cccccc22;
|
|
57
|
+
}
|
|
58
|
+
td.no-zebra {
|
|
59
|
+
background: none;
|
|
60
|
+
}
|
|
61
|
+
th:first-of-type {
|
|
62
|
+
height: 40px;
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
const TransferIcon = styled(Transfer)`
|
|
67
|
+
padding-left: 4px;
|
|
68
|
+
`;
|
|
69
|
+
|
|
70
|
+
const getFormattedTextForConfigKey = (textKey: FareTableText) => {
|
|
71
|
+
switch (textKey) {
|
|
72
|
+
case FareTableText.cash:
|
|
73
|
+
return (
|
|
74
|
+
<FormattedMessage
|
|
75
|
+
defaultMessage={
|
|
76
|
+
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.cash"]
|
|
77
|
+
}
|
|
78
|
+
id="otpUi.TripDetails.fareDetailsHeaders.cash"
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
case FareTableText.electronic:
|
|
82
|
+
return (
|
|
83
|
+
<FormattedMessage
|
|
84
|
+
defaultMessage={
|
|
85
|
+
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.electronic"]
|
|
86
|
+
}
|
|
87
|
+
id="otpUi.TripDetails.fareDetailsHeaders.electronic"
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
case FareTableText.youth:
|
|
91
|
+
return (
|
|
92
|
+
<FormattedMessage
|
|
93
|
+
defaultMessage={
|
|
94
|
+
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.youth"]
|
|
95
|
+
}
|
|
96
|
+
id="otpUi.TripDetails.fareDetailsHeaders.youth"
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
case FareTableText.senior:
|
|
100
|
+
return (
|
|
101
|
+
<FormattedMessage
|
|
102
|
+
defaultMessage={
|
|
103
|
+
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.senior"]
|
|
104
|
+
}
|
|
105
|
+
id="otpUi.TripDetails.fareDetailsHeaders.senior"
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
case FareTableText.special:
|
|
109
|
+
return (
|
|
110
|
+
<FormattedMessage
|
|
111
|
+
defaultMessage={
|
|
112
|
+
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.special"]
|
|
113
|
+
}
|
|
114
|
+
id="otpUi.TripDetails.fareDetailsHeaders.special"
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
case FareTableText.regular:
|
|
118
|
+
default:
|
|
119
|
+
return (
|
|
120
|
+
<FormattedMessage
|
|
121
|
+
defaultMessage={
|
|
122
|
+
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.regular"]
|
|
123
|
+
}
|
|
124
|
+
id="otpUi.TripDetails.fareDetailsHeaders.regular"
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const FareTypeTable = ({
|
|
131
|
+
cols,
|
|
132
|
+
fareTotals,
|
|
133
|
+
header,
|
|
134
|
+
legs
|
|
135
|
+
}: FareTypeTableProps): JSX.Element => {
|
|
136
|
+
const colsToRender = cols.filter(col => fareTotals[col.key]);
|
|
137
|
+
if (colsToRender.length) {
|
|
138
|
+
return (
|
|
139
|
+
<Table>
|
|
140
|
+
<TableHeader>
|
|
141
|
+
<th className="main">
|
|
142
|
+
{boldText(getFormattedTextForConfigKey(header))}
|
|
143
|
+
</th>
|
|
144
|
+
{colsToRender.map(col => {
|
|
145
|
+
const fare = fareTotals[col.key];
|
|
146
|
+
return (
|
|
147
|
+
<th key={col.key}>
|
|
148
|
+
{boldText(getFormattedTextForConfigKey(col.header))}
|
|
149
|
+
<br />
|
|
150
|
+
{renderFare(
|
|
151
|
+
fare?.currency?.currencyCode,
|
|
152
|
+
(fare?.cents || 0) / 100
|
|
153
|
+
)}
|
|
154
|
+
</th>
|
|
155
|
+
);
|
|
156
|
+
})}
|
|
157
|
+
</TableHeader>
|
|
158
|
+
{legs.map((leg, index) => (
|
|
159
|
+
<tr key={index}>
|
|
160
|
+
<td className="no-zebra">{leg.routeShortName}</td>
|
|
161
|
+
{colsToRender.map(col => {
|
|
162
|
+
const fare = leg.fares[col.key];
|
|
163
|
+
return (
|
|
164
|
+
<td key={col.key}>
|
|
165
|
+
{renderFare(
|
|
166
|
+
fare?.price.currency?.currencyCode,
|
|
167
|
+
(fare?.price.cents || 0) / 100
|
|
168
|
+
)}
|
|
169
|
+
{fare?.isTransfer && <TransferIcon size={16} />}
|
|
170
|
+
</td>
|
|
171
|
+
);
|
|
172
|
+
})}
|
|
173
|
+
</tr>
|
|
174
|
+
))}
|
|
175
|
+
</Table>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return null;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const FareLegDetails = ({
|
|
182
|
+
layout,
|
|
183
|
+
legs,
|
|
184
|
+
transitFareDetails,
|
|
185
|
+
transitFares
|
|
186
|
+
}: FareLegTableProps): JSX.Element => {
|
|
187
|
+
const fareKeys = Object.keys(transitFareDetails);
|
|
188
|
+
|
|
189
|
+
const legsWithFares = legs
|
|
190
|
+
.map((leg, index) => {
|
|
191
|
+
const fares = fareKeys.reduce((prev, key) => {
|
|
192
|
+
const fareForKey = transitFareDetails[key]?.find(
|
|
193
|
+
detail => detail.legIndex === index
|
|
194
|
+
);
|
|
195
|
+
if (fareForKey) {
|
|
196
|
+
prev[key] = fareForKey;
|
|
197
|
+
}
|
|
198
|
+
return prev;
|
|
199
|
+
}, {});
|
|
200
|
+
return {
|
|
201
|
+
...leg,
|
|
202
|
+
fares
|
|
203
|
+
};
|
|
204
|
+
})
|
|
205
|
+
.filter(leg => leg.transitLeg);
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<div>
|
|
209
|
+
{layout.map(config => (
|
|
210
|
+
<FareTypeTable
|
|
211
|
+
cols={config.cols}
|
|
212
|
+
fareTotals={transitFares}
|
|
213
|
+
header={config.header}
|
|
214
|
+
key={config.header}
|
|
215
|
+
legs={legsWithFares}
|
|
216
|
+
/>
|
|
217
|
+
))}
|
|
218
|
+
</div>
|
|
219
|
+
);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export default FareLegDetails;
|
package/src/index.tsx
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import flatten from "flat";
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
-
// @ts-ignore FIXME: Create TypeScript types for core-utils packages.
|
|
4
2
|
import coreUtils from "@opentripplanner/core-utils";
|
|
5
3
|
import { FlexBookingInfo } from "@opentripplanner/types";
|
|
6
4
|
import React, { ReactElement } from "react";
|
|
7
|
-
import { FormattedMessage
|
|
5
|
+
import { FormattedMessage } from "react-intl";
|
|
8
6
|
import { CalendarAlt } from "@styled-icons/fa-solid/CalendarAlt";
|
|
9
7
|
import { HandPaper } from "@styled-icons/fa-solid/HandPaper";
|
|
10
8
|
import { Heartbeat } from "@styled-icons/fa-solid/Heartbeat";
|
|
11
9
|
import { MoneyBillAlt } from "@styled-icons/fa-solid/MoneyBillAlt";
|
|
12
10
|
import { PhoneVolume } from "@styled-icons/fa-solid/PhoneVolume";
|
|
13
11
|
import { Route } from "@styled-icons/fa-solid/Route";
|
|
14
|
-
import { FareDetails } from "./fare-detail";
|
|
15
12
|
|
|
16
13
|
import * as S from "./styled";
|
|
17
14
|
import TripDetail from "./trip-detail";
|
|
15
|
+
import FareLegTable from "./fare-table";
|
|
16
|
+
import { boldText, renderFare } from "./utils";
|
|
18
17
|
|
|
19
18
|
import {
|
|
20
19
|
CaloriesDetailsProps,
|
|
@@ -31,35 +30,6 @@ import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
|
31
30
|
// - the yaml loader for jest returns messages with flattened ids.
|
|
32
31
|
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
33
32
|
|
|
34
|
-
/**
|
|
35
|
-
* Format text bold (used with FormattedMessage).
|
|
36
|
-
*/
|
|
37
|
-
// TODO: Find a better place for this utility.
|
|
38
|
-
function boldText(contents: ReactElement): ReactElement {
|
|
39
|
-
return <strong>{contents}</strong>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Render formatted fare.
|
|
44
|
-
* @param currencyCode The ISO currency code to use (USD, GBP, EUR).
|
|
45
|
-
* @param fare The fare value, in currency units, to be shown.
|
|
46
|
-
* @returns The formatted fare value according to the selected locale.
|
|
47
|
-
*/
|
|
48
|
-
function renderFare(currencyCode: string, fare: number): ReactElement {
|
|
49
|
-
return (
|
|
50
|
-
<FormattedNumber
|
|
51
|
-
currency={currencyCode}
|
|
52
|
-
// For dollars in locales such as 'fr',
|
|
53
|
-
// this will limit the display to just the dollar sign
|
|
54
|
-
// (otherwise it will render e.g. '2,50 $US' instead of '2,50 $').
|
|
55
|
-
currencyDisplay="narrowSymbol"
|
|
56
|
-
value={fare}
|
|
57
|
-
// eslint-disable-next-line react/style-prop-object
|
|
58
|
-
style="currency"
|
|
59
|
-
/>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
33
|
/**
|
|
64
34
|
* Helper function to specify the link to dietary table.
|
|
65
35
|
*/
|
|
@@ -148,16 +118,18 @@ const TransitFare = ({
|
|
|
148
118
|
export function TripDetails({
|
|
149
119
|
CaloriesDetails = DefaultCaloriesDetails,
|
|
150
120
|
className = "",
|
|
151
|
-
DepartureDetails = null,
|
|
152
121
|
defaultFareKey = "regular",
|
|
122
|
+
DepartureDetails = null,
|
|
123
|
+
FareDetails = null,
|
|
124
|
+
fareDetailsLayout,
|
|
153
125
|
fareKeyNameMap = {},
|
|
154
|
-
itinerary
|
|
155
|
-
fareDetailsLayout
|
|
126
|
+
itinerary
|
|
156
127
|
}: TripDetailsProps): ReactElement {
|
|
157
128
|
// process the transit fare
|
|
158
129
|
const fareResult = coreUtils.itinerary.calculateTncFares(itinerary);
|
|
159
130
|
const { maxTNCFare, minTNCFare, tncCurrencyCode } = fareResult;
|
|
160
131
|
const transitFares = itinerary?.fare?.fare;
|
|
132
|
+
const fareDetails = itinerary.fare?.details;
|
|
161
133
|
|
|
162
134
|
let companies = "";
|
|
163
135
|
itinerary.legs.forEach(leg => {
|
|
@@ -182,10 +154,7 @@ export function TripDetails({
|
|
|
182
154
|
fare = (
|
|
183
155
|
<S.Fare>
|
|
184
156
|
<TransitFareWrapper>
|
|
185
|
-
<summary
|
|
186
|
-
role="button"
|
|
187
|
-
style={{ display: fareKeys.length > 1 ? "list-item" : "" }}
|
|
188
|
-
>
|
|
157
|
+
<summary style={{ display: fareKeys.length > 1 ? "list-item" : "" }}>
|
|
189
158
|
<TransitFare
|
|
190
159
|
fareNameFallback={
|
|
191
160
|
<FormattedMessage
|
|
@@ -201,20 +170,31 @@ export function TripDetails({
|
|
|
201
170
|
transitFares={transitFares}
|
|
202
171
|
/>
|
|
203
172
|
</summary>
|
|
204
|
-
{
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
173
|
+
{fareDetailsLayout ? (
|
|
174
|
+
// Show full ƒare details by leg
|
|
175
|
+
<FareLegTable
|
|
176
|
+
layout={fareDetailsLayout}
|
|
177
|
+
legs={itinerary.legs}
|
|
178
|
+
transitFareDetails={fareDetails}
|
|
179
|
+
transitFares={transitFares}
|
|
180
|
+
/>
|
|
181
|
+
) : (
|
|
182
|
+
// Just show the fares for each payment type
|
|
183
|
+
fareKeys.map(fareKey => {
|
|
184
|
+
// Don't show the default fare twice!
|
|
185
|
+
if (fareKey === defaultFare) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
return (
|
|
189
|
+
<TransitFare
|
|
190
|
+
fareKey={fareKey}
|
|
191
|
+
key={fareKey}
|
|
192
|
+
fareKeyNameMap={fareKeyNameMap}
|
|
193
|
+
transitFares={transitFares}
|
|
194
|
+
/>
|
|
195
|
+
);
|
|
196
|
+
})
|
|
197
|
+
)}
|
|
218
198
|
</TransitFareWrapper>
|
|
219
199
|
{minTNCFare !== 0 && (
|
|
220
200
|
<S.TNCFare>
|
|
@@ -295,14 +275,12 @@ export function TripDetails({
|
|
|
295
275
|
{fare && (
|
|
296
276
|
<TripDetail
|
|
297
277
|
// Any custom description for the transit fare needs to be handled by the slot.
|
|
298
|
-
// TODO: add leg info
|
|
299
278
|
description={
|
|
300
|
-
|
|
301
|
-
Object.keys(itinerary.fare.details).length > 0 && (
|
|
279
|
+
FareDetails && (
|
|
302
280
|
<FareDetails
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
281
|
+
maxTNCFare={maxTNCFare}
|
|
282
|
+
minTNCFare={minTNCFare}
|
|
283
|
+
transitFares={transitFares}
|
|
306
284
|
/>
|
|
307
285
|
)
|
|
308
286
|
}
|