@opentripplanner/trip-details 9.0.7 → 9.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"fares-v2-table.js","names":["_react","_interopRequireDefault","require","_coreUtils","_reactIntl","_styledComponents","_Transfer","_utils","_styled","getLegCost","getItineraryCost","descope","getLegRouteName","coreUtils","itinerary","FailDash","default","createElement","Fragment","InvisibleA11yLabel","FormattedMessage","id","TransferIcon","styled","Transfer","withConfig","displayName","componentId","StripedTable","table","categoryReducer","acc","cur","some","m","push","categorySorter","favoriteId","a","b","aId","bId","FaresV2Table","legs","favoriteMediumId","favoriteRiderCategoryId","intl","useIntl","transitLegs","filter","leg","transitLeg","fareProducts","flatMap","mediums","map","fp","_fp$product","product","medium","reduce","sort","riders","_fp$product2","riderCategory","r","length","name","productUseIds","Set","rows","key","style","textAlign","scope","tripId","forEach","index","mediumIndex","rider","riderIndex","_dependentAlternateFa","_legPrice$currency","_legPrice$currency2","alternateFareProducts","isDependent","appliedFareProduct","productUseId","Array","from","legPrice","add","dependentAlternateFareProducts","originalAmount","price","amount","newCell","defaultMessage","title","Number","isNaN","formatMessage","description","transferAmount","formatNumber","currency","code","currencyDisplay","size","renderFare","currentRowIndex","fare","InvisibleA11yCaption","_default","exports"],"sources":["../../src/components/fares-v2-table.tsx"],"sourcesContent":["/* eslint-disable no-underscore-dangle */\nimport React from \"react\";\nimport { Leg } from \"@opentripplanner/types\";\nimport coreUtils from \"@opentripplanner/core-utils\";\nimport { FormattedMessage, useIntl } from \"react-intl\";\nimport styled from \"styled-components\";\nimport { Transfer } from \"@styled-icons/boxicons-regular/Transfer\";\n\nimport { renderFare } from \"../utils\";\nimport { InvisibleA11yCaption, InvisibleA11yLabel } from \"../styled\";\n\n// TODO: inline this import? (@opentripplanner/core-utils/src/itinerary)\nconst {\n getLegCost,\n getItineraryCost,\n descope,\n getLegRouteName\n} = coreUtils.itinerary;\n\nconst FailDash = (\n <>\n -\n <InvisibleA11yLabel>\n <FormattedMessage id=\"otpUi.TripDetails.legMissingFareInfo\" />\n </InvisibleA11yLabel>\n </>\n);\n\nconst TransferIcon = styled(Transfer)`\n padding-right: 0.25ch;\n`;\n\nconst StripedTable = styled.table`\n text-align: right;\n\n tr td,\n tr th {\n padding: 4px;\n }\n\n tr td:nth-of-type(2n + 1),\n tr th:nth-of-type(2n) {\n background: #cccccc55;\n border-color: #cccccc55;\n }\n`;\n\ntype IdNamePair = { id: string; name: string };\n\n// Removes duplicates\nconst categoryReducer = (acc: IdNamePair[], cur: IdNamePair) => {\n if (!acc.some(m => descope(m?.id) === descope(cur?.id))) {\n acc.push(cur);\n }\n return acc;\n};\n\n// Put the preferred medium first, and then all the others alphabetical\nconst categorySorter = (favoriteId?: string) => (\n a: IdNamePair,\n b: IdNamePair\n): number => {\n const aId = descope(a?.id);\n const bId = descope(b?.id);\n\n if (favoriteId && aId === favoriteId) {\n return -1;\n }\n if (favoriteId && bId === favoriteId) {\n return 1;\n }\n\n return aId > bId ? 1 : -1;\n};\n\n// TODO: This component currently can only show one type of fare per medium\nconst FaresV2Table = ({\n legs,\n favoriteMediumId,\n favoriteRiderCategoryId\n}: {\n legs: Leg[];\n favoriteMediumId?: string;\n favoriteRiderCategoryId?: string;\n}): JSX.Element => {\n const intl = useIntl();\n\n const transitLegs = legs.filter(leg => leg.transitLeg);\n\n // Get all fare products across all legs\n const fareProducts = transitLegs.flatMap(leg => leg.fareProducts);\n\n // Reduce these into mediums and riders\n const mediums = fareProducts\n .map(fp => fp.product?.medium)\n .filter(m => m !== null)\n .reduce(categoryReducer, [])\n .sort(categorySorter(favoriteMediumId));\n const riders = fareProducts\n .map(fp => fp.product?.riderCategory)\n .filter(r => r !== null)\n .reduce(categoryReducer, [])\n .sort(categorySorter(favoriteRiderCategoryId));\n\n // Ensure we have at least one rider/medium\n if (riders.length === 0) {\n riders.push({ name: \"Fare\", id: null });\n }\n if (mediums.length === 0) {\n mediums.push({ name: \"Regular\", id: null });\n }\n\n // Keep track of seen fare ids to indicate transfers\n const productUseIds: Set<string> = new Set();\n\n const rows = [\n [\n <th key=\"faretitle\" style={{ textAlign: \"left\" }} scope=\"col\">\n <InvisibleA11yLabel>\n <FormattedMessage id=\"otpUi.TripDetails.fareCategory\" />\n </InvisibleA11yLabel>\n </th>,\n ...transitLegs.map(leg => (\n <th key={leg.tripId} scope=\"col\">\n {getLegRouteName(leg)}\n </th>\n )),\n transitLegs.length > 1 ? (\n <th key=\"total\" style={{ textAlign: \"right\" }} scope=\"col\">\n <em>\n <FormattedMessage id=\"otpUi.TripDetails.total\" />\n </em>\n </th>\n ) : (\n <></>\n )\n ]\n ];\n\n // non-transit legs don't have fares\n transitLegs.forEach((leg, index) => {\n mediums.forEach((medium, mediumIndex) => {\n riders.forEach((rider, riderIndex) => {\n if (!medium || !rider) return;\n const {\n alternateFareProducts,\n isDependent,\n appliedFareProduct,\n productUseId\n } = getLegCost(\n leg,\n descope(medium.id) || null,\n descope(rider.id) || null,\n Array.from(productUseIds)\n );\n const legPrice = appliedFareProduct?.legPrice;\n\n productUseIds.add(productUseId);\n\n // Only consider alternateFareProducts if current product is dependent\n const dependentAlternateFareProducts =\n isDependent && alternateFareProducts;\n\n // Calculate pre-tranfer amount either via alternate fare or fare-id matching (price.originalAmount)\n const originalAmount =\n dependentAlternateFareProducts?.[0]?.price.amount -\n legPrice?.amount ||\n appliedFareProduct?.price.amount - legPrice?.amount;\n\n const newCell = (\n <>\n {/* Only render the list of fare types once */}\n {index === 0 && (\n <th style={{ textAlign: \"left\" }} scope=\"row\">\n <FormattedMessage\n id={`config.fares.media.${descope(medium.id)}`}\n defaultMessage={medium.name}\n />{\" \"}\n <FormattedMessage\n id={`config.fares.riderCategory.${descope(rider.id)}`}\n defaultMessage={rider.name}\n />\n </th>\n )}\n <td\n style={{ textAlign: legPrice ? \"right\" : \"center\" }}\n title={\n !Number.isNaN(originalAmount) &&\n originalAmount > 0 &&\n index > 0 &&\n intl.formatMessage(\n {\n description:\n \"Text explaining the transfer discount applied to this fare.\",\n id: \"otpUi.TripDetails.transferDiscountExplanation\"\n },\n {\n transferAmount: intl.formatNumber(originalAmount, {\n currency: legPrice?.currency?.code,\n currencyDisplay: \"narrowSymbol\",\n style: \"currency\"\n })\n }\n )\n }\n >\n {!Number.isNaN(originalAmount) &&\n originalAmount > 0 &&\n index > 0 && <TransferIcon size={16} />}\n {/* Leg Price will always be defined if the fare product has a price */}\n {legPrice\n ? renderFare(legPrice?.currency?.code, legPrice?.amount)\n : FailDash}\n </td>\n </>\n );\n const currentRowIndex = 1 + riderIndex + riders.length * mediumIndex;\n if (!rows[currentRowIndex]) {\n rows[currentRowIndex] = [];\n }\n rows[currentRowIndex].push(newCell);\n\n // Generate final column\n if (index === transitLegs.length - 1 && transitLegs.length > 1) {\n const fare = getItineraryCost(\n legs,\n descope(medium.id) || null,\n descope(rider.id) || null\n );\n rows[currentRowIndex].push(\n <td\n style={{ textAlign: fare?.amount ? \"right\" : \"center\" }}\n title={\n !fare?.amount &&\n intl.formatMessage({\n id: \"otpUi.TripDetails.missingFareTotal\"\n })\n }\n >\n <em>\n {fare?.amount\n ? renderFare(fare?.currency.code, fare?.amount)\n : FailDash}\n </em>\n </td>\n );\n }\n });\n });\n });\n\n return (\n <StripedTable>\n <InvisibleA11yCaption>\n <FormattedMessage id=\"otpUi.TripDetails.transitFareTable\" />\n </InvisibleA11yCaption>\n {rows.map((r, index) => (\n <tr key={index}>{r}</tr>\n ))}\n </StripedTable>\n );\n};\n\nexport default FaresV2Table;\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AACA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EsC,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEhB,MAAM,GAAG,OAAO,GAAG;YAAS,CAAE;YACxDG,KAAK,EACH,EAACa,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEhB,MAAM,KACbjD,IAAI,CAACuD,aAAa,CAAC;cACjBhF,EAAE,EAAE;YACN,CAAC;UACF,gBAEDrB,MAAA,CAAAgB,OAAA,CAAAC,aAAA,aACG8F,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAEhB,MAAM,GACT,IAAAc,iBAAU,EAACE,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEN,QAAQ,CAACC,IAAI,EAAEK,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAEhB,MAAM,CAAC,GAC7ChF,QACF,CACF,CACN,CAAC;QACH;MACF,CAAC,CAAC;IACJ,CAAC,CAAC;EACJ,CAAC,CAAC;EAEF,oBACEf,MAAA,CAAAgB,OAAA,CAAAC,aAAA,CAACW,YAAY,qBACX5B,MAAA,CAAAgB,OAAA,CAAAC,aAAA,CAACT,OAAA,CAAAwG,oBAAoB,qBACnBhH,MAAA,CAAAgB,OAAA,CAAAC,aAAA,CAACb,UAAA,CAAAgB,gBAAgB;IAACC,EAAE,EAAC;EAAoC,CAAE,CACvC,CAAC,EACtBiD,IAAI,CAACf,GAAG,CAAC,CAACU,CAAC,EAAEY,KAAK,kBACjB7E,MAAA,CAAAgB,OAAA,CAAAC,aAAA;IAAIsD,GAAG,EAAEM;EAAM,GAAEZ,CAAM,CACxB,CACW,CAAC;AAEnB,CAAC;AAAC,IAAAgD,QAAA,GAAAC,OAAA,CAAAlG,OAAA,GAEa0B,YAAY","ignoreList":[]}
1
+ {"version":3,"file":"fares-v2-table.js","names":["_react","_interopRequireDefault","require","_coreUtils","_reactIntl","_styledComponents","_Transfer","_utils","_styled","getLegCost","getItineraryCost","descope","getLegRouteName","coreUtils","itinerary","FailDash","default","createElement","Fragment","InvisibleA11yLabel","FormattedMessage","id","TransferIcon","styled","Transfer","withConfig","displayName","componentId","StripedTable","table","categoryReducer","acc","cur","some","m","push","categorySorter","favoriteId","a","b","aId","bId","FaresV2Table","legs","favoriteMediumId","favoriteRiderCategoryId","intl","useIntl","transitLegs","filter","leg","transitLeg","fareProducts","flatMap","mediums","map","fp","_fp$product","product","medium","reduce","sort","riders","_fp$product2","riderCategory","riderMediumPairs","rider","rmp","_fp$product3","_rmp$rider","_fp$product4","_rmp$medium","length","name","productUseIds","Set","rows","key","style","textAlign","scope","tripId","forEach","index","currentRowIndex","_medium$id","_rider$id","_dependentAlternateFa","_legPrice$currency","_legPrice$currency2","alternateFareProducts","isDependent","appliedFareProduct","productUseId","Array","from","legPrice","add","dependentAlternateFareProducts","originalAmount","price","amount","newCell","defaultMessage","title","Number","isNaN","formatMessage","description","transferAmount","formatNumber","currency","code","currencyDisplay","size","renderFare","nextRowIndex","_medium$id2","_rider$id2","fare","InvisibleA11yCaption","r","_default","exports"],"sources":["../../src/components/fares-v2-table.tsx"],"sourcesContent":["/* eslint-disable no-underscore-dangle */\nimport React from \"react\";\nimport { Leg } from \"@opentripplanner/types\";\nimport coreUtils from \"@opentripplanner/core-utils\";\nimport { FormattedMessage, useIntl } from \"react-intl\";\nimport styled from \"styled-components\";\nimport { Transfer } from \"@styled-icons/boxicons-regular/Transfer\";\n\nimport { renderFare } from \"../utils\";\nimport { InvisibleA11yCaption, InvisibleA11yLabel } from \"../styled\";\n\nconst {\n getLegCost,\n getItineraryCost,\n descope,\n getLegRouteName\n} = coreUtils.itinerary;\n\nconst FailDash = (\n <>\n -\n <InvisibleA11yLabel>\n <FormattedMessage id=\"otpUi.TripDetails.legMissingFareInfo\" />\n </InvisibleA11yLabel>\n </>\n);\n\nconst TransferIcon = styled(Transfer)`\n padding-right: 0.25ch;\n`;\n\nconst StripedTable = styled.table`\n text-align: right;\n\n tr td,\n tr th {\n padding: 4px;\n }\n\n tr td:nth-of-type(2n + 1),\n tr th:nth-of-type(2n) {\n background: #cccccc55;\n border-color: #cccccc55;\n }\n`;\n\ntype IdNamePair = { id: string; name: string };\n\n// Removes duplicates\nconst categoryReducer = (acc: IdNamePair[], cur: IdNamePair) => {\n if (!acc.some(m => descope(m?.id) === descope(cur?.id))) {\n acc.push(cur);\n }\n return acc;\n};\n\n// Put the preferred medium first, and then all the others alphabetical\nconst categorySorter = (favoriteId?: string) => (\n a: IdNamePair,\n b: IdNamePair\n): number => {\n const aId = descope(a?.id);\n const bId = descope(b?.id);\n\n if (favoriteId && aId === favoriteId) {\n return -1;\n }\n if (favoriteId && bId === favoriteId) {\n return 1;\n }\n\n return aId > bId ? 1 : -1;\n};\n\n// TODO: This component currently can only show one type of fare per medium\nconst FaresV2Table = ({\n legs,\n favoriteMediumId,\n favoriteRiderCategoryId\n}: {\n legs: Leg[];\n favoriteMediumId?: string;\n favoriteRiderCategoryId?: string;\n}): JSX.Element => {\n const intl = useIntl();\n\n const transitLegs = legs.filter(leg => leg.transitLeg);\n\n // Get all fare products across all legs\n const fareProducts = transitLegs.flatMap(leg => leg.fareProducts);\n\n // Reduce these into mediums and riders\n const mediums = fareProducts\n .map(fp => fp.product?.medium)\n .reduce(categoryReducer, [])\n .sort(categorySorter(favoriteMediumId));\n const riders = fareProducts\n .map(fp => fp.product?.riderCategory)\n .reduce(categoryReducer, [])\n .sort(categorySorter(favoriteRiderCategoryId));\n\n // Generate the pairs of riders and mediums, but filter out ones\n // that never occur in the FareProducts\n const riderMediumPairs = mediums\n .flatMap(medium =>\n riders.map(rider => ({\n medium,\n rider\n }))\n )\n .filter(rmp =>\n fareProducts.some(\n fp =>\n fp.product?.riderCategory?.id === rmp.rider?.id &&\n fp.product?.medium?.id === rmp.medium?.id\n )\n );\n\n // Ensure we have at least one rider/medium\n if (riders.length === 0) {\n riders.push({ name: \"Fare\", id: null });\n }\n if (mediums.length === 0) {\n mediums.push({ name: \"Regular\", id: null });\n }\n\n // Keep track of seen fare ids to indicate transfers\n const productUseIds: Set<string> = new Set();\n\n const rows = [\n [\n <th key=\"faretitle\" style={{ textAlign: \"left\" }} scope=\"col\">\n <InvisibleA11yLabel>\n <FormattedMessage id=\"otpUi.TripDetails.fareCategory\" />\n </InvisibleA11yLabel>\n </th>,\n ...transitLegs.map(leg => (\n <th key={leg.tripId} scope=\"col\">\n {getLegRouteName(leg)}\n </th>\n )),\n transitLegs.length > 1 ? (\n <th key=\"total\" style={{ textAlign: \"right\" }} scope=\"col\">\n <em>\n <FormattedMessage id=\"otpUi.TripDetails.total\" />\n </em>\n </th>\n ) : (\n <></>\n )\n ]\n ];\n\n // non-transit legs don't have fares\n transitLegs.forEach((leg, index) => {\n riderMediumPairs.forEach((rmp, currentRowIndex) => {\n const { medium, rider } = rmp;\n const {\n alternateFareProducts,\n isDependent,\n appliedFareProduct,\n productUseId\n } = getLegCost(\n leg,\n descope(medium?.id ?? null),\n descope(rider?.id ?? null),\n Array.from(productUseIds)\n );\n const legPrice = appliedFareProduct?.legPrice;\n\n productUseIds.add(productUseId);\n\n // Only consider alternateFareProducts if current product is dependent\n const dependentAlternateFareProducts =\n isDependent && alternateFareProducts;\n\n // Calculate pre-tranfer amount either via alternate fare or fare-id matching (price.originalAmount)\n const originalAmount =\n dependentAlternateFareProducts?.[0]?.price.amount - legPrice?.amount ||\n appliedFareProduct?.price.amount - legPrice?.amount;\n\n const newCell = (\n <>\n {/* Only render the list of fare types once */}\n {index === 0 && (\n <th style={{ textAlign: \"left\" }} scope=\"row\">\n {medium?.id && (\n <>\n <FormattedMessage\n id={`config.fares.media.${descope(medium.id)}`}\n defaultMessage={medium.name}\n />{\" \"}\n </>\n )}\n {rider?.id && (\n <FormattedMessage\n id={`config.fares.riderCategory.${descope(rider.id)}`}\n defaultMessage={rider.name}\n />\n )}\n {!medium?.id && !rider?.id ? FailDash : null}\n </th>\n )}\n <td\n style={{ textAlign: legPrice ? \"right\" : \"center\" }}\n title={\n !Number.isNaN(originalAmount) &&\n originalAmount > 0 &&\n index > 0 &&\n intl.formatMessage(\n {\n description:\n \"Text explaining the transfer discount applied to this fare.\",\n id: \"otpUi.TripDetails.transferDiscountExplanation\"\n },\n {\n transferAmount: intl.formatNumber(originalAmount, {\n currency: legPrice?.currency?.code,\n currencyDisplay: \"narrowSymbol\",\n style: \"currency\"\n })\n }\n )\n }\n >\n {!Number.isNaN(originalAmount) &&\n originalAmount > 0 &&\n index > 0 && <TransferIcon size={16} />}\n {/* Leg Price will always be defined if the fare product has a price */}\n {legPrice\n ? renderFare(legPrice?.currency?.code, legPrice?.amount)\n : FailDash}\n </td>\n </>\n );\n const nextRowIndex = currentRowIndex + 1;\n if (!rows[nextRowIndex]) {\n rows[nextRowIndex] = [];\n }\n rows[nextRowIndex].push(newCell);\n\n // Generate final column\n if (index === transitLegs.length - 1 && transitLegs.length > 1) {\n const fare = getItineraryCost(\n legs,\n descope(medium?.id ?? null),\n descope(rider?.id ?? null)\n );\n rows[nextRowIndex].push(\n <td\n style={{ textAlign: fare?.amount ? \"right\" : \"center\" }}\n title={\n !fare?.amount &&\n intl.formatMessage({\n id: \"otpUi.TripDetails.missingFareTotal\"\n })\n }\n >\n <em>\n {fare?.amount\n ? renderFare(fare?.currency.code, fare?.amount)\n : FailDash}\n </em>\n </td>\n );\n }\n });\n });\n\n return (\n <StripedTable>\n <InvisibleA11yCaption>\n <FormattedMessage id=\"otpUi.TripDetails.transitFareTable\" />\n </InvisibleA11yCaption>\n {rows.map((r, index) => (\n <tr key={index}>{r}</tr>\n ))}\n </StripedTable>\n );\n};\n\nexport default FaresV2Table;\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AATA;;AAWA,MA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B,MAAM,GAAG,OAAO,GAAG;UAAS,CAAE;UACxDG,KAAK,EACH,EAACe,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAElB,MAAM,KACbvD,IAAI,CAAC6D,aAAa,CAAC;YACjBtF,EAAE,EAAE;UACN,CAAC;QACF,gBAEDrB,MAAA,CAAAgB,OAAA,CAAAC,aAAA,aACGsG,IAAI,aAAJA,IAAI,eAAJA,IAAI,CAAElB,MAAM,GACT,IAAAc,iBAAU,EAACI,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAER,QAAQ,CAACC,IAAI,EAAEO,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAElB,MAAM,CAAC,GAC7CtF,QACF,CACF,CACN,CAAC;MACH;IACF,CAAC,CAAC;EACJ,CAAC,CAAC;EAEF,oBACEf,MAAA,CAAAgB,OAAA,CAAAC,aAAA,CAACW,YAAY,qBACX5B,MAAA,CAAAgB,OAAA,CAAAC,aAAA,CAACT,OAAA,CAAAgH,oBAAoB,qBACnBxH,MAAA,CAAAgB,OAAA,CAAAC,aAAA,CAACb,UAAA,CAAAgB,gBAAgB;IAACC,EAAE,EAAC;EAAoC,CAAE,CACvC,CAAC,EACtBuD,IAAI,CAACrB,GAAG,CAAC,CAACkE,CAAC,EAAEtC,KAAK,kBACjBnF,MAAA,CAAAgB,OAAA,CAAAC,aAAA;IAAI4D,GAAG,EAAEM;EAAM,GAAEsC,CAAM,CACxB,CACW,CAAC;AAEnB,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA3G,OAAA,GAEa0B,YAAY","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentripplanner/trip-details",
3
- "version": "9.0.7",
3
+ "version": "9.1.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",
@@ -15,7 +15,7 @@
15
15
  "@styled-icons/fa-solid": "^10.34.0",
16
16
  "flat": "^5.0.2",
17
17
  "react-animate-height": "^3.0.4",
18
- "@opentripplanner/core-utils": "14.3.2"
18
+ "@opentripplanner/core-utils": "15.0.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@opentripplanner/types": "8.3.1"
@@ -1422,47 +1422,6 @@ exports[`TripDetails FaresV2TableStory smoke-test 1`] = `
1422
1422
  </em>
1423
1423
  </td>
1424
1424
  </tr>
1425
- <tr>
1426
- <th scope="row"
1427
- style="text-align: left;"
1428
- >
1429
- cash special
1430
- </th>
1431
- <td style="text-align: center;">
1432
- -
1433
- <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1434
- No fare information for this leg
1435
- </span>
1436
- </td>
1437
- <td style="text-align: center;">
1438
- -
1439
- <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1440
- No fare information for this leg
1441
- </span>
1442
- </td>
1443
- <td style="text-align: center;">
1444
- -
1445
- <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1446
- No fare information for this leg
1447
- </span>
1448
- </td>
1449
- <td style="text-align: center;">
1450
- -
1451
- <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1452
- No fare information for this leg
1453
- </span>
1454
- </td>
1455
- <td title="No fare total available"
1456
- style="text-align: center;"
1457
- >
1458
- <em>
1459
- -
1460
- <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1461
- No fare information for this leg
1462
- </span>
1463
- </em>
1464
- </td>
1465
- </tr>
1466
1425
  <tr>
1467
1426
  <th scope="row"
1468
1427
  style="text-align: left;"
@@ -1605,6 +1564,38 @@ exports[`TripDetails FaresV2TableStory smoke-test 1`] = `
1605
1564
  </em>
1606
1565
  </td>
1607
1566
  </tr>
1567
+ <tr>
1568
+ <th scope="row"
1569
+ style="text-align: left;"
1570
+ >
1571
+ -
1572
+ <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1573
+ No fare information for this leg
1574
+ </span>
1575
+ </th>
1576
+ <td style="text-align: right;">
1577
+ $0.00
1578
+ </td>
1579
+ <td style="text-align: right;">
1580
+ $0.00
1581
+ </td>
1582
+ <td style="text-align: right;">
1583
+ $0.00
1584
+ </td>
1585
+ <td style="text-align: right;">
1586
+ $0.00
1587
+ </td>
1588
+ <td title="No fare total available"
1589
+ style="text-align: center;"
1590
+ >
1591
+ <em>
1592
+ -
1593
+ <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1594
+ No fare information for this leg
1595
+ </span>
1596
+ </em>
1597
+ </td>
1598
+ </tr>
1608
1599
  </table>
1609
1600
  `;
1610
1601
 
@@ -1907,31 +1898,19 @@ exports[`TripDetails LegFareProductsItinerary smoke-test 1`] = `
1907
1898
  <th scope="row"
1908
1899
  style="text-align: left;"
1909
1900
  >
1910
- cash special
1901
+ cash youth
1911
1902
  </th>
1912
- <td style="text-align: center;">
1913
- -
1914
- <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1915
- No fare information for this leg
1916
- </span>
1903
+ <td style="text-align: right;">
1904
+ $0.00
1917
1905
  </td>
1918
- <td style="text-align: center;">
1919
- -
1920
- <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1921
- No fare information for this leg
1922
- </span>
1906
+ <td style="text-align: right;">
1907
+ $0.00
1923
1908
  </td>
1924
- <td style="text-align: center;">
1925
- -
1926
- <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1927
- No fare information for this leg
1928
- </span>
1909
+ <td style="text-align: right;">
1910
+ $0.00
1929
1911
  </td>
1930
- <td style="text-align: center;">
1931
- -
1932
- <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1933
- No fare information for this leg
1934
- </span>
1912
+ <td style="text-align: right;">
1913
+ $0.00
1935
1914
  </td>
1936
1915
  <td title="No fare total available"
1937
1916
  style="text-align: center;"
@@ -1948,7 +1927,10 @@ exports[`TripDetails LegFareProductsItinerary smoke-test 1`] = `
1948
1927
  <th scope="row"
1949
1928
  style="text-align: left;"
1950
1929
  >
1951
- cash youth
1930
+ -
1931
+ <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
1932
+ No fare information for this leg
1933
+ </span>
1952
1934
  </th>
1953
1935
  <td style="text-align: right;">
1954
1936
  $0.00
@@ -2577,7 +2559,10 @@ exports[`TripDetails OTP2FlexItinerary smoke-test 1`] = `
2577
2559
  <th scope="row"
2578
2560
  style="text-align: left;"
2579
2561
  >
2580
- Regular Fare
2562
+ -
2563
+ <span class="styled__InvisibleA11yLabel-sc-6q2ok2-0 elLeWK">
2564
+ No fare information for this leg
2565
+ </span>
2581
2566
  </th>
2582
2567
  <td style="text-align: right;">
2583
2568
  $2.80
@@ -9,7 +9,6 @@ import { Transfer } from "@styled-icons/boxicons-regular/Transfer";
9
9
  import { renderFare } from "../utils";
10
10
  import { InvisibleA11yCaption, InvisibleA11yLabel } from "../styled";
11
11
 
12
- // TODO: inline this import? (@opentripplanner/core-utils/src/itinerary)
13
12
  const {
14
13
  getLegCost,
15
14
  getItineraryCost,
@@ -93,15 +92,30 @@ const FaresV2Table = ({
93
92
  // Reduce these into mediums and riders
94
93
  const mediums = fareProducts
95
94
  .map(fp => fp.product?.medium)
96
- .filter(m => m !== null)
97
95
  .reduce(categoryReducer, [])
98
96
  .sort(categorySorter(favoriteMediumId));
99
97
  const riders = fareProducts
100
98
  .map(fp => fp.product?.riderCategory)
101
- .filter(r => r !== null)
102
99
  .reduce(categoryReducer, [])
103
100
  .sort(categorySorter(favoriteRiderCategoryId));
104
101
 
102
+ // Generate the pairs of riders and mediums, but filter out ones
103
+ // that never occur in the FareProducts
104
+ const riderMediumPairs = mediums
105
+ .flatMap(medium =>
106
+ riders.map(rider => ({
107
+ medium,
108
+ rider
109
+ }))
110
+ )
111
+ .filter(rmp =>
112
+ fareProducts.some(
113
+ fp =>
114
+ fp.product?.riderCategory?.id === rmp.rider?.id &&
115
+ fp.product?.medium?.id === rmp.medium?.id
116
+ )
117
+ );
118
+
105
119
  // Ensure we have at least one rider/medium
106
120
  if (riders.length === 0) {
107
121
  riders.push({ name: "Fare", id: null });
@@ -139,113 +153,117 @@ const FaresV2Table = ({
139
153
 
140
154
  // non-transit legs don't have fares
141
155
  transitLegs.forEach((leg, index) => {
142
- mediums.forEach((medium, mediumIndex) => {
143
- riders.forEach((rider, riderIndex) => {
144
- if (!medium || !rider) return;
145
- const {
146
- alternateFareProducts,
147
- isDependent,
148
- appliedFareProduct,
149
- productUseId
150
- } = getLegCost(
151
- leg,
152
- descope(medium.id) || null,
153
- descope(rider.id) || null,
154
- Array.from(productUseIds)
155
- );
156
- const legPrice = appliedFareProduct?.legPrice;
156
+ riderMediumPairs.forEach((rmp, currentRowIndex) => {
157
+ const { medium, rider } = rmp;
158
+ const {
159
+ alternateFareProducts,
160
+ isDependent,
161
+ appliedFareProduct,
162
+ productUseId
163
+ } = getLegCost(
164
+ leg,
165
+ descope(medium?.id ?? null),
166
+ descope(rider?.id ?? null),
167
+ Array.from(productUseIds)
168
+ );
169
+ const legPrice = appliedFareProduct?.legPrice;
157
170
 
158
- productUseIds.add(productUseId);
171
+ productUseIds.add(productUseId);
159
172
 
160
- // Only consider alternateFareProducts if current product is dependent
161
- const dependentAlternateFareProducts =
162
- isDependent && alternateFareProducts;
173
+ // Only consider alternateFareProducts if current product is dependent
174
+ const dependentAlternateFareProducts =
175
+ isDependent && alternateFareProducts;
163
176
 
164
- // Calculate pre-tranfer amount either via alternate fare or fare-id matching (price.originalAmount)
165
- const originalAmount =
166
- dependentAlternateFareProducts?.[0]?.price.amount -
167
- legPrice?.amount ||
168
- appliedFareProduct?.price.amount - legPrice?.amount;
177
+ // Calculate pre-tranfer amount either via alternate fare or fare-id matching (price.originalAmount)
178
+ const originalAmount =
179
+ dependentAlternateFareProducts?.[0]?.price.amount - legPrice?.amount ||
180
+ appliedFareProduct?.price.amount - legPrice?.amount;
169
181
 
170
- const newCell = (
171
- <>
172
- {/* Only render the list of fare types once */}
173
- {index === 0 && (
174
- <th style={{ textAlign: "left" }} scope="row">
175
- <FormattedMessage
176
- id={`config.fares.media.${descope(medium.id)}`}
177
- defaultMessage={medium.name}
178
- />{" "}
182
+ const newCell = (
183
+ <>
184
+ {/* Only render the list of fare types once */}
185
+ {index === 0 && (
186
+ <th style={{ textAlign: "left" }} scope="row">
187
+ {medium?.id && (
188
+ <>
189
+ <FormattedMessage
190
+ id={`config.fares.media.${descope(medium.id)}`}
191
+ defaultMessage={medium.name}
192
+ />{" "}
193
+ </>
194
+ )}
195
+ {rider?.id && (
179
196
  <FormattedMessage
180
197
  id={`config.fares.riderCategory.${descope(rider.id)}`}
181
198
  defaultMessage={rider.name}
182
199
  />
183
- </th>
184
- )}
185
- <td
186
- style={{ textAlign: legPrice ? "right" : "center" }}
187
- title={
188
- !Number.isNaN(originalAmount) &&
189
- originalAmount > 0 &&
190
- index > 0 &&
191
- intl.formatMessage(
192
- {
193
- description:
194
- "Text explaining the transfer discount applied to this fare.",
195
- id: "otpUi.TripDetails.transferDiscountExplanation"
196
- },
197
- {
198
- transferAmount: intl.formatNumber(originalAmount, {
199
- currency: legPrice?.currency?.code,
200
- currencyDisplay: "narrowSymbol",
201
- style: "currency"
202
- })
203
- }
204
- )
205
- }
206
- >
207
- {!Number.isNaN(originalAmount) &&
208
- originalAmount > 0 &&
209
- index > 0 && <TransferIcon size={16} />}
210
- {/* Leg Price will always be defined if the fare product has a price */}
211
- {legPrice
212
- ? renderFare(legPrice?.currency?.code, legPrice?.amount)
200
+ )}
201
+ {!medium?.id && !rider?.id ? FailDash : null}
202
+ </th>
203
+ )}
204
+ <td
205
+ style={{ textAlign: legPrice ? "right" : "center" }}
206
+ title={
207
+ !Number.isNaN(originalAmount) &&
208
+ originalAmount > 0 &&
209
+ index > 0 &&
210
+ intl.formatMessage(
211
+ {
212
+ description:
213
+ "Text explaining the transfer discount applied to this fare.",
214
+ id: "otpUi.TripDetails.transferDiscountExplanation"
215
+ },
216
+ {
217
+ transferAmount: intl.formatNumber(originalAmount, {
218
+ currency: legPrice?.currency?.code,
219
+ currencyDisplay: "narrowSymbol",
220
+ style: "currency"
221
+ })
222
+ }
223
+ )
224
+ }
225
+ >
226
+ {!Number.isNaN(originalAmount) &&
227
+ originalAmount > 0 &&
228
+ index > 0 && <TransferIcon size={16} />}
229
+ {/* Leg Price will always be defined if the fare product has a price */}
230
+ {legPrice
231
+ ? renderFare(legPrice?.currency?.code, legPrice?.amount)
232
+ : FailDash}
233
+ </td>
234
+ </>
235
+ );
236
+ const nextRowIndex = currentRowIndex + 1;
237
+ if (!rows[nextRowIndex]) {
238
+ rows[nextRowIndex] = [];
239
+ }
240
+ rows[nextRowIndex].push(newCell);
241
+
242
+ // Generate final column
243
+ if (index === transitLegs.length - 1 && transitLegs.length > 1) {
244
+ const fare = getItineraryCost(
245
+ legs,
246
+ descope(medium?.id ?? null),
247
+ descope(rider?.id ?? null)
248
+ );
249
+ rows[nextRowIndex].push(
250
+ <td
251
+ style={{ textAlign: fare?.amount ? "right" : "center" }}
252
+ title={
253
+ !fare?.amount &&
254
+ intl.formatMessage({
255
+ id: "otpUi.TripDetails.missingFareTotal"
256
+ })
257
+ }
258
+ >
259
+ <em>
260
+ {fare?.amount
261
+ ? renderFare(fare?.currency.code, fare?.amount)
213
262
  : FailDash}
214
- </td>
215
- </>
263
+ </em>
264
+ </td>
216
265
  );
217
- const currentRowIndex = 1 + riderIndex + riders.length * mediumIndex;
218
- if (!rows[currentRowIndex]) {
219
- rows[currentRowIndex] = [];
220
- }
221
- rows[currentRowIndex].push(newCell);
222
-
223
- // Generate final column
224
- if (index === transitLegs.length - 1 && transitLegs.length > 1) {
225
- const fare = getItineraryCost(
226
- legs,
227
- descope(medium.id) || null,
228
- descope(rider.id) || null
229
- );
230
- rows[currentRowIndex].push(
231
- <td
232
- style={{ textAlign: fare?.amount ? "right" : "center" }}
233
- title={
234
- !fare?.amount &&
235
- intl.formatMessage({
236
- id: "otpUi.TripDetails.missingFareTotal"
237
- })
238
- }
239
- >
240
- <em>
241
- {fare?.amount
242
- ? renderFare(fare?.currency.code, fare?.amount)
243
- : FailDash}
244
- </em>
245
- </td>
246
- );
247
- }
248
- });
266
+ }
249
267
  });
250
268
  });
251
269