@opentripplanner/map-popup 7.0.0 → 8.0.0
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/index.js +22 -14
- package/esm/index.js.map +1 -1
- package/esm/util.js +9 -8
- package/esm/util.js.map +1 -1
- package/i18n/en-US.yml +3 -1
- package/lib/index.d.ts +7 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +92 -126
- package/lib/index.js.map +1 -1
- package/lib/styled.js +17 -10
- package/lib/styled.js.map +1 -1
- package/lib/util.d.ts +4 -3
- package/lib/util.d.ts.map +1 -1
- package/lib/util.js +58 -52
- package/lib/util.js.map +1 -1
- package/package.json +3 -3
- package/src/MapPopup.story.tsx +28 -35
- package/src/__snapshots__/MapPopup.story.tsx.snap +3 -3
- package/src/index.tsx +24 -20
- package/src/util.ts +27 -18
- package/tsconfig.tsbuildinfo +1 -1
package/lib/styled.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
6
|
exports.ViewStopButton = void 0;
|
|
8
|
-
|
|
7
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
8
|
/* eslint-disable-next-line import/prefer-default-export */
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
exports.ViewStopButton = styled_components_1.default.button `
|
|
10
|
+
background: none;
|
|
11
|
+
border-bottom: none;
|
|
12
|
+
${props => props.stopId != null
|
|
13
|
+
? "border-left: 1px solid #000; margin-left: 5px;"
|
|
14
|
+
: "border-left: none; padding-left: 0;"};
|
|
15
|
+
border-right: none;
|
|
16
|
+
border-top: none;
|
|
17
|
+
color: #008;
|
|
18
|
+
font-family: inherit;
|
|
19
|
+
padding-top: 0;
|
|
20
|
+
`;
|
|
14
21
|
//# sourceMappingURL=styled.js.map
|
package/lib/styled.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled.js","
|
|
1
|
+
{"version":3,"file":"styled.js","sourceRoot":"","sources":["../src/styled.ts"],"names":[],"mappings":";;;;;;AAAA,0EAAuC;AAEvC,2DAA2D;AAC9C,QAAA,cAAc,GAAG,2BAAM,CAAC,MAAM,CAAqB;;;IAG5D,KAAK,CAAC,EAAE,CACR,KAAK,CAAC,MAAM,IAAI,IAAI;IAClB,CAAC,CAAC,gDAAgD;IAClD,CAAC,CAAC,qCAAqC;;;;;;CAM5C,CAAC"}
|
package/lib/util.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RentalVehicle, VehicleRentalStation } from "@opentripplanner/types/otp2";
|
|
2
|
+
import { Agency, Company, Stop } from "@opentripplanner/types";
|
|
2
3
|
import { IntlShape } from "react-intl";
|
|
3
4
|
export type StopIdAgencyMap = Record<string, Agency>;
|
|
4
|
-
export type Entity =
|
|
5
|
+
export type Entity = VehicleRentalStation | Stop | RentalVehicle;
|
|
5
6
|
export declare function getNetwork(entity: Entity, configCompanies: Company[]): string;
|
|
6
7
|
export declare function makeDefaultGetEntityName(intl: IntlShape, defaultEnglishMessages: {
|
|
7
8
|
[key: string]: string;
|
|
8
|
-
}): (entity: Entity, configCompanies: Company[], feedName?: string) => string | null;
|
|
9
|
+
}): (entity: Entity, configCompanies: Company[], feedName?: string, includeParenthetical?: boolean) => string | null;
|
|
9
10
|
//# sourceMappingURL=util.d.ts.map
|
package/lib/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,oBAAoB,EACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACrD,MAAM,MAAM,MAAM,GAAG,oBAAoB,GAAG,IAAI,GAAG,aAAa,CAAC;AAEjE,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,GAAG,MAAM,CAS7E;AAGD,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,SAAS,EACf,sBAAsB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,YAGvC,MAAM,mBACG,OAAO,EAAE,aACf,MAAM,qCAEhB,MAAM,GAAG,IAAI,CA8DjB"}
|
package/lib/util.js
CHANGED
|
@@ -1,59 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.makeDefaultGetEntityName = makeDefaultGetEntityName;
|
|
9
|
-
var _coreUtils = _interopRequireDefault(require("@opentripplanner/core-utils"));
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.makeDefaultGetEntityName = exports.getNetwork = void 0;
|
|
7
|
+
const core_utils_1 = __importDefault(require("@opentripplanner/core-utils"));
|
|
10
8
|
function getNetwork(entity, configCompanies) {
|
|
11
|
-
|
|
9
|
+
return ("rentalNetwork" in entity &&
|
|
10
|
+
(core_utils_1.default.itinerary.getCompaniesLabelFromNetworks(entity.rentalNetwork.networkId, configCompanies) ||
|
|
11
|
+
entity.rentalNetwork.networkId));
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
exports.getNetwork = getNetwork;
|
|
14
14
|
// eslint-disable-next-line import/prefer-default-export
|
|
15
15
|
function makeDefaultGetEntityName(intl, defaultEnglishMessages) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
16
|
+
return function defaultGetEntityName(entity, configCompanies, feedName, includeParenthetical = true) {
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
let stationName = entity.name || entity.id;
|
|
19
|
+
// If the station name or id is a giant UUID (with more than 3 "-" characters)
|
|
20
|
+
// best not to show that at all. The company name will still be shown.
|
|
21
|
+
// Also ignore "Default Vehicle Type"
|
|
22
|
+
if ((stationName.match(/-/g) || []).length > 3 ||
|
|
23
|
+
stationName === "Default vehicle type") {
|
|
24
|
+
stationName = null;
|
|
25
|
+
}
|
|
26
|
+
if ("vehicleType" in entity &&
|
|
27
|
+
!("availableVehicles" in entity) &&
|
|
28
|
+
((_a = entity.vehicleType) === null || _a === void 0 ? void 0 : _a.formFactor) === "BICYCLE") {
|
|
29
|
+
stationName = intl.formatMessage({
|
|
30
|
+
defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingBike"],
|
|
31
|
+
description: "Popup title for a free-floating bike",
|
|
32
|
+
id: "otpUi.MapPopup.floatingBike"
|
|
33
|
+
}, { name: stationName });
|
|
34
|
+
}
|
|
35
|
+
else if ("vehicleType" in entity &&
|
|
36
|
+
((_b = entity.vehicleType) === null || _b === void 0 ? void 0 : _b.formFactor) === "CAR") {
|
|
37
|
+
// TODO: Stop generating this / passing it to the car string? Is it needed?
|
|
38
|
+
// In English we say "Car: " instead
|
|
39
|
+
const network = getNetwork(entity, configCompanies);
|
|
40
|
+
stationName = intl.formatMessage({
|
|
41
|
+
defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingCar"],
|
|
42
|
+
description: "Popup title for a free-floating car",
|
|
43
|
+
id: "otpUi.MapPopup.floatingCar"
|
|
44
|
+
}, {
|
|
45
|
+
company: network,
|
|
46
|
+
name: stationName
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else if ("vehicleType" in entity &&
|
|
50
|
+
!("availableVehicles" in entity) &&
|
|
51
|
+
((_c = entity.vehicleType) === null || _c === void 0 ? void 0 : _c.formFactor.startsWith("SCOOTER"))) {
|
|
52
|
+
stationName = intl.formatMessage({
|
|
53
|
+
defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingEScooter"],
|
|
54
|
+
description: "Popup title for a free-floating e-scooter",
|
|
55
|
+
id: "otpUi.MapPopup.floatingEScooter"
|
|
56
|
+
}, { name: stationName });
|
|
57
|
+
}
|
|
58
|
+
else if (includeParenthetical && feedName && "code" in entity) {
|
|
59
|
+
stationName = `${stationName} (${feedName} ${entity.code})`;
|
|
60
|
+
}
|
|
61
|
+
return stationName;
|
|
62
|
+
};
|
|
58
63
|
}
|
|
64
|
+
exports.makeDefaultGetEntityName = makeDefaultGetEntityName;
|
|
59
65
|
//# sourceMappingURL=util.js.map
|
package/lib/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;AAMA,6EAAoD;AAKpD,SAAgB,UAAU,CAAC,MAAc,EAAE,eAA0B;IACnE,OAAO,CACL,eAAe,IAAI,MAAM;QACzB,CAAC,oBAAS,CAAC,SAAS,CAAC,6BAA6B,CAChD,MAAM,CAAC,aAAa,CAAC,SAAS,EAC9B,eAAe,CAChB;YACC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAClC,CAAC;AACJ,CAAC;AATD,gCASC;AAED,wDAAwD;AACxD,SAAgB,wBAAwB,CACtC,IAAe,EACf,sBAAiD;IAEjD,OAAO,SAAS,oBAAoB,CAClC,MAAc,EACd,eAA0B,EAC1B,QAAiB,EACjB,oBAAoB,GAAG,IAAI;;QAE3B,IAAI,WAAW,GAAkB,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,EAAE,CAAC;QAC1D,8EAA8E;QAC9E,sEAAsE;QACtE,qCAAqC;QACrC,IACE,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;YAC1C,WAAW,KAAK,sBAAsB,EACtC;YACA,WAAW,GAAG,IAAI,CAAC;SACpB;QAED,IACE,aAAa,IAAI,MAAM;YACvB,CAAC,CAAC,mBAAmB,IAAI,MAAM,CAAC;YAChC,CAAA,MAAA,MAAM,CAAC,WAAW,0CAAE,UAAU,MAAK,SAAS,EAC5C;YACA,WAAW,GAAG,IAAI,CAAC,aAAa,CAC9B;gBACE,cAAc,EAAE,sBAAsB,CAAC,6BAA6B,CAAC;gBACrE,WAAW,EAAE,sCAAsC;gBACnD,EAAE,EAAE,6BAA6B;aAClC,EACD,EAAE,IAAI,EAAE,WAAW,EAAE,CACtB,CAAC;SACH;aAAM,IACL,aAAa,IAAI,MAAM;YACvB,CAAA,MAAA,MAAM,CAAC,WAAW,0CAAE,UAAU,MAAK,KAAK,EACxC;YACA,2EAA2E;YAC3E,oCAAoC;YACpC,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;YACpD,WAAW,GAAG,IAAI,CAAC,aAAa,CAC9B;gBACE,cAAc,EAAE,sBAAsB,CAAC,4BAA4B,CAAC;gBACpE,WAAW,EAAE,qCAAqC;gBAClD,EAAE,EAAE,4BAA4B;aACjC,EACD;gBACE,OAAO,EAAE,OAAO;gBAChB,IAAI,EAAE,WAAW;aAClB,CACF,CAAC;SACH;aAAM,IACL,aAAa,IAAI,MAAM;YACvB,CAAC,CAAC,mBAAmB,IAAI,MAAM,CAAC;aAChC,MAAA,MAAM,CAAC,WAAW,0CAAE,UAAU,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA,EACpD;YACA,WAAW,GAAG,IAAI,CAAC,aAAa,CAC9B;gBACE,cAAc,EACZ,sBAAsB,CAAC,iCAAiC,CAAC;gBAC3D,WAAW,EAAE,2CAA2C;gBACxD,EAAE,EAAE,iCAAiC;aACtC,EACD,EAAE,IAAI,EAAE,WAAW,EAAE,CACtB,CAAC;SACH;aAAM,IAAI,oBAAoB,IAAI,QAAQ,IAAI,MAAM,IAAI,MAAM,EAAE;YAC/D,WAAW,GAAG,GAAG,WAAW,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC;SAC7D;QACD,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AAvED,4DAuEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentripplanner/map-popup",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "A component for displaying map popup contents",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
"private": false,
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"flat": "^5.0.2",
|
|
15
|
+
"@opentripplanner/core-utils": "14.2.0",
|
|
15
16
|
"@opentripplanner/base-map": "6.0.0",
|
|
16
17
|
"@opentripplanner/building-blocks": "3.0.1",
|
|
17
|
-
"@opentripplanner/core-utils": "13.0.1",
|
|
18
18
|
"@opentripplanner/from-to-location-picker": "4.0.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@opentripplanner/types": "
|
|
21
|
+
"@opentripplanner/types": "8.2.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "^18.2.0",
|
package/src/MapPopup.story.tsx
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { action } from "
|
|
2
|
+
import { action } from "storybook/actions";
|
|
3
3
|
import styled from "styled-components";
|
|
4
|
-
import {
|
|
4
|
+
import { Stop } from "@opentripplanner/types";
|
|
5
|
+
import {
|
|
6
|
+
RentalVehicle,
|
|
7
|
+
VehicleRentalStation
|
|
8
|
+
} from "@opentripplanner/types/otp2";
|
|
5
9
|
import { IntlProvider } from "react-intl";
|
|
6
|
-
import { Meta } from "@storybook/react";
|
|
10
|
+
import { Meta } from "@storybook/react-vite";
|
|
7
11
|
import MapPopupContents, { Feed } from "./index";
|
|
8
12
|
|
|
9
13
|
// HOC to wrap components with IntlProvider
|
|
@@ -68,57 +72,46 @@ const SAMPLE_FEEDS: Feed[] = [
|
|
|
68
72
|
}
|
|
69
73
|
];
|
|
70
74
|
|
|
71
|
-
const
|
|
72
|
-
"stroke-width": 2,
|
|
75
|
+
const VEHICLE_RENTAL_STATION: VehicleRentalStation = {
|
|
73
76
|
allowDropoff: true,
|
|
74
77
|
allowPickup: true,
|
|
75
|
-
|
|
78
|
+
availableVehicles: {
|
|
79
|
+
total: 6,
|
|
80
|
+
byType: [{ count: 6, vehicleType: { formFactor: "BICYCLE" } }]
|
|
81
|
+
},
|
|
82
|
+
availableSpaces: {
|
|
83
|
+
total: 11,
|
|
84
|
+
byType: [{ count: 12, vehicleType: { formFactor: "BICYCLE" } }]
|
|
85
|
+
},
|
|
76
86
|
id: '"hub_1580"',
|
|
77
|
-
isCarStation: false,
|
|
78
|
-
isFloatingBike: false,
|
|
79
87
|
lat: 45.5219604810172,
|
|
80
88
|
lon: -122.6896771788597,
|
|
81
89
|
name: "SW Morrison at 18th",
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
spacesAvailable: 11,
|
|
85
|
-
vehiclesAvailable: 6
|
|
90
|
+
rentalNetwork: { networkId: "BIKETOWN" },
|
|
91
|
+
realtime: true
|
|
86
92
|
};
|
|
87
93
|
|
|
88
|
-
const FLOATING_VEHICLE = {
|
|
89
|
-
|
|
90
|
-
allowDropoff: false,
|
|
91
|
-
allowPickup: true,
|
|
92
|
-
color: "#f00",
|
|
94
|
+
const FLOATING_VEHICLE: RentalVehicle = {
|
|
95
|
+
allowPickupNow: true,
|
|
93
96
|
id: '"bike_6861"',
|
|
94
|
-
|
|
95
|
-
isFloatingBike: true,
|
|
97
|
+
vehicleType: { formFactor: "BICYCLE" },
|
|
96
98
|
lat: 45.525486666666666,
|
|
97
99
|
lon: -122.70486,
|
|
98
100
|
name: "0541",
|
|
99
|
-
|
|
100
|
-
realTimeData: true,
|
|
101
|
-
spacesAvailable: 0,
|
|
102
|
-
vehiclesAvailable: 1
|
|
101
|
+
rentalNetwork: { networkId: "BIKETOWN" }
|
|
103
102
|
};
|
|
104
103
|
|
|
105
|
-
const FLOATING_CAR = {
|
|
106
|
-
|
|
107
|
-
allowDropoff: false,
|
|
108
|
-
allowPickup: true,
|
|
109
|
-
color: "#333",
|
|
104
|
+
const FLOATING_CAR: RentalVehicle = {
|
|
105
|
+
allowPickupNow: true,
|
|
110
106
|
id: "car_6861",
|
|
111
|
-
|
|
112
|
-
isFloatingCar: true,
|
|
107
|
+
vehicleType: { formFactor: "CAR" },
|
|
113
108
|
lat: 52.52,
|
|
114
109
|
lon: 13.405,
|
|
115
110
|
name: "0541",
|
|
116
|
-
|
|
117
|
-
realTimeData: true,
|
|
118
|
-
spacesAvailable: 0
|
|
111
|
+
rentalNetwork: { networkId: "MILES" }
|
|
119
112
|
};
|
|
120
113
|
|
|
121
|
-
const getEntityPrefixExample = (entity: Stop |
|
|
114
|
+
const getEntityPrefixExample = (entity: Stop | VehicleRentalStation) => {
|
|
122
115
|
const DemoIcon = styled.span`
|
|
123
116
|
background-color: blue;
|
|
124
117
|
border-radius: 50px;
|
|
@@ -171,7 +164,7 @@ export const StopEntityNoStopCode = (): JSX.Element => (
|
|
|
171
164
|
|
|
172
165
|
export const StationEntity = (): JSX.Element => (
|
|
173
166
|
<MapPopupContents
|
|
174
|
-
entity={
|
|
167
|
+
entity={VEHICLE_RENTAL_STATION}
|
|
175
168
|
setLocation={action("setLocation")}
|
|
176
169
|
setViewedStop={action("setViewedStop")}
|
|
177
170
|
/>
|
|
@@ -265,7 +265,7 @@ exports[`Map Popup StopEntityNoStopCode smoke-test 1`] = `
|
|
|
265
265
|
W Burnside & SW 2nd
|
|
266
266
|
</header>
|
|
267
267
|
<p class="styled__PopupRow-sc-12kjso7-2 ckOOWr">
|
|
268
|
-
<button class="styled__ViewStopButton-sc-12v7ov3-0
|
|
268
|
+
<button class="styled__ViewStopButton-sc-12v7ov3-0 bbtcwi">
|
|
269
269
|
Stop Viewer
|
|
270
270
|
</button>
|
|
271
271
|
</p>
|
|
@@ -392,11 +392,11 @@ exports[`Map Popup StopEntityWithFeedName smoke-test 1`] = `
|
|
|
392
392
|
role="presentation"
|
|
393
393
|
>
|
|
394
394
|
<header class="styled__PopupTitle-sc-12kjso7-3 jRNaQh">
|
|
395
|
-
W Burnside & SW 2nd
|
|
395
|
+
W Burnside & SW 2nd
|
|
396
396
|
</header>
|
|
397
397
|
<p class="styled__PopupRow-sc-12kjso7-2 ckOOWr">
|
|
398
398
|
<strong>
|
|
399
|
-
Stop ID: 9526
|
|
399
|
+
Stop ID: TriMet 9526
|
|
400
400
|
</strong>
|
|
401
401
|
<button class="styled__ViewStopButton-sc-12v7ov3-0 hXaHvR">
|
|
402
402
|
Stop Viewer
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useCallback } from "react";
|
|
2
2
|
import FromToLocationPicker from "@opentripplanner/from-to-location-picker";
|
|
3
3
|
|
|
4
|
+
import { RentalVehicle, VehicleRentalStation } from "@opentripplanner/types/otp2";
|
|
4
5
|
// eslint-disable-next-line prettier/prettier
|
|
5
6
|
import type {
|
|
6
7
|
Company,
|
|
@@ -8,15 +9,15 @@ import type {
|
|
|
8
9
|
Location,
|
|
9
10
|
Stop,
|
|
10
11
|
StopEventHandler,
|
|
11
|
-
TileLayerStation
|
|
12
12
|
} from "@opentripplanner/types";
|
|
13
13
|
|
|
14
14
|
import { FocusTrapWrapper } from "@opentripplanner/building-blocks";
|
|
15
15
|
import { flatten } from "flat";
|
|
16
16
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
17
17
|
import { Styled } from "@opentripplanner/base-map";
|
|
18
|
+
import coreUtils from "@opentripplanner/core-utils";
|
|
18
19
|
|
|
19
|
-
import {
|
|
20
|
+
import { makeDefaultGetEntityName, type StopIdAgencyMap } from "./util";
|
|
20
21
|
import { ViewStopButton } from "./styled";
|
|
21
22
|
|
|
22
23
|
// Load the default messages.
|
|
@@ -36,7 +37,7 @@ export type Feed = {
|
|
|
36
37
|
};
|
|
37
38
|
|
|
38
39
|
|
|
39
|
-
const generateLocation = (entity:
|
|
40
|
+
const generateLocation = (entity: MapPopupEntity, name: string) => {
|
|
40
41
|
// @ts-expect-error some of these values may be null, but that's ok
|
|
41
42
|
const { lon: entityLon, lat: entityLat, x, y } = entity
|
|
42
43
|
|
|
@@ -47,7 +48,7 @@ const generateLocation = (entity: Entity, name: string) => {
|
|
|
47
48
|
return { lat, lon, name };
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
const StationHubDetails = ({
|
|
51
|
+
const StationHubDetails = ({ availableVehicles, availableSpaces }: { availableVehicles: number, availableSpaces: number }) => {
|
|
51
52
|
return (
|
|
52
53
|
<Styled.PopupRow>
|
|
53
54
|
<div>
|
|
@@ -57,7 +58,7 @@ const StationHubDetails = ({ station }: { station: TileLayerStation }) => {
|
|
|
57
58
|
}
|
|
58
59
|
description="Label text for the number of bikes available"
|
|
59
60
|
id="otpUi.MapPopup.availableBikes"
|
|
60
|
-
values={{ value:
|
|
61
|
+
values={{ value: availableVehicles }}
|
|
61
62
|
/>
|
|
62
63
|
</div>
|
|
63
64
|
<div>
|
|
@@ -67,14 +68,14 @@ const StationHubDetails = ({ station }: { station: TileLayerStation }) => {
|
|
|
67
68
|
}
|
|
68
69
|
description="Label text for the number of docks available"
|
|
69
70
|
id="otpUi.MapPopup.availableDocks"
|
|
70
|
-
values={{ value:
|
|
71
|
+
values={{ value: availableSpaces }}
|
|
71
72
|
/>
|
|
72
73
|
</div>
|
|
73
74
|
</Styled.PopupRow>
|
|
74
75
|
)
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
const StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => void; }) => {
|
|
78
|
+
const StopDetails = ({ id, feedName, setViewedStop }: { id: string, feedName?: string, setViewedStop: () => void; }) => {
|
|
78
79
|
return (
|
|
79
80
|
<Styled.PopupRow>
|
|
80
81
|
{id &&
|
|
@@ -84,6 +85,7 @@ const StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => v
|
|
|
84
85
|
description="Displays the stop id"
|
|
85
86
|
id="otpUi.MapPopup.stopId"
|
|
86
87
|
values={{
|
|
88
|
+
feedName,
|
|
87
89
|
stopId: id
|
|
88
90
|
}}
|
|
89
91
|
/>
|
|
@@ -99,20 +101,20 @@ const StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => v
|
|
|
99
101
|
)
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
type MapPopupEntity = Stop | VehicleRentalStation | RentalVehicle
|
|
105
|
+
|
|
102
106
|
type Props = {
|
|
103
107
|
closePopup?: (arg?: boolean) => void
|
|
104
108
|
configCompanies?: ConfiguredCompany[];
|
|
105
|
-
entity:
|
|
106
|
-
getEntityName?: (entity:
|
|
107
|
-
getEntityPrefix?: (entity:
|
|
109
|
+
entity: MapPopupEntity
|
|
110
|
+
getEntityName?: (entity: MapPopupEntity, configCompanies: Company[], feedName?: string, includeParenthetical?: boolean) => string;
|
|
111
|
+
getEntityPrefix?: (entity: MapPopupEntity) => JSX.Element
|
|
108
112
|
feeds?: Feed[]
|
|
109
113
|
setLocation?: ({ location, locationType }: { location: Location, locationType: string }) => void;
|
|
110
114
|
setViewedStop?: StopEventHandler;
|
|
111
115
|
};
|
|
112
116
|
|
|
113
|
-
|
|
114
|
-
return "vehiclesAvailable" in entity
|
|
115
|
-
}
|
|
117
|
+
const entityIsStop = (entity: MapPopupEntity): entity is Stop => "gtfsId" in entity;
|
|
116
118
|
|
|
117
119
|
/**
|
|
118
120
|
* Renders a map popup for a stop, scooter, or shared bike
|
|
@@ -142,12 +144,13 @@ export function MapPopup({
|
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
const name = getNameFunc(entity, configCompanies, feedName);
|
|
147
|
+
const titleName = getNameFunc(entity, configCompanies, feedName, false);
|
|
145
148
|
|
|
146
|
-
const stationNetwork =
|
|
149
|
+
const stationNetwork = "rentalNetwork" in entity && (coreUtils.itinerary.getCompaniesLabelFromNetworks(entity?.rentalNetwork.networkId, configCompanies) || entity?.rentalNetwork.networkId);
|
|
147
150
|
|
|
148
|
-
const
|
|
149
|
-
const entityIsStationHub =
|
|
150
|
-
const stopId =
|
|
151
|
+
const vehiclesAvailable = "availableVehicles" in entity;
|
|
152
|
+
const entityIsStationHub = vehiclesAvailable && entity?.availableVehicles !== undefined;
|
|
153
|
+
const stopId = entityIsStop(entity) ? entity.code : "";
|
|
151
154
|
const id = `focus-${encodeURIComponent(entity.id).replace(/%/g, "")}-popup`
|
|
152
155
|
|
|
153
156
|
return (
|
|
@@ -159,16 +162,17 @@ export function MapPopup({
|
|
|
159
162
|
defaultMessage={defaultMessages["otpUi.MapPopup.popupTitle"]}
|
|
160
163
|
description="Text for title of the popup, contains an optional company name"
|
|
161
164
|
id="otpUi.MapPopup.popupTitle"
|
|
162
|
-
values={{ name, stationNetwork }}
|
|
165
|
+
values={{ name: titleName, stationNetwork }}
|
|
163
166
|
/>
|
|
164
167
|
</Styled.PopupTitle>
|
|
165
168
|
{/* render dock info if it is available */}
|
|
166
|
-
{entityIsStationHub && <StationHubDetails
|
|
169
|
+
{entityIsStationHub && <StationHubDetails availableSpaces={entity.availableSpaces?.total} availableVehicles={entity.availableVehicles?.total} />}
|
|
167
170
|
|
|
168
171
|
{/* render stop viewer link if available */}
|
|
169
|
-
{setViewedStop &&
|
|
172
|
+
{setViewedStop && entityIsStop(entity) && (
|
|
170
173
|
<StopDetails
|
|
171
174
|
id={stopId}
|
|
175
|
+
feedName={feedName}
|
|
172
176
|
setViewedStop={useCallback(() => setViewedStop(entity as Stop), [entity])}
|
|
173
177
|
/>
|
|
174
178
|
)}
|
package/src/util.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
TileLayerStation
|
|
7
|
-
} from "@opentripplanner/types";
|
|
2
|
+
RentalVehicle,
|
|
3
|
+
VehicleRentalStation
|
|
4
|
+
} from "@opentripplanner/types/otp2";
|
|
5
|
+
import { Agency, Company, Stop } from "@opentripplanner/types";
|
|
8
6
|
import { IntlShape } from "react-intl";
|
|
9
7
|
import coreUtils from "@opentripplanner/core-utils";
|
|
10
8
|
|
|
11
9
|
export type StopIdAgencyMap = Record<string, Agency>;
|
|
12
|
-
export type Entity =
|
|
10
|
+
export type Entity = VehicleRentalStation | Stop | RentalVehicle;
|
|
13
11
|
|
|
14
12
|
export function getNetwork(entity: Entity, configCompanies: Company[]): string {
|
|
15
13
|
return (
|
|
16
|
-
"
|
|
14
|
+
"rentalNetwork" in entity &&
|
|
17
15
|
(coreUtils.itinerary.getCompaniesLabelFromNetworks(
|
|
18
|
-
|
|
16
|
+
entity.rentalNetwork.networkId,
|
|
19
17
|
configCompanies
|
|
20
18
|
) ||
|
|
21
|
-
entity.
|
|
19
|
+
entity.rentalNetwork.networkId)
|
|
22
20
|
);
|
|
23
21
|
}
|
|
24
22
|
|
|
@@ -30,7 +28,8 @@ export function makeDefaultGetEntityName(
|
|
|
30
28
|
return function defaultGetEntityName(
|
|
31
29
|
entity: Entity,
|
|
32
30
|
configCompanies: Company[],
|
|
33
|
-
feedName?: string
|
|
31
|
+
feedName?: string,
|
|
32
|
+
includeParenthetical = true
|
|
34
33
|
): string | null {
|
|
35
34
|
let stationName: string | null = entity.name || entity.id;
|
|
36
35
|
// If the station name or id is a giant UUID (with more than 3 "-" characters)
|
|
@@ -43,7 +42,11 @@ export function makeDefaultGetEntityName(
|
|
|
43
42
|
stationName = null;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
if (
|
|
45
|
+
if (
|
|
46
|
+
"vehicleType" in entity &&
|
|
47
|
+
!("availableVehicles" in entity) &&
|
|
48
|
+
entity.vehicleType?.formFactor === "BICYCLE"
|
|
49
|
+
) {
|
|
47
50
|
stationName = intl.formatMessage(
|
|
48
51
|
{
|
|
49
52
|
defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingBike"],
|
|
@@ -52,10 +55,13 @@ export function makeDefaultGetEntityName(
|
|
|
52
55
|
},
|
|
53
56
|
{ name: stationName }
|
|
54
57
|
);
|
|
55
|
-
} else if (
|
|
58
|
+
} else if (
|
|
59
|
+
"vehicleType" in entity &&
|
|
60
|
+
entity.vehicleType?.formFactor === "CAR"
|
|
61
|
+
) {
|
|
56
62
|
// TODO: Stop generating this / passing it to the car string? Is it needed?
|
|
57
63
|
// In English we say "Car: " instead
|
|
58
|
-
const
|
|
64
|
+
const network = getNetwork(entity, configCompanies);
|
|
59
65
|
stationName = intl.formatMessage(
|
|
60
66
|
{
|
|
61
67
|
defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingCar"],
|
|
@@ -63,12 +69,15 @@ export function makeDefaultGetEntityName(
|
|
|
63
69
|
id: "otpUi.MapPopup.floatingCar"
|
|
64
70
|
},
|
|
65
71
|
{
|
|
66
|
-
company:
|
|
72
|
+
company: network,
|
|
67
73
|
name: stationName
|
|
68
74
|
}
|
|
69
75
|
);
|
|
70
|
-
} else if (
|
|
71
|
-
|
|
76
|
+
} else if (
|
|
77
|
+
"vehicleType" in entity &&
|
|
78
|
+
!("availableVehicles" in entity) &&
|
|
79
|
+
entity.vehicleType?.formFactor.startsWith("SCOOTER")
|
|
80
|
+
) {
|
|
72
81
|
stationName = intl.formatMessage(
|
|
73
82
|
{
|
|
74
83
|
defaultMessage:
|
|
@@ -78,7 +87,7 @@ export function makeDefaultGetEntityName(
|
|
|
78
87
|
},
|
|
79
88
|
{ name: stationName }
|
|
80
89
|
);
|
|
81
|
-
} else if (feedName && "code" in entity) {
|
|
90
|
+
} else if (includeParenthetical && feedName && "code" in entity) {
|
|
82
91
|
stationName = `${stationName} (${feedName} ${entity.code})`;
|
|
83
92
|
}
|
|
84
93
|
return stationName;
|