@opentripplanner/trip-details 2.1.0-alpha.1 → 2.1.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/__mocks__/{custom-messages.yml → custom-english-messages.yml} +7 -0
- package/__mocks__/custom-french-messages.yml +10 -0
- package/esm/fare-table.js +153 -0
- package/esm/fare-table.js.map +1 -0
- package/esm/index.js +26 -46
- package/esm/index.js.map +1 -1
- package/esm/types.js +11 -0
- package/esm/types.js.map +1 -1
- package/esm/utils.js +29 -0
- package/esm/utils.js.map +1 -0
- package/i18n/en-US.yml +7 -0
- package/i18n/fr.yml +7 -0
- package/lib/fare-table.d.ts +4 -0
- package/lib/fare-table.d.ts.map +1 -0
- package/lib/fare-table.js +160 -0
- package/lib/fare-table.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +32 -52
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +32 -11
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +18 -0
- package/lib/types.js.map +1 -1
- package/lib/utils.d.ts +13 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +41 -0
- package/lib/utils.js.map +1 -0
- package/package.json +4 -4
- package/src/TripDetails.story.tsx +61 -38
- package/src/fare-table.tsx +222 -0
- package/src/index.tsx +38 -60
- package/src/types.ts +34 -11
- package/src/utils.tsx +30 -0
- package/tsconfig.tsbuildinfo +177 -24
- package/esm/fare-detail.js +0 -111
- package/esm/fare-detail.js.map +0 -1
- package/lib/fare-detail.d.ts +0 -3
- package/lib/fare-detail.d.ts.map +0 -1
- package/lib/fare-detail.js +0 -115
- package/lib/fare-detail.js.map +0 -1
- package/src/fare-detail.tsx +0 -157
package/lib/fare-detail.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.FareDetails = void 0;
|
|
9
|
-
|
|
10
|
-
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
|
-
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
|
-
|
|
14
|
-
var _reactIntl = require("react-intl");
|
|
15
|
-
|
|
16
|
-
/* eslint-disable import/prefer-default-export */
|
|
17
|
-
const TableHeader = _styledComponents.default.thead.withConfig({
|
|
18
|
-
displayName: "fare-detail__TableHeader",
|
|
19
|
-
componentId: "sc-9025ni-0"
|
|
20
|
-
})(["th{max-width:5ch;min-width:5ch;padding:0.75em 1.5em;text-align:center;}th:nth-of-type(2n + 1){background:#cccccc22;}th.main{color:#ffffffcc;background:#333333;}"]);
|
|
21
|
-
|
|
22
|
-
const TotalRow = _styledComponents.default.tr.withConfig({
|
|
23
|
-
displayName: "fare-detail__TotalRow",
|
|
24
|
-
componentId: "sc-9025ni-1"
|
|
25
|
-
})(["border-top:2px solid #333;font-weight:600;"]);
|
|
26
|
-
|
|
27
|
-
const Table = _styledComponents.default.table.withConfig({
|
|
28
|
-
displayName: "fare-detail__Table",
|
|
29
|
-
componentId: "sc-9025ni-2"
|
|
30
|
-
})(["border-collapse:collapse;display:block;font-family:sans-serif;margin:-8px;margin-bottom:16px;padding:0;td{text-align:right;}td:nth-of-type(2n + 1){background:#cccccc22;}td.no-zebra{background:transparent;}th:first-of-type{height:40px;}"]);
|
|
31
|
-
|
|
32
|
-
const FareTypeTable = props => {
|
|
33
|
-
const {
|
|
34
|
-
header,
|
|
35
|
-
fareTotals,
|
|
36
|
-
cols,
|
|
37
|
-
legs
|
|
38
|
-
} = props;
|
|
39
|
-
return /*#__PURE__*/_react.default.createElement(Table, null, /*#__PURE__*/_react.default.createElement(TableHeader, null, /*#__PURE__*/_react.default.createElement("th", {
|
|
40
|
-
className: "main"
|
|
41
|
-
}, header), cols.map(col => /*#__PURE__*/_react.default.createElement("th", {
|
|
42
|
-
key: col.header
|
|
43
|
-
}, col.header))), legs.map((leg, index) => /*#__PURE__*/_react.default.createElement("tr", {
|
|
44
|
-
key: index
|
|
45
|
-
}, /*#__PURE__*/_react.default.createElement("td", {
|
|
46
|
-
className: "no-zebra"
|
|
47
|
-
}, leg.routeShortName), cols.map(col => {
|
|
48
|
-
var _fare$price, _legs$0$fares, _legs$0$fares$col$key, _legs$0$fares$col$key2;
|
|
49
|
-
|
|
50
|
-
const fare = leg.fares[col.key];
|
|
51
|
-
return /*#__PURE__*/_react.default.createElement("td", {
|
|
52
|
-
key: col.key
|
|
53
|
-
}, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedNumber, {
|
|
54
|
-
value: (fare === null || fare === void 0 ? void 0 : (_fare$price = fare.price) === null || _fare$price === void 0 ? void 0 : _fare$price.cents) / 100 || 0 // This isn't a "real" style prop
|
|
55
|
-
// eslint-disable-next-line react/style-prop-object
|
|
56
|
-
,
|
|
57
|
-
style: "currency",
|
|
58
|
-
currency: (fare === null || fare === void 0 ? void 0 : fare.price.currency.currencyCode) || ( // This is how the itinerary-wide currency code is calculated on the back-end
|
|
59
|
-
legs === null || legs === void 0 ? void 0 : (_legs$0$fares = legs[0].fares) === null || _legs$0$fares === void 0 ? void 0 : (_legs$0$fares$col$key = _legs$0$fares[col.key]) === null || _legs$0$fares$col$key === void 0 ? void 0 : (_legs$0$fares$col$key2 = _legs$0$fares$col$key.price) === null || _legs$0$fares$col$key2 === void 0 ? void 0 : _legs$0$fares$col$key2.currency.currencyCode),
|
|
60
|
-
currencyDisplay: "narrowSymbol"
|
|
61
|
-
}));
|
|
62
|
-
}))), /*#__PURE__*/_react.default.createElement(TotalRow, null, /*#__PURE__*/_react.default.createElement("td", {
|
|
63
|
-
className: "no-zebra"
|
|
64
|
-
}, "Total"), cols.map(col => {
|
|
65
|
-
var _fare$currency;
|
|
66
|
-
|
|
67
|
-
const fare = fareTotals[col.key];
|
|
68
|
-
return /*#__PURE__*/_react.default.createElement("td", {
|
|
69
|
-
key: col.key
|
|
70
|
-
}, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedNumber, {
|
|
71
|
-
value: ((fare === null || fare === void 0 ? void 0 : fare.cents) || 0) / 100 // This isn't a "real" style prop
|
|
72
|
-
// eslint-disable-next-line react/style-prop-object
|
|
73
|
-
,
|
|
74
|
-
style: "currency",
|
|
75
|
-
currency: fare === null || fare === void 0 ? void 0 : (_fare$currency = fare.currency) === null || _fare$currency === void 0 ? void 0 : _fare$currency.currencyCode,
|
|
76
|
-
currencyDisplay: "narrowSymbol"
|
|
77
|
-
}));
|
|
78
|
-
})));
|
|
79
|
-
}; // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const FareDetails = props => {
|
|
83
|
-
const {
|
|
84
|
-
legs,
|
|
85
|
-
transitFares,
|
|
86
|
-
layout
|
|
87
|
-
} = props;
|
|
88
|
-
const fareKeys = Object.keys(transitFares.details);
|
|
89
|
-
const legsWithFares = legs.map((leg, index) => {
|
|
90
|
-
const fares = fareKeys.reduce((prev, key) => {
|
|
91
|
-
var _transitFares$details;
|
|
92
|
-
|
|
93
|
-
const fareForKey = (_transitFares$details = transitFares.details[key]) === null || _transitFares$details === void 0 ? void 0 : _transitFares$details.find(detail => detail.legIndex === index);
|
|
94
|
-
|
|
95
|
-
if (fareForKey) {
|
|
96
|
-
prev[key] = fareForKey;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return prev;
|
|
100
|
-
}, {});
|
|
101
|
-
return { ...leg,
|
|
102
|
-
fares
|
|
103
|
-
};
|
|
104
|
-
}).filter(leg => leg.transitLeg);
|
|
105
|
-
return /*#__PURE__*/_react.default.createElement("div", null, layout.map(config => /*#__PURE__*/_react.default.createElement(FareTypeTable, {
|
|
106
|
-
header: config.header,
|
|
107
|
-
cols: config.cols,
|
|
108
|
-
key: config.header,
|
|
109
|
-
legs: legsWithFares,
|
|
110
|
-
fareTotals: transitFares.fare
|
|
111
|
-
})));
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
exports.FareDetails = FareDetails;
|
|
115
|
-
//# sourceMappingURL=fare-detail.js.map
|
package/lib/fare-detail.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fare-detail.tsx"],"names":["TableHeader","styled","thead","TotalRow","tr","Table","table","FareTypeTable","props","header","fareTotals","cols","legs","map","col","leg","index","routeShortName","fare","fares","key","price","cents","currency","currencyCode","FareDetails","transitFares","layout","fareKeys","Object","keys","details","legsWithFares","reduce","prev","fareForKey","find","detail","legIndex","filter","transitLeg","config"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AAoBA,MAAMA,WAAW,GAAGC,0BAAOC,KAAV;AAAA;AAAA;AAAA,wKAAjB;;AAgBA,MAAMC,QAAQ,GAAGF,0BAAOG,EAAV;AAAA;AAAA;AAAA,kDAAd;;AAKA,MAAMC,KAAK,GAAGJ,0BAAOK,KAAV;AAAA;AAAA;AAAA,mPAAX;;AAuBA,MAAMC,aAAa,GAAIC,KAAD,IAA4C;AAChE,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,UAAV;AAAsBC,IAAAA,IAAtB;AAA4BC,IAAAA;AAA5B,MAAqCJ,KAA3C;AACA,sBACE,6BAAC,KAAD,qBACE,6BAAC,WAAD,qBACE;AAAI,IAAA,SAAS,EAAC;AAAd,KAAsBC,MAAtB,CADF,EAEGE,IAAI,CAACE,GAAL,CAASC,GAAG,iBACX;AAAI,IAAA,GAAG,EAAEA,GAAG,CAACL;AAAb,KAAsBK,GAAG,CAACL,MAA1B,CADD,CAFH,CADF,EAOGG,IAAI,CAACC,GAAL,CAAS,CAACE,GAAD,EAAMC,KAAN,kBACR;AAAI,IAAA,GAAG,EAAEA;AAAT,kBACE;AAAI,IAAA,SAAS,EAAC;AAAd,KAA0BD,GAAG,CAACE,cAA9B,CADF,EAEGN,IAAI,C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IADD,CADH,CADF;AAaD,CAnCM","sourcesContent":["/* eslint-disable import/prefer-default-export */\nimport { Leg, Money } from \"@opentripplanner/types\";\n\nimport React from \"react\";\nimport styled from \"styled-components\";\nimport { FormattedNumber } from \"react-intl\";\nimport { FareDetailsProps } from \"./types\";\n\ntype LegWithFare = Leg & { fares: { [key: string]: { price: Money } } };\n\ninterface FareTypeTableProps {\n header: string;\n cols: {\n key: string;\n header: string;\n }[];\n legs: LegWithFare[];\n fareTotals: { [fareKey: string]: Money };\n}\n\nconst TableHeader = styled.thead`\n th {\n max-width: 5ch;\n min-width: 5ch;\n padding: 0.75em 1.5em;\n text-align: center;\n }\n th:nth-of-type(2n + 1) {\n background: #cccccc22;\n }\n th.main {\n color: #ffffffcc;\n background: #333333;\n }\n`;\n\nconst TotalRow = styled.tr`\n border-top: 2px solid #333;\n font-weight: 600;\n`;\n\nconst Table = styled.table`\n border-collapse: collapse;\n display: block;\n font-family: sans-serif;\n margin: -8px;\n /* This line can not be sorted alphabetically, because it must come after the margin rule */\n margin-bottom: 16px;\n padding: 0;\n\n td {\n text-align: right;\n }\n td:nth-of-type(2n + 1) {\n background: #cccccc22;\n }\n td.no-zebra {\n background: transparent;\n }\n th:first-of-type {\n height: 40px;\n }\n`;\n\nconst FareTypeTable = (props: FareTypeTableProps): JSX.Element => {\n const { header, fareTotals, cols, legs } = props;\n return (\n <Table>\n <TableHeader>\n <th className=\"main\">{header}</th>\n {cols.map(col => (\n <th key={col.header}>{col.header}</th>\n ))}\n </TableHeader>\n {legs.map((leg, index) => (\n <tr key={index}>\n <td className=\"no-zebra\">{leg.routeShortName}</td>\n {cols.map(col => {\n const fare = leg.fares[col.key];\n return (\n <td key={col.key}>\n <FormattedNumber\n value={fare?.price?.cents / 100 || 0}\n // This isn't a \"real\" style prop\n // eslint-disable-next-line react/style-prop-object\n style=\"currency\"\n currency={\n fare?.price.currency.currencyCode ||\n // This is how the itinerary-wide currency code is calculated on the back-end\n legs?.[0].fares?.[col.key]?.price?.currency.currencyCode\n }\n currencyDisplay=\"narrowSymbol\"\n />\n </td>\n );\n })}\n </tr>\n ))}\n <TotalRow>\n <td className=\"no-zebra\">Total</td>\n {cols.map(col => {\n const fare = fareTotals[col.key];\n return (\n <td key={col.key}>\n <FormattedNumber\n value={(fare?.cents || 0) / 100}\n // This isn't a \"real\" style prop\n // eslint-disable-next-line react/style-prop-object\n style=\"currency\"\n currency={fare?.currency?.currencyCode}\n currencyDisplay=\"narrowSymbol\"\n />\n </td>\n );\n })}\n </TotalRow>\n </Table>\n );\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport const FareDetails = (props: FareDetailsProps): JSX.Element => {\n const { legs, transitFares, layout } = props;\n const fareKeys = Object.keys(transitFares.details);\n\n const legsWithFares = legs\n .map((leg, index) => {\n const fares = fareKeys.reduce((prev, key) => {\n const fareForKey = transitFares.details[key]?.find(\n detail => detail.legIndex === index\n );\n if (fareForKey) {\n prev[key] = fareForKey;\n }\n return prev;\n }, {});\n return {\n ...leg,\n fares\n };\n })\n .filter(leg => leg.transitLeg);\n\n return (\n <div>\n {layout.map(config => (\n <FareTypeTable\n header={config.header}\n cols={config.cols}\n key={config.header}\n legs={legsWithFares}\n fareTotals={transitFares.fare}\n />\n ))}\n </div>\n );\n};\n"],"file":"fare-detail.js"}
|
package/src/fare-detail.tsx
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/prefer-default-export */
|
|
2
|
-
import { Leg, Money } from "@opentripplanner/types";
|
|
3
|
-
|
|
4
|
-
import React from "react";
|
|
5
|
-
import styled from "styled-components";
|
|
6
|
-
import { FormattedNumber } from "react-intl";
|
|
7
|
-
import { FareDetailsProps } from "./types";
|
|
8
|
-
|
|
9
|
-
type LegWithFare = Leg & { fares: { [key: string]: { price: Money } } };
|
|
10
|
-
|
|
11
|
-
interface FareTypeTableProps {
|
|
12
|
-
header: string;
|
|
13
|
-
cols: {
|
|
14
|
-
key: string;
|
|
15
|
-
header: string;
|
|
16
|
-
}[];
|
|
17
|
-
legs: LegWithFare[];
|
|
18
|
-
fareTotals: { [fareKey: string]: Money };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const TableHeader = styled.thead`
|
|
22
|
-
th {
|
|
23
|
-
max-width: 5ch;
|
|
24
|
-
min-width: 5ch;
|
|
25
|
-
padding: 0.75em 1.5em;
|
|
26
|
-
text-align: center;
|
|
27
|
-
}
|
|
28
|
-
th:nth-of-type(2n + 1) {
|
|
29
|
-
background: #cccccc22;
|
|
30
|
-
}
|
|
31
|
-
th.main {
|
|
32
|
-
color: #ffffffcc;
|
|
33
|
-
background: #333333;
|
|
34
|
-
}
|
|
35
|
-
`;
|
|
36
|
-
|
|
37
|
-
const TotalRow = styled.tr`
|
|
38
|
-
border-top: 2px solid #333;
|
|
39
|
-
font-weight: 600;
|
|
40
|
-
`;
|
|
41
|
-
|
|
42
|
-
const Table = styled.table`
|
|
43
|
-
border-collapse: collapse;
|
|
44
|
-
display: block;
|
|
45
|
-
font-family: sans-serif;
|
|
46
|
-
margin: -8px;
|
|
47
|
-
/* This line can not be sorted alphabetically, because it must come after the margin rule */
|
|
48
|
-
margin-bottom: 16px;
|
|
49
|
-
padding: 0;
|
|
50
|
-
|
|
51
|
-
td {
|
|
52
|
-
text-align: right;
|
|
53
|
-
}
|
|
54
|
-
td:nth-of-type(2n + 1) {
|
|
55
|
-
background: #cccccc22;
|
|
56
|
-
}
|
|
57
|
-
td.no-zebra {
|
|
58
|
-
background: transparent;
|
|
59
|
-
}
|
|
60
|
-
th:first-of-type {
|
|
61
|
-
height: 40px;
|
|
62
|
-
}
|
|
63
|
-
`;
|
|
64
|
-
|
|
65
|
-
const FareTypeTable = (props: FareTypeTableProps): JSX.Element => {
|
|
66
|
-
const { header, fareTotals, cols, legs } = props;
|
|
67
|
-
return (
|
|
68
|
-
<Table>
|
|
69
|
-
<TableHeader>
|
|
70
|
-
<th className="main">{header}</th>
|
|
71
|
-
{cols.map(col => (
|
|
72
|
-
<th key={col.header}>{col.header}</th>
|
|
73
|
-
))}
|
|
74
|
-
</TableHeader>
|
|
75
|
-
{legs.map((leg, index) => (
|
|
76
|
-
<tr key={index}>
|
|
77
|
-
<td className="no-zebra">{leg.routeShortName}</td>
|
|
78
|
-
{cols.map(col => {
|
|
79
|
-
const fare = leg.fares[col.key];
|
|
80
|
-
return (
|
|
81
|
-
<td key={col.key}>
|
|
82
|
-
<FormattedNumber
|
|
83
|
-
value={fare?.price?.cents / 100 || 0}
|
|
84
|
-
// This isn't a "real" style prop
|
|
85
|
-
// eslint-disable-next-line react/style-prop-object
|
|
86
|
-
style="currency"
|
|
87
|
-
currency={
|
|
88
|
-
fare?.price.currency.currencyCode ||
|
|
89
|
-
// This is how the itinerary-wide currency code is calculated on the back-end
|
|
90
|
-
legs?.[0].fares?.[col.key]?.price?.currency.currencyCode
|
|
91
|
-
}
|
|
92
|
-
currencyDisplay="narrowSymbol"
|
|
93
|
-
/>
|
|
94
|
-
</td>
|
|
95
|
-
);
|
|
96
|
-
})}
|
|
97
|
-
</tr>
|
|
98
|
-
))}
|
|
99
|
-
<TotalRow>
|
|
100
|
-
<td className="no-zebra">Total</td>
|
|
101
|
-
{cols.map(col => {
|
|
102
|
-
const fare = fareTotals[col.key];
|
|
103
|
-
return (
|
|
104
|
-
<td key={col.key}>
|
|
105
|
-
<FormattedNumber
|
|
106
|
-
value={(fare?.cents || 0) / 100}
|
|
107
|
-
// This isn't a "real" style prop
|
|
108
|
-
// eslint-disable-next-line react/style-prop-object
|
|
109
|
-
style="currency"
|
|
110
|
-
currency={fare?.currency?.currencyCode}
|
|
111
|
-
currencyDisplay="narrowSymbol"
|
|
112
|
-
/>
|
|
113
|
-
</td>
|
|
114
|
-
);
|
|
115
|
-
})}
|
|
116
|
-
</TotalRow>
|
|
117
|
-
</Table>
|
|
118
|
-
);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
122
|
-
export const FareDetails = (props: FareDetailsProps): JSX.Element => {
|
|
123
|
-
const { legs, transitFares, layout } = props;
|
|
124
|
-
const fareKeys = Object.keys(transitFares.details);
|
|
125
|
-
|
|
126
|
-
const legsWithFares = legs
|
|
127
|
-
.map((leg, index) => {
|
|
128
|
-
const fares = fareKeys.reduce((prev, key) => {
|
|
129
|
-
const fareForKey = transitFares.details[key]?.find(
|
|
130
|
-
detail => detail.legIndex === index
|
|
131
|
-
);
|
|
132
|
-
if (fareForKey) {
|
|
133
|
-
prev[key] = fareForKey;
|
|
134
|
-
}
|
|
135
|
-
return prev;
|
|
136
|
-
}, {});
|
|
137
|
-
return {
|
|
138
|
-
...leg,
|
|
139
|
-
fares
|
|
140
|
-
};
|
|
141
|
-
})
|
|
142
|
-
.filter(leg => leg.transitLeg);
|
|
143
|
-
|
|
144
|
-
return (
|
|
145
|
-
<div>
|
|
146
|
-
{layout.map(config => (
|
|
147
|
-
<FareTypeTable
|
|
148
|
-
header={config.header}
|
|
149
|
-
cols={config.cols}
|
|
150
|
-
key={config.header}
|
|
151
|
-
legs={legsWithFares}
|
|
152
|
-
fareTotals={transitFares.fare}
|
|
153
|
-
/>
|
|
154
|
-
))}
|
|
155
|
-
</div>
|
|
156
|
-
);
|
|
157
|
-
};
|