@opentripplanner/trip-details 4.0.2-alpha.2 → 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 +2 -2
- package/lib/fare-table.d.ts.map +1 -1
- package/lib/fare-table.js +43 -57
- package/lib/fare-table.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +74 -73
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +29 -27
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +0 -18
- package/lib/types.js.map +1 -1
- package/lib/utils.d.ts +1 -3
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +0 -57
- package/lib/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/TripDetails.story.tsx +37 -88
- package/src/fare-table.tsx +57 -85
- package/src/index.tsx +94 -90
- package/src/types.ts +29 -29
- package/src/utils.tsx +2 -73
- package/tsconfig.tsbuildinfo +1 -1
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
|
|
|
143
|
-
|
|
117
|
+
let fare;
|
|
118
|
+
if (fareTypes.length > 0) {
|
|
119
|
+
const defaultFareTotal = getItineraryCost(
|
|
120
|
+
itinerary.legs,
|
|
121
|
+
defaultFareType.riderCategoryId,
|
|
122
|
+
defaultFareType.mediumId
|
|
123
|
+
);
|
|
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
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Prettier does not recognize the import type syntax.
|
|
2
2
|
// eslint-disable-next-line prettier/prettier
|
|
3
|
-
import type { MassUnitOption,
|
|
3
|
+
import type { MassUnitOption, Itinerary, Money, Leg } from "@opentripplanner/types";
|
|
4
4
|
import type { ReactElement } from "react";
|
|
5
5
|
|
|
6
6
|
export interface TimeActiveDetailsProps {
|
|
@@ -19,48 +19,48 @@ export interface DepartureDetailsProps {
|
|
|
19
19
|
departureDate: Date;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
senior = "senior",
|
|
26
|
-
special = "special",
|
|
27
|
-
cash = "cash",
|
|
28
|
-
electronic = "electronic"
|
|
22
|
+
export interface FareType {
|
|
23
|
+
riderCategoryId: string;
|
|
24
|
+
mediumId: string;
|
|
29
25
|
}
|
|
30
26
|
|
|
27
|
+
/**
|
|
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,
|
|
30
|
+
* with each row being an individual transit leg from the itinerary.
|
|
31
|
+
*/
|
|
31
32
|
export interface FareTableLayout {
|
|
32
|
-
cols: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
fareContainer?: string;
|
|
37
|
-
}[];
|
|
38
|
-
header: FareTableText;
|
|
33
|
+
cols: (FareType & {
|
|
34
|
+
columnHeaderKey: string;
|
|
35
|
+
})[]
|
|
36
|
+
headerKey: string;
|
|
39
37
|
}
|
|
40
|
-
export interface TransitFareData {
|
|
41
|
-
[key: string]: Money
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface FareDetailsProps {
|
|
45
|
-
maxTNCFare: number;
|
|
46
|
-
minTNCFare: number;
|
|
47
|
-
transitFares: TransitFareData;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
38
|
export interface FareLegTableProps {
|
|
51
39
|
layout?: FareTableLayout[];
|
|
52
|
-
|
|
40
|
+
legs: Leg[];
|
|
53
41
|
}
|
|
54
42
|
|
|
43
|
+
// Total fare amount corresponding to a fare key
|
|
44
|
+
export type FareTotals = (FareType & { price: Money })[]
|
|
45
|
+
|
|
55
46
|
export interface TransitFareProps {
|
|
56
|
-
|
|
47
|
+
headerKey: string;
|
|
48
|
+
fareMediumId: string
|
|
49
|
+
riderCategoryId: string
|
|
57
50
|
fareNameFallback?: ReactElement;
|
|
58
51
|
fareKeyNameMap: {
|
|
59
52
|
[key: string]: string;
|
|
60
53
|
};
|
|
61
|
-
|
|
54
|
+
fareTotals: FareTotals;
|
|
62
55
|
}
|
|
63
56
|
|
|
57
|
+
export interface FareDetailsProps {
|
|
58
|
+
maxTNCFare: number;
|
|
59
|
+
minTNCFare: number;
|
|
60
|
+
legs: Leg[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
64
|
export interface TripDetailsProps {
|
|
65
65
|
/**
|
|
66
66
|
* Used for additional styling with styled components for example.
|
|
@@ -73,7 +73,7 @@ export interface TripDetailsProps {
|
|
|
73
73
|
/**
|
|
74
74
|
* Determines which transit fare should be displayed by default, should there be multiple transit fare types.
|
|
75
75
|
*/
|
|
76
|
-
|
|
76
|
+
defaultFareType?: { headerKey: string } & FareType;
|
|
77
77
|
/**
|
|
78
78
|
* Slot for a custom component to render the expandable section for departure.
|
|
79
79
|
*/
|
package/src/utils.tsx
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import React, { ReactElement } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { flatten } from "flat";
|
|
4
|
-
import { FareTableText } from "./types";
|
|
5
|
-
|
|
6
|
-
// Load the default messages.
|
|
7
|
-
import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
8
|
-
|
|
9
|
-
// HACK: We should flatten the messages loaded above because
|
|
10
|
-
// the YAML loaders behave differently between webpack and our version of jest:
|
|
11
|
-
// - the yaml loader for webpack returns a nested object,
|
|
12
|
-
// - the yaml loader for jest returns messages with flattened ids.
|
|
13
|
-
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
2
|
+
import { FormattedNumber } from "react-intl";
|
|
14
3
|
|
|
15
4
|
/**
|
|
16
5
|
* Format text bold (used with FormattedMessage).
|
|
17
6
|
*/
|
|
18
|
-
export function boldText(contents: ReactElement): ReactElement {
|
|
7
|
+
export function boldText(contents: ReactElement | string): ReactElement {
|
|
19
8
|
return <strong>{contents}</strong>;
|
|
20
9
|
}
|
|
21
10
|
|
|
@@ -39,63 +28,3 @@ export function renderFare(currencyCode: string, fare: number): ReactElement {
|
|
|
39
28
|
/>
|
|
40
29
|
);
|
|
41
30
|
}
|
|
42
|
-
|
|
43
|
-
export const getFormattedTextForConfigKey = (textKey: FareTableText) => {
|
|
44
|
-
switch (textKey) {
|
|
45
|
-
case FareTableText.cash:
|
|
46
|
-
return (
|
|
47
|
-
<FormattedMessage
|
|
48
|
-
defaultMessage={
|
|
49
|
-
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.cash"]
|
|
50
|
-
}
|
|
51
|
-
id="otpUi.TripDetails.fareDetailsHeaders.cash"
|
|
52
|
-
/>
|
|
53
|
-
);
|
|
54
|
-
case FareTableText.electronic:
|
|
55
|
-
return (
|
|
56
|
-
<FormattedMessage
|
|
57
|
-
defaultMessage={
|
|
58
|
-
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.electronic"]
|
|
59
|
-
}
|
|
60
|
-
id="otpUi.TripDetails.fareDetailsHeaders.electronic"
|
|
61
|
-
/>
|
|
62
|
-
);
|
|
63
|
-
case FareTableText.youth:
|
|
64
|
-
return (
|
|
65
|
-
<FormattedMessage
|
|
66
|
-
defaultMessage={
|
|
67
|
-
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.youth"]
|
|
68
|
-
}
|
|
69
|
-
id="otpUi.TripDetails.fareDetailsHeaders.youth"
|
|
70
|
-
/>
|
|
71
|
-
);
|
|
72
|
-
case FareTableText.senior:
|
|
73
|
-
return (
|
|
74
|
-
<FormattedMessage
|
|
75
|
-
defaultMessage={
|
|
76
|
-
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.senior"]
|
|
77
|
-
}
|
|
78
|
-
id="otpUi.TripDetails.fareDetailsHeaders.senior"
|
|
79
|
-
/>
|
|
80
|
-
);
|
|
81
|
-
case FareTableText.special:
|
|
82
|
-
return (
|
|
83
|
-
<FormattedMessage
|
|
84
|
-
defaultMessage={
|
|
85
|
-
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.special"]
|
|
86
|
-
}
|
|
87
|
-
id="otpUi.TripDetails.fareDetailsHeaders.special"
|
|
88
|
-
/>
|
|
89
|
-
);
|
|
90
|
-
case FareTableText.regular:
|
|
91
|
-
default:
|
|
92
|
-
return (
|
|
93
|
-
<FormattedMessage
|
|
94
|
-
defaultMessage={
|
|
95
|
-
defaultMessages["otpUi.TripDetails.fareDetailsHeaders.regular"]
|
|
96
|
-
}
|
|
97
|
-
id="otpUi.TripDetails.fareDetailsHeaders.regular"
|
|
98
|
-
/>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
};
|