@opentripplanner/trip-details 8.0.1 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/components/fares-v2-table.js +194 -0
- package/esm/components/fares-v2-table.js.map +1 -0
- package/esm/components/fares.js +28 -58
- package/esm/components/fares.js.map +1 -1
- package/esm/index.js +5 -5
- package/esm/index.js.map +1 -1
- package/esm/styled.js +29 -22
- package/esm/styled.js.map +1 -1
- package/esm/trip-detail.js +1 -8
- package/esm/trip-detail.js.map +1 -1
- package/esm/types.js.map +1 -1
- package/i18n/en-US.yml +2 -7
- package/i18n/es.yml +0 -7
- package/i18n/fr.yml +2 -7
- package/i18n/ko.yml +2 -9
- package/i18n/nb_NO.yml +1 -4
- package/i18n/pl.yml +24 -19
- package/i18n/ru.yml +3 -10
- package/i18n/ta.yml +20 -25
- package/i18n/tl.yml +2 -9
- package/i18n/tr.yml +0 -7
- package/i18n/vi.yml +2 -9
- package/i18n/zh_Hans.yml +2 -9
- package/i18n/zh_Hant.yml +0 -7
- package/lib/components/departure-date.js +45 -42
- package/lib/components/departure-date.js.map +1 -1
- package/lib/components/emissions.js +57 -64
- package/lib/components/emissions.js.map +1 -1
- package/lib/components/fares-v2-table.d.ts +9 -0
- package/lib/components/fares-v2-table.d.ts.map +1 -0
- package/lib/components/fares-v2-table.js +158 -0
- package/lib/components/fares-v2-table.js.map +1 -0
- package/lib/components/fares.d.ts +4 -4
- package/lib/components/fares.d.ts.map +1 -1
- package/lib/components/fares.js +87 -151
- package/lib/components/fares.js.map +1 -1
- package/lib/components/flex-booking-info.js +55 -38
- package/lib/components/flex-booking-info.js.map +1 -1
- package/lib/components/time-active.js +40 -66
- package/lib/components/time-active.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +53 -66
- package/lib/index.js.map +1 -1
- package/lib/styled.d.ts +1 -0
- package/lib/styled.d.ts.map +1 -1
- package/lib/styled.js +120 -86
- package/lib/styled.js.map +1 -1
- package/lib/trip-detail.d.ts.map +1 -1
- package/lib/trip-detail.js +65 -71
- package/lib/trip-detail.js.map +1 -1
- package/lib/types.d.ts +4 -40
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +1 -4
- package/lib/types.js.map +1 -1
- package/lib/utils.js +17 -23
- package/lib/utils.js.map +1 -1
- package/package.json +3 -5
- package/src/TripDetails.story.tsx +47 -158
- package/src/__snapshots__/TripDetails.story.tsx.snap +1726 -924
- package/src/components/fares-v2-table.tsx +262 -0
- package/src/components/fares.tsx +48 -85
- package/src/index.tsx +5 -4
- package/src/styled.ts +11 -2
- package/src/trip-detail.tsx +1 -10
- package/src/types.ts +4 -39
- package/tsconfig.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/__mocks__/custom-english-messages.yml +0 -14
- package/__mocks__/custom-french-messages.yml +0 -9
- package/esm/components/fare-table.js +0 -122
- package/esm/components/fare-table.js.map +0 -1
- package/i18n/i18n-exceptions.json +0 -12
- package/lib/components/fare-table.d.ts +0 -5
- package/lib/components/fare-table.d.ts.map +0 -1
- package/lib/components/fare-table.js +0 -118
- package/lib/components/fare-table.js.map +0 -1
- package/src/components/fare-table.tsx +0 -215
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/* eslint-disable no-underscore-dangle */
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Leg } from "@opentripplanner/types";
|
|
4
|
+
import coreUtils from "@opentripplanner/core-utils";
|
|
5
|
+
import { FormattedMessage, useIntl } from "react-intl";
|
|
6
|
+
import styled from "styled-components";
|
|
7
|
+
import { Transfer } from "@styled-icons/boxicons-regular/Transfer";
|
|
8
|
+
|
|
9
|
+
import { renderFare } from "../utils";
|
|
10
|
+
import { InvisibleA11yCaption, InvisibleA11yLabel } from "../styled";
|
|
11
|
+
|
|
12
|
+
// TODO: inline this import? (@opentripplanner/core-utils/src/itinerary)
|
|
13
|
+
const {
|
|
14
|
+
getLegCost,
|
|
15
|
+
getItineraryCost,
|
|
16
|
+
descope,
|
|
17
|
+
getLegRouteName
|
|
18
|
+
} = coreUtils.itinerary;
|
|
19
|
+
|
|
20
|
+
const FailDash = (
|
|
21
|
+
<>
|
|
22
|
+
-
|
|
23
|
+
<InvisibleA11yLabel>
|
|
24
|
+
<FormattedMessage id="otpUi.TripDetails.legMissingFareInfo" />
|
|
25
|
+
</InvisibleA11yLabel>
|
|
26
|
+
</>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const TransferIcon = styled(Transfer)`
|
|
30
|
+
padding-right: 0.25ch;
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
const StripedTable = styled.table`
|
|
34
|
+
text-align: right;
|
|
35
|
+
|
|
36
|
+
tr td,
|
|
37
|
+
tr th {
|
|
38
|
+
padding: 4px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
tr td:nth-of-type(2n + 1),
|
|
42
|
+
tr th:nth-of-type(2n) {
|
|
43
|
+
background: #cccccc55;
|
|
44
|
+
border-color: #cccccc55;
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
type IdNamePair = { id: string; name: string };
|
|
49
|
+
|
|
50
|
+
// Removes duplicates
|
|
51
|
+
const categoryReducer = (acc: IdNamePair[], cur: IdNamePair) => {
|
|
52
|
+
if (!acc.some(m => descope(m?.id) === descope(cur?.id))) {
|
|
53
|
+
acc.push(cur);
|
|
54
|
+
}
|
|
55
|
+
return acc;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Put the preferred medium first, and then all the others alphabetical
|
|
59
|
+
const categorySorter = (favoriteId?: string) => (
|
|
60
|
+
a: IdNamePair,
|
|
61
|
+
b: IdNamePair
|
|
62
|
+
): number => {
|
|
63
|
+
const aId = descope(a?.id);
|
|
64
|
+
const bId = descope(b?.id);
|
|
65
|
+
|
|
66
|
+
if (favoriteId && aId === favoriteId) {
|
|
67
|
+
return -1;
|
|
68
|
+
}
|
|
69
|
+
if (favoriteId && bId === favoriteId) {
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return aId > bId ? 1 : -1;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// TODO: This component currently can only show one type of fare per medium
|
|
77
|
+
const FaresV2Table = ({
|
|
78
|
+
legs,
|
|
79
|
+
favoriteMediumId,
|
|
80
|
+
favoriteRiderCategoryId
|
|
81
|
+
}: {
|
|
82
|
+
legs: Leg[];
|
|
83
|
+
favoriteMediumId?: string;
|
|
84
|
+
favoriteRiderCategoryId?: string;
|
|
85
|
+
}): JSX.Element => {
|
|
86
|
+
const intl = useIntl();
|
|
87
|
+
|
|
88
|
+
const transitLegs = legs.filter(leg => leg.transitLeg);
|
|
89
|
+
|
|
90
|
+
// Get all fare products across all legs
|
|
91
|
+
const fareProducts = transitLegs.flatMap(leg => leg.fareProducts);
|
|
92
|
+
|
|
93
|
+
// Reduce these into mediums and riders
|
|
94
|
+
const mediums = fareProducts
|
|
95
|
+
.map(fp => fp.product?.medium)
|
|
96
|
+
.filter(m => m !== null)
|
|
97
|
+
.reduce(categoryReducer, [])
|
|
98
|
+
.sort(categorySorter(favoriteMediumId));
|
|
99
|
+
const riders = fareProducts
|
|
100
|
+
.map(fp => fp.product?.riderCategory)
|
|
101
|
+
.filter(r => r !== null)
|
|
102
|
+
.reduce(categoryReducer, [])
|
|
103
|
+
.sort(categorySorter(favoriteRiderCategoryId));
|
|
104
|
+
|
|
105
|
+
// Ensure we have at least one rider/medium
|
|
106
|
+
if (riders.length === 0) {
|
|
107
|
+
riders.push({ name: "Fare", id: null });
|
|
108
|
+
}
|
|
109
|
+
if (mediums.length === 0) {
|
|
110
|
+
mediums.push({ name: "Regular", id: null });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Keep track of seen fare ids to indicate transfers
|
|
114
|
+
const productUseIds: Set<string> = new Set();
|
|
115
|
+
|
|
116
|
+
const rows = [
|
|
117
|
+
[
|
|
118
|
+
<th key="faretitle" style={{ textAlign: "left" }}>
|
|
119
|
+
<InvisibleA11yLabel>
|
|
120
|
+
<FormattedMessage id="otpUi.TripDetails.transitFare" />
|
|
121
|
+
</InvisibleA11yLabel>
|
|
122
|
+
</th>,
|
|
123
|
+
...transitLegs.map(leg => (
|
|
124
|
+
<th key={leg.tripId}>{getLegRouteName(leg)}</th>
|
|
125
|
+
)),
|
|
126
|
+
transitLegs.length > 1 ? (
|
|
127
|
+
<th key="total" style={{ textAlign: "right" }}>
|
|
128
|
+
<em>
|
|
129
|
+
<FormattedMessage id="otpUi.TripDetails.total" />
|
|
130
|
+
</em>
|
|
131
|
+
</th>
|
|
132
|
+
) : (
|
|
133
|
+
<></>
|
|
134
|
+
)
|
|
135
|
+
]
|
|
136
|
+
];
|
|
137
|
+
|
|
138
|
+
// non-transit legs don't have fares
|
|
139
|
+
transitLegs.forEach((leg, index) => {
|
|
140
|
+
mediums.forEach((medium, mediumIndex) => {
|
|
141
|
+
riders.forEach((rider, riderIndex) => {
|
|
142
|
+
if (!medium || !rider) return;
|
|
143
|
+
const {
|
|
144
|
+
alternateFareProducts,
|
|
145
|
+
isDependent,
|
|
146
|
+
appliedFareProduct,
|
|
147
|
+
productUseId
|
|
148
|
+
} = getLegCost(
|
|
149
|
+
leg,
|
|
150
|
+
descope(medium.id) || null,
|
|
151
|
+
descope(rider.id) || null,
|
|
152
|
+
Array.from(productUseIds)
|
|
153
|
+
);
|
|
154
|
+
const legPrice = appliedFareProduct?.legPrice;
|
|
155
|
+
|
|
156
|
+
productUseIds.add(productUseId);
|
|
157
|
+
|
|
158
|
+
// Only consider alternateFareProducts if current product is dependent
|
|
159
|
+
const dependentAlternateFareProducts =
|
|
160
|
+
isDependent && alternateFareProducts;
|
|
161
|
+
|
|
162
|
+
// Calculate pre-tranfer amount either via alternate fare or fare-id matching (price.originalAmount)
|
|
163
|
+
const originalAmount =
|
|
164
|
+
dependentAlternateFareProducts?.[0]?.price.amount -
|
|
165
|
+
legPrice?.amount ||
|
|
166
|
+
appliedFareProduct?.price.amount - legPrice?.amount;
|
|
167
|
+
|
|
168
|
+
const newCell = (
|
|
169
|
+
<>
|
|
170
|
+
{/* Only render the list of fare types once */}
|
|
171
|
+
{index === 0 && (
|
|
172
|
+
<th style={{ textAlign: "left" }}>
|
|
173
|
+
<FormattedMessage
|
|
174
|
+
id={`config.fares.media.${descope(medium.id)}`}
|
|
175
|
+
defaultMessage={medium.name}
|
|
176
|
+
/>{" "}
|
|
177
|
+
<FormattedMessage
|
|
178
|
+
id={`config.fares.riderCategory.${descope(rider.id)}`}
|
|
179
|
+
defaultMessage={rider.name}
|
|
180
|
+
/>
|
|
181
|
+
</th>
|
|
182
|
+
)}
|
|
183
|
+
<td
|
|
184
|
+
style={{ textAlign: legPrice ? "right" : "center" }}
|
|
185
|
+
title={
|
|
186
|
+
!Number.isNaN(originalAmount) &&
|
|
187
|
+
originalAmount > 0 &&
|
|
188
|
+
index > 0 &&
|
|
189
|
+
intl.formatMessage(
|
|
190
|
+
{
|
|
191
|
+
description:
|
|
192
|
+
"Text explaining the transfer discount applied to this fare.",
|
|
193
|
+
id: "otpUi.TripDetails.transferDiscountExplanation"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
transferAmount: intl.formatNumber(originalAmount, {
|
|
197
|
+
currency: legPrice?.currency?.code,
|
|
198
|
+
currencyDisplay: "narrowSymbol",
|
|
199
|
+
style: "currency"
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
>
|
|
205
|
+
{!Number.isNaN(originalAmount) &&
|
|
206
|
+
originalAmount > 0 &&
|
|
207
|
+
index > 0 && <TransferIcon size={16} />}
|
|
208
|
+
{/* Leg Price will always be defined if the fare product has a price */}
|
|
209
|
+
{legPrice
|
|
210
|
+
? renderFare(legPrice?.currency?.code, legPrice?.amount)
|
|
211
|
+
: FailDash}
|
|
212
|
+
</td>
|
|
213
|
+
</>
|
|
214
|
+
);
|
|
215
|
+
const currentRowIndex = 1 + riderIndex + riders.length * mediumIndex;
|
|
216
|
+
if (!rows[currentRowIndex]) {
|
|
217
|
+
rows[currentRowIndex] = [];
|
|
218
|
+
}
|
|
219
|
+
rows[currentRowIndex].push(newCell);
|
|
220
|
+
|
|
221
|
+
// Generate final column
|
|
222
|
+
if (index === transitLegs.length - 1 && transitLegs.length > 1) {
|
|
223
|
+
const fare = getItineraryCost(
|
|
224
|
+
legs,
|
|
225
|
+
descope(medium.id) || null,
|
|
226
|
+
descope(rider.id) || null
|
|
227
|
+
);
|
|
228
|
+
rows[currentRowIndex].push(
|
|
229
|
+
<td
|
|
230
|
+
style={{ textAlign: fare?.amount ? "right" : "center" }}
|
|
231
|
+
title={
|
|
232
|
+
!fare?.amount &&
|
|
233
|
+
intl.formatMessage({
|
|
234
|
+
id: "otpUi.TripDetails.missingFareTotal"
|
|
235
|
+
})
|
|
236
|
+
}
|
|
237
|
+
>
|
|
238
|
+
<em>
|
|
239
|
+
{fare?.amount
|
|
240
|
+
? renderFare(fare?.currency.code, fare?.amount)
|
|
241
|
+
: FailDash}
|
|
242
|
+
</em>
|
|
243
|
+
</td>
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<StripedTable>
|
|
252
|
+
<InvisibleA11yCaption>
|
|
253
|
+
<FormattedMessage id="otpUi.TripDetails.transitFareTable" />
|
|
254
|
+
</InvisibleA11yCaption>
|
|
255
|
+
{rows.map((r, index) => (
|
|
256
|
+
<tr key={index}>{r}</tr>
|
|
257
|
+
))}
|
|
258
|
+
</StripedTable>
|
|
259
|
+
);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
export default FaresV2Table;
|
package/src/components/fares.tsx
CHANGED
|
@@ -1,40 +1,39 @@
|
|
|
1
1
|
import React, { ReactElement } from "react";
|
|
2
2
|
import { FormattedMessage } from "react-intl";
|
|
3
|
-
import flatten from "flat";
|
|
4
3
|
import coreUtils from "@opentripplanner/core-utils";
|
|
5
4
|
import { FareProductSelector, Itinerary } from "@opentripplanner/types";
|
|
6
5
|
import { MoneyBillAlt } from "@styled-icons/fa-solid";
|
|
6
|
+
import { flatten } from "flat";
|
|
7
7
|
import * as S from "../styled";
|
|
8
8
|
import { boldText, renderFare } from "../utils";
|
|
9
9
|
import TripDetail from "../trip-detail";
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
10
|
+
import { FareDetailsProps } from "../types";
|
|
11
|
+
import FaresV2Table from "./fares-v2-table";
|
|
12
12
|
|
|
13
13
|
// Load the default messages.
|
|
14
14
|
import defaultEnglishMessages from "../../i18n/en-US.yml";
|
|
15
15
|
|
|
16
|
+
export interface FaresProps {
|
|
17
|
+
itinerary: Itinerary;
|
|
18
|
+
FareDetails?: React.ElementType<FareDetailsProps>;
|
|
19
|
+
defaultFareType?: FareProductSelector;
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
// HACK: We should flatten the messages loaded above because
|
|
17
23
|
// the YAML loaders behave differently between webpack and our version of jest:
|
|
18
24
|
// - the yaml loader for webpack returns a nested object,
|
|
19
25
|
// - the yaml loader for jest returns messages with flattened ids.
|
|
20
26
|
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
21
27
|
|
|
22
|
-
export interface FaresProps {
|
|
23
|
-
itinerary: Itinerary;
|
|
24
|
-
FareDetails?: React.ElementType<FareDetailsProps>;
|
|
25
|
-
fareConfig?: FareConfig;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
28
|
export default function Fares({
|
|
29
29
|
itinerary,
|
|
30
30
|
FareDetails,
|
|
31
|
-
|
|
31
|
+
defaultFareType
|
|
32
32
|
}: FaresProps): ReactElement | null {
|
|
33
|
+
// process the transit fare
|
|
33
34
|
const fareResult = coreUtils.itinerary.calculateTncFares(itinerary);
|
|
34
35
|
const { currencyCode, maxTNCFare, minTNCFare } = fareResult;
|
|
35
36
|
|
|
36
|
-
const { defaultFareType, fareDetailsLayout, fareKeyNameMap } = fareConfig;
|
|
37
|
-
|
|
38
37
|
const { companies, fareTypes } = itinerary.legs.reduce<{
|
|
39
38
|
companies: string;
|
|
40
39
|
fareTypes: FareProductSelector[];
|
|
@@ -64,84 +63,48 @@ export default function Fares({
|
|
|
64
63
|
{ companies: "", fareTypes: [] }
|
|
65
64
|
);
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
fare = defaultFareTotal !== undefined && (
|
|
87
|
-
<S.Fare>
|
|
88
|
-
<TransitFareWrapper>
|
|
89
|
-
<summary style={{ display: fareTypes.length > 1 ? "list-item" : "" }}>
|
|
90
|
-
<FormattedMessage
|
|
91
|
-
defaultMessage={
|
|
92
|
-
defaultMessages["otpUi.TripDetails.transitFareEntry"]
|
|
93
|
-
}
|
|
94
|
-
description="Text showing the price of tickets on public transportation."
|
|
95
|
-
id="otpUi.TripDetails.transitFareEntry"
|
|
96
|
-
values={{
|
|
97
|
-
name:
|
|
98
|
-
fareKeyNameMap?.[defaultFareType.headerKey] ||
|
|
99
|
-
fareNameFallback,
|
|
100
|
-
strong: boldText,
|
|
101
|
-
value: renderFare(
|
|
102
|
-
defaultFareTotal.currency?.code || "USD",
|
|
103
|
-
defaultFareTotal?.amount
|
|
104
|
-
)
|
|
105
|
-
}}
|
|
106
|
-
/>
|
|
107
|
-
</summary>
|
|
108
|
-
{fareDetailsLayout ? (
|
|
109
|
-
// Show full ƒare details by leg
|
|
110
|
-
<FareLegTable layout={fareDetailsLayout} legs={itinerary.legs} />
|
|
111
|
-
) : (
|
|
112
|
-
// Just show the fares for each payment type
|
|
113
|
-
fareTypes.map(fareType => {
|
|
114
|
-
// Don't show the default fare twice!
|
|
115
|
-
if (fareType) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
return (
|
|
66
|
+
const defaultFareTotal = coreUtils.itinerary.getItineraryCost(
|
|
67
|
+
itinerary.legs,
|
|
68
|
+
defaultFareType?.mediumId || null,
|
|
69
|
+
defaultFareType?.riderCategoryId || null
|
|
70
|
+
);
|
|
71
|
+
// Depending on if there are additional fares to display either render a <span> or a <details>
|
|
72
|
+
const fare = defaultFareTotal !== undefined && (
|
|
73
|
+
<S.Fare>
|
|
74
|
+
<S.TransitFare>
|
|
75
|
+
<summary style={{ display: fareTypes.length > 1 ? "list-item" : "" }}>
|
|
76
|
+
<FormattedMessage
|
|
77
|
+
defaultMessage={
|
|
78
|
+
defaultMessages["otpUi.TripDetails.transitFareEntry"]
|
|
79
|
+
}
|
|
80
|
+
description="Text showing the price of tickets on public transportation."
|
|
81
|
+
id="otpUi.TripDetails.transitFareEntry"
|
|
82
|
+
values={{
|
|
83
|
+
name: (
|
|
119
84
|
<FormattedMessage
|
|
120
85
|
defaultMessage={
|
|
121
|
-
defaultMessages["otpUi.TripDetails.
|
|
86
|
+
defaultMessages["otpUi.TripDetails.transitFare"]
|
|
122
87
|
}
|
|
123
88
|
description="Text showing the price of tickets on public transportation."
|
|
124
|
-
id="otpUi.TripDetails.
|
|
125
|
-
key={Object.values(fareType).join("-")}
|
|
126
|
-
values={{
|
|
127
|
-
name:
|
|
128
|
-
fareKeyNameMap?.[defaultFareType.headerKey] ||
|
|
129
|
-
fareNameFallback,
|
|
130
|
-
strong: boldText,
|
|
131
|
-
value: renderFare(
|
|
132
|
-
defaultFareTotal.currency?.code || "USD",
|
|
133
|
-
defaultFareTotal?.amount /
|
|
134
|
-
defaultFareTotal?.currency?.digits
|
|
135
|
-
)
|
|
136
|
-
}}
|
|
89
|
+
id="otpUi.TripDetails.transitFare"
|
|
137
90
|
/>
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
91
|
+
),
|
|
92
|
+
strong: boldText,
|
|
93
|
+
value: renderFare(
|
|
94
|
+
defaultFareTotal.currency?.code || "USD",
|
|
95
|
+
defaultFareTotal?.amount
|
|
96
|
+
)
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
</summary>
|
|
100
|
+
<FaresV2Table
|
|
101
|
+
legs={itinerary.legs}
|
|
102
|
+
favoriteMediumId={defaultFareType?.mediumId}
|
|
103
|
+
favoriteRiderCategoryId={defaultFareType?.riderCategoryId}
|
|
104
|
+
/>
|
|
105
|
+
</S.TransitFare>
|
|
106
|
+
</S.Fare>
|
|
107
|
+
);
|
|
145
108
|
const tncFare = minTNCFare !== 0 && (
|
|
146
109
|
<S.Fare>
|
|
147
110
|
<S.TNCFare>
|
package/src/index.tsx
CHANGED
|
@@ -2,9 +2,9 @@ import React, { ReactElement } from "react";
|
|
|
2
2
|
import { FormattedMessage } from "react-intl";
|
|
3
3
|
import { flatten } from "flat";
|
|
4
4
|
import * as S from "./styled";
|
|
5
|
-
import FareLegTable from "./components/fare-table";
|
|
6
5
|
import { TripDetailsProps } from "./types";
|
|
7
6
|
import FlexBookingInfo from "./components/flex-booking-info";
|
|
7
|
+
import FaresV2Table from "./components/fares-v2-table";
|
|
8
8
|
import Emissions from "./components/emissions";
|
|
9
9
|
import Fares from "./components/fares";
|
|
10
10
|
import TimeActive, { DefaultTimeActiveDetails } from "./components/time-active";
|
|
@@ -29,9 +29,9 @@ function cn(className: string, arg1: string): string {
|
|
|
29
29
|
export function TripDetails({
|
|
30
30
|
className = "",
|
|
31
31
|
co2Config,
|
|
32
|
+
defaultFareType,
|
|
32
33
|
DepartureDetails = null,
|
|
33
34
|
FareDetails = null,
|
|
34
|
-
fareConfig,
|
|
35
35
|
itinerary,
|
|
36
36
|
showApproximateMinutesActive,
|
|
37
37
|
TimeActiveDetails = DefaultTimeActiveDetails
|
|
@@ -46,6 +46,7 @@ export function TripDetails({
|
|
|
46
46
|
id="otpUi.TripDetails.title"
|
|
47
47
|
/>
|
|
48
48
|
</S.TripDetailsHeader>
|
|
49
|
+
|
|
49
50
|
<S.TripDetailsBody>
|
|
50
51
|
<DepartureDate
|
|
51
52
|
itinerary={itinerary}
|
|
@@ -53,8 +54,8 @@ export function TripDetails({
|
|
|
53
54
|
/>
|
|
54
55
|
<Fares
|
|
55
56
|
itinerary={itinerary}
|
|
56
|
-
fareConfig={fareConfig}
|
|
57
57
|
FareDetails={FareDetails}
|
|
58
|
+
defaultFareType={defaultFareType}
|
|
58
59
|
/>
|
|
59
60
|
<TimeActive
|
|
60
61
|
itinerary={itinerary}
|
|
@@ -71,4 +72,4 @@ export function TripDetails({
|
|
|
71
72
|
export default TripDetails;
|
|
72
73
|
|
|
73
74
|
// Rename styled components for export.
|
|
74
|
-
export { S as Styled,
|
|
75
|
+
export { S as Styled, FaresV2Table };
|
package/src/styled.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import styled from "styled-components";
|
|
1
|
+
import styled, { css } from "styled-components";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const InvisibleA11yStyles = css`
|
|
4
4
|
display: inline-block;
|
|
5
5
|
clip: rect(0, 0, 0, 0);
|
|
6
6
|
height: 0;
|
|
@@ -8,6 +8,14 @@ export const InvisibleA11yLabel = styled.span`
|
|
|
8
8
|
position: absolute;
|
|
9
9
|
width: 0;
|
|
10
10
|
`;
|
|
11
|
+
export const InvisibleA11yLabel = styled.span`
|
|
12
|
+
${InvisibleA11yStyles}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
// Warning: https://github.com/opentripplanner/otp-ui/pull/855#discussion_r2248534209
|
|
16
|
+
export const InvisibleA11yCaption = styled.caption`
|
|
17
|
+
${InvisibleA11yStyles}
|
|
18
|
+
`;
|
|
11
19
|
|
|
12
20
|
const BaseButton = styled.button`
|
|
13
21
|
background: transparent;
|
|
@@ -88,6 +96,7 @@ export const TripDetails = styled.div`
|
|
|
88
96
|
margin-bottom: 15px;
|
|
89
97
|
margin-top: 16px;
|
|
90
98
|
padding: 10px 16px;
|
|
99
|
+
overflow-x: scroll;
|
|
91
100
|
`;
|
|
92
101
|
|
|
93
102
|
export const TripDetailsBody = styled.div``;
|
package/src/trip-detail.tsx
CHANGED
|
@@ -13,17 +13,8 @@ type Props = {
|
|
|
13
13
|
summary: ReactElement | string;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
// TODO: Remove
|
|
17
|
-
/**
|
|
18
|
-
* Copied from https://stackoverflow.com/questions/50940640/how-to-determine-if-jest-is-running-the-code-or-not
|
|
19
|
-
*/
|
|
20
|
-
function isRunningJest() {
|
|
21
|
-
return process.env.JEST_WORKER_ID !== undefined;
|
|
22
|
-
}
|
|
23
|
-
|
|
16
|
+
// TODO: Remove this helper method by moving to semantically correct HTML
|
|
24
17
|
function uuidv4(): string {
|
|
25
|
-
if (isRunningJest()) return "mocked-random-id";
|
|
26
|
-
|
|
27
18
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
28
19
|
// eslint-disable-next-line no-bitwise
|
|
29
20
|
const r = (Math.random() * 16) | 0;
|
package/src/types.ts
CHANGED
|
@@ -24,24 +24,6 @@ export interface DepartureDetailsProps {
|
|
|
24
24
|
departureDate: Date;
|
|
25
25
|
}
|
|
26
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 columns defined here,
|
|
30
|
-
* with each row being an individual transit leg from the itinerary.
|
|
31
|
-
*/
|
|
32
|
-
export interface FareTableLayout {
|
|
33
|
-
cols: (FareProductSelector & {
|
|
34
|
-
columnHeaderKey: string;
|
|
35
|
-
})[]
|
|
36
|
-
headerKey: string;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Interface containing the lgs and the layout of the fare table.
|
|
40
|
-
*/
|
|
41
|
-
export interface FareLegTableProps {
|
|
42
|
-
layout?: FareTableLayout[];
|
|
43
|
-
legs: Leg[];
|
|
44
|
-
}
|
|
45
27
|
|
|
46
28
|
// Total fare amount corresponding to a fare key
|
|
47
29
|
export type FareTotals = (FareProductSelector & { price: Money })[]
|
|
@@ -52,23 +34,6 @@ export interface FareDetailsProps {
|
|
|
52
34
|
minTNCFare: number;
|
|
53
35
|
}
|
|
54
36
|
|
|
55
|
-
export interface FareConfig {
|
|
56
|
-
/**
|
|
57
|
-
* Determines which transit fare should be displayed by default, should there be multiple transit fare types.
|
|
58
|
-
*/
|
|
59
|
-
defaultFareType?: { headerKey: string } & FareProductSelector;
|
|
60
|
-
/**
|
|
61
|
-
* Column and table configuration for fare details/fare by leg table.
|
|
62
|
-
*/
|
|
63
|
-
fareDetailsLayout?: FareTableLayout[];
|
|
64
|
-
/**
|
|
65
|
-
* Mapping between fare keys and human-readable names for them.
|
|
66
|
-
*/
|
|
67
|
-
fareKeyNameMap?: {
|
|
68
|
-
[name: string]: string;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
37
|
export interface TripDetailsProps {
|
|
73
38
|
/**
|
|
74
39
|
* Used for additional styling with styled components for example.
|
|
@@ -78,6 +43,10 @@ export interface TripDetailsProps {
|
|
|
78
43
|
* Object containing the CO₂ config.
|
|
79
44
|
*/
|
|
80
45
|
co2Config?: CO2ConfigType;
|
|
46
|
+
/**
|
|
47
|
+
* Determines which transit fare should be displayed by default, should there be multiple transit fare types.
|
|
48
|
+
*/
|
|
49
|
+
defaultFareType?: FareProductSelector;
|
|
81
50
|
/**
|
|
82
51
|
* Slot for a custom component to render the expandable section for departure.
|
|
83
52
|
*/
|
|
@@ -86,10 +55,6 @@ export interface TripDetailsProps {
|
|
|
86
55
|
* Slot for a custom component to render the expandable section for fares.
|
|
87
56
|
*/
|
|
88
57
|
FareDetails?: React.ElementType<FareDetailsProps>;
|
|
89
|
-
/**
|
|
90
|
-
* Configuration for fare details/fare by leg table.
|
|
91
|
-
*/
|
|
92
|
-
fareConfig?: FareConfig;
|
|
93
58
|
/**
|
|
94
59
|
* Itinerary that the user has selected to view, contains multiple legs.
|
|
95
60
|
*/
|