@opentripplanner/trip-details 2.0.0 → 2.1.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/fare-detail.js +111 -0
- package/esm/fare-detail.js.map +1 -0
- package/esm/index.js +24 -19
- package/esm/index.js.map +1 -1
- package/i18n/en-US.yml +6 -5
- package/i18n/fr.yml +6 -5
- package/lib/fare-detail.d.ts +3 -0
- package/lib/fare-detail.d.ts.map +1 -0
- package/lib/fare-detail.js +115 -0
- package/lib/fare-detail.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +25 -18
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +15 -14
- package/lib/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/TripDetails.story.tsx +123 -124
- package/src/fare-detail.tsx +157 -0
- package/src/index.tsx +25 -17
- package/src/types.ts +15 -14
- package/tsconfig.tsbuildinfo +77 -124
package/lib/index.js
CHANGED
|
@@ -28,6 +28,8 @@ var _PhoneVolume = require("@styled-icons/fa-solid/PhoneVolume");
|
|
|
28
28
|
|
|
29
29
|
var _Route = require("@styled-icons/fa-solid/Route");
|
|
30
30
|
|
|
31
|
+
var _fareDetail = require("./fare-detail");
|
|
32
|
+
|
|
31
33
|
var S = _interopRequireWildcard(require("./styled"));
|
|
32
34
|
|
|
33
35
|
exports.Styled = S;
|
|
@@ -40,7 +42,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
40
42
|
|
|
41
43
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
42
44
|
|
|
43
|
-
//
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
46
|
+
// @ts-ignore FIXME: Create TypeScript types for core-utils packages.
|
|
44
47
|
// Load the default messages.
|
|
45
48
|
// HACK: We should flatten the messages loaded above because
|
|
46
49
|
// the YAML loaders behave differently between webpack and our version of jest:
|
|
@@ -145,7 +148,7 @@ const TransitFare = ({
|
|
|
145
148
|
values: {
|
|
146
149
|
name: fareKeyNameMap[fareKey] || fareNameFallback || fareKey,
|
|
147
150
|
strong: boldText,
|
|
148
|
-
value: renderFare(currentFare.currencyCode, currentFare.
|
|
151
|
+
value: renderFare(currentFare.currency.currencyCode, currentFare.cents / 100)
|
|
149
152
|
}
|
|
150
153
|
}));
|
|
151
154
|
};
|
|
@@ -159,25 +162,21 @@ function TripDetails({
|
|
|
159
162
|
className = "",
|
|
160
163
|
DepartureDetails = null,
|
|
161
164
|
defaultFareKey = "regular",
|
|
162
|
-
FareDetails = null,
|
|
163
165
|
fareKeyNameMap = {},
|
|
164
|
-
itinerary
|
|
166
|
+
itinerary,
|
|
167
|
+
fareDetailsLayout
|
|
165
168
|
}) {
|
|
169
|
+
var _itinerary$fare;
|
|
170
|
+
|
|
166
171
|
// process the transit fare
|
|
167
|
-
const fareResult = _coreUtils.default.itinerary.
|
|
172
|
+
const fareResult = _coreUtils.default.itinerary.calculateTncFares(itinerary);
|
|
168
173
|
|
|
169
174
|
const {
|
|
170
175
|
maxTNCFare,
|
|
171
176
|
minTNCFare,
|
|
172
|
-
tncCurrencyCode
|
|
173
|
-
transitFares
|
|
177
|
+
tncCurrencyCode
|
|
174
178
|
} = fareResult;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (!transitFares[defaultFareKey]) {
|
|
178
|
-
defaultFare = "regular";
|
|
179
|
-
}
|
|
180
|
-
|
|
179
|
+
const transitFares = itinerary === null || itinerary === void 0 ? void 0 : (_itinerary$fare = itinerary.fare) === null || _itinerary$fare === void 0 ? void 0 : _itinerary$fare.fare;
|
|
181
180
|
let companies = "";
|
|
182
181
|
itinerary.legs.forEach(leg => {
|
|
183
182
|
if (leg.tncData) {
|
|
@@ -188,9 +187,16 @@ function TripDetails({
|
|
|
188
187
|
const fareKeys = transitFares && Object.keys(transitFares).sort();
|
|
189
188
|
|
|
190
189
|
if (transitFares && fareKeys.length > 0) {
|
|
191
|
-
|
|
190
|
+
let defaultFare = defaultFareKey;
|
|
191
|
+
|
|
192
|
+
if (!transitFares[defaultFareKey]) {
|
|
193
|
+
defaultFare = "regular";
|
|
194
|
+
} // Depending on if there are additional fares to display either render a <span> or a <details>
|
|
195
|
+
|
|
196
|
+
|
|
192
197
|
const TransitFareWrapper = transitFares && fareKeys.length > 1 ? S.TransitFare : S.TransitFareSingle;
|
|
193
198
|
fare = /*#__PURE__*/_react.default.createElement(S.Fare, null, /*#__PURE__*/_react.default.createElement(TransitFareWrapper, null, /*#__PURE__*/_react.default.createElement("summary", {
|
|
199
|
+
role: "button",
|
|
194
200
|
style: {
|
|
195
201
|
display: fareKeys.length > 1 ? "list-item" : ""
|
|
196
202
|
}
|
|
@@ -268,11 +274,12 @@ function TripDetails({
|
|
|
268
274
|
}
|
|
269
275
|
}))
|
|
270
276
|
}), fare && /*#__PURE__*/_react.default.createElement(_tripDetail.default // Any custom description for the transit fare needs to be handled by the slot.
|
|
277
|
+
// TODO: add leg info
|
|
271
278
|
, {
|
|
272
|
-
description:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
279
|
+
description: fareDetailsLayout && Object.keys(itinerary.fare.details).length > 0 && /*#__PURE__*/_react.default.createElement(_fareDetail.FareDetails, {
|
|
280
|
+
transitFares: itinerary.fare,
|
|
281
|
+
legs: itinerary.legs,
|
|
282
|
+
layout: fareDetailsLayout
|
|
276
283
|
}),
|
|
277
284
|
icon: /*#__PURE__*/_react.default.createElement(_MoneyBillAlt.MoneyBillAlt, {
|
|
278
285
|
size: 17
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.tsx"],"names":["defaultMessages","defaultEnglishMessages","boldText","contents","renderFare","currencyCode","fare","dietaryLink","getFlexMessageValues","info","hasLeadTime","coreUtils","itinerary","isAdvanceBookingRequired","hasPhone","contactInfo","phoneNumber","leadDays","latestBookingTime","daysPrior","DefaultCaloriesDetails","bikeSeconds","calories","walkSeconds","bikeMinutes","Math","round","strong","walkMinutes","TransitFare","fareKey","fareNameFallback","fareKeyNameMap","transitFares","currentFare","name","value","transitFare","TripDetails","CaloriesDetails","className","DepartureDetails","defaultFareKey","FareDetails","fareResult","calculateFares","maxTNCFare","minTNCFare","tncCurrencyCode","defaultFare","companies","legs","forEach","leg","tncData","company","fareKeys","Object","keys","sort","length","TransitFareWrapper","S","TransitFareSingle","display","map","toLowerCase","departureDate","Date","startTime","bikeDuration","caloriesBurned","walkDuration","calculatePhysicalActivity","containsFlex","some","isFlex","pickupBookingInfo","filter","dropOffBookingInfo","pickupMessage","dropOffMessage"],"mappings":";;;;;;;;;;AAAA;;AAEA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AACA;;AASA;;;;;;AAtBA;AAqBA;AAGA;AACA;AACA;AACA;AACA,MAAMA,eAAuC,GAAG,mBAAQC,aAAR,CAAhD;AAEA;AACA;AACA;AACA;;AACA,SAASC,QAAT,CAAkBC,QAAlB,EAAwD;AACtD,sBAAO,6CAASA,QAAT,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,UAAT,CAAoBC,YAApB,EAA0CC,IAA1C,EAAsE;AACpE,sBACE,6BAAC,0BAAD;AACE,IAAA,QAAQ,EAAED,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,2BAAD;AACE,MAAA,cAAc,EACZhF,eAAe,CAAC,qCAAD,CAFnB;AAIE,MAAA,WAAW,EAAC,6EAJd;AAKE,MAAA,EAAE,EAAC,qCALL;AAME,MAAA,MAAM,EAAEQ,oBAAoB,CAACC,IAAD;AAN9B,MADF,CAJJ;AAeE,IAAA,WAAW,EAAEA,IAAI,CAACuE;AAfpB,IADF,CAnFJ,EAsGGD,kBAAkB,IACjBA,kBAAkB,CAACd,GAAnB,CAAuBxD,IAAI,iBACzB,6BAAC,mBAAD;AACE,IAAA,WAAW,EAAEA,IAAI,CAACwE,cADpB;AAEE,IAAA,IAAI,EACFtE,mBAAUC,SAAV,CAAoBC,wBAApB,CAA6CJ,IAA7C,iBACE,6BAAC,wBAAD;AAAa,MAAA,IAAI,EAAE;AAAnB,MADF,gBAGE,6BAAC,oBAAD;AAAW,MAAA,IAAI,EAAE;AAAjB,MANN;AASE,IAAA,GAAG,EAAEA,IAAI,CAACwE,cATZ;AAUE,IAAA,OAAO,eACL,6BAAC,CAAD,CAAG,kBAAH,qBACE,6BAAC,2BAAD;AACE,MAAA,cAAc,EACZjF,eAAe,CAAC,sCAAD,CAFnB;AAIE,MAAA,WAAW,EAAC,oEAJd;AAKE,MAAA,EAAE,EAAC,sCALL;AAME,MAAA,MAAM,EAAEQ,oBAAoB,CAACC,IAAD;AAN9B,MADF;AAXJ,IADF,CAvGJ,CARF,CADF;AA4ID;;eAEc6B,W,EAEf","sourcesContent":["import flatten from \"flat\";\n// @ts-expect-error FIXME: Create TypeScript types for core-utils packages.\nimport coreUtils from \"@opentripplanner/core-utils\";\nimport { FlexBookingInfo } from \"@opentripplanner/types\";\nimport React, { ReactElement } from \"react\";\nimport { FormattedMessage, FormattedNumber } from \"react-intl\";\nimport { CalendarAlt } from \"@styled-icons/fa-solid/CalendarAlt\";\nimport { HandPaper } from \"@styled-icons/fa-solid/HandPaper\";\nimport { Heartbeat } from \"@styled-icons/fa-solid/Heartbeat\";\nimport { MoneyBillAlt } from \"@styled-icons/fa-solid/MoneyBillAlt\";\nimport { PhoneVolume } from \"@styled-icons/fa-solid/PhoneVolume\";\nimport { Route } from \"@styled-icons/fa-solid/Route\";\n\nimport * as S from \"./styled\";\nimport TripDetail from \"./trip-detail\";\n\nimport {\n CaloriesDetailsProps,\n TransitFareProps,\n TripDetailsProps\n} from \"./types\";\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\n/**\n * Format text bold (used with FormattedMessage).\n */\n// TODO: Find a better place for this utility.\nfunction boldText(contents: ReactElement): ReactElement {\n return <strong>{contents}</strong>;\n}\n\n/**\n * Render formatted fare.\n * @param currencyCode The ISO currency code to use (USD, GBP, EUR).\n * @param fare The fare value, in currency units, to be shown.\n * @returns The formatted fare value according to the selected locale.\n */\nfunction renderFare(currencyCode: string, fare: number): ReactElement {\n return (\n <FormattedNumber\n currency={currencyCode}\n // For dollars in locales such as 'fr',\n // this will limit the display to just the dollar sign\n // (otherwise it will render e.g. '2,50 $US' instead of '2,50 $').\n currencyDisplay=\"narrowSymbol\"\n value={fare}\n // eslint-disable-next-line react/style-prop-object\n style=\"currency\"\n />\n );\n}\n\n/**\n * Helper function to specify the link to dietary table.\n */\nfunction dietaryLink(contents: ReactElement): ReactElement {\n return (\n <a\n href=\"https://health.gov/dietaryguidelines/dga2005/document/html/chapter3.htm#table4\"\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {contents}\n </a>\n );\n}\n\n/**\n * Helper function that assembles values for flex pickup/dropoff messages.\n */\nfunction getFlexMessageValues(info: FlexBookingInfo) {\n return {\n hasLeadTime: coreUtils.itinerary.isAdvanceBookingRequired(info),\n hasPhone: !!info?.contactInfo?.phoneNumber,\n leadDays: info.latestBookingTime.daysPrior,\n phoneNumber: info?.contactInfo?.phoneNumber\n };\n}\n\n/**\n * Default rendering if no component is provided for the CaloriesDetails\n * slot in the TripDetails component.\n */\nfunction DefaultCaloriesDetails({\n bikeSeconds,\n calories,\n walkSeconds\n}: CaloriesDetailsProps): ReactElement {\n return (\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.caloriesDescription\"]}\n description=\"Text describing how the calories relate to the walking and biking duration of a trip.\"\n id=\"otpUi.TripDetails.caloriesDescription\"\n values={{\n bikeMinutes: Math.round(bikeSeconds / 60),\n calories: Math.round(calories),\n dietaryLink,\n strong: boldText,\n walkMinutes: Math.round(walkSeconds / 60)\n }}\n />\n );\n}\n\n/**\n * Helper component that renders a transit fare entry.\n */\nconst TransitFare = ({\n fareKey,\n fareNameFallback,\n fareKeyNameMap,\n transitFares\n}: TransitFareProps): ReactElement => {\n const currentFare = transitFares[fareKey];\n\n return (\n <span>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.transitFareEntry\"]}\n description=\"Text showing the price of tickets on public transportation.\"\n id=\"otpUi.TripDetails.transitFareEntry\"\n values={{\n name: fareKeyNameMap[fareKey] || fareNameFallback || fareKey,\n strong: boldText,\n value: renderFare(\n currentFare.currencyCode,\n currentFare.transitFare / 100\n )\n }}\n />\n </span>\n );\n};\n\n/**\n * Renders trip details such as departure instructions, fare amount, and calories spent.\n */\nexport function TripDetails({\n CaloriesDetails = DefaultCaloriesDetails,\n className = \"\",\n DepartureDetails = null,\n defaultFareKey = \"regular\",\n FareDetails = null,\n fareKeyNameMap = {},\n itinerary\n}: TripDetailsProps): ReactElement {\n // process the transit fare\n const fareResult = coreUtils.itinerary.calculateFares(itinerary, true);\n const { maxTNCFare, minTNCFare, tncCurrencyCode, transitFares } = fareResult;\n\n let defaultFare = defaultFareKey;\n if (!transitFares[defaultFareKey]) {\n defaultFare = \"regular\";\n }\n\n let companies = \"\";\n itinerary.legs.forEach(leg => {\n if (leg.tncData) {\n companies = leg.tncData.company;\n }\n });\n let fare;\n\n const fareKeys = transitFares && Object.keys(transitFares).sort();\n\n if (transitFares && fareKeys.length > 0) {\n // Depending on if there are additional fares to display either render a <span> or a <details>\n const TransitFareWrapper =\n transitFares && fareKeys.length > 1 ? S.TransitFare : S.TransitFareSingle;\n\n fare = (\n <S.Fare>\n <TransitFareWrapper>\n <summary style={{ display: fareKeys.length > 1 ? \"list-item\" : \"\" }}>\n <TransitFare\n fareNameFallback={\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.TripDetails.transitFare\"]\n }\n description=\"Text showing the price of tickets on public transportation.\"\n id=\"otpUi.TripDetails.transitFare\"\n />\n }\n fareKey={defaultFare}\n fareKeyNameMap={fareKeyNameMap}\n transitFares={transitFares}\n />\n </summary>\n {fareKeys.map(fareKey => {\n // Don't show the default fare twice!\n if (fareKey === defaultFare) {\n return null;\n }\n return (\n <TransitFare\n fareKey={fareKey}\n key={fareKey}\n fareKeyNameMap={fareKeyNameMap}\n transitFares={transitFares}\n />\n );\n })}\n </TransitFareWrapper>\n {minTNCFare !== 0 && (\n <S.TNCFare>\n <br />\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.tncFare\"]}\n description=\"Text showing the price paid to transportation network companies.\"\n id=\"otpUi.TripDetails.tncFare\"\n values={{\n companies: (\n // S.TNCFareCompanies capitalizes the TNC company ID (e.g. \"COMPANY\")\n // after it is converted to lowercase, so it renders as \"Company\".\n <S.TNCFareCompanies>\n {companies.toLowerCase()}\n </S.TNCFareCompanies>\n ),\n maxTNCFare: renderFare(tncCurrencyCode, maxTNCFare),\n minTNCFare: renderFare(tncCurrencyCode, minTNCFare),\n strong: boldText\n }}\n />\n </S.TNCFare>\n )}\n </S.Fare>\n );\n }\n\n const departureDate = new Date(itinerary.startTime);\n\n // Compute calories burned.\n const {\n bikeDuration,\n caloriesBurned,\n walkDuration\n } = coreUtils.itinerary.calculatePhysicalActivity(itinerary);\n\n // Parse flex info and generate appropriate strings\n const containsFlex = itinerary.legs.some(coreUtils.itinerary.isFlex);\n const pickupBookingInfo = itinerary.legs\n .map(leg => leg.pickupBookingInfo)\n .filter(info => !!info);\n const dropOffBookingInfo = itinerary.legs\n .map(leg => leg.dropOffBookingInfo)\n .filter(info => !!info);\n\n return (\n <S.TripDetails className={className}>\n <S.TripDetailsHeader>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.title\"]}\n description=\"Title (heading) text of the component.\"\n id=\"otpUi.TripDetails.title\"\n />\n </S.TripDetailsHeader>\n <S.TripDetailsBody>\n <TripDetail\n // Any custom description for the Departure message needs to be handled by the slot.\n description={\n DepartureDetails && (\n <DepartureDetails departureDate={departureDate} />\n )\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 {fare && (\n <TripDetail\n // Any custom description for the transit fare needs to be handled by the slot.\n description={\n FareDetails && (\n <FareDetails\n maxTNCFare={maxTNCFare}\n minTNCFare={minTNCFare}\n transitFares={transitFares}\n />\n )\n }\n icon={<MoneyBillAlt size={17} />}\n summary={fare}\n />\n )}\n {caloriesBurned > 0 && (\n <TripDetail\n icon={<Heartbeat size={17} />}\n summary={\n <S.CaloriesSummary>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.calories\"]}\n description=\"Text showing the number of calories for the walking and biking legs of a trip.\"\n id=\"otpUi.TripDetails.calories\"\n values={{\n calories: caloriesBurned,\n strong: boldText\n }}\n />\n </S.CaloriesSummary>\n }\n description={\n CaloriesDetails && (\n <CaloriesDetails\n bikeSeconds={bikeDuration}\n calories={caloriesBurned}\n walkSeconds={walkDuration}\n />\n )\n }\n />\n )}\n {containsFlex && (\n <TripDetail\n summary={\n <S.FlexSummary>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.TripDetails.tripIncludesFlex\"]\n }\n description=\"Text stating that portions of the trip include a flex (on-demand) transit service.\"\n id=\"otpUi.TripDetails.tripIncludesFlex\"\n />\n </S.FlexSummary>\n }\n icon={<Route size={17} />}\n />\n )}\n {pickupBookingInfo &&\n pickupBookingInfo.map(info => (\n <TripDetail\n key={info.pickupMessage}\n icon={<PhoneVolume size={17} />}\n summary={\n <S.FlexPickupSummary>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.TripDetails.flexPickupMessage\"]\n }\n description=\"Instructions for booking and boarding the flex (on-demand) transit service.\"\n id=\"otpUi.TripDetails.flexPickupMessage\"\n values={getFlexMessageValues(info)}\n />\n </S.FlexPickupSummary>\n }\n description={info.pickupMessage}\n />\n ))}\n {dropOffBookingInfo &&\n dropOffBookingInfo.map(info => (\n <TripDetail\n description={info.dropOffMessage}\n icon={\n coreUtils.itinerary.isAdvanceBookingRequired(info) ? (\n <PhoneVolume size={17} />\n ) : (\n <HandPaper size={17} />\n )\n }\n key={info.dropOffMessage}\n summary={\n <S.FlexDropOffSummary>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.TripDetails.flexDropOffMessage\"]\n }\n description=\"Instructions for getting off the flex (on-demand) transit service.\"\n id=\"otpUi.TripDetails.flexDropOffMessage\"\n values={getFlexMessageValues(info)}\n />\n </S.FlexDropOffSummary>\n }\n />\n ))}\n </S.TripDetailsBody>\n </S.TripDetails>\n );\n}\n\nexport default TripDetails;\n\n// Rename styled components for export\nexport { S as Styled };\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["defaultMessages","defaultEnglishMessages","boldText","contents","renderFare","currencyCode","fare","dietaryLink","getFlexMessageValues","info","hasLeadTime","coreUtils","itinerary","isAdvanceBookingRequired","hasPhone","contactInfo","phoneNumber","leadDays","latestBookingTime","daysPrior","DefaultCaloriesDetails","bikeSeconds","calories","walkSeconds","bikeMinutes","Math","round","strong","walkMinutes","TransitFare","fareKey","fareNameFallback","fareKeyNameMap","transitFares","currentFare","name","value","currency","cents","TripDetails","CaloriesDetails","className","DepartureDetails","defaultFareKey","fareDetailsLayout","fareResult","calculateTncFares","maxTNCFare","minTNCFare","tncCurrencyCode","companies","legs","forEach","leg","tncData","company","fareKeys","Object","keys","sort","length","defaultFare","TransitFareWrapper","S","TransitFareSingle","display","map","toLowerCase","departureDate","Date","startTime","bikeDuration","caloriesBurned","walkDuration","calculatePhysicalActivity","containsFlex","some","isFlex","pickupBookingInfo","filter","dropOffBookingInfo","details","pickupMessage","dropOffMessage"],"mappings":";;;;;;;;;;AAAA;;AAGA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AACA;;AASA;;;;;;AAxBA;AACA;AAsBA;AAGA;AACA;AACA;AACA;AACA,MAAMA,eAAuC,GAAG,mBAAQC,aAAR,CAAhD;AAEA;AACA;AACA;AACA;;AACA,SAASC,QAAT,CAAkBC,QAAlB,EAAwD;AACtD,sBAAO,6CAASA,QAAT,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,UAAT,CAAoBC,YAApB,EAA0CC,IAA1C,EAAsE;AACpE,sBACE,6BAAC,0BAAD;AACE,IAAA,QAAQ,EAAED,YADZ,CAEE;AACA;AACA;AAJF;AAKE,IAAA,eAAe,EAAC,cALlB;AAME,IAAA,KAAK,EAAEC,IANT,CAOE;AAPF;AAQE,IAAA,KAAK,EAAC;AARR,IADF;AAYD;AAED;AACA;AACA;;;AACA,SAASC,WAAT,CAAqBJ,QAArB,EAA2D;AACzD,sBACE;AACE,IAAA,IAAI,EAAC,gFADP;AAEE,IAAA,GAAG,EAAC,qBAFN;AAGE,IAAA,MAAM,EAAC;AAHT,KAKGA,QALH,CADF;AASD;AAED;AACA;AACA;;;AACA,SAASK,oBAAT,CAA8BC,IAA9B,EAAqD;AAAA;;AACnD,SAAO;AACLC,IAAAA,WAAW,EAAEC,m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ADF,CAJJ;AAeE,IAAA,WAAW,EAAEA,IAAI,CAACyE;AAfpB,IADF,CArFJ,EAwGGF,kBAAkB,IACjBA,kBAAkB,CAACd,GAAnB,CAAuBzD,IAAI,iBACzB,6BAAC,mBAAD;AACE,IAAA,WAAW,EAAEA,IAAI,CAAC0E,cADpB;AAEE,IAAA,IAAI,EACFxE,mBAAUC,SAAV,CAAoBC,wBAApB,CAA6CJ,IAA7C,iBACE,6BAAC,wBAAD;AAAa,MAAA,IAAI,EAAE;AAAnB,MADF,gBAGE,6BAAC,oBAAD;AAAW,MAAA,IAAI,EAAE;AAAjB,MANN;AASE,IAAA,GAAG,EAAEA,IAAI,CAAC0E,cATZ;AAUE,IAAA,OAAO,eACL,6BAAC,CAAD,CAAG,kBAAH,qBACE,6BAAC,2BAAD;AACE,MAAA,cAAc,EACZnF,eAAe,CAAC,sCAAD,CAFnB;AAIE,MAAA,WAAW,EAAC,oEAJd;AAKE,MAAA,EAAE,EAAC,sCALL;AAME,MAAA,MAAM,EAAEQ,oBAAoB,CAACC,IAAD;AAN9B,MADF;AAXJ,IADF,CAzGJ,CARF,CADF;AA8ID;;eAEc8B,W,EAEf","sourcesContent":["import flatten from \"flat\";\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore FIXME: Create TypeScript types for core-utils packages.\nimport coreUtils from \"@opentripplanner/core-utils\";\nimport { FlexBookingInfo } from \"@opentripplanner/types\";\nimport React, { ReactElement } from \"react\";\nimport { FormattedMessage, FormattedNumber } from \"react-intl\";\nimport { CalendarAlt } from \"@styled-icons/fa-solid/CalendarAlt\";\nimport { HandPaper } from \"@styled-icons/fa-solid/HandPaper\";\nimport { Heartbeat } from \"@styled-icons/fa-solid/Heartbeat\";\nimport { MoneyBillAlt } from \"@styled-icons/fa-solid/MoneyBillAlt\";\nimport { PhoneVolume } from \"@styled-icons/fa-solid/PhoneVolume\";\nimport { Route } from \"@styled-icons/fa-solid/Route\";\nimport { FareDetails } from \"./fare-detail\";\n\nimport * as S from \"./styled\";\nimport TripDetail from \"./trip-detail\";\n\nimport {\n CaloriesDetailsProps,\n TransitFareProps,\n TripDetailsProps\n} from \"./types\";\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\n/**\n * Format text bold (used with FormattedMessage).\n */\n// TODO: Find a better place for this utility.\nfunction boldText(contents: ReactElement): ReactElement {\n return <strong>{contents}</strong>;\n}\n\n/**\n * Render formatted fare.\n * @param currencyCode The ISO currency code to use (USD, GBP, EUR).\n * @param fare The fare value, in currency units, to be shown.\n * @returns The formatted fare value according to the selected locale.\n */\nfunction renderFare(currencyCode: string, fare: number): ReactElement {\n return (\n <FormattedNumber\n currency={currencyCode}\n // For dollars in locales such as 'fr',\n // this will limit the display to just the dollar sign\n // (otherwise it will render e.g. '2,50 $US' instead of '2,50 $').\n currencyDisplay=\"narrowSymbol\"\n value={fare}\n // eslint-disable-next-line react/style-prop-object\n style=\"currency\"\n />\n );\n}\n\n/**\n * Helper function to specify the link to dietary table.\n */\nfunction dietaryLink(contents: ReactElement): ReactElement {\n return (\n <a\n href=\"https://health.gov/dietaryguidelines/dga2005/document/html/chapter3.htm#table4\"\n rel=\"noopener noreferrer\"\n target=\"_blank\"\n >\n {contents}\n </a>\n );\n}\n\n/**\n * Helper function that assembles values for flex pickup/dropoff messages.\n */\nfunction getFlexMessageValues(info: FlexBookingInfo) {\n return {\n hasLeadTime: coreUtils.itinerary.isAdvanceBookingRequired(info),\n hasPhone: !!info?.contactInfo?.phoneNumber,\n leadDays: info.latestBookingTime.daysPrior,\n phoneNumber: info?.contactInfo?.phoneNumber\n };\n}\n\n/**\n * Default rendering if no component is provided for the CaloriesDetails\n * slot in the TripDetails component.\n */\nfunction DefaultCaloriesDetails({\n bikeSeconds,\n calories,\n walkSeconds\n}: CaloriesDetailsProps): ReactElement {\n return (\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.caloriesDescription\"]}\n description=\"Text describing how the calories relate to the walking and biking duration of a trip.\"\n id=\"otpUi.TripDetails.caloriesDescription\"\n values={{\n bikeMinutes: Math.round(bikeSeconds / 60),\n calories: Math.round(calories),\n dietaryLink,\n strong: boldText,\n walkMinutes: Math.round(walkSeconds / 60)\n }}\n />\n );\n}\n\n/**\n * Helper component that renders a transit fare entry.\n */\nconst TransitFare = ({\n fareKey,\n fareNameFallback,\n fareKeyNameMap,\n transitFares\n}: TransitFareProps): ReactElement => {\n const currentFare = transitFares[fareKey];\n\n return (\n <span>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.transitFareEntry\"]}\n description=\"Text showing the price of tickets on public transportation.\"\n id=\"otpUi.TripDetails.transitFareEntry\"\n values={{\n name: fareKeyNameMap[fareKey] || fareNameFallback || fareKey,\n strong: boldText,\n value: renderFare(\n currentFare.currency.currencyCode,\n currentFare.cents / 100\n )\n }}\n />\n </span>\n );\n};\n\n/**\n * Renders trip details such as departure instructions, fare amount, and calories spent.\n */\nexport function TripDetails({\n CaloriesDetails = DefaultCaloriesDetails,\n className = \"\",\n DepartureDetails = null,\n defaultFareKey = \"regular\",\n fareKeyNameMap = {},\n itinerary,\n fareDetailsLayout\n}: TripDetailsProps): ReactElement {\n // process the transit fare\n const fareResult = coreUtils.itinerary.calculateTncFares(itinerary);\n const { maxTNCFare, minTNCFare, tncCurrencyCode } = fareResult;\n const transitFares = itinerary?.fare?.fare;\n\n let companies = \"\";\n itinerary.legs.forEach(leg => {\n if (leg.tncData) {\n companies = leg.tncData.company;\n }\n });\n let fare;\n\n const fareKeys = transitFares && Object.keys(transitFares).sort();\n\n if (transitFares && fareKeys.length > 0) {\n let defaultFare = defaultFareKey;\n if (!transitFares[defaultFareKey]) {\n defaultFare = \"regular\";\n }\n\n // Depending on if there are additional fares to display either render a <span> or a <details>\n const TransitFareWrapper =\n transitFares && fareKeys.length > 1 ? S.TransitFare : S.TransitFareSingle;\n\n fare = (\n <S.Fare>\n <TransitFareWrapper>\n <summary\n role=\"button\"\n style={{ display: fareKeys.length > 1 ? \"list-item\" : \"\" }}\n >\n <TransitFare\n fareNameFallback={\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.TripDetails.transitFare\"]\n }\n description=\"Text showing the price of tickets on public transportation.\"\n id=\"otpUi.TripDetails.transitFare\"\n />\n }\n fareKey={defaultFare}\n fareKeyNameMap={fareKeyNameMap}\n transitFares={transitFares}\n />\n </summary>\n {fareKeys.map(fareKey => {\n // Don't show the default fare twice!\n if (fareKey === defaultFare) {\n return null;\n }\n return (\n <TransitFare\n fareKey={fareKey}\n key={fareKey}\n fareKeyNameMap={fareKeyNameMap}\n transitFares={transitFares}\n />\n );\n })}\n </TransitFareWrapper>\n {minTNCFare !== 0 && (\n <S.TNCFare>\n <br />\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.tncFare\"]}\n description=\"Text showing the price paid to transportation network companies.\"\n id=\"otpUi.TripDetails.tncFare\"\n values={{\n companies: (\n // S.TNCFareCompanies capitalizes the TNC company ID (e.g. \"COMPANY\")\n // after it is converted to lowercase, so it renders as \"Company\".\n <S.TNCFareCompanies>\n {companies.toLowerCase()}\n </S.TNCFareCompanies>\n ),\n maxTNCFare: renderFare(tncCurrencyCode, maxTNCFare),\n minTNCFare: renderFare(tncCurrencyCode, minTNCFare),\n strong: boldText\n }}\n />\n </S.TNCFare>\n )}\n </S.Fare>\n );\n }\n\n const departureDate = new Date(itinerary.startTime);\n\n // Compute calories burned.\n const {\n bikeDuration,\n caloriesBurned,\n walkDuration\n } = coreUtils.itinerary.calculatePhysicalActivity(itinerary);\n\n // Parse flex info and generate appropriate strings\n const containsFlex = itinerary.legs.some(coreUtils.itinerary.isFlex);\n const pickupBookingInfo = itinerary.legs\n .map(leg => leg.pickupBookingInfo)\n .filter(info => !!info);\n const dropOffBookingInfo = itinerary.legs\n .map(leg => leg.dropOffBookingInfo)\n .filter(info => !!info);\n\n return (\n <S.TripDetails className={className}>\n <S.TripDetailsHeader>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.title\"]}\n description=\"Title (heading) text of the component.\"\n id=\"otpUi.TripDetails.title\"\n />\n </S.TripDetailsHeader>\n <S.TripDetailsBody>\n <TripDetail\n // Any custom description for the Departure message needs to be handled by the slot.\n description={\n DepartureDetails && (\n <DepartureDetails departureDate={departureDate} />\n )\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 {fare && (\n <TripDetail\n // Any custom description for the transit fare needs to be handled by the slot.\n // TODO: add leg info\n description={\n fareDetailsLayout &&\n Object.keys(itinerary.fare.details).length > 0 && (\n <FareDetails\n transitFares={itinerary.fare}\n legs={itinerary.legs}\n layout={fareDetailsLayout}\n />\n )\n }\n icon={<MoneyBillAlt size={17} />}\n summary={fare}\n />\n )}\n {caloriesBurned > 0 && (\n <TripDetail\n icon={<Heartbeat size={17} />}\n summary={\n <S.CaloriesSummary>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.TripDetails.calories\"]}\n description=\"Text showing the number of calories for the walking and biking legs of a trip.\"\n id=\"otpUi.TripDetails.calories\"\n values={{\n calories: caloriesBurned,\n strong: boldText\n }}\n />\n </S.CaloriesSummary>\n }\n description={\n CaloriesDetails && (\n <CaloriesDetails\n bikeSeconds={bikeDuration}\n calories={caloriesBurned}\n walkSeconds={walkDuration}\n />\n )\n }\n />\n )}\n {containsFlex && (\n <TripDetail\n summary={\n <S.FlexSummary>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.TripDetails.tripIncludesFlex\"]\n }\n description=\"Text stating that portions of the trip include a flex (on-demand) transit service.\"\n id=\"otpUi.TripDetails.tripIncludesFlex\"\n />\n </S.FlexSummary>\n }\n icon={<Route size={17} />}\n />\n )}\n {pickupBookingInfo &&\n pickupBookingInfo.map(info => (\n <TripDetail\n key={info.pickupMessage}\n icon={<PhoneVolume size={17} />}\n summary={\n <S.FlexPickupSummary>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.TripDetails.flexPickupMessage\"]\n }\n description=\"Instructions for booking and boarding the flex (on-demand) transit service.\"\n id=\"otpUi.TripDetails.flexPickupMessage\"\n values={getFlexMessageValues(info)}\n />\n </S.FlexPickupSummary>\n }\n description={info.pickupMessage}\n />\n ))}\n {dropOffBookingInfo &&\n dropOffBookingInfo.map(info => (\n <TripDetail\n description={info.dropOffMessage}\n icon={\n coreUtils.itinerary.isAdvanceBookingRequired(info) ? (\n <PhoneVolume size={17} />\n ) : (\n <HandPaper size={17} />\n )\n }\n key={info.dropOffMessage}\n summary={\n <S.FlexDropOffSummary>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.TripDetails.flexDropOffMessage\"]\n }\n description=\"Instructions for getting off the flex (on-demand) transit service.\"\n id=\"otpUi.TripDetails.flexDropOffMessage\"\n values={getFlexMessageValues(info)}\n />\n </S.FlexDropOffSummary>\n }\n />\n ))}\n </S.TripDetailsBody>\n </S.TripDetails>\n );\n}\n\nexport default TripDetails;\n\n// Rename styled components for export\nexport { S as Styled };\n"],"file":"index.js"}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Itinerary } from "@opentripplanner/types";
|
|
1
|
+
import type { Itinerary, Leg, Fare } from "@opentripplanner/types";
|
|
2
2
|
import type { ReactElement } from "react";
|
|
3
3
|
export interface CaloriesDetailsProps {
|
|
4
4
|
bikeSeconds: number;
|
|
@@ -8,16 +8,17 @@ export interface CaloriesDetailsProps {
|
|
|
8
8
|
export interface DepartureDetailsProps {
|
|
9
9
|
departureDate: Date;
|
|
10
10
|
}
|
|
11
|
-
export interface
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
export interface FareDetailsLayout {
|
|
12
|
+
header: string;
|
|
13
|
+
cols: {
|
|
14
|
+
key: string;
|
|
15
|
+
header: string;
|
|
16
|
+
}[];
|
|
16
17
|
}
|
|
17
18
|
export interface FareDetailsProps {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
transitFares: Fare;
|
|
20
|
+
legs: Leg[];
|
|
21
|
+
layout: FareDetailsLayout[];
|
|
21
22
|
}
|
|
22
23
|
export interface TransitFareProps {
|
|
23
24
|
fareKey: string;
|
|
@@ -25,7 +26,7 @@ export interface TransitFareProps {
|
|
|
25
26
|
fareKeyNameMap: {
|
|
26
27
|
[key: string]: string;
|
|
27
28
|
};
|
|
28
|
-
transitFares:
|
|
29
|
+
transitFares: Fare;
|
|
29
30
|
}
|
|
30
31
|
export interface TripDetailsProps {
|
|
31
32
|
/**
|
|
@@ -44,16 +45,16 @@ export interface TripDetailsProps {
|
|
|
44
45
|
* Slot for a custom component to render the expandable section for departure.
|
|
45
46
|
*/
|
|
46
47
|
DepartureDetails?: React.ElementType<DepartureDetailsProps>;
|
|
47
|
-
/**
|
|
48
|
-
* Slot for a custom component to render the expandable section for fares.
|
|
49
|
-
*/
|
|
50
|
-
FareDetails?: React.ElementType<FareDetailsProps>;
|
|
51
48
|
/**
|
|
52
49
|
* Mapping between fare keys and human-readable names for them.
|
|
53
50
|
*/
|
|
54
51
|
fareKeyNameMap?: {
|
|
55
52
|
[name: string]: string;
|
|
56
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Column and table configuration for fare details/fare by leg table.
|
|
56
|
+
*/
|
|
57
|
+
fareDetailsLayout?: FareDetailsLayout[];
|
|
57
58
|
/**
|
|
58
59
|
* Itinerary that the user has selected to view, contains multiple legs.
|
|
59
60
|
*/
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;KAChB,EAAE,CAAC;CACL;AAED,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,IAAI,CAAC;IACnB,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,MAAM,EAAE,iBAAiB,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,YAAY,CAAC;IAChC,cAAc,EAAE;QACd,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;IACF,YAAY,EAAE,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,eAAe,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC;IAC1D;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,gBAAgB,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAC5D;;OAEG;IACH,cAAc,CAAC,EAAE;QACf,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;KACxB,CAAC;IACF;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACxC;;OAEG;IACH,SAAS,EAAE,SAAS,CAAC;CACtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentripplanner/trip-details",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-alpha.1",
|
|
4
4
|
"description": "A component for displaying details about a trip planning itinerary",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -11,18 +11,18 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"private": false,
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@opentripplanner/core-utils": "^4.
|
|
14
|
+
"@opentripplanner/core-utils": "^4.6.0",
|
|
15
15
|
"@styled-icons/fa-solid": "^10.34.0",
|
|
16
16
|
"flat": "^5.0.2",
|
|
17
17
|
"velocity-react": "^1.4.3"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@opentripplanner/types": "^1.
|
|
20
|
+
"@opentripplanner/types": "^1.2.2",
|
|
21
21
|
"@types/flat": "^5.0.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "^16.14.0",
|
|
25
|
-
"react-intl": "^5.
|
|
25
|
+
"react-intl": "^5.24.6",
|
|
26
26
|
"styled-components": "^5.3.0"
|
|
27
27
|
},
|
|
28
28
|
"bugs": {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import flatten from "flat";
|
|
2
2
|
import React, { ReactElement } from "react";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
ComponentMeta,
|
|
5
|
+
ComponentStory,
|
|
6
|
+
Parameters,
|
|
7
|
+
StoryContext
|
|
8
|
+
} from "@storybook/react";
|
|
5
9
|
import styled from "styled-components";
|
|
6
10
|
// The below eslint-disable is due to https://github.com/storybookjs/storybook/issues/13408
|
|
7
11
|
// eslint-disable-next-line import/no-named-as-default
|
|
@@ -10,22 +14,11 @@ import * as TripDetailsClasses from "./styled";
|
|
|
10
14
|
import {
|
|
11
15
|
CaloriesDetailsProps,
|
|
12
16
|
DepartureDetailsProps,
|
|
13
|
-
FareDetailsProps,
|
|
14
17
|
TripDetailsProps
|
|
15
18
|
} from "./types";
|
|
16
19
|
|
|
17
|
-
import englishMessages from "../i18n/en-US.yml";
|
|
18
|
-
import frenchMessages from "../i18n/fr.yml";
|
|
19
20
|
import customMessages from "../__mocks__/custom-messages.yml";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Describes args passed to stories.
|
|
23
|
-
*/
|
|
24
|
-
interface StoryArgs {
|
|
25
|
-
locale?: string;
|
|
26
|
-
useCustomMessages?: boolean;
|
|
27
|
-
useLocalizedMessages?: boolean;
|
|
28
|
-
}
|
|
21
|
+
import { FareDetails } from "./fare-detail";
|
|
29
22
|
|
|
30
23
|
// import mock itinaries. These are all trip plan outputs from OTP.
|
|
31
24
|
const bikeOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-only.json");
|
|
@@ -54,6 +47,52 @@ const StyledTripDetails = styled(TripDetails)`
|
|
|
54
47
|
}
|
|
55
48
|
`;
|
|
56
49
|
|
|
50
|
+
const fareByLegLayout = [
|
|
51
|
+
{
|
|
52
|
+
header: "Adult",
|
|
53
|
+
cols: [
|
|
54
|
+
{
|
|
55
|
+
key: "regular",
|
|
56
|
+
header: "Cash"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: "electronicRegular",
|
|
60
|
+
header: "ORCA"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: "electronicSpecial",
|
|
64
|
+
header: "ORCA Lift"
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
header: "Youth",
|
|
70
|
+
cols: [
|
|
71
|
+
{
|
|
72
|
+
key: "youth",
|
|
73
|
+
header: "Cash"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
key: "electronicYouth",
|
|
77
|
+
header: "ORCA"
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
header: "Senior",
|
|
83
|
+
cols: [
|
|
84
|
+
{
|
|
85
|
+
key: "senior",
|
|
86
|
+
header: "Cash"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
key: "electronicSenior",
|
|
90
|
+
header: "ORCA"
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
];
|
|
95
|
+
|
|
57
96
|
const longDateFormat = "MMMM D, YYYY";
|
|
58
97
|
|
|
59
98
|
const englishFareKeyMap = {
|
|
@@ -92,18 +131,6 @@ const CustomDepartureDetails = ({
|
|
|
92
131
|
</>
|
|
93
132
|
);
|
|
94
133
|
|
|
95
|
-
const CustomFareDetails = ({
|
|
96
|
-
maxTNCFare,
|
|
97
|
-
minTNCFare,
|
|
98
|
-
transitFares
|
|
99
|
-
}: FareDetailsProps): ReactElement => (
|
|
100
|
-
<>
|
|
101
|
-
Custom details about fares (transitFares: {JSON.stringify(transitFares)}{" "}
|
|
102
|
-
(cents), minTNCFare: {minTNCFare} and maxTNCFare: {maxTNCFare} can be
|
|
103
|
-
constructed dynamically using any markup.
|
|
104
|
-
</>
|
|
105
|
-
);
|
|
106
|
-
|
|
107
134
|
const CustomCaloriesDetails = ({
|
|
108
135
|
bikeSeconds,
|
|
109
136
|
calories,
|
|
@@ -122,17 +149,19 @@ const CustomCaloriesDetails = ({
|
|
|
122
149
|
* @param Component The component to render.
|
|
123
150
|
*/
|
|
124
151
|
function createTripDetailsTemplate(
|
|
125
|
-
Component:
|
|
126
|
-
) {
|
|
127
|
-
const TripDetailsTemplate = (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
152
|
+
Component: typeof TripDetails = TripDetails
|
|
153
|
+
): ComponentStory<typeof TripDetails> {
|
|
154
|
+
const TripDetailsTemplate = (
|
|
155
|
+
{
|
|
156
|
+
CaloriesDetails,
|
|
157
|
+
DepartureDetails,
|
|
158
|
+
itinerary,
|
|
159
|
+
fareDetailsLayout
|
|
160
|
+
}: TripDetailsProps,
|
|
161
|
+
{ globals, parameters }: StoryContext
|
|
162
|
+
): ReactElement => {
|
|
163
|
+
const { locale } = globals;
|
|
164
|
+
const { useCustomFareKeyMap } = parameters;
|
|
136
165
|
const fareKeyNameMap = useCustomFareKeyMap
|
|
137
166
|
? locale === "en-US"
|
|
138
167
|
? englishFareKeyMap
|
|
@@ -141,104 +170,45 @@ function createTripDetailsTemplate(
|
|
|
141
170
|
return (
|
|
142
171
|
<Component
|
|
143
172
|
CaloriesDetails={CaloriesDetails}
|
|
144
|
-
defaultFare={defaultFare}
|
|
145
173
|
DepartureDetails={DepartureDetails}
|
|
146
|
-
FareDetails={FareDetails}
|
|
147
174
|
fareKeyNameMap={fareKeyNameMap}
|
|
148
175
|
itinerary={itinerary}
|
|
176
|
+
fareDetailsLayout={fareDetailsLayout}
|
|
149
177
|
/>
|
|
150
178
|
);
|
|
151
179
|
};
|
|
152
180
|
return TripDetailsTemplate;
|
|
153
181
|
}
|
|
154
182
|
|
|
155
|
-
const intlDecorator = (
|
|
156
|
-
Story: StoryType,
|
|
157
|
-
context: {
|
|
158
|
-
args: StoryArgs;
|
|
159
|
-
}
|
|
160
|
-
): ReactElement => {
|
|
161
|
-
const { args } = context;
|
|
162
|
-
const { locale, useCustomMessages, useLocalizedMessages } = args;
|
|
163
|
-
const messages = locale === "en-US" ? englishMessages : frenchMessages;
|
|
164
|
-
|
|
165
|
-
// Construct a messages object that customizes a subset
|
|
166
|
-
// of the default messages of the desired locale.
|
|
167
|
-
// The structure of the message objects is
|
|
168
|
-
// flattened before it is passed to IntlProvider.
|
|
169
|
-
// Note: the spread operator (...) is rejected if used with flatten,
|
|
170
|
-
// so we use Object.assign instead
|
|
171
|
-
// (see e.g. https://github.com/Microsoft/TypeScript/issues/10727#issuecomment-423712256).
|
|
172
|
-
let mergedMessages: Record<string, string> = flatten(messages);
|
|
173
|
-
if (useCustomMessages) {
|
|
174
|
-
mergedMessages = Object.assign(mergedMessages, flatten(customMessages));
|
|
175
|
-
}
|
|
176
|
-
return (
|
|
177
|
-
<IntlProvider
|
|
178
|
-
locale={locale}
|
|
179
|
-
messages={useLocalizedMessages ? mergedMessages : null}
|
|
180
|
-
>
|
|
181
|
-
<Story />
|
|
182
|
-
</IntlProvider>
|
|
183
|
-
);
|
|
184
|
-
};
|
|
185
|
-
|
|
186
183
|
/**
|
|
187
184
|
* Helper to simplify story declaration.
|
|
188
185
|
*/
|
|
189
186
|
function makeStory(
|
|
190
|
-
args:
|
|
191
|
-
|
|
192
|
-
|
|
187
|
+
args: TripDetailsProps,
|
|
188
|
+
parameters?: Parameters,
|
|
189
|
+
Component?: typeof TripDetails
|
|
190
|
+
): ComponentStory<typeof TripDetails> {
|
|
193
191
|
const BoundTripDetails = createTripDetailsTemplate(Component).bind({});
|
|
194
192
|
BoundTripDetails.args = args;
|
|
193
|
+
BoundTripDetails.parameters = parameters;
|
|
195
194
|
return BoundTripDetails;
|
|
196
195
|
}
|
|
197
196
|
|
|
198
|
-
const decoratorPropDescription = "(This prop is used by the decorator.)";
|
|
199
|
-
// Hide story controls for some props.
|
|
200
|
-
const noControl = {
|
|
201
|
-
control: { type: false }
|
|
202
|
-
};
|
|
203
|
-
// Hide some story args completely.
|
|
204
|
-
const hiddenProp = {
|
|
205
|
-
table: { disable: true }
|
|
206
|
-
};
|
|
207
|
-
|
|
208
197
|
export default {
|
|
209
|
-
argTypes: {
|
|
210
|
-
CaloriesDetails: noControl,
|
|
211
|
-
className: noControl,
|
|
212
|
-
Component: hiddenProp,
|
|
213
|
-
defaultFareKey: noControl,
|
|
214
|
-
DepartureDetails: noControl,
|
|
215
|
-
FareDetails: noControl,
|
|
216
|
-
fareKeyNameMap: noControl,
|
|
217
|
-
itinerary: noControl,
|
|
218
|
-
locale: {
|
|
219
|
-
control: "radio",
|
|
220
|
-
description: decoratorPropDescription,
|
|
221
|
-
options: ["en-US", "fr"]
|
|
222
|
-
},
|
|
223
|
-
useCustomFareKeyMap: hiddenProp,
|
|
224
|
-
useCustomMessages: {
|
|
225
|
-
description: decoratorPropDescription
|
|
226
|
-
},
|
|
227
|
-
useLocalizedMessages: {
|
|
228
|
-
description: decoratorPropDescription
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
198
|
args: {
|
|
232
|
-
defaultFareKey: "regular"
|
|
233
|
-
locale: "en-US",
|
|
234
|
-
useCustomMessages: false,
|
|
235
|
-
useLocalizedMessages: true
|
|
199
|
+
defaultFareKey: "regular"
|
|
236
200
|
},
|
|
237
201
|
component: TripDetails,
|
|
238
|
-
|
|
239
|
-
|
|
202
|
+
parameters: {
|
|
203
|
+
// Hide all controls
|
|
204
|
+
// (there are no args that the user can interactively change for this component).
|
|
205
|
+
controls: {
|
|
206
|
+
hideNoControlsWarning: true,
|
|
207
|
+
include: []
|
|
208
|
+
}
|
|
209
|
+
},
|
|
240
210
|
title: "TripDetails"
|
|
241
|
-
} as
|
|
211
|
+
} as ComponentMeta<typeof TripDetails>;
|
|
242
212
|
|
|
243
213
|
export const WalkOnlyItinerary = makeStory({
|
|
244
214
|
itinerary: walkOnlyItinerary
|
|
@@ -256,6 +226,7 @@ export const StyledWalkTransitWalkItinerary = makeStory(
|
|
|
256
226
|
{
|
|
257
227
|
itinerary: walkTransitWalkItinerary
|
|
258
228
|
},
|
|
229
|
+
null,
|
|
259
230
|
StyledTripDetails
|
|
260
231
|
);
|
|
261
232
|
|
|
@@ -263,11 +234,16 @@ export const BikeTransitBikeItinerary = makeStory({
|
|
|
263
234
|
itinerary: bikeTransitBikeItinerary
|
|
264
235
|
});
|
|
265
236
|
|
|
266
|
-
export const WalkInterlinedTransitItinerary = makeStory(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
237
|
+
export const WalkInterlinedTransitItinerary = makeStory(
|
|
238
|
+
{
|
|
239
|
+
defaultFareKey: "electronicRegular",
|
|
240
|
+
itinerary: walkInterlinedTransitItinerary,
|
|
241
|
+
fareDetailsLayout: fareByLegLayout
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
useCustomFareKeyMap: true
|
|
245
|
+
}
|
|
246
|
+
);
|
|
271
247
|
|
|
272
248
|
export const WalkTransitTransferItinerary = makeStory({
|
|
273
249
|
itinerary: walkTransitWalkTransitWalkItinerary
|
|
@@ -293,18 +269,32 @@ export const EScooterRentalTransitItinerary = makeStory({
|
|
|
293
269
|
itinerary: eScooterRentalTransiteScooterRentalItinerary
|
|
294
270
|
});
|
|
295
271
|
|
|
296
|
-
export const TncTransitItinerary = makeStory(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
272
|
+
export const TncTransitItinerary = makeStory(
|
|
273
|
+
{
|
|
274
|
+
itinerary: tncTransitTncItinerary
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
useCustomFareKeyMap: true
|
|
278
|
+
}
|
|
279
|
+
);
|
|
300
280
|
|
|
301
|
-
|
|
281
|
+
const flattenedMessages = flatten(customMessages);
|
|
282
|
+
export const TncTransitItineraryWithCustomMessages = makeStory(
|
|
302
283
|
{
|
|
303
284
|
CaloriesDetails: CustomCaloriesDetails,
|
|
304
285
|
defaultFareKey: "electronicRegular",
|
|
305
286
|
DepartureDetails: CustomDepartureDetails,
|
|
306
|
-
|
|
307
|
-
|
|
287
|
+
itinerary: tncTransitTncItinerary
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
// For illustration purposes,
|
|
291
|
+
// override a subset of localized strings with custom messages.
|
|
292
|
+
reactIntl: {
|
|
293
|
+
messages: {
|
|
294
|
+
"en-US": flattenedMessages,
|
|
295
|
+
fr: flattenedMessages
|
|
296
|
+
}
|
|
297
|
+
},
|
|
308
298
|
useCustomFareKeyMap: true
|
|
309
299
|
},
|
|
310
300
|
StyledTripDetails
|
|
@@ -313,3 +303,12 @@ export const TncTransitItineraryWithCustomDetails = makeStory(
|
|
|
313
303
|
export const FlexItinerary = makeStory({
|
|
314
304
|
itinerary: fareComponentsItinerary
|
|
315
305
|
});
|
|
306
|
+
|
|
307
|
+
const exampleItinerary = walkInterlinedTransitItinerary;
|
|
308
|
+
export const FareDetailsComponent = () => (
|
|
309
|
+
<FareDetails
|
|
310
|
+
transitFares={exampleItinerary.fare}
|
|
311
|
+
legs={exampleItinerary.legs}
|
|
312
|
+
layout={fareByLegLayout}
|
|
313
|
+
/>
|
|
314
|
+
);
|