Skip to content

Commit a53a715

Browse files
Merge branch 'print-trip-heading-attribute' of https://github.com/nikkisato/otp-ui into pr/910
2 parents 40eebb0 + 7ff2489 commit a53a715

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1883
-439
lines changed

.github/workflows/node-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
run: pnpm run lint:js
2020
- name: Lint styles
2121
run: pnpm run lint:styles
22+
- name: Build packages
23+
run: pnpm run build:cjs && pnpm run build:esm
2224
- name: i18n check (en-US, fr only)
2325
run: pnpm run check:i18n-en-fr
2426
- name: Type check

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,11 @@
103103
"check:i18n-all": "node packages/scripts/lib/run-validate-i18n.js packages/**/src packages/**/i18n",
104104
"check:i18n-en-fr": "node packages/scripts/lib/run-validate-i18n.js packages/**/src packages/**/i18n/en-US.yml packages/**/i18n/fr.yml",
105105
"clean": "git clean -Xdf",
106-
"prepublish": "pnpm build:cjs && pnpm build:esm",
106+
"prepublish": "pnpm typescript && pnpm build:cjs && pnpm build:esm",
107107
"check-eslint-config": "eslint --print-config jestconfig.js | eslint-config-prettier-check",
108108
"coverage": "jest --coverage",
109109
"deploy-storybook": "storybook-to-ghpages",
110110
"dev": "storybook dev -p 5555",
111-
"postinstall": "pnpm prepublish",
112111
"build-storybook": "storybook build",
113112
"lint:js": "eslint . --ext .js,.jsx,.ts,.tsx --ignore-pattern esm --ignore-pattern lib --ignore-pattern node_modules --ignore-pattern storybook-static --quiet",
114113
"lint:graphql": "eslint . --ext .graphql --ignore-pattern esm --ignore-pattern lib --ignore-pattern node_modules --ignore-pattern storybook-static",

packages/core-utils/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ This package depends on the [date-fns library](https://date-fns.org), which reli
77
## Usage
88

99
```
10+
1011
TBD
1112
```

packages/core-utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opentripplanner/core-utils",
3-
"version": "14.3.1",
3+
"version": "14.3.3",
44
"description": "Core functionality that is shared among numerous UI components",
55
"engines": {
66
"node": ">=13"

packages/core-utils/src/__tests__/itinerary.ts

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ElevationProfile } from "@opentripplanner/types";
22
import {
33
calculateTncFares,
4+
descope,
45
getCompanyFromLeg,
5-
getDisplayedStopId,
6+
getDisplayedStopCode,
67
getElevationProfile,
78
getItineraryCost,
89
getLegCost,
@@ -31,6 +32,30 @@ const basePlace = {
3132
};
3233

3334
describe("util > itinerary", () => {
35+
describe("descope", () => {
36+
it("should return the descope'd part for standard scoped strings", () => {
37+
expect(descope("agency:cash")).toBe("cash");
38+
expect(descope("foo:bar")).toBe("bar");
39+
});
40+
41+
it("should return the input if it is not scoped", () => {
42+
expect(descope("cash")).toBe("cash");
43+
expect(descope("")).toBe("");
44+
});
45+
46+
it("should only return the segment after the first ':'", () => {
47+
expect(descope("aaaa:bbbb:cccc")).toBe("bbbb:cccc");
48+
expect(descope(":value")).toBe("value");
49+
expect(descope("value:")).toBe("");
50+
expect(descope(":")).toBe("");
51+
});
52+
53+
it("should handle null and undefined", () => {
54+
expect(descope(null)).toBeNull();
55+
expect(descope(undefined)).toBeUndefined();
56+
});
57+
});
58+
3459
describe("getElevationProfile", () => {
3560
it("should work with REST legacy data and GraphQL elevationProfile", () => {
3661
const legacyOutput = getElevationProfile(
@@ -89,47 +114,35 @@ describe("util > itinerary", () => {
89114
});
90115
});
91116

92-
describe("getDisplayedStopId", () => {
117+
describe("getDisplayedStopCode", () => {
93118
it("should return the stop code if one is provided", () => {
94119
const place = {
95120
...basePlace,
96121
stopCode: "code123",
97122
stopId: "xagency:id123"
98123
};
99-
expect(getDisplayedStopId(place)).toEqual("code123");
124+
expect(getDisplayedStopCode(place)).toEqual("code123");
100125
const stop = {
101126
...basePlace,
102127
code: "code123",
103128
id: "xagency:id123"
104129
};
105-
expect(getDisplayedStopId(stop)).toEqual("code123");
130+
expect(getDisplayedStopCode(stop)).toEqual("code123");
106131
});
107-
it("should return the id part of stopId it contains and agencyId (and no stopCode is provided)", () => {
132+
it("should return undefined if id is present and no stopCode is provided", () => {
108133
const place = {
109134
...basePlace,
110135
stopId: "xagency:id123"
111136
};
112-
expect(getDisplayedStopId(place)).toEqual("id123");
137+
expect(getDisplayedStopCode(place)).toBeFalsy();
113138
const stop = {
114139
...basePlace,
115140
id: "xagency:id123"
116141
};
117-
expect(getDisplayedStopId(stop)).toEqual("id123");
118-
});
119-
it("should return the whole stopId it does not contain an agency part (and no stopCode is provided)", () => {
120-
const place = {
121-
...basePlace,
122-
stopId: "wholeid123"
123-
};
124-
expect(getDisplayedStopId(place)).toEqual("wholeid123");
125-
const stop = {
126-
...basePlace,
127-
stopId: "wholeid123"
128-
};
129-
expect(getDisplayedStopId(stop)).toEqual("wholeid123");
142+
expect(getDisplayedStopCode(stop)).toBeFalsy();
130143
});
131-
it("should return null if stopId is null (and no stopCode is provided)", () => {
132-
expect(getDisplayedStopId(basePlace)).toBeFalsy();
144+
it("should return undefined if stopId is null (and no stopCode is provided)", () => {
145+
expect(getDisplayedStopCode(basePlace)).toBeFalsy();
133146
});
134147
});
135148

packages/core-utils/src/itinerary.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -595,28 +595,31 @@ export function calculateEmissions(
595595
}
596596

597597
/**
598-
* Returns the user-facing stop id to display for a stop or place, using the following priority:
599-
* 1. stop code,
600-
* 2. stop id without the agency id portion, if stop id contains an agency portion,
601-
* 3. stop id, whether null or not (this is the fallback case).
598+
* Returns the user-facing stop code to display for a stop or place
602599
*/
603-
export function getDisplayedStopId(placeOrStop: Place | Stop): string {
604-
let stopId;
605-
let stopCode;
600+
export function getDisplayedStopCode(
601+
placeOrStop: Place | Stop
602+
): string | undefined {
606603
if ("stopId" in placeOrStop) {
607-
({ stopCode, stopId } = placeOrStop);
608-
} else if ("id" in placeOrStop) {
609-
({ code: stopCode, id: stopId } = placeOrStop);
604+
return placeOrStop.stopCode ?? undefined;
610605
}
611-
return stopCode || stopId?.split(":")[1] || stopId;
606+
if ("id" in placeOrStop) {
607+
return placeOrStop.code ?? undefined;
608+
}
609+
return undefined;
612610
}
613611

614612
/**
615613
* Removes the first part of the OTP standard scope (":"), if it is present
614+
* If it's null or undefined, return the original value.
616615
* @param item String that is potentially scoped with `:` character
617616
* @returns descoped string
618617
*/
619-
export const descope = (item: string): string => item?.split(":")?.[1];
618+
export const descope = (item?: string | null): string | null | undefined => {
619+
if (!item) return item;
620+
const index = item.indexOf(":");
621+
return index === -1 ? item : item.substring(index + 1);
622+
};
620623

621624
export type ExtendedMoney = Money & { originalAmount?: number };
622625

@@ -638,8 +641,8 @@ export const zeroDollars = (currency: Currency): Money => ({
638641
*/
639642
export function getLegCost(
640643
leg: Leg,
641-
mediumId: string | null,
642-
riderCategoryId: string | null,
644+
mediumId?: string | null,
645+
riderCategoryId?: string | null,
643646
seenFareIds?: string[]
644647
): {
645648
alternateFareProducts?: AppliedFareProduct[];
@@ -662,6 +665,7 @@ export function getLegCost(
662665

663666
const productMediaId =
664667
descope(product?.medium?.id) || product?.medium?.id || null;
668+
665669
return (
666670
productRiderCategoryId === riderCategoryId &&
667671
productMediaId === mediumId &&
@@ -709,8 +713,8 @@ export function getLegCost(
709713
*/
710714
export function getItineraryCost(
711715
legs: Leg[],
712-
mediumId: string | string[] | null,
713-
riderCategoryId: string | string[] | null
716+
mediumId?: string | string[] | null,
717+
riderCategoryId?: string | string[] | null
714718
): Money | undefined {
715719
// TODO: Better input type handling
716720
if (Array.isArray(mediumId) || Array.isArray(riderCategoryId)) {
@@ -772,7 +776,7 @@ export function getItineraryCost(
772776
);
773777
}
774778

775-
const pickupDropoffTypeToOtp1 = otp2Type => {
779+
const pickupDropoffTypeToOtp1 = (otp2Type: string): string | null => {
776780
switch (otp2Type) {
777781
case "COORDINATE_WITH_DRIVER":
778782
return "coordinateWithDriver";

packages/geocoder/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Usage
22

33
```
4+
45
TBD
56
```

packages/geocoder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opentripplanner/geocoder",
3-
"version": "3.0.6",
3+
"version": "3.0.7",
44
"description": "Geocoding tools for multiple geocoding providers",
55
"main": "lib/index.js",
66
"module": "esm/index.js",

packages/icons/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@opentripplanner/icons",
3-
"version": "4.1.2",
3+
"version": "4.1.3",
44
"description": "Icons for otp-ui",
55
"main": "lib/index.js",
66
"module": "esm/index.js",

packages/icons/src/trimet-leg-icon.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import BiketownIcon from "./companies/biketown-icon";
88
const { getLegRouteLongName } = coreUtils.itinerary;
99

1010
const TriMetLegIcon = ({ leg, ...props }) => {
11-
// Custom TriMet icon logic.
11+
// Custom TriMet icon logic
1212
const routeLongName = getLegRouteLongName(leg);
1313
if (routeLongName && routeLongName.startsWith("Portland Streetcar")) {
1414
return <TriMetModeIcon mode="STREETCAR" {...props} />;

0 commit comments

Comments
 (0)