@opentripplanner/trip-details 9.2.1 → 9.3.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/components/departure-date.js +18 -8
- package/esm/components/departure-date.js.map +1 -1
- package/esm/components/time-active.js +2 -2
- package/esm/components/time-active.js.map +1 -1
- package/esm/components/transit-time.js +36 -0
- package/esm/components/transit-time.js.map +1 -0
- package/esm/index.js +15 -4
- package/esm/index.js.map +1 -1
- package/esm/types.js.map +1 -1
- package/i18n/en-US.yml +6 -0
- package/i18n/fr.yml +6 -0
- package/lib/components/departure-date.d.ts +3 -2
- package/lib/components/departure-date.d.ts.map +1 -1
- package/lib/components/departure-date.js +18 -8
- package/lib/components/departure-date.js.map +1 -1
- package/lib/components/time-active.d.ts +3 -3
- package/lib/components/time-active.d.ts.map +1 -1
- package/lib/components/time-active.js +2 -2
- package/lib/components/time-active.js.map +1 -1
- package/lib/components/transit-time.d.ts +7 -0
- package/lib/components/transit-time.d.ts.map +1 -0
- package/lib/components/transit-time.js +40 -0
- package/lib/components/transit-time.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -4
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +10 -0
- 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 +28 -5
- package/src/__snapshots__/TripDetails.story.tsx.snap +313 -0
- package/src/components/departure-date.tsx +24 -13
- package/src/components/time-active.tsx +4 -4
- package/src/components/transit-time.tsx +40 -0
- package/src/index.tsx +14 -3
- package/src/types.ts +15 -5
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { ReactElement } from "react";
|
|
2
|
+
import { FormattedMessage } from "react-intl";
|
|
3
|
+
import { Clock } from "@styled-icons/fa-solid/Clock";
|
|
4
|
+
import { Leg } from "@opentripplanner/types";
|
|
5
|
+
import flatten from "flat";
|
|
6
|
+
import TripDetail from "../trip-detail";
|
|
7
|
+
import { boldText } from "../utils";
|
|
8
|
+
|
|
9
|
+
import defaultEnglishMessages from "../../i18n/en-US.yml";
|
|
10
|
+
|
|
11
|
+
const defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);
|
|
12
|
+
|
|
13
|
+
/** Time on board transit vehicles, excluding transfer activity and waiting. */
|
|
14
|
+
export default function TransitTime({
|
|
15
|
+
legs
|
|
16
|
+
}: {
|
|
17
|
+
legs: Leg[];
|
|
18
|
+
}): ReactElement | null {
|
|
19
|
+
const transitLegs = legs.filter(leg => leg.transitLeg);
|
|
20
|
+
if (transitLegs.length === 0) return null;
|
|
21
|
+
|
|
22
|
+
const minutes = Math.round(
|
|
23
|
+
transitLegs.reduce((seconds, leg) => seconds + leg.duration, 0) / 60
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<TripDetail
|
|
28
|
+
className="transit-time"
|
|
29
|
+
icon={<Clock size={17} />}
|
|
30
|
+
summary={
|
|
31
|
+
<FormattedMessage
|
|
32
|
+
defaultMessage={defaultMessages["otpUi.TripDetails.transitTime"]}
|
|
33
|
+
description="Time spent on board transit vehicles, excluding transfers and waiting."
|
|
34
|
+
id="otpUi.TripDetails.transitTime"
|
|
35
|
+
values={{ minutes, strong: boldText }}
|
|
36
|
+
/>
|
|
37
|
+
}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { ReactElement } from "react";
|
|
2
2
|
import { FormattedMessage } from "react-intl";
|
|
3
3
|
import { flatten } from "flat";
|
|
4
|
+
import coreUtils from "@opentripplanner/core-utils";
|
|
4
5
|
import * as S from "./styled";
|
|
5
6
|
import { TripDetailsProps } from "./types";
|
|
6
7
|
import FlexBookingInfo from "./components/flex-booking-info";
|
|
@@ -9,6 +10,7 @@ import Emissions from "./components/emissions";
|
|
|
9
10
|
import Fares from "./components/fares";
|
|
10
11
|
import TimeActive, { DefaultTimeActiveDetails } from "./components/time-active";
|
|
11
12
|
import DepartureDate from "./components/departure-date";
|
|
13
|
+
import TransitTime from "./components/transit-time";
|
|
12
14
|
|
|
13
15
|
// Load the default messages.
|
|
14
16
|
import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
@@ -35,8 +37,15 @@ export function TripDetails({
|
|
|
35
37
|
itinerary,
|
|
36
38
|
mediumRiderWhitelist,
|
|
37
39
|
showApproximateMinutesActive,
|
|
38
|
-
|
|
40
|
+
showTransitTime = false,
|
|
41
|
+
TimeActiveDetails = DefaultTimeActiveDetails,
|
|
42
|
+
transitOnly = false
|
|
39
43
|
}: TripDetailsProps): ReactElement {
|
|
44
|
+
const timing = coreUtils.itinerary.getItinerarySummaryTiming(
|
|
45
|
+
itinerary,
|
|
46
|
+
transitOnly
|
|
47
|
+
);
|
|
48
|
+
|
|
40
49
|
return (
|
|
41
50
|
<S.TripDetails className={cn(className, "trip-details")}>
|
|
42
51
|
{/* this can be presentation as S.TripDetails is already labeled by this */}
|
|
@@ -50,9 +59,11 @@ export function TripDetails({
|
|
|
50
59
|
|
|
51
60
|
<S.TripDetailsBody>
|
|
52
61
|
<DepartureDate
|
|
53
|
-
|
|
62
|
+
startTime={timing.startTime}
|
|
54
63
|
DepartureDetails={DepartureDetails}
|
|
64
|
+
isBoarding={transitOnly && timing.legs[0]?.transitLeg === true}
|
|
55
65
|
/>
|
|
66
|
+
{showTransitTime && <TransitTime legs={itinerary.legs} />}
|
|
56
67
|
<Fares
|
|
57
68
|
itinerary={itinerary}
|
|
58
69
|
FareDetails={FareDetails}
|
|
@@ -60,7 +71,7 @@ export function TripDetails({
|
|
|
60
71
|
mediumRiderWhitelist={mediumRiderWhitelist}
|
|
61
72
|
/>
|
|
62
73
|
<TimeActive
|
|
63
|
-
|
|
74
|
+
legs={timing.legs}
|
|
64
75
|
TimeActiveDetails={TimeActiveDetails}
|
|
65
76
|
showApproximateMinutesActive={showApproximateMinutesActive}
|
|
66
77
|
/>
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Prettier does not recognize the import type syntax.
|
|
2
2
|
// eslint-disable-next-line prettier/prettier
|
|
3
|
-
import type {
|
|
4
|
-
FareProductSelector,
|
|
5
|
-
Itinerary,
|
|
6
|
-
Leg,
|
|
3
|
+
import type {
|
|
4
|
+
FareProductSelector,
|
|
5
|
+
Itinerary,
|
|
6
|
+
Leg,
|
|
7
7
|
MassUnitOption,
|
|
8
8
|
MediumRiderWhitelist,
|
|
9
9
|
Money
|
|
@@ -68,8 +68,18 @@ export interface TripDetailsProps {
|
|
|
68
68
|
* show the '~' symbol in the trip details panel
|
|
69
69
|
*/
|
|
70
70
|
showApproximateMinutesActive?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Show time on board transit vehicles, excluding transfers and waiting.
|
|
73
|
+
*/
|
|
74
|
+
showTransitTime?: boolean;
|
|
71
75
|
/**
|
|
72
76
|
* Slot for a custom component to render the expandable section for time active.
|
|
73
77
|
*/
|
|
74
78
|
TimeActiveDetails?: React.ElementType<TimeActiveDetailsProps>;
|
|
75
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Use the first transit departure and count only transfer activity between
|
|
81
|
+
* the first and last transit legs.
|
|
82
|
+
* Defaults to false. Trips without transit retain their full-journey timing.
|
|
83
|
+
*/
|
|
84
|
+
transitOnly?: boolean;
|
|
85
|
+
}
|