@opentripplanner/map-popup 6.1.0 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.js +11 -9
- package/esm/index.js.map +1 -1
- package/esm/util.js +10 -6
- package/esm/util.js.map +1 -1
- package/i18n/en-US.yml +3 -1
- package/i18n/pl.yml +7 -7
- package/lib/index.d.ts +4 -5
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +91 -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 -2
- package/lib/util.d.ts.map +1 -1
- package/lib/util.js +55 -50
- package/lib/util.js.map +1 -1
- package/package.json +5 -5
- package/src/MapPopup.story.tsx +14 -14
- package/src/__snapshots__/MapPopup.story.tsx.snap +3 -3
- package/src/index.tsx +24 -16
- package/src/util.ts +27 -14
- 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,7 +1,9 @@
|
|
|
1
|
-
import { Agency, Company, Station, Stop } from "@opentripplanner/types";
|
|
1
|
+
import { Agency, Company, Station, Stop, TileLayerStation } from "@opentripplanner/types";
|
|
2
2
|
import { IntlShape } from "react-intl";
|
|
3
3
|
export type StopIdAgencyMap = Record<string, Agency>;
|
|
4
|
+
export type Entity = Station | Stop | TileLayerStation;
|
|
5
|
+
export declare function getNetwork(entity: Entity, configCompanies: Company[]): string;
|
|
4
6
|
export declare function makeDefaultGetEntityName(intl: IntlShape, defaultEnglishMessages: {
|
|
5
7
|
[key: string]: string;
|
|
6
|
-
}): (entity:
|
|
8
|
+
}): (entity: Entity, configCompanies: Company[], feedName?: string, includeParenthetical?: boolean) => string | null;
|
|
7
9
|
//# 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,
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,IAAI,EACJ,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACrD,MAAM,MAAM,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,gBAAgB,CAAC;AAEvD,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,CAoDjB"}
|
package/lib/util.js
CHANGED
|
@@ -1,55 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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"));
|
|
8
|
+
function getNetwork(entity, configCompanies) {
|
|
9
|
+
return ("network" in entity &&
|
|
10
|
+
(core_utils_1.default.itinerary.getCompaniesLabelFromNetworks([entity.network], configCompanies) ||
|
|
11
|
+
entity.network));
|
|
12
|
+
}
|
|
13
|
+
exports.getNetwork = getNetwork;
|
|
9
14
|
// eslint-disable-next-line import/prefer-default-export
|
|
10
15
|
function makeDefaultGetEntityName(intl, defaultEnglishMessages) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
};
|
|
16
|
+
return function defaultGetEntityName(entity, configCompanies, feedName, includeParenthetical = true) {
|
|
17
|
+
let stationName = entity.name || entity.id;
|
|
18
|
+
// If the station name or id is a giant UUID (with more than 3 "-" characters)
|
|
19
|
+
// best not to show that at all. The company name will still be shown.
|
|
20
|
+
// Also ignore "Default Vehicle Type"
|
|
21
|
+
if ((stationName.match(/-/g) || []).length > 3 ||
|
|
22
|
+
stationName === "Default vehicle type") {
|
|
23
|
+
stationName = null;
|
|
24
|
+
}
|
|
25
|
+
if ("isFloatingBike" in entity && entity.isFloatingBike) {
|
|
26
|
+
stationName = intl.formatMessage({
|
|
27
|
+
defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingBike"],
|
|
28
|
+
description: "Popup title for a free-floating bike",
|
|
29
|
+
id: "otpUi.MapPopup.floatingBike"
|
|
30
|
+
}, { name: stationName });
|
|
31
|
+
}
|
|
32
|
+
else if ("isFloatingCar" in entity && entity.isFloatingCar) {
|
|
33
|
+
// TODO: Stop generating this / passing it to the car string? Is it needed?
|
|
34
|
+
// In English we say "Car: " instead
|
|
35
|
+
const stationNetwork = getNetwork(entity, configCompanies);
|
|
36
|
+
stationName = intl.formatMessage({
|
|
37
|
+
defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingCar"],
|
|
38
|
+
description: "Popup title for a free-floating car",
|
|
39
|
+
id: "otpUi.MapPopup.floatingCar"
|
|
40
|
+
}, {
|
|
41
|
+
company: stationNetwork,
|
|
42
|
+
name: stationName
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else if ("isFloatingVehicle" in entity && entity.isFloatingVehicle) {
|
|
46
|
+
// assumes that all floating vehicles are E-scooters
|
|
47
|
+
stationName = intl.formatMessage({
|
|
48
|
+
defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingEScooter"],
|
|
49
|
+
description: "Popup title for a free-floating e-scooter",
|
|
50
|
+
id: "otpUi.MapPopup.floatingEScooter"
|
|
51
|
+
}, { name: stationName });
|
|
52
|
+
}
|
|
53
|
+
else if (includeParenthetical && feedName && "code" in entity) {
|
|
54
|
+
stationName = `${stationName} (${feedName} ${entity.code})`;
|
|
55
|
+
}
|
|
56
|
+
return stationName;
|
|
57
|
+
};
|
|
54
58
|
}
|
|
59
|
+
exports.makeDefaultGetEntityName = makeDefaultGetEntityName;
|
|
55
60
|
//# 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":";;;;;;AAQA,6EAAoD;AAKpD,SAAgB,UAAU,CAAC,MAAc,EAAE,eAA0B;IACnE,OAAO,CACL,SAAS,IAAI,MAAM;QACnB,CAAC,oBAAS,CAAC,SAAS,CAAC,6BAA6B,CAChD,CAAC,MAAM,CAAC,OAAO,CAAC,EAChB,eAAe,CAChB;YACC,MAAM,CAAC,OAAO,CAAC,CAClB,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,IAAI,gBAAgB,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc,EAAE;YACvD,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,IAAI,eAAe,IAAI,MAAM,IAAI,MAAM,CAAC,aAAa,EAAE;YAC5D,2EAA2E;YAC3E,oCAAoC;YACpC,MAAM,cAAc,GAAG,UAAU,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;YAC3D,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,cAAc;gBACvB,IAAI,EAAE,WAAW;aAClB,CACF,CAAC;SACH;aAAM,IAAI,mBAAmB,IAAI,MAAM,IAAI,MAAM,CAAC,iBAAiB,EAAE;YACpE,oDAAoD;YACpD,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;AA7DD,4DA6DC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentripplanner/map-popup",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "A component for displaying map popup contents",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"flat": "^5.0.2",
|
|
15
15
|
"@opentripplanner/building-blocks": "3.0.1",
|
|
16
|
-
"@opentripplanner/
|
|
17
|
-
"@opentripplanner/
|
|
18
|
-
"@opentripplanner/
|
|
16
|
+
"@opentripplanner/base-map": "6.0.0",
|
|
17
|
+
"@opentripplanner/core-utils": "14.0.0",
|
|
18
|
+
"@opentripplanner/from-to-location-picker": "4.0.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@opentripplanner/types": "
|
|
21
|
+
"@opentripplanner/types": "8.0.0"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "^18.2.0",
|
package/src/MapPopup.story.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { action } from "
|
|
2
|
+
import { action } from "storybook/actions";
|
|
3
3
|
import styled from "styled-components";
|
|
4
4
|
import { Station, Stop } from "@opentripplanner/types";
|
|
5
5
|
import { IntlProvider } from "react-intl";
|
|
6
|
-
import { Meta } from "@storybook/react";
|
|
6
|
+
import { Meta } from "@storybook/react-vite";
|
|
7
7
|
import MapPopupContents, { Feed } from "./index";
|
|
8
8
|
|
|
9
9
|
// HOC to wrap components with IntlProvider
|
|
@@ -72,34 +72,34 @@ const STATION = {
|
|
|
72
72
|
"stroke-width": 2,
|
|
73
73
|
allowDropoff: true,
|
|
74
74
|
allowPickup: true,
|
|
75
|
-
bikesAvailable: 6,
|
|
76
75
|
color: "#f00",
|
|
77
76
|
id: '"hub_1580"',
|
|
78
77
|
isCarStation: false,
|
|
79
78
|
isFloatingBike: false,
|
|
79
|
+
lat: 45.5219604810172,
|
|
80
|
+
lon: -122.6896771788597,
|
|
80
81
|
name: "SW Morrison at 18th",
|
|
81
|
-
|
|
82
|
+
network: "BIKETOWN",
|
|
82
83
|
realTimeData: true,
|
|
83
84
|
spacesAvailable: 11,
|
|
84
|
-
|
|
85
|
-
y: 45.5219604810172
|
|
85
|
+
vehiclesAvailable: 6
|
|
86
86
|
};
|
|
87
87
|
|
|
88
88
|
const FLOATING_VEHICLE = {
|
|
89
89
|
"stroke-width": 1,
|
|
90
90
|
allowDropoff: false,
|
|
91
91
|
allowPickup: true,
|
|
92
|
-
bikesAvailable: 1,
|
|
93
92
|
color: "#f00",
|
|
94
93
|
id: '"bike_6861"',
|
|
95
94
|
isCarStation: false,
|
|
96
95
|
isFloatingBike: true,
|
|
96
|
+
lat: 45.525486666666666,
|
|
97
|
+
lon: -122.70486,
|
|
97
98
|
name: "0541",
|
|
98
|
-
|
|
99
|
+
network: "BIKETOWN",
|
|
99
100
|
realTimeData: true,
|
|
100
101
|
spacesAvailable: 0,
|
|
101
|
-
|
|
102
|
-
y: 45.525486666666666
|
|
102
|
+
vehiclesAvailable: 1
|
|
103
103
|
};
|
|
104
104
|
|
|
105
105
|
const FLOATING_CAR = {
|
|
@@ -110,12 +110,12 @@ const FLOATING_CAR = {
|
|
|
110
110
|
id: "car_6861",
|
|
111
111
|
isCarStation: false,
|
|
112
112
|
isFloatingCar: true,
|
|
113
|
+
lat: 52.52,
|
|
114
|
+
lon: 13.405,
|
|
113
115
|
name: "0541",
|
|
114
|
-
|
|
116
|
+
network: "MILES", // https://miles-mobility.com
|
|
115
117
|
realTimeData: true,
|
|
116
|
-
spacesAvailable: 0
|
|
117
|
-
x: 13.405,
|
|
118
|
-
y: 52.52
|
|
118
|
+
spacesAvailable: 0
|
|
119
119
|
};
|
|
120
120
|
|
|
121
121
|
const getEntityPrefixExample = (entity: Stop | Station) => {
|
|
@@ -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 hXaHvR">
|
|
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,20 +1,26 @@
|
|
|
1
1
|
import React, { useCallback } from "react";
|
|
2
2
|
import FromToLocationPicker from "@opentripplanner/from-to-location-picker";
|
|
3
|
-
import coreUtils from "@opentripplanner/core-utils";
|
|
4
3
|
|
|
5
4
|
// eslint-disable-next-line prettier/prettier
|
|
6
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
Company,
|
|
7
|
+
ConfiguredCompany,
|
|
8
|
+
Location,
|
|
9
|
+
Stop,
|
|
10
|
+
StopEventHandler,
|
|
11
|
+
TileLayerStation
|
|
12
|
+
} from "@opentripplanner/types";
|
|
7
13
|
|
|
8
14
|
import { FocusTrapWrapper } from "@opentripplanner/building-blocks";
|
|
9
15
|
import { flatten } from "flat";
|
|
10
16
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
11
17
|
import { Styled } from "@opentripplanner/base-map";
|
|
12
18
|
|
|
19
|
+
import { Entity, getNetwork, makeDefaultGetEntityName, type StopIdAgencyMap } from "./util";
|
|
13
20
|
import { ViewStopButton } from "./styled";
|
|
14
21
|
|
|
15
22
|
// Load the default messages.
|
|
16
23
|
import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
17
|
-
import { makeDefaultGetEntityName, type StopIdAgencyMap } from "./util";
|
|
18
24
|
|
|
19
25
|
// HACK: We should flatten the messages loaded above because
|
|
20
26
|
// the YAML loaders behave differently between webpack and our version of jest:
|
|
@@ -41,7 +47,7 @@ const generateLocation = (entity: Entity, name: string) => {
|
|
|
41
47
|
return { lat, lon, name };
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
const StationHubDetails = ({ station }: { station:
|
|
50
|
+
const StationHubDetails = ({ station }: { station: TileLayerStation }) => {
|
|
45
51
|
return (
|
|
46
52
|
<Styled.PopupRow>
|
|
47
53
|
<div>
|
|
@@ -51,7 +57,7 @@ const StationHubDetails = ({ station }: { station: Station }) => {
|
|
|
51
57
|
}
|
|
52
58
|
description="Label text for the number of bikes available"
|
|
53
59
|
id="otpUi.MapPopup.availableBikes"
|
|
54
|
-
values={{ value: station.
|
|
60
|
+
values={{ value: station.vehiclesAvailable }}
|
|
55
61
|
/>
|
|
56
62
|
</div>
|
|
57
63
|
<div>
|
|
@@ -68,7 +74,7 @@ const StationHubDetails = ({ station }: { station: Station }) => {
|
|
|
68
74
|
)
|
|
69
75
|
}
|
|
70
76
|
|
|
71
|
-
const StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => void; }) => {
|
|
77
|
+
const StopDetails = ({ id, feedName, setViewedStop }: { id: string, feedName?: string, setViewedStop: () => void; }) => {
|
|
72
78
|
return (
|
|
73
79
|
<Styled.PopupRow>
|
|
74
80
|
{id &&
|
|
@@ -78,6 +84,7 @@ const StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => v
|
|
|
78
84
|
description="Displays the stop id"
|
|
79
85
|
id="otpUi.MapPopup.stopId"
|
|
80
86
|
values={{
|
|
87
|
+
feedName,
|
|
81
88
|
stopId: id
|
|
82
89
|
}}
|
|
83
90
|
/>
|
|
@@ -93,20 +100,19 @@ const StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => v
|
|
|
93
100
|
)
|
|
94
101
|
}
|
|
95
102
|
|
|
96
|
-
type Entity = Stop | Station
|
|
97
103
|
type Props = {
|
|
98
|
-
closePopup?: (arg?:
|
|
104
|
+
closePopup?: (arg?: boolean) => void
|
|
99
105
|
configCompanies?: ConfiguredCompany[];
|
|
100
106
|
entity: Entity
|
|
101
|
-
getEntityName?: (entity: Entity, configCompanies: Company[], feedName?: string) => string;
|
|
107
|
+
getEntityName?: (entity: Entity, configCompanies: Company[], feedName?: string, includeParenthetical?: boolean) => string;
|
|
102
108
|
getEntityPrefix?: (entity: Entity) => JSX.Element
|
|
103
109
|
feeds?: Feed[]
|
|
104
110
|
setLocation?: ({ location, locationType }: { location: Location, locationType: string }) => void;
|
|
105
111
|
setViewedStop?: StopEventHandler;
|
|
106
112
|
};
|
|
107
113
|
|
|
108
|
-
function entityIsStation(entity: Entity): entity is
|
|
109
|
-
return "
|
|
114
|
+
function entityIsStation(entity: Entity): entity is TileLayerStation {
|
|
115
|
+
return "vehiclesAvailable" in entity
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
/**
|
|
@@ -137,12 +143,13 @@ export function MapPopup({
|
|
|
137
143
|
}
|
|
138
144
|
|
|
139
145
|
const name = getNameFunc(entity, configCompanies, feedName);
|
|
146
|
+
const titleName = getNameFunc(entity, configCompanies, feedName, false);
|
|
140
147
|
|
|
141
|
-
const stationNetwork =
|
|
148
|
+
const stationNetwork = getNetwork(entity, configCompanies);
|
|
142
149
|
|
|
143
150
|
const bikesAvailablePresent = entityIsStation(entity)
|
|
144
|
-
const entityIsStationHub = bikesAvailablePresent && entity
|
|
145
|
-
const stopId = !bikesAvailablePresent && entity
|
|
151
|
+
const entityIsStationHub = bikesAvailablePresent && entity.vehiclesAvailable !== undefined && !entity.isFloatingBike;
|
|
152
|
+
const stopId = !bikesAvailablePresent && "code" in entity && entity.code;
|
|
146
153
|
const id = `focus-${encodeURIComponent(entity.id).replace(/%/g, "")}-popup`
|
|
147
154
|
|
|
148
155
|
return (
|
|
@@ -154,7 +161,7 @@ export function MapPopup({
|
|
|
154
161
|
defaultMessage={defaultMessages["otpUi.MapPopup.popupTitle"]}
|
|
155
162
|
description="Text for title of the popup, contains an optional company name"
|
|
156
163
|
id="otpUi.MapPopup.popupTitle"
|
|
157
|
-
values={{ name, stationNetwork }}
|
|
164
|
+
values={{ name: titleName, stationNetwork }}
|
|
158
165
|
/>
|
|
159
166
|
</Styled.PopupTitle>
|
|
160
167
|
{/* render dock info if it is available */}
|
|
@@ -164,7 +171,8 @@ export function MapPopup({
|
|
|
164
171
|
{setViewedStop && !bikesAvailablePresent && (
|
|
165
172
|
<StopDetails
|
|
166
173
|
id={stopId}
|
|
167
|
-
|
|
174
|
+
feedName={feedName}
|
|
175
|
+
setViewedStop={useCallback(() => setViewedStop(entity as Stop), [entity])}
|
|
168
176
|
/>
|
|
169
177
|
)}
|
|
170
178
|
|
package/src/util.ts
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Agency,
|
|
3
|
+
Company,
|
|
4
|
+
Station,
|
|
5
|
+
Stop,
|
|
6
|
+
TileLayerStation
|
|
7
|
+
} from "@opentripplanner/types";
|
|
2
8
|
import { IntlShape } from "react-intl";
|
|
3
9
|
import coreUtils from "@opentripplanner/core-utils";
|
|
4
10
|
|
|
5
11
|
export type StopIdAgencyMap = Record<string, Agency>;
|
|
12
|
+
export type Entity = Station | Stop | TileLayerStation;
|
|
13
|
+
|
|
14
|
+
export function getNetwork(entity: Entity, configCompanies: Company[]): string {
|
|
15
|
+
return (
|
|
16
|
+
"network" in entity &&
|
|
17
|
+
(coreUtils.itinerary.getCompaniesLabelFromNetworks(
|
|
18
|
+
[entity.network],
|
|
19
|
+
configCompanies
|
|
20
|
+
) ||
|
|
21
|
+
entity.network)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
6
24
|
|
|
7
25
|
// eslint-disable-next-line import/prefer-default-export
|
|
8
26
|
export function makeDefaultGetEntityName(
|
|
@@ -10,19 +28,11 @@ export function makeDefaultGetEntityName(
|
|
|
10
28
|
defaultEnglishMessages: { [key: string]: string }
|
|
11
29
|
) {
|
|
12
30
|
return function defaultGetEntityName(
|
|
13
|
-
entity:
|
|
31
|
+
entity: Entity,
|
|
14
32
|
configCompanies: Company[],
|
|
15
|
-
feedName?: string
|
|
33
|
+
feedName?: string,
|
|
34
|
+
includeParenthetical = true
|
|
16
35
|
): string | null {
|
|
17
|
-
// TODO: Stop generating this / passing it to the car string? Is it needed?
|
|
18
|
-
// In English we say "Car: " instead
|
|
19
|
-
const stationNetworks =
|
|
20
|
-
"networks" in entity &&
|
|
21
|
-
(coreUtils.itinerary.getCompaniesLabelFromNetworks(
|
|
22
|
-
entity?.networks || [],
|
|
23
|
-
configCompanies
|
|
24
|
-
) ||
|
|
25
|
-
entity?.networks?.[0]);
|
|
26
36
|
let stationName: string | null = entity.name || entity.id;
|
|
27
37
|
// If the station name or id is a giant UUID (with more than 3 "-" characters)
|
|
28
38
|
// best not to show that at all. The company name will still be shown.
|
|
@@ -44,6 +54,9 @@ export function makeDefaultGetEntityName(
|
|
|
44
54
|
{ name: stationName }
|
|
45
55
|
);
|
|
46
56
|
} else if ("isFloatingCar" in entity && entity.isFloatingCar) {
|
|
57
|
+
// TODO: Stop generating this / passing it to the car string? Is it needed?
|
|
58
|
+
// In English we say "Car: " instead
|
|
59
|
+
const stationNetwork = getNetwork(entity, configCompanies);
|
|
47
60
|
stationName = intl.formatMessage(
|
|
48
61
|
{
|
|
49
62
|
defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingCar"],
|
|
@@ -51,7 +64,7 @@ export function makeDefaultGetEntityName(
|
|
|
51
64
|
id: "otpUi.MapPopup.floatingCar"
|
|
52
65
|
},
|
|
53
66
|
{
|
|
54
|
-
company:
|
|
67
|
+
company: stationNetwork,
|
|
55
68
|
name: stationName
|
|
56
69
|
}
|
|
57
70
|
);
|
|
@@ -66,7 +79,7 @@ export function makeDefaultGetEntityName(
|
|
|
66
79
|
},
|
|
67
80
|
{ name: stationName }
|
|
68
81
|
);
|
|
69
|
-
} else if (feedName && "code" in entity) {
|
|
82
|
+
} else if (includeParenthetical && feedName && "code" in entity) {
|
|
70
83
|
stationName = `${stationName} (${feedName} ${entity.code})`;
|
|
71
84
|
}
|
|
72
85
|
return stationName;
|