@opentripplanner/trip-details 7.0.1-alpha.1 → 8.0.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/components/departure-date.js +42 -0
- package/esm/components/departure-date.js.map +1 -0
- package/esm/components/emissions.js +68 -0
- package/esm/components/emissions.js.map +1 -0
- package/esm/{fare-table.js → components/fare-table.js} +6 -6
- package/esm/components/fare-table.js.map +1 -0
- package/esm/components/fares.js +151 -0
- package/esm/components/fares.js.map +1 -0
- package/esm/components/flex-booking-info.js +51 -0
- package/esm/components/flex-booking-info.js.map +1 -0
- package/esm/components/time-active.js +69 -0
- package/esm/components/time-active.js.map +1 -0
- package/esm/index.js +40 -289
- package/esm/index.js.map +1 -1
- package/esm/trip-detail.js +4 -2
- package/esm/trip-detail.js.map +1 -1
- package/esm/types.js.map +1 -1
- package/i18n/ko.yml +2 -2
- package/i18n/nb_NO.yml +0 -1
- package/i18n/pl.yml +30 -1
- package/i18n/ru.yml +3 -3
- package/i18n/ta.yml +18 -20
- package/i18n/tl.yml +2 -2
- package/i18n/vi.yml +2 -2
- package/i18n/zh_Hans.yml +2 -2
- package/lib/components/departure-date.d.ts +10 -0
- package/lib/components/departure-date.d.ts.map +1 -0
- package/lib/components/departure-date.js +51 -0
- package/lib/components/departure-date.js.map +1 -0
- package/lib/components/emissions.d.ts +8 -0
- package/lib/components/emissions.d.ts.map +1 -0
- package/lib/components/emissions.js +75 -0
- package/lib/components/emissions.js.map +1 -0
- package/lib/{fare-table.d.ts → components/fare-table.d.ts} +1 -1
- package/lib/components/fare-table.d.ts.map +1 -0
- package/lib/{fare-table.js → components/fare-table.js} +6 -6
- package/lib/components/fare-table.js.map +1 -0
- package/lib/components/fares.d.ts +10 -0
- package/lib/components/fares.d.ts.map +1 -0
- package/lib/components/fares.js +162 -0
- package/lib/components/fares.js.map +1 -0
- package/lib/components/flex-booking-info.d.ts +6 -0
- package/lib/components/flex-booking-info.d.ts.map +1 -0
- package/lib/components/flex-booking-info.js +47 -0
- package/lib/components/flex-booking-info.js.map +1 -0
- package/lib/components/time-active.d.ts +14 -0
- package/lib/components/time-active.d.ts.map +1 -0
- package/lib/components/time-active.js +79 -0
- package/lib/components/time-active.js.map +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +27 -262
- package/lib/index.js.map +1 -1
- package/lib/trip-detail.d.ts +2 -1
- package/lib/trip-detail.d.ts.map +1 -1
- package/lib/trip-detail.js +4 -2
- package/lib/trip-detail.js.map +1 -1
- package/lib/types.d.ts +20 -19
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js.map +1 -1
- package/package.json +3 -3
- package/src/TripDetails.story.tsx +26 -28
- package/src/__snapshots__/TripDetails.story.tsx.snap +108 -108
- package/src/components/departure-date.tsx +53 -0
- package/src/components/emissions.tsx +97 -0
- package/src/{fare-table.tsx → components/fare-table.tsx} +5 -4
- package/src/components/fares.tsx +205 -0
- package/src/components/flex-booking-info.tsx +57 -0
- package/src/components/time-active.tsx +90 -0
- package/src/index.tsx +28 -365
- package/src/trip-detail.tsx +8 -2
- package/src/types.ts +18 -17
- package/tsconfig.tsbuildinfo +1 -1
- package/README.md +0 -6
- package/esm/fare-table.js.map +0 -1
- package/lib/fare-table.d.ts.map +0 -1
- package/lib/fare-table.js.map +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Itinerary } from "@opentripplanner/types";
|
|
2
|
+
import React, { ReactElement } from "react";
|
|
3
|
+
import { FormattedMessage } from "react-intl";
|
|
4
|
+
import { CalendarAlt } from "@styled-icons/fa-solid/CalendarAlt";
|
|
5
|
+
import flatten from "flat";
|
|
6
|
+
import { boldText } from "../utils";
|
|
7
|
+
import { DepartureDetailsProps } from "../types";
|
|
8
|
+
import TripDetail from "../trip-detail";
|
|
9
|
+
import * as S from "../styled";
|
|
10
|
+
|
|
11
|
+
// Load the default messages.
|
|
12
|
+
import defaultEnglishMessages from "../../i18n/en-US.yml";
|
|
13
|
+
|
|
14
|
+
// HACK: We should flatten the messages loaded above because
|
|
15
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
16
|
+
// - the yaml loader for webpack returns a nested object,
|
|
17
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
18
|
+
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
19
|
+
|
|
20
|
+
interface DepartureDateProps {
|
|
21
|
+
itinerary: Itinerary;
|
|
22
|
+
DepartureDetails?: React.ElementType<DepartureDetailsProps>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default function DepartureDate({
|
|
26
|
+
itinerary,
|
|
27
|
+
DepartureDetails
|
|
28
|
+
}: DepartureDateProps): ReactElement {
|
|
29
|
+
const departureDate = new Date(itinerary.startTime);
|
|
30
|
+
return (
|
|
31
|
+
<TripDetail
|
|
32
|
+
className="departure-date"
|
|
33
|
+
// Any custom description for the Departure message needs to be handled by the slot.
|
|
34
|
+
description={
|
|
35
|
+
DepartureDetails && <DepartureDetails departureDate={departureDate} />
|
|
36
|
+
}
|
|
37
|
+
icon={<CalendarAlt size={17} />}
|
|
38
|
+
summary={
|
|
39
|
+
<S.Timing>
|
|
40
|
+
<FormattedMessage
|
|
41
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.departure"]}
|
|
42
|
+
description="Text showing the departure date/time for a trip."
|
|
43
|
+
id="otpUi.TripDetails.departure"
|
|
44
|
+
values={{
|
|
45
|
+
departureDate,
|
|
46
|
+
strong: boldText
|
|
47
|
+
}}
|
|
48
|
+
/>
|
|
49
|
+
</S.Timing>
|
|
50
|
+
}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React, { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { FormattedMessage, FormattedNumber } from "react-intl";
|
|
3
|
+
import { Itinerary } from "@opentripplanner/types";
|
|
4
|
+
import { Leaf } from "@styled-icons/fa-solid/Leaf";
|
|
5
|
+
import coreUtils from "@opentripplanner/core-utils";
|
|
6
|
+
import flatten from "flat";
|
|
7
|
+
import { boldText } from "../utils";
|
|
8
|
+
import TripDetail from "../trip-detail";
|
|
9
|
+
import { CO2ConfigType } from "../types";
|
|
10
|
+
import * as S from "../styled";
|
|
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
|
+
function CO2DescriptionLink(contents: ReactNode): ReactElement {
|
|
22
|
+
return (
|
|
23
|
+
<a
|
|
24
|
+
href="https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx"
|
|
25
|
+
rel="noopener noreferrer"
|
|
26
|
+
target="_blank"
|
|
27
|
+
>
|
|
28
|
+
{contents}
|
|
29
|
+
</a>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default function Emissions({
|
|
34
|
+
itinerary,
|
|
35
|
+
co2Config
|
|
36
|
+
}: {
|
|
37
|
+
itinerary: Itinerary;
|
|
38
|
+
co2Config: CO2ConfigType;
|
|
39
|
+
}): JSX.Element | null {
|
|
40
|
+
// Calculate CO₂ if it's not provided by the itinerary
|
|
41
|
+
const co2 =
|
|
42
|
+
itinerary.co2 ||
|
|
43
|
+
(co2Config?.enabled &&
|
|
44
|
+
coreUtils.itinerary.calculateEmissions(
|
|
45
|
+
itinerary,
|
|
46
|
+
co2Config?.carbonIntensity,
|
|
47
|
+
co2Config?.units
|
|
48
|
+
));
|
|
49
|
+
|
|
50
|
+
if (!co2 || co2 < 0 || !co2Config?.enabled) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const totalDistance = itinerary.legs.reduce(
|
|
55
|
+
(total, leg) => total + leg.distance,
|
|
56
|
+
0
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<TripDetail
|
|
61
|
+
className="emissions"
|
|
62
|
+
icon={<Leaf size={17} />}
|
|
63
|
+
summary={
|
|
64
|
+
<S.CO2Summary>
|
|
65
|
+
<FormattedMessage
|
|
66
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.co2"]}
|
|
67
|
+
description="Text showing the quantity of CO₂ emitted by this trip."
|
|
68
|
+
id="otpUi.TripDetails.co2"
|
|
69
|
+
values={{
|
|
70
|
+
co2: (
|
|
71
|
+
<FormattedNumber
|
|
72
|
+
value={Math.round(co2)}
|
|
73
|
+
// eslint-disable-next-line react/style-prop-object
|
|
74
|
+
style="unit"
|
|
75
|
+
unit={co2Config?.units || "gram"}
|
|
76
|
+
unitDisplay="narrow"
|
|
77
|
+
/>
|
|
78
|
+
),
|
|
79
|
+
strong: boldText
|
|
80
|
+
}}
|
|
81
|
+
/>
|
|
82
|
+
</S.CO2Summary>
|
|
83
|
+
}
|
|
84
|
+
description={
|
|
85
|
+
<FormattedMessage
|
|
86
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.co2description"]}
|
|
87
|
+
description="Text explaining how the CO₂ emissions are calculated."
|
|
88
|
+
id="otpUi.TripDetails.co2description"
|
|
89
|
+
values={{
|
|
90
|
+
link: CO2DescriptionLink,
|
|
91
|
+
totalDistance
|
|
92
|
+
}}
|
|
93
|
+
/>
|
|
94
|
+
}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
@@ -10,13 +10,13 @@ import {
|
|
|
10
10
|
} from "@opentripplanner/core-utils/lib/itinerary";
|
|
11
11
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
12
12
|
import { flatten } from "flat";
|
|
13
|
-
import { boldText, renderFare } from "
|
|
13
|
+
import { boldText, renderFare } from "../utils";
|
|
14
14
|
|
|
15
|
-
import { FareLegTableProps, FareTableLayout } from "
|
|
15
|
+
import { FareLegTableProps, FareTableLayout } from "../types";
|
|
16
16
|
|
|
17
17
|
// Load the default messages.
|
|
18
|
-
import defaultEnglishMessages from "
|
|
19
|
-
import { InvisibleA11yLabel } from "
|
|
18
|
+
import defaultEnglishMessages from "../../i18n/en-US.yml";
|
|
19
|
+
import { InvisibleA11yLabel } from "../styled";
|
|
20
20
|
|
|
21
21
|
// HACK: We should flatten the messages loaded above because
|
|
22
22
|
// the YAML loaders behave differently between webpack and our version of jest:
|
|
@@ -99,6 +99,7 @@ const FareTypeTable = ({
|
|
|
99
99
|
}));
|
|
100
100
|
|
|
101
101
|
const headerString = useGetHeaderString(headerKey);
|
|
102
|
+
|
|
102
103
|
if (colsToRender.length) {
|
|
103
104
|
return (
|
|
104
105
|
<Table>
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import React, { ReactElement } from "react";
|
|
2
|
+
import { FormattedMessage } from "react-intl";
|
|
3
|
+
import flatten from "flat";
|
|
4
|
+
import coreUtils from "@opentripplanner/core-utils";
|
|
5
|
+
import { FareProductSelector, Itinerary } from "@opentripplanner/types";
|
|
6
|
+
import { MoneyBillAlt } from "@styled-icons/fa-solid";
|
|
7
|
+
import * as S from "../styled";
|
|
8
|
+
import { boldText, renderFare } from "../utils";
|
|
9
|
+
import TripDetail from "../trip-detail";
|
|
10
|
+
import { FareConfig, FareDetailsProps } from "../types";
|
|
11
|
+
import FareLegTable from "./fare-table";
|
|
12
|
+
|
|
13
|
+
// Load the default messages.
|
|
14
|
+
import defaultEnglishMessages from "../../i18n/en-US.yml";
|
|
15
|
+
|
|
16
|
+
// HACK: We should flatten the messages loaded above because
|
|
17
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
18
|
+
// - the yaml loader for webpack returns a nested object,
|
|
19
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
20
|
+
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
21
|
+
|
|
22
|
+
export interface FaresProps {
|
|
23
|
+
itinerary: Itinerary;
|
|
24
|
+
FareDetails?: React.ElementType<FareDetailsProps>;
|
|
25
|
+
fareConfig?: FareConfig;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default function Fares({
|
|
29
|
+
itinerary,
|
|
30
|
+
FareDetails,
|
|
31
|
+
fareConfig = {}
|
|
32
|
+
}: FaresProps): ReactElement | null {
|
|
33
|
+
const fareResult = coreUtils.itinerary.calculateTncFares(itinerary);
|
|
34
|
+
const { currencyCode, maxTNCFare, minTNCFare } = fareResult;
|
|
35
|
+
|
|
36
|
+
const { defaultFareType, fareDetailsLayout, fareKeyNameMap } = fareConfig;
|
|
37
|
+
|
|
38
|
+
const { companies, fareTypes } = itinerary.legs.reduce<{
|
|
39
|
+
companies: string;
|
|
40
|
+
fareTypes: FareProductSelector[];
|
|
41
|
+
}>(
|
|
42
|
+
(prev, leg) => {
|
|
43
|
+
if (leg.rideHailingEstimate) {
|
|
44
|
+
prev.companies = leg.rideHailingEstimate.provider.id;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (leg.fareProducts) {
|
|
48
|
+
leg.fareProducts.forEach(fp => {
|
|
49
|
+
const mediumId = fp.product.medium?.id;
|
|
50
|
+
const riderCategoryId = fp.product.riderCategory?.id;
|
|
51
|
+
if (
|
|
52
|
+
!prev.fareTypes.find(
|
|
53
|
+
ft =>
|
|
54
|
+
ft.mediumId === mediumId &&
|
|
55
|
+
ft.riderCategoryId === riderCategoryId
|
|
56
|
+
)
|
|
57
|
+
) {
|
|
58
|
+
prev.fareTypes.push({ mediumId, riderCategoryId });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return prev;
|
|
63
|
+
},
|
|
64
|
+
{ companies: "", fareTypes: [] }
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
let fare;
|
|
68
|
+
if (fareTypes.length > 0 && defaultFareType) {
|
|
69
|
+
const defaultFareTotal = coreUtils.itinerary.getItineraryCost(
|
|
70
|
+
itinerary.legs,
|
|
71
|
+
defaultFareType.mediumId,
|
|
72
|
+
defaultFareType.riderCategoryId
|
|
73
|
+
);
|
|
74
|
+
// Depending on if there are additional fares to display either render a <span> or a <details>
|
|
75
|
+
const TransitFareWrapper =
|
|
76
|
+
fareTypes.length > 1 ? S.TransitFare : S.TransitFareSingle;
|
|
77
|
+
|
|
78
|
+
const fareNameFallback = (
|
|
79
|
+
<FormattedMessage
|
|
80
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.transitFare"]}
|
|
81
|
+
description="Text showing the price of tickets on public transportation."
|
|
82
|
+
id="otpUi.TripDetails.transitFare"
|
|
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 (
|
|
119
|
+
<FormattedMessage
|
|
120
|
+
defaultMessage={
|
|
121
|
+
defaultMessages["otpUi.TripDetails.transitFareEntry"]
|
|
122
|
+
}
|
|
123
|
+
description="Text showing the price of tickets on public transportation."
|
|
124
|
+
id="otpUi.TripDetails.transitFareEntry"
|
|
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
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
})
|
|
140
|
+
)}
|
|
141
|
+
</TransitFareWrapper>
|
|
142
|
+
</S.Fare>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const tncFare = minTNCFare !== 0 && (
|
|
146
|
+
<S.Fare>
|
|
147
|
+
<S.TNCFare>
|
|
148
|
+
<FormattedMessage
|
|
149
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.tncFare"]}
|
|
150
|
+
description="Text showing the price paid to transportation network companies."
|
|
151
|
+
id="otpUi.TripDetails.tncFare"
|
|
152
|
+
values={{
|
|
153
|
+
companies: (
|
|
154
|
+
// S.TNCFareCompanies capitalizes the TNC company ID (e.g. "COMPANY")
|
|
155
|
+
// after it is converted to lowercase, so it renders as "Company".
|
|
156
|
+
<S.TNCFareCompanies>{companies.toLowerCase()}</S.TNCFareCompanies>
|
|
157
|
+
),
|
|
158
|
+
maxTNCFare: renderFare(currencyCode, maxTNCFare),
|
|
159
|
+
minTNCFare: renderFare(currencyCode, minTNCFare),
|
|
160
|
+
strong: boldText
|
|
161
|
+
}}
|
|
162
|
+
/>
|
|
163
|
+
</S.TNCFare>
|
|
164
|
+
</S.Fare>
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<>
|
|
169
|
+
{!!fare && (
|
|
170
|
+
<TripDetail
|
|
171
|
+
className="fares"
|
|
172
|
+
// Any custom description for the transit fare needs to be handled by the slot.
|
|
173
|
+
description={
|
|
174
|
+
FareDetails && (
|
|
175
|
+
<FareDetails
|
|
176
|
+
legs={itinerary.legs}
|
|
177
|
+
maxTNCFare={maxTNCFare}
|
|
178
|
+
minTNCFare={minTNCFare}
|
|
179
|
+
/>
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
icon={<MoneyBillAlt size={17} />}
|
|
183
|
+
summary={fare}
|
|
184
|
+
/>
|
|
185
|
+
)}
|
|
186
|
+
{!!tncFare && (
|
|
187
|
+
<TripDetail
|
|
188
|
+
className="tnc-fare"
|
|
189
|
+
// Any custom description for the transit fare needs to be handled by the slot.
|
|
190
|
+
description={
|
|
191
|
+
FareDetails && (
|
|
192
|
+
<FareDetails
|
|
193
|
+
legs={itinerary.legs}
|
|
194
|
+
maxTNCFare={maxTNCFare}
|
|
195
|
+
minTNCFare={minTNCFare}
|
|
196
|
+
/>
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
icon={<MoneyBillAlt size={17} />}
|
|
200
|
+
summary={tncFare}
|
|
201
|
+
/>
|
|
202
|
+
)}
|
|
203
|
+
</>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FormattedMessage } from "react-intl";
|
|
3
|
+
import { Route } from "@styled-icons/fa-solid/Route";
|
|
4
|
+
import { Itinerary } from "@opentripplanner/types";
|
|
5
|
+
import coreUtils from "@opentripplanner/core-utils";
|
|
6
|
+
import { flatten } from "flat";
|
|
7
|
+
import TripDetail from "../trip-detail";
|
|
8
|
+
import * as S from "../styled";
|
|
9
|
+
|
|
10
|
+
// Load the default messages.
|
|
11
|
+
import defaultEnglishMessages from "../../i18n/en-US.yml";
|
|
12
|
+
|
|
13
|
+
// HACK: We should flatten the messages loaded above because
|
|
14
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
15
|
+
// - the yaml loader for webpack returns a nested object,
|
|
16
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
17
|
+
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
18
|
+
|
|
19
|
+
export default function FlexBookingInfo({
|
|
20
|
+
itinerary
|
|
21
|
+
}: {
|
|
22
|
+
itinerary: Itinerary;
|
|
23
|
+
}): JSX.Element | null {
|
|
24
|
+
const containsFlex = itinerary.legs.some(coreUtils.itinerary.isFlex);
|
|
25
|
+
if (!containsFlex) return null;
|
|
26
|
+
const pickupBookingInfo = itinerary.legs
|
|
27
|
+
.map(leg => leg.pickupBookingInfo)
|
|
28
|
+
.filter(info => !!info);
|
|
29
|
+
const dropOffBookingInfo = itinerary.legs
|
|
30
|
+
.map(leg => leg.dropOffBookingInfo)
|
|
31
|
+
.filter(info => !!info);
|
|
32
|
+
return (
|
|
33
|
+
<TripDetail
|
|
34
|
+
className="flex-booking-info"
|
|
35
|
+
summary={
|
|
36
|
+
<S.FlexSummary>
|
|
37
|
+
<FormattedMessage
|
|
38
|
+
defaultMessage={
|
|
39
|
+
defaultMessages["otpUi.TripDetails.tripIncludesFlex"]
|
|
40
|
+
}
|
|
41
|
+
description="Text stating that portions of the trip include a flex (on-demand) transit service."
|
|
42
|
+
id="otpUi.TripDetails.tripIncludesFlex"
|
|
43
|
+
values={{
|
|
44
|
+
extraMessage: [
|
|
45
|
+
...new Set([
|
|
46
|
+
...pickupBookingInfo.map(info => info.message),
|
|
47
|
+
...dropOffBookingInfo.map(info => info.message)
|
|
48
|
+
])
|
|
49
|
+
].join(" ")
|
|
50
|
+
}}
|
|
51
|
+
/>
|
|
52
|
+
</S.FlexSummary>
|
|
53
|
+
}
|
|
54
|
+
icon={<Route size={17} />}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React, { ReactElement } from "react";
|
|
2
|
+
import { FormattedMessage } from "react-intl";
|
|
3
|
+
import { Heartbeat } from "@styled-icons/fa-solid/Heartbeat";
|
|
4
|
+
import { Itinerary } from "@opentripplanner/types";
|
|
5
|
+
import flatten from "flat";
|
|
6
|
+
import TripDetail from "../trip-detail";
|
|
7
|
+
import { boldText } from "../utils";
|
|
8
|
+
import { TimeActiveDetailsProps } from "../types";
|
|
9
|
+
|
|
10
|
+
// Load the default messages.
|
|
11
|
+
import defaultEnglishMessages from "../../i18n/en-US.yml";
|
|
12
|
+
|
|
13
|
+
// HACK: We should flatten the messages loaded above because
|
|
14
|
+
// the YAML loaders behave differently between webpack and our version of jest:
|
|
15
|
+
// - the yaml loader for webpack returns a nested object,
|
|
16
|
+
// - the yaml loader for jest returns messages with flattened ids.
|
|
17
|
+
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Default rendering if no component is provided for the TimeActiveDetails
|
|
21
|
+
* slot in the TripDetails component.
|
|
22
|
+
*/
|
|
23
|
+
export function DefaultTimeActiveDetails({
|
|
24
|
+
bikeMinutes,
|
|
25
|
+
walkMinutes
|
|
26
|
+
}: TimeActiveDetailsProps): ReactElement {
|
|
27
|
+
return (
|
|
28
|
+
<FormattedMessage
|
|
29
|
+
defaultMessage={
|
|
30
|
+
defaultMessages["otpUi.TripDetails.timeActiveDescription"]
|
|
31
|
+
}
|
|
32
|
+
description="Text describing the walking and biking durations of a trip."
|
|
33
|
+
id="otpUi.TripDetails.timeActiveDescription"
|
|
34
|
+
values={{
|
|
35
|
+
bikeMinutes,
|
|
36
|
+
strong: boldText,
|
|
37
|
+
walkMinutes
|
|
38
|
+
}}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default function TimeActive({
|
|
44
|
+
itinerary,
|
|
45
|
+
TimeActiveDetails,
|
|
46
|
+
showApproximateMinutesActive
|
|
47
|
+
}: {
|
|
48
|
+
itinerary: Itinerary;
|
|
49
|
+
TimeActiveDetails: React.ComponentType<TimeActiveDetailsProps>;
|
|
50
|
+
showApproximateMinutesActive: boolean;
|
|
51
|
+
}): JSX.Element | null {
|
|
52
|
+
let walkDurationSeconds = 0;
|
|
53
|
+
let bikeDurationSeconds = 0;
|
|
54
|
+
itinerary.legs.forEach(leg => {
|
|
55
|
+
if (leg.mode.startsWith("WALK")) walkDurationSeconds += leg.duration;
|
|
56
|
+
if (leg.mode.startsWith("BICYCLE")) bikeDurationSeconds += leg.duration;
|
|
57
|
+
});
|
|
58
|
+
const bikeMinutes = Math.round(bikeDurationSeconds / 60);
|
|
59
|
+
const walkMinutes = Math.round(walkDurationSeconds / 60);
|
|
60
|
+
const minutesActive = bikeMinutes + walkMinutes;
|
|
61
|
+
|
|
62
|
+
if (minutesActive <= 0) return null;
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<TripDetail
|
|
66
|
+
className="time-active"
|
|
67
|
+
icon={<Heartbeat size={17} />}
|
|
68
|
+
summary={
|
|
69
|
+
<FormattedMessage
|
|
70
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.minutesActive"]}
|
|
71
|
+
description="Text showing the number of minutes spent walking or biking throughout trip."
|
|
72
|
+
id="otpUi.TripDetails.minutesActive"
|
|
73
|
+
values={{
|
|
74
|
+
approximatePrefix: showApproximateMinutesActive,
|
|
75
|
+
minutes: minutesActive,
|
|
76
|
+
strong: boldText
|
|
77
|
+
}}
|
|
78
|
+
/>
|
|
79
|
+
}
|
|
80
|
+
description={
|
|
81
|
+
TimeActiveDetails && (
|
|
82
|
+
<TimeActiveDetails
|
|
83
|
+
bikeMinutes={bikeMinutes}
|
|
84
|
+
walkMinutes={walkMinutes}
|
|
85
|
+
/>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
/>
|
|
89
|
+
);
|
|
90
|
+
}
|