@opentripplanner/trip-details 9.0.5 → 9.0.6
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/README.md +3 -0
- package/lib/components/departure-date.js +43 -18
- package/lib/components/departure-date.js.map +1 -1
- package/lib/components/emissions.js +65 -30
- package/lib/components/emissions.js.map +1 -1
- package/lib/components/fares-v2-table.js +180 -142
- package/lib/components/fares-v2-table.js.map +1 -1
- package/lib/components/fares.js +125 -65
- package/lib/components/fares.js.map +1 -1
- package/lib/components/flex-booking-info.js +39 -28
- package/lib/components/flex-booking-info.js.map +1 -1
- package/lib/components/time-active.js +67 -33
- package/lib/components/time-active.js.map +1 -1
- package/lib/index.js +68 -26
- package/lib/index.js.map +1 -1
- package/lib/styled.js +94 -95
- package/lib/styled.js.map +1 -1
- package/lib/trip-detail.js +64 -38
- package/lib/trip-detail.js.map +1 -1
- package/lib/types.js +5 -1
- package/lib/types.js.map +1 -1
- package/lib/utils.js +26 -12
- package/lib/utils.js.map +1 -1
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/README.md
ADDED
|
@@ -1,25 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = DepartureDate;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _reactIntl = require("react-intl");
|
|
10
|
+
var _CalendarAlt = require("@styled-icons/fa-solid/CalendarAlt");
|
|
11
|
+
var _flat = _interopRequireDefault(require("flat"));
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
var _tripDetail = _interopRequireDefault(require("../trip-detail"));
|
|
14
|
+
var S = _interopRequireWildcard(require("../styled"));
|
|
15
|
+
var _enUS = _interopRequireDefault(require("../../i18n/en-US.yml"));
|
|
16
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
8
17
|
// Load the default messages.
|
|
9
|
-
|
|
18
|
+
|
|
10
19
|
// HACK: We should flatten the messages loaded above because
|
|
11
20
|
// the YAML loaders behave differently between webpack and our version of jest:
|
|
12
21
|
// - the yaml loader for webpack returns a nested object,
|
|
13
22
|
// - the yaml loader for jest returns messages with flattened ids.
|
|
14
|
-
const defaultMessages =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
const defaultMessages = (0, _flat.default)(_enUS.default);
|
|
24
|
+
function DepartureDate({
|
|
25
|
+
itinerary,
|
|
26
|
+
DepartureDetails
|
|
27
|
+
}) {
|
|
28
|
+
const departureDate = new Date(itinerary.startTime);
|
|
29
|
+
return /*#__PURE__*/_react.default.createElement(_tripDetail.default, {
|
|
30
|
+
className: "departure-date"
|
|
31
|
+
// Any custom description for the Departure message needs to be handled by the slot.
|
|
32
|
+
,
|
|
33
|
+
description: DepartureDetails && /*#__PURE__*/_react.default.createElement(DepartureDetails, {
|
|
34
|
+
departureDate: departureDate
|
|
35
|
+
}),
|
|
36
|
+
icon: /*#__PURE__*/_react.default.createElement(_CalendarAlt.CalendarAlt, {
|
|
37
|
+
size: 17
|
|
38
|
+
}),
|
|
39
|
+
summary: /*#__PURE__*/_react.default.createElement(S.Timing, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
40
|
+
defaultMessage: defaultMessages["otpUi.TripDetails.departure"],
|
|
41
|
+
description: "Text showing the departure date/time for a trip.",
|
|
42
|
+
id: "otpUi.TripDetails.departure",
|
|
43
|
+
values: {
|
|
44
|
+
departureDate,
|
|
45
|
+
strong: _utils.boldText
|
|
46
|
+
}
|
|
47
|
+
}))
|
|
48
|
+
});
|
|
24
49
|
}
|
|
25
50
|
//# sourceMappingURL=departure-date.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"departure-date.js","
|
|
1
|
+
{"version":3,"file":"departure-date.js","names":["_react","_interopRequireDefault","require","_reactIntl","_CalendarAlt","_flat","_utils","_tripDetail","S","_interopRequireWildcard","_enUS","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","defaultMessages","flatten","defaultEnglishMessages","DepartureDate","itinerary","DepartureDetails","departureDate","Date","startTime","createElement","className","description","icon","CalendarAlt","size","summary","Timing","FormattedMessage","defaultMessage","id","values","strong","boldText"],"sources":["../../src/components/departure-date.tsx"],"sourcesContent":["import { Itinerary } from \"@opentripplanner/types\";\nimport React, { ReactElement } from \"react\";\nimport { FormattedMessage } from \"react-intl\";\nimport { CalendarAlt } from \"@styled-icons/fa-solid/CalendarAlt\";\nimport flatten from \"flat\";\nimport { boldText } from \"../utils\";\nimport { DepartureDetailsProps } from \"../types\";\nimport TripDetail from \"../trip-detail\";\nimport * as S from \"../styled\";\n\n// Load the default messages.\nimport defaultEnglishMessages from \"../../i18n/en-US.yml\";\n\n// HACK: We should flatten the messages loaded above because\n// the YAML loaders behave differently between webpack and our version of jest:\n// - the yaml loader for webpack returns a nested object,\n// - the yaml loader for jest returns messages with flattened ids.\nconst defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);\n\ninterface DepartureDateProps {\n itinerary: Itinerary;\n DepartureDetails?: React.ElementType<DepartureDetailsProps>;\n}\n\nexport default function DepartureDate({\n itinerary,\n DepartureDetails\n}: DepartureDateProps): ReactElement {\n const departureDate = new Date(itinerary.startTime);\n return (\n <TripDetail\n className=\"departure-date\"\n // Any custom description for the Departure message needs to be handled by the slot.\n description={\n DepartureDetails && <DepartureDetails departureDate={departureDate} />\n }\n icon={<CalendarAlt size={17} />}\n summary={\n <S.Timing>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.departure\"]}\n description=\"Text showing the departure date/time for a trip.\"\n id=\"otpUi.TripDetails.departure\"\n values={{\n departureDate,\n strong: boldText\n }}\n />\n </S.Timing>\n }\n />\n );\n}\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,IAAAK,WAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,CAAA,GAAAC,uBAAA,CAAAP,OAAA;AAGA,IAAAQ,KAAA,GAAAT,sBAAA,CAAAC,OAAA;AAA0D,SAAAO,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAA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A,CAACpC,UAAA,CAAA4C,gBAAgB;MACfC,cAAc,EAAElB,eAAe,CAAC,6BAA6B,CAAE;MAC/DW,WAAW,EAAC,kDAAkD;MAC9DQ,EAAE,EAAC,6BAA6B;MAChCC,MAAM,EAAE;QACNd,aAAa;QACbe,MAAM,EAAEC;MACV;IAAE,CACH,CACO;EACX,CACF,CAAC;AAEN","ignoreList":[]}
|
|
@@ -1,39 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = Emissions;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _reactIntl = require("react-intl");
|
|
10
|
+
var _Leaf = require("@styled-icons/fa-solid/Leaf");
|
|
11
|
+
var _coreUtils = _interopRequireDefault(require("@opentripplanner/core-utils"));
|
|
12
|
+
var _flat = _interopRequireDefault(require("flat"));
|
|
13
|
+
var _utils = require("../utils");
|
|
14
|
+
var _tripDetail = _interopRequireDefault(require("../trip-detail"));
|
|
15
|
+
var S = _interopRequireWildcard(require("../styled"));
|
|
16
|
+
var _enUS = _interopRequireDefault(require("../../i18n/en-US.yml"));
|
|
17
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
9
18
|
// Load the default messages.
|
|
10
|
-
|
|
19
|
+
|
|
11
20
|
// HACK: We should flatten the messages loaded above because
|
|
12
21
|
// the YAML loaders behave differently between webpack and our version of jest:
|
|
13
22
|
// - the yaml loader for webpack returns a nested object,
|
|
14
23
|
// - the yaml loader for jest returns messages with flattened ids.
|
|
15
|
-
const defaultMessages =
|
|
24
|
+
const defaultMessages = (0, _flat.default)(_enUS.default);
|
|
16
25
|
function CO2DescriptionLink(contents) {
|
|
17
|
-
|
|
26
|
+
return /*#__PURE__*/_react.default.createElement("a", {
|
|
27
|
+
href: "https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx",
|
|
28
|
+
rel: "noopener noreferrer",
|
|
29
|
+
target: "_blank"
|
|
30
|
+
}, contents);
|
|
18
31
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
function Emissions({
|
|
33
|
+
itinerary,
|
|
34
|
+
co2Config
|
|
35
|
+
}) {
|
|
36
|
+
// Calculate CO₂ if it's not provided by the itinerary
|
|
37
|
+
const co2 = itinerary.co2 || (co2Config === null || co2Config === void 0 ? void 0 : co2Config.enabled) && _coreUtils.default.itinerary.calculateEmissions(itinerary, co2Config === null || co2Config === void 0 ? void 0 : co2Config.carbonIntensity, co2Config === null || co2Config === void 0 ? void 0 : co2Config.units);
|
|
38
|
+
if (!co2 || co2 < 0 || !(co2Config !== null && co2Config !== void 0 && co2Config.enabled)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const totalDistance = itinerary.legs.reduce((total, leg) => total + leg.distance, 0);
|
|
42
|
+
return /*#__PURE__*/_react.default.createElement(_tripDetail.default, {
|
|
43
|
+
className: "emissions",
|
|
44
|
+
icon: /*#__PURE__*/_react.default.createElement(_Leaf.Leaf, {
|
|
45
|
+
size: 17
|
|
46
|
+
}),
|
|
47
|
+
summary: /*#__PURE__*/_react.default.createElement(S.CO2Summary, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
48
|
+
defaultMessage: defaultMessages["otpUi.TripDetails.co2"],
|
|
49
|
+
description: "Text showing the quantity of CO\u2082 emitted by this trip.",
|
|
50
|
+
id: "otpUi.TripDetails.co2",
|
|
51
|
+
values: {
|
|
52
|
+
co2: /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedNumber, {
|
|
53
|
+
value: Math.round(co2)
|
|
54
|
+
// eslint-disable-next-line react/style-prop-object
|
|
55
|
+
,
|
|
56
|
+
style: "unit",
|
|
57
|
+
unit: (co2Config === null || co2Config === void 0 ? void 0 : co2Config.units) || "gram",
|
|
58
|
+
unitDisplay: "narrow"
|
|
59
|
+
}),
|
|
60
|
+
strong: _utils.boldText
|
|
61
|
+
}
|
|
62
|
+
})),
|
|
63
|
+
description: /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
64
|
+
defaultMessage: defaultMessages["otpUi.TripDetails.co2description"],
|
|
65
|
+
description: "Text explaining how the CO\u2082 emissions are calculated.",
|
|
66
|
+
id: "otpUi.TripDetails.co2description",
|
|
67
|
+
values: {
|
|
68
|
+
link: CO2DescriptionLink,
|
|
69
|
+
totalDistance
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
});
|
|
38
73
|
}
|
|
39
74
|
//# sourceMappingURL=emissions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emissions.js","
|
|
1
|
+
{"version":3,"file":"emissions.js","names":["_react","_interopRequireDefault","require","_reactIntl","_Leaf","_coreUtils","_flat","_utils","_tripDetail","S","_interopRequireWildcard","_enUS","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","defaultMessages","flatten","defaultEnglishMessages","CO2DescriptionLink","contents","createElement","href","rel","target","Emissions","itinerary","co2Config","co2","enabled","coreUtils","calculateEmissions","carbonIntensity","units","totalDistance","legs","reduce","total","leg","distance","className","icon","Leaf","size","summary","CO2Summary","FormattedMessage","defaultMessage","description","id","values","FormattedNumber","value","Math","round","style","unit","unitDisplay","strong","boldText","link"],"sources":["../../src/components/emissions.tsx"],"sourcesContent":["import React, { ReactElement, ReactNode } from \"react\";\nimport { FormattedMessage, FormattedNumber } from \"react-intl\";\nimport { Itinerary } from \"@opentripplanner/types\";\nimport { Leaf } from \"@styled-icons/fa-solid/Leaf\";\nimport coreUtils from \"@opentripplanner/core-utils\";\nimport flatten from \"flat\";\nimport { boldText } from \"../utils\";\nimport TripDetail from \"../trip-detail\";\nimport { CO2ConfigType } from \"../types\";\nimport * as S from \"../styled\";\n\n// Load the default messages.\nimport defaultEnglishMessages from \"../../i18n/en-US.yml\";\n\n// HACK: We should flatten the messages loaded above because\n// the YAML loaders behave differently between webpack and our version of jest:\n// - the yaml loader for webpack returns a nested object,\n// - the yaml loader for jest returns messages with flattened ids.\nconst defaultMessages: Record<string, string> = flatten(defaultEnglishMessages);\n\nfunction CO2DescriptionLink(contents: ReactNode): ReactElement {\n return (\n <a\n href=\"https://www.itf-oecd.org/sites/default/files/life-cycle-assessment-calculations-2020.xlsx\"\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {contents}\n </a>\n );\n}\n\nexport default function Emissions({\n itinerary,\n co2Config\n}: {\n itinerary: Itinerary;\n co2Config: CO2ConfigType;\n}): JSX.Element | null {\n // Calculate CO₂ if it's not provided by the itinerary\n const co2 =\n itinerary.co2 ||\n (co2Config?.enabled &&\n coreUtils.itinerary.calculateEmissions(\n itinerary,\n co2Config?.carbonIntensity,\n co2Config?.units\n ));\n\n if (!co2 || co2 < 0 || !co2Config?.enabled) {\n return null;\n }\n\n const totalDistance = itinerary.legs.reduce(\n (total, leg) => total + leg.distance,\n 0\n );\n\n return (\n <TripDetail\n className=\"emissions\"\n icon={<Leaf size={17} />}\n summary={\n <S.CO2Summary>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.co2\"]}\n description=\"Text showing the quantity of CO₂ emitted by this trip.\"\n id=\"otpUi.TripDetails.co2\"\n values={{\n co2: (\n <FormattedNumber\n value={Math.round(co2)}\n // eslint-disable-next-line react/style-prop-object\n style=\"unit\"\n unit={co2Config?.units || \"gram\"}\n unitDisplay=\"narrow\"\n />\n ),\n strong: boldText\n }}\n />\n </S.CO2Summary>\n }\n description={\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.co2description\"]}\n description=\"Text explaining how the CO₂ emissions are calculated.\"\n id=\"otpUi.TripDetails.co2description\"\n values={{\n link: CO2DescriptionLink,\n totalDistance\n }}\n />\n }\n />\n );\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,KAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAP,sBAAA,CAAAC,OAAA;AAEA,IAAAO,CAAA,GAAAC,uBAAA,CAAAR,OAAA;AAGA,IAAAS,KAAA,GAAAV,sBAAA,CAAAC,OAAA;AAA0D,SAAAQ,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CA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,MAAA,CAAAsB,OAAA,CAAAc,aAAA,CAACjC,UAAA,CAAA0D,gBAAgB;MACfC,cAAc,EAAE/B,eAAe,CAAC,kCAAkC,CAAE;MACpEgC,WAAW,EAAC,4DAAuD;MACnEC,EAAE,EAAC,kCAAkC;MACrCC,MAAM,EAAE;QACNU,IAAI,EAAEzC,kBAAkB;QACxBe;MACF;IAAE,CACH;EACF,CACF,CAAC;AAEN","ignoreList":[]}
|
|
@@ -1,153 +1,191 @@
|
|
|
1
|
-
|
|
2
|
-
import React from "react";
|
|
3
|
-
import coreUtils from "@opentripplanner/core-utils";
|
|
4
|
-
import { FormattedMessage, useIntl } from "react-intl";
|
|
5
|
-
import styled from "styled-components";
|
|
6
|
-
import { Transfer } from "@styled-icons/boxicons-regular/Transfer";
|
|
7
|
-
import { renderFare } from "../utils";
|
|
8
|
-
import { InvisibleA11yCaption, InvisibleA11yLabel } from "../styled";
|
|
9
|
-
// TODO: inline this import? (@opentripplanner/core-utils/src/itinerary)
|
|
10
|
-
const { getLegCost, getItineraryCost, descope, getLegRouteName } = coreUtils.itinerary;
|
|
11
|
-
const FailDash = (React.createElement(React.Fragment, null,
|
|
12
|
-
"-",
|
|
13
|
-
React.createElement(InvisibleA11yLabel, null,
|
|
14
|
-
React.createElement(FormattedMessage, { id: "otpUi.TripDetails.legMissingFareInfo" }))));
|
|
15
|
-
const TransferIcon = styled(Transfer) `
|
|
16
|
-
padding-right: 0.25ch;
|
|
17
|
-
`;
|
|
18
|
-
const StripedTable = styled.table `
|
|
19
|
-
text-align: right;
|
|
1
|
+
"use strict";
|
|
20
2
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _coreUtils = _interopRequireDefault(require("@opentripplanner/core-utils"));
|
|
10
|
+
var _reactIntl = require("react-intl");
|
|
11
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
12
|
+
var _Transfer = require("@styled-icons/boxicons-regular/Transfer");
|
|
13
|
+
var _utils = require("../utils");
|
|
14
|
+
var _styled = require("../styled");
|
|
15
|
+
/* eslint-disable no-underscore-dangle */
|
|
25
16
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
// TODO: inline this import? (@opentripplanner/core-utils/src/itinerary)
|
|
18
|
+
const {
|
|
19
|
+
getLegCost,
|
|
20
|
+
getItineraryCost,
|
|
21
|
+
descope,
|
|
22
|
+
getLegRouteName
|
|
23
|
+
} = _coreUtils.default.itinerary;
|
|
24
|
+
const FailDash = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "-", /*#__PURE__*/_react.default.createElement(_styled.InvisibleA11yLabel, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
25
|
+
id: "otpUi.TripDetails.legMissingFareInfo"
|
|
26
|
+
})));
|
|
27
|
+
const TransferIcon = (0, _styledComponents.default)(_Transfer.Transfer).withConfig({
|
|
28
|
+
displayName: "fares-v2-table__TransferIcon",
|
|
29
|
+
componentId: "sc-h3t2h2-0"
|
|
30
|
+
})(["padding-right:0.25ch;"]);
|
|
31
|
+
const StripedTable = _styledComponents.default.table.withConfig({
|
|
32
|
+
displayName: "fares-v2-table__StripedTable",
|
|
33
|
+
componentId: "sc-h3t2h2-1"
|
|
34
|
+
})(["text-align:right;tr td,tr th{padding:4px;}tr td:nth-of-type(2n + 1),tr th:nth-of-type(2n){background:#cccccc55;border-color:#cccccc55;}"]);
|
|
32
35
|
// Removes duplicates
|
|
33
36
|
const categoryReducer = (acc, cur) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
if (!acc.some(m => descope(m === null || m === void 0 ? void 0 : m.id) === descope(cur === null || cur === void 0 ? void 0 : cur.id))) {
|
|
38
|
+
acc.push(cur);
|
|
39
|
+
}
|
|
40
|
+
return acc;
|
|
38
41
|
};
|
|
42
|
+
|
|
39
43
|
// Put the preferred medium first, and then all the others alphabetical
|
|
40
|
-
const categorySorter =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
const categorySorter = favoriteId => (a, b) => {
|
|
45
|
+
const aId = descope(a === null || a === void 0 ? void 0 : a.id);
|
|
46
|
+
const bId = descope(b === null || b === void 0 ? void 0 : b.id);
|
|
47
|
+
if (favoriteId && aId === favoriteId) {
|
|
48
|
+
return -1;
|
|
49
|
+
}
|
|
50
|
+
if (favoriteId && bId === favoriteId) {
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
return aId > bId ? 1 : -1;
|
|
50
54
|
};
|
|
55
|
+
|
|
51
56
|
// TODO: This component currently can only show one type of fare per medium
|
|
52
|
-
const FaresV2Table = ({
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
57
|
+
const FaresV2Table = ({
|
|
58
|
+
legs,
|
|
59
|
+
favoriteMediumId,
|
|
60
|
+
favoriteRiderCategoryId
|
|
61
|
+
}) => {
|
|
62
|
+
const intl = (0, _reactIntl.useIntl)();
|
|
63
|
+
const transitLegs = legs.filter(leg => leg.transitLeg);
|
|
64
|
+
|
|
65
|
+
// Get all fare products across all legs
|
|
66
|
+
const fareProducts = transitLegs.flatMap(leg => leg.fareProducts);
|
|
67
|
+
|
|
68
|
+
// Reduce these into mediums and riders
|
|
69
|
+
const mediums = fareProducts.map(fp => {
|
|
70
|
+
var _fp$product;
|
|
71
|
+
return (_fp$product = fp.product) === null || _fp$product === void 0 ? void 0 : _fp$product.medium;
|
|
72
|
+
}).filter(m => m !== null).reduce(categoryReducer, []).sort(categorySorter(favoriteMediumId));
|
|
73
|
+
const riders = fareProducts.map(fp => {
|
|
74
|
+
var _fp$product2;
|
|
75
|
+
return (_fp$product2 = fp.product) === null || _fp$product2 === void 0 ? void 0 : _fp$product2.riderCategory;
|
|
76
|
+
}).filter(r => r !== null).reduce(categoryReducer, []).sort(categorySorter(favoriteRiderCategoryId));
|
|
77
|
+
|
|
78
|
+
// Ensure we have at least one rider/medium
|
|
79
|
+
if (riders.length === 0) {
|
|
80
|
+
riders.push({
|
|
81
|
+
name: "Fare",
|
|
82
|
+
id: null
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (mediums.length === 0) {
|
|
86
|
+
mediums.push({
|
|
87
|
+
name: "Regular",
|
|
88
|
+
id: null
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Keep track of seen fare ids to indicate transfers
|
|
93
|
+
const productUseIds = new Set();
|
|
94
|
+
const rows = [[/*#__PURE__*/_react.default.createElement("th", {
|
|
95
|
+
key: "faretitle",
|
|
96
|
+
style: {
|
|
97
|
+
textAlign: "left"
|
|
98
|
+
},
|
|
99
|
+
scope: "col"
|
|
100
|
+
}, /*#__PURE__*/_react.default.createElement(_styled.InvisibleA11yLabel, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
101
|
+
id: "otpUi.TripDetails.fareCategory"
|
|
102
|
+
}))), ...transitLegs.map(leg => /*#__PURE__*/_react.default.createElement("th", {
|
|
103
|
+
key: leg.tripId,
|
|
104
|
+
scope: "col"
|
|
105
|
+
}, getLegRouteName(leg))), transitLegs.length > 1 ? /*#__PURE__*/_react.default.createElement("th", {
|
|
106
|
+
key: "total",
|
|
107
|
+
style: {
|
|
108
|
+
textAlign: "right"
|
|
109
|
+
},
|
|
110
|
+
scope: "col"
|
|
111
|
+
}, /*#__PURE__*/_react.default.createElement("em", null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
112
|
+
id: "otpUi.TripDetails.total"
|
|
113
|
+
}))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null)]];
|
|
114
|
+
|
|
115
|
+
// non-transit legs don't have fares
|
|
116
|
+
transitLegs.forEach((leg, index) => {
|
|
117
|
+
mediums.forEach((medium, mediumIndex) => {
|
|
118
|
+
riders.forEach((rider, riderIndex) => {
|
|
119
|
+
var _dependentAlternateFa, _legPrice$currency, _legPrice$currency2;
|
|
120
|
+
if (!medium || !rider) return;
|
|
121
|
+
const {
|
|
122
|
+
alternateFareProducts,
|
|
123
|
+
isDependent,
|
|
124
|
+
appliedFareProduct,
|
|
125
|
+
productUseId
|
|
126
|
+
} = getLegCost(leg, descope(medium.id) || null, descope(rider.id) || null, Array.from(productUseIds));
|
|
127
|
+
const legPrice = appliedFareProduct === null || appliedFareProduct === void 0 ? void 0 : appliedFareProduct.legPrice;
|
|
128
|
+
productUseIds.add(productUseId);
|
|
129
|
+
|
|
130
|
+
// Only consider alternateFareProducts if current product is dependent
|
|
131
|
+
const dependentAlternateFareProducts = isDependent && alternateFareProducts;
|
|
132
|
+
|
|
133
|
+
// Calculate pre-tranfer amount either via alternate fare or fare-id matching (price.originalAmount)
|
|
134
|
+
const originalAmount = (dependentAlternateFareProducts === null || dependentAlternateFareProducts === void 0 || (_dependentAlternateFa = dependentAlternateFareProducts[0]) === null || _dependentAlternateFa === void 0 ? void 0 : _dependentAlternateFa.price.amount) - (legPrice === null || legPrice === void 0 ? void 0 : legPrice.amount) || (appliedFareProduct === null || appliedFareProduct === void 0 ? void 0 : appliedFareProduct.price.amount) - (legPrice === null || legPrice === void 0 ? void 0 : legPrice.amount);
|
|
135
|
+
const newCell = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, index === 0 && /*#__PURE__*/_react.default.createElement("th", {
|
|
136
|
+
style: {
|
|
137
|
+
textAlign: "left"
|
|
138
|
+
},
|
|
139
|
+
scope: "row"
|
|
140
|
+
}, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
141
|
+
id: `config.fares.media.${descope(medium.id)}`,
|
|
142
|
+
defaultMessage: medium.name
|
|
143
|
+
}), " ", /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
144
|
+
id: `config.fares.riderCategory.${descope(rider.id)}`,
|
|
145
|
+
defaultMessage: rider.name
|
|
146
|
+
})), /*#__PURE__*/_react.default.createElement("td", {
|
|
147
|
+
style: {
|
|
148
|
+
textAlign: legPrice ? "right" : "center"
|
|
149
|
+
},
|
|
150
|
+
title: !Number.isNaN(originalAmount) && originalAmount > 0 && index > 0 && intl.formatMessage({
|
|
151
|
+
description: "Text explaining the transfer discount applied to this fare.",
|
|
152
|
+
id: "otpUi.TripDetails.transferDiscountExplanation"
|
|
153
|
+
}, {
|
|
154
|
+
transferAmount: intl.formatNumber(originalAmount, {
|
|
155
|
+
currency: legPrice === null || legPrice === void 0 || (_legPrice$currency = legPrice.currency) === null || _legPrice$currency === void 0 ? void 0 : _legPrice$currency.code,
|
|
156
|
+
currencyDisplay: "narrowSymbol",
|
|
157
|
+
style: "currency"
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
}, !Number.isNaN(originalAmount) && originalAmount > 0 && index > 0 && /*#__PURE__*/_react.default.createElement(TransferIcon, {
|
|
161
|
+
size: 16
|
|
162
|
+
}), legPrice ? (0, _utils.renderFare)(legPrice === null || legPrice === void 0 || (_legPrice$currency2 = legPrice.currency) === null || _legPrice$currency2 === void 0 ? void 0 : _legPrice$currency2.code, legPrice === null || legPrice === void 0 ? void 0 : legPrice.amount) : FailDash));
|
|
163
|
+
const currentRowIndex = 1 + riderIndex + riders.length * mediumIndex;
|
|
164
|
+
if (!rows[currentRowIndex]) {
|
|
165
|
+
rows[currentRowIndex] = [];
|
|
166
|
+
}
|
|
167
|
+
rows[currentRowIndex].push(newCell);
|
|
168
|
+
|
|
169
|
+
// Generate final column
|
|
170
|
+
if (index === transitLegs.length - 1 && transitLegs.length > 1) {
|
|
171
|
+
const fare = getItineraryCost(legs, descope(medium.id) || null, descope(rider.id) || null);
|
|
172
|
+
rows[currentRowIndex].push(/*#__PURE__*/_react.default.createElement("td", {
|
|
173
|
+
style: {
|
|
174
|
+
textAlign: fare !== null && fare !== void 0 && fare.amount ? "right" : "center"
|
|
175
|
+
},
|
|
176
|
+
title: !(fare !== null && fare !== void 0 && fare.amount) && intl.formatMessage({
|
|
177
|
+
id: "otpUi.TripDetails.missingFareTotal"
|
|
178
|
+
})
|
|
179
|
+
}, /*#__PURE__*/_react.default.createElement("em", null, fare !== null && fare !== void 0 && fare.amount ? (0, _utils.renderFare)(fare === null || fare === void 0 ? void 0 : fare.currency.code, fare === null || fare === void 0 ? void 0 : fare.amount) : FailDash)));
|
|
180
|
+
}
|
|
181
|
+
});
|
|
146
182
|
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
183
|
+
});
|
|
184
|
+
return /*#__PURE__*/_react.default.createElement(StripedTable, null, /*#__PURE__*/_react.default.createElement(_styled.InvisibleA11yCaption, null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
185
|
+
id: "otpUi.TripDetails.transitFareTable"
|
|
186
|
+
})), rows.map((r, index) => /*#__PURE__*/_react.default.createElement("tr", {
|
|
187
|
+
key: index
|
|
188
|
+
}, r)));
|
|
151
189
|
};
|
|
152
|
-
|
|
190
|
+
var _default = exports.default = FaresV2Table;
|
|
153
191
|
//# sourceMappingURL=fares-v2-table.js.map
|