@opentripplanner/trip-details 4.0.2-alpha.2 → 5.0.0-alpha.2
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 +48 -65
- package/esm/fare-table.js.map +1 -1
- package/esm/index.js +86 -90
- 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 +44 -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 +71 -74
- 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 +51 -88
- package/src/fare-table.tsx +56 -87
- package/src/index.tsx +89 -91
- 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,72 @@ 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.mediumId, col.riderCategoryId))
|
|
88
|
+
.map(col => ({
|
|
89
|
+
...col,
|
|
90
|
+
total: getItineraryCost(legs, col.riderCategoryId, col.mediumId)
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
const headerString = useGetHeaderString(headerKey);
|
|
90
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
|
-
{renderFare(
|
|
110
|
-
fare?.currency?.currencyCode,
|
|
111
|
-
(fare?.cents || 0) / 100
|
|
112
|
-
)}
|
|
115
|
+
{renderFare(fare?.currency?.code, fare?.amount || 0)}
|
|
113
116
|
</th>
|
|
114
117
|
);
|
|
115
118
|
})}
|
|
116
119
|
</TableHeader>
|
|
117
|
-
{
|
|
120
|
+
{filteredLegs.map((leg, index) => (
|
|
118
121
|
<tr key={index}>
|
|
119
122
|
<td className="no-zebra">
|
|
120
|
-
{leg.routeShortName || leg.
|
|
123
|
+
{leg.routeShortName || leg.routeLongName}
|
|
121
124
|
</td>
|
|
122
125
|
{colsToRender.map(col => {
|
|
123
|
-
const fare =
|
|
124
|
-
|
|
125
|
-
: leg.fares[col.key];
|
|
126
|
+
const fare = getLegCost(leg, col.mediumId, col.riderCategoryId);
|
|
127
|
+
console.log(fare);
|
|
126
128
|
|
|
127
129
|
return (
|
|
128
130
|
<td
|
|
129
|
-
key={col.
|
|
131
|
+
key={col.columnHeaderKey}
|
|
130
132
|
title={
|
|
131
133
|
"transferAmount" in fare &&
|
|
132
|
-
fare?.transferAmount &&
|
|
134
|
+
fare?.transferAmount?.amount > 0 &&
|
|
133
135
|
intl.formatMessage(
|
|
134
136
|
{
|
|
135
137
|
defaultMessage:
|
|
@@ -142,9 +144,9 @@ const FareTypeTable = ({
|
|
|
142
144
|
},
|
|
143
145
|
{
|
|
144
146
|
transferAmount: intl.formatNumber(
|
|
145
|
-
fare
|
|
147
|
+
fare?.transferAmount?.amount,
|
|
146
148
|
{
|
|
147
|
-
currency: fare?.price?.currency?.
|
|
149
|
+
currency: fare?.price?.currency?.code,
|
|
148
150
|
currencyDisplay: "narrowSymbol",
|
|
149
151
|
style: "currency"
|
|
150
152
|
}
|
|
@@ -153,15 +155,15 @@ const FareTypeTable = ({
|
|
|
153
155
|
)
|
|
154
156
|
}
|
|
155
157
|
>
|
|
156
|
-
{
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
{"transferAmount" in fare &&
|
|
159
|
+
fare?.transferAmount?.amount > 0 && (
|
|
160
|
+
<>
|
|
161
|
+
<TransferIcon size={16} />{" "}
|
|
162
|
+
</>
|
|
163
|
+
)}
|
|
162
164
|
{renderFare(
|
|
163
|
-
fare?.price?.currency?.
|
|
164
|
-
|
|
165
|
+
fare?.price?.currency?.code,
|
|
166
|
+
fare?.price?.amount || 0
|
|
165
167
|
)}
|
|
166
168
|
</td>
|
|
167
169
|
);
|
|
@@ -174,53 +176,20 @@ const FareTypeTable = ({
|
|
|
174
176
|
return null;
|
|
175
177
|
};
|
|
176
178
|
|
|
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
|
-
|
|
179
|
+
const FareLegTable = ({ layout, legs }: FareLegTableProps): JSX.Element => {
|
|
180
|
+
// the layout argument contains an object for every table to be displayed
|
|
210
181
|
return (
|
|
211
182
|
<div>
|
|
212
183
|
{layout.map(config => (
|
|
213
184
|
<FareTypeTable
|
|
214
185
|
cols={config.cols}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
legs={legsWithFares}
|
|
219
|
-
hasLegProducts={hasLegProducts}
|
|
186
|
+
headerKey={config.headerKey}
|
|
187
|
+
key={config.headerKey}
|
|
188
|
+
legs={legs}
|
|
220
189
|
/>
|
|
221
190
|
))}
|
|
222
191
|
</div>
|
|
223
192
|
);
|
|
224
193
|
};
|
|
225
194
|
|
|
226
|
-
export default
|
|
195
|
+
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,13 @@ 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,
|
|
114
70
|
DepartureDetails = null,
|
|
115
71
|
displayTimeActive = true,
|
|
116
72
|
FareDetails = null,
|
|
@@ -122,63 +78,105 @@ export function TripDetails({
|
|
|
122
78
|
// process the transit fare
|
|
123
79
|
const fareResult = coreUtils.itinerary.calculateTncFares(itinerary);
|
|
124
80
|
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
81
|
|
|
137
|
-
if
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
82
|
+
// Depending on if there are additional fares to display either render a <span> or a <details>.
|
|
83
|
+
const { companies, fareTypes } = itinerary.legs.reduce<{
|
|
84
|
+
companies: string;
|
|
85
|
+
fareTypes: FareType[];
|
|
86
|
+
}>(
|
|
87
|
+
(prev, leg) => {
|
|
88
|
+
if (leg.rideHailingEstimate) {
|
|
89
|
+
prev.companies = leg.rideHailingEstimate.provider.id;
|
|
90
|
+
}
|
|
91
|
+
if (leg.fareProducts) {
|
|
92
|
+
leg.fareProducts.forEach(fp => {
|
|
93
|
+
const mediumId = fp.product.medium.id;
|
|
94
|
+
const riderCategoryId = fp.product.riderCategory.id;
|
|
95
|
+
if (
|
|
96
|
+
!prev.fareTypes.find(
|
|
97
|
+
ft =>
|
|
98
|
+
ft.mediumId === mediumId &&
|
|
99
|
+
ft.riderCategoryId === riderCategoryId
|
|
100
|
+
)
|
|
101
|
+
) {
|
|
102
|
+
prev.fareTypes.push({ mediumId, riderCategoryId });
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return prev;
|
|
107
|
+
},
|
|
108
|
+
{ companies: "", fareTypes: [] }
|
|
109
|
+
);
|
|
142
110
|
|
|
143
|
-
|
|
111
|
+
let fare;
|
|
112
|
+
if (fareTypes.length > 0 && defaultFareType) {
|
|
113
|
+
const defaultFareTotal = getItineraryCost(
|
|
114
|
+
itinerary.legs,
|
|
115
|
+
defaultFareType.mediumId,
|
|
116
|
+
defaultFareType.riderCategoryId
|
|
117
|
+
);
|
|
118
|
+
// Depending on if there are additional fares to display either render a <span> or a <details>
|
|
144
119
|
const TransitFareWrapper =
|
|
145
|
-
|
|
120
|
+
fareTypes.length > 1 ? S.TransitFare : S.TransitFareSingle;
|
|
146
121
|
|
|
147
|
-
|
|
122
|
+
const fareNameFallback = (
|
|
123
|
+
<FormattedMessage
|
|
124
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.transitFare"]}
|
|
125
|
+
description="Text showing the price of tickets on public transportation."
|
|
126
|
+
id="otpUi.TripDetails.transitFare"
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
fare = defaultFareTotal.amount && (
|
|
148
131
|
<S.Fare>
|
|
149
132
|
<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
|
-
/>
|
|
133
|
+
<summary style={{ display: fareTypes.length > 1 ? "list-item" : "" }}>
|
|
134
|
+
<FormattedMessage
|
|
135
|
+
defaultMessage={
|
|
136
|
+
defaultMessages["otpUi.TripDetails.transitFareEntry"]
|
|
160
137
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
138
|
+
description="Text showing the price of tickets on public transportation."
|
|
139
|
+
id="otpUi.TripDetails.transitFareEntry"
|
|
140
|
+
values={{
|
|
141
|
+
name:
|
|
142
|
+
fareKeyNameMap[defaultFareType.headerKey] || fareNameFallback,
|
|
143
|
+
strong: boldText,
|
|
144
|
+
value: renderFare(
|
|
145
|
+
defaultFareTotal.currency?.code || "USD",
|
|
146
|
+
defaultFareTotal?.amount / defaultFareTotal?.currency?.digits
|
|
147
|
+
)
|
|
148
|
+
}}
|
|
164
149
|
/>
|
|
165
150
|
</summary>
|
|
166
151
|
{fareDetailsLayout ? (
|
|
167
152
|
// Show full ƒare details by leg
|
|
168
|
-
<FareLegTable layout={fareDetailsLayout}
|
|
153
|
+
<FareLegTable layout={fareDetailsLayout} legs={itinerary.legs} />
|
|
169
154
|
) : (
|
|
170
155
|
// Just show the fares for each payment type
|
|
171
|
-
|
|
156
|
+
fareTypes.map(fareType => {
|
|
172
157
|
// Don't show the default fare twice!
|
|
173
|
-
if (
|
|
158
|
+
if (fareType) {
|
|
174
159
|
return null;
|
|
175
160
|
}
|
|
176
161
|
return (
|
|
177
|
-
<
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
162
|
+
<FormattedMessage
|
|
163
|
+
key={Object.values(fareType).join("-")}
|
|
164
|
+
defaultMessage={
|
|
165
|
+
defaultMessages["otpUi.TripDetails.transitFareEntry"]
|
|
166
|
+
}
|
|
167
|
+
description="Text showing the price of tickets on public transportation."
|
|
168
|
+
id="otpUi.TripDetails.transitFareEntry"
|
|
169
|
+
values={{
|
|
170
|
+
name:
|
|
171
|
+
fareKeyNameMap[defaultFareType.headerKey] ||
|
|
172
|
+
fareNameFallback,
|
|
173
|
+
strong: boldText,
|
|
174
|
+
value: renderFare(
|
|
175
|
+
defaultFareTotal.currency?.code || "USD",
|
|
176
|
+
defaultFareTotal?.amount /
|
|
177
|
+
defaultFareTotal?.currency?.digits
|
|
178
|
+
)
|
|
179
|
+
}}
|
|
182
180
|
/>
|
|
183
181
|
);
|
|
184
182
|
})
|
|
@@ -280,7 +278,7 @@ export function TripDetails({
|
|
|
280
278
|
</S.Timing>
|
|
281
279
|
}
|
|
282
280
|
/>
|
|
283
|
-
{fare && (
|
|
281
|
+
{!!fare && (
|
|
284
282
|
<TripDetail
|
|
285
283
|
// Any custom description for the transit fare needs to be handled by the slot.
|
|
286
284
|
description={
|
|
@@ -288,7 +286,7 @@ export function TripDetails({
|
|
|
288
286
|
<FareDetails
|
|
289
287
|
maxTNCFare={maxTNCFare}
|
|
290
288
|
minTNCFare={minTNCFare}
|
|
291
|
-
|
|
289
|
+
legs={itinerary.legs}
|
|
292
290
|
/>
|
|
293
291
|
)
|
|
294
292
|
}
|
|
@@ -304,7 +302,7 @@ export function TripDetails({
|
|
|
304
302
|
<FareDetails
|
|
305
303
|
maxTNCFare={maxTNCFare}
|
|
306
304
|
minTNCFare={minTNCFare}
|
|
307
|
-
|
|
305
|
+
legs={itinerary.legs}
|
|
308
306
|
/>
|
|
309
307
|
)
|
|
310
308
|
}
|
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
|
-
};
|