@opentripplanner/trip-details 2.0.2-alpha.1 → 2.1.0-alpha.2
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 +9 -10
- package/esm/index.js.map +1 -1
- 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 +9 -8
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +17 -18
- package/lib/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/TripDetails.story.tsx +70 -22
- package/src/fare-detail.tsx +154 -0
- package/src/index.tsx +9 -8
- package/src/types.ts +17 -18
- package/tsconfig.tsbuildinfo +204 -24
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","currency","cents","TripDetails","CaloriesDetails","className","DepartureDetails","defaultFareKey","FareDetails","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","pickupMessage","dropO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AACE,MAAA,cAAc,EACZlF,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;;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\";\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 FareDetails = null,\n fareKeyNameMap = {},\n itinerary\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 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;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AACA;;AASA;;;;;;AADA;AAGA;AACA;AACA;AACA;AACA,MAAMA,eAAuC,GAAG,mBAAQC,aAAR,CAAhD;AAEA;AACA;AACA;AACA;;AACA,SAASC,QAAT,CA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AAA,MAAM,EAAEQ,oBAAoB,CAACC,IAAD;AAN9B,MADF;AAXJ,IADF,CAzGJ,CARF,CADF;AA8ID;;eAEc8B,W,EAEf","sourcesContent":["import flatten from \"flat\";\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 { Fare, Leg, Itinerary, Money } from "@opentripplanner/types";
|
|
2
2
|
import type { ReactElement } from "react";
|
|
3
3
|
export interface CaloriesDetailsProps {
|
|
4
4
|
bikeSeconds: number;
|
|
@@ -8,21 +8,20 @@ export interface CaloriesDetailsProps {
|
|
|
8
8
|
export interface DepartureDetailsProps {
|
|
9
9
|
departureDate: Date;
|
|
10
10
|
}
|
|
11
|
+
export interface FareDetailsLayout {
|
|
12
|
+
header: string;
|
|
13
|
+
cols: {
|
|
14
|
+
key: string;
|
|
15
|
+
header: string;
|
|
16
|
+
}[];
|
|
17
|
+
}
|
|
11
18
|
export interface TransitFareData {
|
|
12
|
-
[key: string]:
|
|
13
|
-
currency: {
|
|
14
|
-
currencyCode: string;
|
|
15
|
-
defaultFractionDigits: number;
|
|
16
|
-
currency: string;
|
|
17
|
-
symbol: string;
|
|
18
|
-
};
|
|
19
|
-
cents: number;
|
|
20
|
-
};
|
|
19
|
+
[key: string]: Money;
|
|
21
20
|
}
|
|
22
21
|
export interface FareDetailsProps {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
transitFares: Fare;
|
|
23
|
+
legs: Leg[];
|
|
24
|
+
layout: FareDetailsLayout[];
|
|
26
25
|
}
|
|
27
26
|
export interface TransitFareProps {
|
|
28
27
|
fareKey: string;
|
|
@@ -30,7 +29,7 @@ export interface TransitFareProps {
|
|
|
30
29
|
fareKeyNameMap: {
|
|
31
30
|
[key: string]: string;
|
|
32
31
|
};
|
|
33
|
-
transitFares:
|
|
32
|
+
transitFares: Fare;
|
|
34
33
|
}
|
|
35
34
|
export interface TripDetailsProps {
|
|
36
35
|
/**
|
|
@@ -49,16 +48,16 @@ export interface TripDetailsProps {
|
|
|
49
48
|
* Slot for a custom component to render the expandable section for departure.
|
|
50
49
|
*/
|
|
51
50
|
DepartureDetails?: React.ElementType<DepartureDetailsProps>;
|
|
52
|
-
/**
|
|
53
|
-
* Slot for a custom component to render the expandable section for fares.
|
|
54
|
-
*/
|
|
55
|
-
FareDetails?: React.ElementType<FareDetailsProps>;
|
|
56
51
|
/**
|
|
57
52
|
* Mapping between fare keys and human-readable names for them.
|
|
58
53
|
*/
|
|
59
54
|
fareKeyNameMap?: {
|
|
60
55
|
[name: string]: string;
|
|
61
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* Column and table configuration for fare details/fare by leg table.
|
|
59
|
+
*/
|
|
60
|
+
fareDetailsLayout?: FareDetailsLayout[];
|
|
62
61
|
/**
|
|
63
62
|
* Itinerary that the user has selected to view, contains multiple legs.
|
|
64
63
|
*/
|
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,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC1E,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;CACr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
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0-alpha.2",
|
|
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,13 +11,13 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"private": false,
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@opentripplanner/core-utils": "^
|
|
14
|
+
"@opentripplanner/core-utils": "^5.0.1",
|
|
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": "^
|
|
20
|
+
"@opentripplanner/types": "^2.0.0",
|
|
21
21
|
"@types/flat": "^5.0.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
},
|
|
31
31
|
"gitHead": "0af1b7cda60bd4252b219dcf893e01c2acb2ed5d",
|
|
32
32
|
"scripts": {
|
|
33
|
-
"tsc": "tsc
|
|
33
|
+
"tsc": "tsc"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -14,11 +14,11 @@ import * as TripDetailsClasses from "./styled";
|
|
|
14
14
|
import {
|
|
15
15
|
CaloriesDetailsProps,
|
|
16
16
|
DepartureDetailsProps,
|
|
17
|
-
FareDetailsProps,
|
|
18
17
|
TripDetailsProps
|
|
19
18
|
} from "./types";
|
|
20
19
|
|
|
21
20
|
import customMessages from "../__mocks__/custom-messages.yml";
|
|
21
|
+
import { FareDetails } from "./fare-detail";
|
|
22
22
|
|
|
23
23
|
// import mock itinaries. These are all trip plan outputs from OTP.
|
|
24
24
|
const bikeOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/bike-only.json");
|
|
@@ -34,6 +34,7 @@ const walkOnlyItinerary = require("@opentripplanner/itinerary-body/src/__mocks__
|
|
|
34
34
|
const walkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk.json");
|
|
35
35
|
const walkTransitWalkTransitWalkItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/walk-transit-walk-transit-walk.json");
|
|
36
36
|
const fareComponentsItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/fare-components.json");
|
|
37
|
+
const otp2ScooterItinerary = require("@opentripplanner/itinerary-body/src/__mocks__/itineraries/otp2-scooter.json");
|
|
37
38
|
|
|
38
39
|
// Change currency code on one of the itineraries for illustration.
|
|
39
40
|
// (other currency fields in the itinerary object are not used for display).
|
|
@@ -47,6 +48,52 @@ const StyledTripDetails = styled(TripDetails)`
|
|
|
47
48
|
}
|
|
48
49
|
`;
|
|
49
50
|
|
|
51
|
+
const fareByLegLayout = [
|
|
52
|
+
{
|
|
53
|
+
header: "Adult",
|
|
54
|
+
cols: [
|
|
55
|
+
{
|
|
56
|
+
key: "regular",
|
|
57
|
+
header: "Cash"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: "electronicRegular",
|
|
61
|
+
header: "ORCA"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
key: "electronicSpecial",
|
|
65
|
+
header: "ORCA Lift"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
header: "Youth",
|
|
71
|
+
cols: [
|
|
72
|
+
{
|
|
73
|
+
key: "youth",
|
|
74
|
+
header: "Cash"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "electronicYouth",
|
|
78
|
+
header: "ORCA"
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
header: "Senior",
|
|
84
|
+
cols: [
|
|
85
|
+
{
|
|
86
|
+
key: "senior",
|
|
87
|
+
header: "Cash"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
key: "electronicSenior",
|
|
91
|
+
header: "ORCA"
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
|
|
50
97
|
const longDateFormat = "MMMM D, YYYY";
|
|
51
98
|
|
|
52
99
|
const englishFareKeyMap = {
|
|
@@ -85,18 +132,6 @@ const CustomDepartureDetails = ({
|
|
|
85
132
|
</>
|
|
86
133
|
);
|
|
87
134
|
|
|
88
|
-
const CustomFareDetails = ({
|
|
89
|
-
maxTNCFare,
|
|
90
|
-
minTNCFare,
|
|
91
|
-
transitFares
|
|
92
|
-
}: FareDetailsProps): ReactElement => (
|
|
93
|
-
<>
|
|
94
|
-
Custom details about fares (transitFares: {JSON.stringify(transitFares)}{" "}
|
|
95
|
-
(cents), minTNCFare: {minTNCFare} and maxTNCFare: {maxTNCFare} can be
|
|
96
|
-
constructed dynamically using any markup.
|
|
97
|
-
</>
|
|
98
|
-
);
|
|
99
|
-
|
|
100
135
|
const CustomCaloriesDetails = ({
|
|
101
136
|
bikeSeconds,
|
|
102
137
|
calories,
|
|
@@ -120,10 +155,9 @@ function createTripDetailsTemplate(
|
|
|
120
155
|
const TripDetailsTemplate = (
|
|
121
156
|
{
|
|
122
157
|
CaloriesDetails,
|
|
123
|
-
defaultFare,
|
|
124
158
|
DepartureDetails,
|
|
125
|
-
|
|
126
|
-
|
|
159
|
+
itinerary,
|
|
160
|
+
fareDetailsLayout
|
|
127
161
|
}: TripDetailsProps,
|
|
128
162
|
{ globals, parameters }: StoryContext
|
|
129
163
|
): ReactElement => {
|
|
@@ -137,11 +171,10 @@ function createTripDetailsTemplate(
|
|
|
137
171
|
return (
|
|
138
172
|
<Component
|
|
139
173
|
CaloriesDetails={CaloriesDetails}
|
|
140
|
-
defaultFare={defaultFare}
|
|
141
174
|
DepartureDetails={DepartureDetails}
|
|
142
|
-
FareDetails={FareDetails}
|
|
143
175
|
fareKeyNameMap={fareKeyNameMap}
|
|
144
176
|
itinerary={itinerary}
|
|
177
|
+
fareDetailsLayout={fareDetailsLayout}
|
|
145
178
|
/>
|
|
146
179
|
);
|
|
147
180
|
};
|
|
@@ -153,7 +186,7 @@ function createTripDetailsTemplate(
|
|
|
153
186
|
*/
|
|
154
187
|
function makeStory(
|
|
155
188
|
args: TripDetailsProps,
|
|
156
|
-
parameters
|
|
189
|
+
parameters?: Parameters,
|
|
157
190
|
Component?: typeof TripDetails
|
|
158
191
|
): ComponentStory<typeof TripDetails> {
|
|
159
192
|
const BoundTripDetails = createTripDetailsTemplate(Component).bind({});
|
|
@@ -205,7 +238,8 @@ export const BikeTransitBikeItinerary = makeStory({
|
|
|
205
238
|
export const WalkInterlinedTransitItinerary = makeStory(
|
|
206
239
|
{
|
|
207
240
|
defaultFareKey: "electronicRegular",
|
|
208
|
-
itinerary: walkInterlinedTransitItinerary
|
|
241
|
+
itinerary: walkInterlinedTransitItinerary,
|
|
242
|
+
fareDetailsLayout: fareByLegLayout
|
|
209
243
|
},
|
|
210
244
|
{
|
|
211
245
|
useCustomFareKeyMap: true
|
|
@@ -236,6 +270,12 @@ export const EScooterRentalTransitItinerary = makeStory({
|
|
|
236
270
|
itinerary: eScooterRentalTransiteScooterRentalItinerary
|
|
237
271
|
});
|
|
238
272
|
|
|
273
|
+
// The render of this itinerary is uninteresting, but the test
|
|
274
|
+
// is if we can parse an OTP2 itinerary without crashing
|
|
275
|
+
export const OTP2EScooterRentalTransitItinerary = makeStory({
|
|
276
|
+
itinerary: otp2ScooterItinerary
|
|
277
|
+
});
|
|
278
|
+
|
|
239
279
|
export const TncTransitItinerary = makeStory(
|
|
240
280
|
{
|
|
241
281
|
itinerary: tncTransitTncItinerary
|
|
@@ -246,12 +286,11 @@ export const TncTransitItinerary = makeStory(
|
|
|
246
286
|
);
|
|
247
287
|
|
|
248
288
|
const flattenedMessages = flatten(customMessages);
|
|
249
|
-
export const
|
|
289
|
+
export const TncTransitItineraryWithCustomMessages = makeStory(
|
|
250
290
|
{
|
|
251
291
|
CaloriesDetails: CustomCaloriesDetails,
|
|
252
292
|
defaultFareKey: "electronicRegular",
|
|
253
293
|
DepartureDetails: CustomDepartureDetails,
|
|
254
|
-
FareDetails: CustomFareDetails,
|
|
255
294
|
itinerary: tncTransitTncItinerary
|
|
256
295
|
},
|
|
257
296
|
{
|
|
@@ -271,3 +310,12 @@ export const TncTransitItineraryWithCustomMessagesAndDetails = makeStory(
|
|
|
271
310
|
export const FlexItinerary = makeStory({
|
|
272
311
|
itinerary: fareComponentsItinerary
|
|
273
312
|
});
|
|
313
|
+
|
|
314
|
+
const exampleItinerary = walkInterlinedTransitItinerary;
|
|
315
|
+
export const FareDetailsComponent = () => (
|
|
316
|
+
<FareDetails
|
|
317
|
+
transitFares={exampleItinerary.fare}
|
|
318
|
+
legs={exampleItinerary.legs}
|
|
319
|
+
layout={fareByLegLayout}
|
|
320
|
+
/>
|
|
321
|
+
);
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
interface FareTypeTableProps {
|
|
10
|
+
header: string;
|
|
11
|
+
cols: {
|
|
12
|
+
key: string;
|
|
13
|
+
header: string;
|
|
14
|
+
}[];
|
|
15
|
+
legs: (Leg & { fares: { [key: string]: { price: Money } } })[];
|
|
16
|
+
fareTotals: { [fareKey: string]: Money };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const TableHeader = styled.thead`
|
|
20
|
+
th {
|
|
21
|
+
min-width: 5ch;
|
|
22
|
+
padding: 0.75em 1.5em;
|
|
23
|
+
text-align: center;
|
|
24
|
+
}
|
|
25
|
+
th:nth-of-type(2n + 1) {
|
|
26
|
+
background: #cccccc22;
|
|
27
|
+
}
|
|
28
|
+
th.main {
|
|
29
|
+
color: #ffffffcc;
|
|
30
|
+
background: #333333;
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
const TotalRow = styled.tr`
|
|
35
|
+
border-top: 2px solid #333;
|
|
36
|
+
font-weight: 600;
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
const Table = styled.table`
|
|
40
|
+
border-collapse: collapse;
|
|
41
|
+
display: block;
|
|
42
|
+
font-family: sans-serif;
|
|
43
|
+
margin: -8px;
|
|
44
|
+
/* This line can not be sorted alphabetically, because it must come after the margin rule */
|
|
45
|
+
margin-bottom: 16px;
|
|
46
|
+
padding: 0;
|
|
47
|
+
|
|
48
|
+
td {
|
|
49
|
+
text-align: right;
|
|
50
|
+
}
|
|
51
|
+
td:nth-of-type(2n + 1) {
|
|
52
|
+
background: #cccccc22;
|
|
53
|
+
}
|
|
54
|
+
td.no-zebra {
|
|
55
|
+
background: transparent;
|
|
56
|
+
}
|
|
57
|
+
th:first-of-type {
|
|
58
|
+
height: 40px;
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
const FareTypeTable = (props: FareTypeTableProps): JSX.Element => {
|
|
63
|
+
const { header, fareTotals, cols, legs } = props;
|
|
64
|
+
return (
|
|
65
|
+
<Table>
|
|
66
|
+
<TableHeader>
|
|
67
|
+
<th className="main">{header}</th>
|
|
68
|
+
{cols.map(col => (
|
|
69
|
+
<th key={col.header}>{col.header}</th>
|
|
70
|
+
))}
|
|
71
|
+
</TableHeader>
|
|
72
|
+
{legs.map((leg, index) => (
|
|
73
|
+
<tr key={index}>
|
|
74
|
+
<td className="no-zebra">{leg.routeShortName}</td>
|
|
75
|
+
{cols.map(col => {
|
|
76
|
+
const fare = leg.fares[col.key];
|
|
77
|
+
return (
|
|
78
|
+
<td key={col.key}>
|
|
79
|
+
<FormattedNumber
|
|
80
|
+
value={fare?.price?.cents / 100 || 0}
|
|
81
|
+
// This isn't a "real" style prop
|
|
82
|
+
// eslint-disable-next-line react/style-prop-object
|
|
83
|
+
style="currency"
|
|
84
|
+
currency={
|
|
85
|
+
fare?.price.currency.currencyCode ||
|
|
86
|
+
// This is how the itinerary-wide currency code is calculated on the back-end
|
|
87
|
+
legs?.[0].fares?.[col.key]?.price?.currency.currencyCode
|
|
88
|
+
}
|
|
89
|
+
currencyDisplay="narrowSymbol"
|
|
90
|
+
/>
|
|
91
|
+
</td>
|
|
92
|
+
);
|
|
93
|
+
})}
|
|
94
|
+
</tr>
|
|
95
|
+
))}
|
|
96
|
+
<TotalRow>
|
|
97
|
+
<td className="no-zebra">Total</td>
|
|
98
|
+
{cols.map(col => {
|
|
99
|
+
const fare = fareTotals[col.key];
|
|
100
|
+
return (
|
|
101
|
+
<td key={col.key}>
|
|
102
|
+
<FormattedNumber
|
|
103
|
+
value={(fare?.cents || 0) / 100}
|
|
104
|
+
// This isn't a "real" style prop
|
|
105
|
+
// eslint-disable-next-line react/style-prop-object
|
|
106
|
+
style="currency"
|
|
107
|
+
currency={fare?.currency?.currencyCode}
|
|
108
|
+
currencyDisplay="narrowSymbol"
|
|
109
|
+
/>
|
|
110
|
+
</td>
|
|
111
|
+
);
|
|
112
|
+
})}
|
|
113
|
+
</TotalRow>
|
|
114
|
+
</Table>
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
119
|
+
export const FareDetails = (props: FareDetailsProps): JSX.Element => {
|
|
120
|
+
const { legs, transitFares, layout } = props;
|
|
121
|
+
const fareKeys = Object.keys(transitFares.details);
|
|
122
|
+
|
|
123
|
+
const legsWithFares = legs
|
|
124
|
+
.map((leg, index) => {
|
|
125
|
+
const fares = fareKeys.reduce((prev, key) => {
|
|
126
|
+
const fareForKey = transitFares.details[key]?.find(
|
|
127
|
+
detail => detail.legIndex === index
|
|
128
|
+
);
|
|
129
|
+
if (fareForKey) {
|
|
130
|
+
prev[key] = fareForKey;
|
|
131
|
+
}
|
|
132
|
+
return prev;
|
|
133
|
+
}, {});
|
|
134
|
+
return {
|
|
135
|
+
...leg,
|
|
136
|
+
fares
|
|
137
|
+
};
|
|
138
|
+
})
|
|
139
|
+
.filter(leg => leg.transitLeg);
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div>
|
|
143
|
+
{layout.map(config => (
|
|
144
|
+
<FareTypeTable
|
|
145
|
+
header={config.header}
|
|
146
|
+
cols={config.cols}
|
|
147
|
+
key={config.header}
|
|
148
|
+
legs={legsWithFares}
|
|
149
|
+
fareTotals={transitFares.fare}
|
|
150
|
+
/>
|
|
151
|
+
))}
|
|
152
|
+
</div>
|
|
153
|
+
);
|
|
154
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import flatten from "flat";
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
-
// @ts-ignore FIXME: Create TypeScript types for core-utils packages.
|
|
4
2
|
import coreUtils from "@opentripplanner/core-utils";
|
|
5
3
|
import { FlexBookingInfo } from "@opentripplanner/types";
|
|
6
4
|
import React, { ReactElement } from "react";
|
|
@@ -11,6 +9,7 @@ import { Heartbeat } from "@styled-icons/fa-solid/Heartbeat";
|
|
|
11
9
|
import { MoneyBillAlt } from "@styled-icons/fa-solid/MoneyBillAlt";
|
|
12
10
|
import { PhoneVolume } from "@styled-icons/fa-solid/PhoneVolume";
|
|
13
11
|
import { Route } from "@styled-icons/fa-solid/Route";
|
|
12
|
+
import { FareDetails } from "./fare-detail";
|
|
14
13
|
|
|
15
14
|
import * as S from "./styled";
|
|
16
15
|
import TripDetail from "./trip-detail";
|
|
@@ -149,9 +148,9 @@ export function TripDetails({
|
|
|
149
148
|
className = "",
|
|
150
149
|
DepartureDetails = null,
|
|
151
150
|
defaultFareKey = "regular",
|
|
152
|
-
FareDetails = null,
|
|
153
151
|
fareKeyNameMap = {},
|
|
154
|
-
itinerary
|
|
152
|
+
itinerary,
|
|
153
|
+
fareDetailsLayout
|
|
155
154
|
}: TripDetailsProps): ReactElement {
|
|
156
155
|
// process the transit fare
|
|
157
156
|
const fareResult = coreUtils.itinerary.calculateTncFares(itinerary);
|
|
@@ -294,12 +293,14 @@ export function TripDetails({
|
|
|
294
293
|
{fare && (
|
|
295
294
|
<TripDetail
|
|
296
295
|
// Any custom description for the transit fare needs to be handled by the slot.
|
|
296
|
+
// TODO: add leg info
|
|
297
297
|
description={
|
|
298
|
-
|
|
298
|
+
fareDetailsLayout &&
|
|
299
|
+
Object.keys(itinerary.fare.details).length > 0 && (
|
|
299
300
|
<FareDetails
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
301
|
+
transitFares={itinerary.fare}
|
|
302
|
+
legs={itinerary.legs}
|
|
303
|
+
layout={fareDetailsLayout}
|
|
303
304
|
/>
|
|
304
305
|
)
|
|
305
306
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Prettier does not recognize the import type syntax.
|
|
2
2
|
// eslint-disable-next-line prettier/prettier
|
|
3
|
-
import type { Itinerary } from "@opentripplanner/types";
|
|
3
|
+
import type { Fare, Leg, Itinerary, Money } from "@opentripplanner/types";
|
|
4
4
|
import type { ReactElement } from "react";
|
|
5
5
|
|
|
6
6
|
export interface CaloriesDetailsProps {
|
|
@@ -13,22 +13,21 @@ export interface DepartureDetailsProps {
|
|
|
13
13
|
departureDate: Date;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export interface FareDetailsLayout {
|
|
17
|
+
header: string;
|
|
18
|
+
cols: {
|
|
19
|
+
key: string;
|
|
20
|
+
header: string;
|
|
21
|
+
}[];
|
|
22
|
+
}
|
|
16
23
|
export interface TransitFareData {
|
|
17
|
-
[key: string]:
|
|
18
|
-
currency: {
|
|
19
|
-
currencyCode: string
|
|
20
|
-
defaultFractionDigits: number
|
|
21
|
-
currency: string
|
|
22
|
-
symbol: string
|
|
23
|
-
};
|
|
24
|
-
cents: number;
|
|
25
|
-
}
|
|
24
|
+
[key: string]: Money
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
export interface FareDetailsProps {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
transitFares: Fare;
|
|
29
|
+
legs: Leg[];
|
|
30
|
+
layout: FareDetailsLayout[];
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
export interface TransitFareProps {
|
|
@@ -37,7 +36,7 @@ export interface TransitFareProps {
|
|
|
37
36
|
fareKeyNameMap: {
|
|
38
37
|
[key: string]: string;
|
|
39
38
|
};
|
|
40
|
-
transitFares:
|
|
39
|
+
transitFares: Fare;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
export interface TripDetailsProps {
|
|
@@ -57,16 +56,16 @@ export interface TripDetailsProps {
|
|
|
57
56
|
* Slot for a custom component to render the expandable section for departure.
|
|
58
57
|
*/
|
|
59
58
|
DepartureDetails?: React.ElementType<DepartureDetailsProps>;
|
|
60
|
-
/**
|
|
61
|
-
* Slot for a custom component to render the expandable section for fares.
|
|
62
|
-
*/
|
|
63
|
-
FareDetails?: React.ElementType<FareDetailsProps>;
|
|
64
59
|
/**
|
|
65
60
|
* Mapping between fare keys and human-readable names for them.
|
|
66
61
|
*/
|
|
67
62
|
fareKeyNameMap?: {
|
|
68
63
|
[name: string]: string;
|
|
69
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* Column and table configuration for fare details/fare by leg table.
|
|
67
|
+
*/
|
|
68
|
+
fareDetailsLayout?: FareDetailsLayout[];
|
|
70
69
|
/**
|
|
71
70
|
* Itinerary that the user has selected to view, contains multiple legs.
|
|
72
71
|
*/
|