@opentripplanner/map-popup 0.0.1 → 1.0.0-alpha.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/lib/util.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,SAAS,EACf,sBAAsB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,YAGvC,OAAO,GAAG,IAAI,mBACL,OAAO,EAAE,KACzB,MAAM,CAkDV"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,SAAS,EACf,sBAAsB,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,YAGvC,OAAO,GAAG,IAAI,mBACL,OAAO,EAAE,KACzB,MAAM,GAAG,IAAI,CAkDjB"}
package/lib/util.js CHANGED
@@ -1,50 +1,56 @@
1
1
  "use strict";
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 = void 0;
7
- const core_utils_1 = __importDefault(require("@opentripplanner/core-utils"));
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.makeDefaultGetEntityName = makeDefaultGetEntityName;
9
+
10
+ var _coreUtils = _interopRequireDefault(require("@opentripplanner/core-utils"));
11
+
8
12
  // eslint-disable-next-line import/prefer-default-export
9
13
  function makeDefaultGetEntityName(intl, defaultEnglishMessages) {
10
- return function defaultGetEntityName(entity, configCompanies) {
11
- var _a;
12
- const stationNetworks = "networks" in entity &&
13
- (core_utils_1.default.itinerary.getCompaniesLabelFromNetworks((entity === null || entity === void 0 ? void 0 : entity.networks) || [], configCompanies) ||
14
- ((_a = entity === null || entity === void 0 ? void 0 : entity.networks) === null || _a === void 0 ? void 0 : _a[0]));
15
- let stationName = entity.name || entity.id;
16
- // If the station name or id is a giant UUID (with more than 3 "-" characters)
17
- // best not to show that at all. The company name will still be shown.
18
- if ((stationName.match(/-/g) || []).length > 3) {
19
- stationName = null;
20
- }
21
- if ("isFloatingBike" in entity && entity.isFloatingBike) {
22
- stationName = intl.formatMessage({
23
- defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingBike"],
24
- description: "Popup title for a free-floating bike",
25
- id: "otpUi.MapPopup.floatingBike"
26
- }, { name: stationName || stationNetworks });
27
- }
28
- else if ("isFloatingCar" in entity && entity.isFloatingCar) {
29
- stationName = intl.formatMessage({
30
- defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingCar"],
31
- description: "Popup title for a free-floating car",
32
- id: "otpUi.MapPopup.floatingCar"
33
- }, {
34
- company: stationNetworks,
35
- name: stationName
36
- });
37
- }
38
- else if ("isFloatingVehicle" in entity && entity.isFloatingVehicle) {
39
- // assumes that all floating vehicles are E-scooters
40
- stationName = intl.formatMessage({
41
- defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingEScooter"],
42
- description: "Popup title for a free-floating e-scooter",
43
- id: "otpUi.MapPopup.floatingEScooter"
44
- }, { name: stationName || stationNetworks });
45
- }
46
- return stationName;
47
- };
14
+ return function defaultGetEntityName(entity, configCompanies) {
15
+ var _entity$networks;
16
+
17
+ const stationNetworks = "networks" in entity && (_coreUtils.default.itinerary.getCompaniesLabelFromNetworks((entity === null || entity === void 0 ? void 0 : entity.networks) || [], configCompanies) || (entity === null || entity === void 0 ? void 0 : (_entity$networks = entity.networks) === null || _entity$networks === void 0 ? void 0 : _entity$networks[0]));
18
+ let stationName = entity.name || entity.id; // 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
+
21
+ if ((stationName.match(/-/g) || []).length > 3) {
22
+ stationName = null;
23
+ }
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
+ }, {
31
+ name: stationName || stationNetworks
32
+ });
33
+ } else if ("isFloatingCar" in entity && entity.isFloatingCar) {
34
+ stationName = intl.formatMessage({
35
+ defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingCar"],
36
+ description: "Popup title for a free-floating car",
37
+ id: "otpUi.MapPopup.floatingCar"
38
+ }, {
39
+ company: stationNetworks,
40
+ name: stationName
41
+ });
42
+ } else if ("isFloatingVehicle" in entity && entity.isFloatingVehicle) {
43
+ // assumes that all floating vehicles are E-scooters
44
+ stationName = intl.formatMessage({
45
+ defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingEScooter"],
46
+ description: "Popup title for a free-floating e-scooter",
47
+ id: "otpUi.MapPopup.floatingEScooter"
48
+ }, {
49
+ name: stationName || stationNetworks
50
+ });
51
+ }
52
+
53
+ return stationName;
54
+ };
48
55
  }
49
- exports.makeDefaultGetEntityName = makeDefaultGetEntityName;
50
56
  //# sourceMappingURL=util.js.map
package/lib/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;AAEA,6EAAoD;AAEpD,wDAAwD;AACxD,SAAgB,wBAAwB,CACtC,IAAe,EACf,sBAAiD;IAEjD,OAAO,SAAS,oBAAoB,CAClC,MAAsB,EACtB,eAA0B;;QAE1B,MAAM,eAAe,GACnB,UAAU,IAAI,MAAM;YACpB,CAAC,oBAAS,CAAC,SAAS,CAAC,6BAA6B,CAChD,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,KAAI,EAAE,EACtB,eAAe,CAChB;iBACC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,0CAAG,CAAC,CAAC,CAAA,CAAC,CAAC;QAC3B,IAAI,WAAW,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,EAAE,CAAC;QAC3C,8EAA8E;QAC9E,sEAAsE;QACtE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YAC9C,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,IAAI,eAAe,EAAE,CACzC,CAAC;SACH;aAAM,IAAI,eAAe,IAAI,MAAM,IAAI,MAAM,CAAC,aAAa,EAAE;YAC5D,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,eAAe;gBACxB,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,IAAI,eAAe,EAAE,CACzC,CAAC;SACH;QACD,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AAzDD,4DAyDC"}
1
+ {"version":3,"sources":["../src/util.ts"],"names":["makeDefaultGetEntityName","intl","defaultEnglishMessages","defaultGetEntityName","entity","configCompanies","stationNetworks","coreUtils","itinerary","getCompaniesLabelFromNetworks","networks","stationName","name","id","match","length","isFloatingBike","formatMessage","defaultMessage","description","isFloatingCar","company","isFloatingVehicle"],"mappings":";;;;;;;;;AAEA;;AAEA;AACO,SAASA,wBAAT,CACLC,IADK,EAELC,sBAFK,EAGL;AACA,SAAO,SAASC,oBAAT,CACLC,MADK,EAELC,eAFK,EAGU;AAAA;;AACf,UAAMC,eAAe,GACnB,cAAcF,MAAd,KACCG,mBAAUC,SAAV,CAAoBC,6BAApB,CACC,CAAAL,MAAM,SAAN,IAAAA,MAAM,WAAN,YAAAA,MAAM,CAAEM,QAAR,KAAoB,EADrB,EAECL,eAFD,MAICD,MAJD,aAICA,MAJD,2CAICA,MAAM,CAAEM,QAJT,qDAIC,iBAAmB,CAAnB,CAJD,CADD,CADF;AAOA,QAAIC,WAA0B,GAAGP,MAAM,CAACQ,IAAP,IAAeR,MAAM,CAACS,EAAvD,CARe,CASf;AACA;;AACA,QAAI,CAACF,WAAW,CAACG,KAAZ,CAAkB,IAAlB,KAA2B,EAA5B,EAAgCC,MAAhC,GAAyC,CAA7C,EAAgD;AAC9CJ,MAAAA,WAAW,GAAG,IAAd;AACD;;AAED,QAAI,oBAAoBP,MAApB,IAA8BA,MAAM,CAACY,cAAzC,EAAyD;AACvDL,MAAAA,WAAW,GAAGV,IAAI,CAACgB,aAAL,CACZ;AACEC,QAAAA,cAAc,EAAEhB,sBAAsB,CAAC,6BAAD,CADxC;AAEEiB,QAAAA,WAAW,EAAE,sCAFf;AAGEN,QAAAA,EAAE,EAAE;AAHN,OADY,EAMZ;AAAED,QAAAA,IAAI,EAAED,WAAW,IAAIL;AAAvB,OANY,CAAd;AAQD,KATD,MASO,IAAI,mBAAmBF,MAAnB,IAA6BA,MAAM,CAACgB,aAAxC,EAAuD;AAC5DT,MAAAA,WAAW,GAAGV,IAAI,CAACgB,aAAL,CACZ;AACEC,QAAAA,cAAc,EAAEhB,sBAAsB,CAAC,4BAAD,CADxC;AAEEiB,QAAAA,WAAW,EAAE,qCAFf;AAGEN,QAAAA,EAAE,EAAE;AAHN,OADY,EAMZ;AACEQ,QAAAA,OAAO,EAAEf,eADX;AAEEM,QAAAA,IAAI,EAAED;AAFR,OANY,CAAd;AAWD,KAZM,MAYA,IAAI,uBAAuBP,MAAvB,IAAiCA,MAAM,CAACkB,iBAA5C,EAA+D;AACpE;AACAX,MAAAA,WAAW,GAAGV,IAAI,CAACgB,aAAL,CACZ;AACEC,QAAAA,cAAc,EACZhB,sBAAsB,CAAC,iCAAD,CAF1B;AAGEiB,QAAAA,WAAW,EAAE,2CAHf;AAIEN,QAAAA,EAAE,EAAE;AAJN,OADY,EAOZ;AAAED,QAAAA,IAAI,EAAED,WAAW,IAAIL;AAAvB,OAPY,CAAd;AASD;;AACD,WAAOK,WAAP;AACD,GApDD;AAqDD","sourcesContent":["import { Company, Station, Stop } from \"@opentripplanner/types\";\nimport { IntlShape } from \"react-intl\";\nimport coreUtils from \"@opentripplanner/core-utils\";\n\n// eslint-disable-next-line import/prefer-default-export\nexport function makeDefaultGetEntityName(\n intl: IntlShape,\n defaultEnglishMessages: { [key: string]: string }\n) {\n return function defaultGetEntityName(\n entity: Station | Stop,\n configCompanies: Company[]\n ): string | null {\n const stationNetworks =\n \"networks\" in entity &&\n (coreUtils.itinerary.getCompaniesLabelFromNetworks(\n entity?.networks || [],\n configCompanies\n ) ||\n entity?.networks?.[0]);\n let stationName: string | null = entity.name || entity.id;\n // If the station name or id is a giant UUID (with more than 3 \"-\" characters)\n // best not to show that at all. The company name will still be shown.\n if ((stationName.match(/-/g) || []).length > 3) {\n stationName = null;\n }\n\n if (\"isFloatingBike\" in entity && entity.isFloatingBike) {\n stationName = intl.formatMessage(\n {\n defaultMessage: defaultEnglishMessages[\"otpUi.MapPopup.floatingBike\"],\n description: \"Popup title for a free-floating bike\",\n id: \"otpUi.MapPopup.floatingBike\"\n },\n { name: stationName || stationNetworks }\n );\n } else if (\"isFloatingCar\" in entity && entity.isFloatingCar) {\n stationName = intl.formatMessage(\n {\n defaultMessage: defaultEnglishMessages[\"otpUi.MapPopup.floatingCar\"],\n description: \"Popup title for a free-floating car\",\n id: \"otpUi.MapPopup.floatingCar\"\n },\n {\n company: stationNetworks,\n name: stationName\n }\n );\n } else if (\"isFloatingVehicle\" in entity && entity.isFloatingVehicle) {\n // assumes that all floating vehicles are E-scooters\n stationName = intl.formatMessage(\n {\n defaultMessage:\n defaultEnglishMessages[\"otpUi.MapPopup.floatingEScooter\"],\n description: \"Popup title for a free-floating e-scooter\",\n id: \"otpUi.MapPopup.floatingEScooter\"\n },\n { name: stationName || stationNetworks }\n );\n }\n return stationName;\n };\n}\n"],"file":"util.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentripplanner/map-popup",
3
- "version": "0.0.1",
3
+ "version": "1.0.0-alpha.1",
4
4
  "description": "A component for displaying map popup contents",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -11,8 +11,8 @@
11
11
  "license": "MIT",
12
12
  "private": false,
13
13
  "dependencies": {
14
- "@opentripplanner/base-map": "^3.0.6",
15
- "@opentripplanner/core-utils": "^7.0.9",
14
+ "@opentripplanner/base-map": "^3.0.7",
15
+ "@opentripplanner/core-utils": "^8.0.0",
16
16
  "@opentripplanner/from-to-location-picker": "^2.1.5",
17
17
  "flat": "^5.0.2"
18
18
  },
@@ -7,45 +7,45 @@ export default {
7
7
  };
8
8
 
9
9
  const STOP = {
10
+ flex: false,
10
11
  id: "9526",
11
- name: "W Burnside & SW 2nd",
12
12
  lat: 45.523009,
13
13
  lon: -122.672529,
14
- flex: false
14
+ name: "W Burnside & SW 2nd"
15
15
  };
16
16
 
17
17
  const STATION = {
18
- id: '"hub_1580"',
19
- name: "SW Morrison at 18th",
20
- x: -122.6896771788597,
21
- y: 45.5219604810172,
18
+ "stroke-width": 2,
22
19
  allowDropoff: true,
23
20
  allowPickup: true,
24
- networks: ["BIKETOWN"],
25
21
  bikesAvailable: 6,
26
- spacesAvailable: 11,
27
- isFloatingBike: false,
22
+ color: "#f00",
23
+ id: '"hub_1580"',
28
24
  isCarStation: false,
25
+ isFloatingBike: false,
26
+ name: "SW Morrison at 18th",
27
+ networks: ["BIKETOWN"],
29
28
  realTimeData: true,
30
- "stroke-width": 2,
31
- color: "#f00"
29
+ spacesAvailable: 11,
30
+ x: -122.6896771788597,
31
+ y: 45.5219604810172
32
32
  };
33
33
 
34
- const SCOOTER = {
35
- id: '"bike_6861"',
36
- name: "0541 BIKETOWN",
37
- x: -122.70486,
38
- y: 45.525486666666666,
34
+ const FLOATING_VEHICLE = {
35
+ "stroke-width": 1,
39
36
  allowDropoff: false,
40
37
  allowPickup: true,
41
- networks: ["BIKETOWN"],
42
38
  bikesAvailable: 1,
43
- spacesAvailable: 0,
44
- isFloatingBike: true,
39
+ color: "#f00",
40
+ id: '"bike_6861"',
45
41
  isCarStation: false,
42
+ isFloatingBike: true,
43
+ name: "0541 BIKETOWN",
44
+ networks: ["BIKETOWN"],
46
45
  realTimeData: true,
47
- "stroke-width": 1,
48
- color: "#f00"
46
+ spacesAvailable: 0,
47
+ x: -122.70486,
48
+ y: 45.525486666666666
49
49
  };
50
50
 
51
51
  export const StopEntity = (): JSX.Element => {
@@ -58,6 +58,10 @@ export const StopEntity = (): JSX.Element => {
58
58
  );
59
59
  };
60
60
 
61
+ export const StopEntityNoHandlers = (): JSX.Element => {
62
+ return <MapPopupContents entity={STOP} />;
63
+ };
64
+
61
65
  export const StationEntity = (): JSX.Element => {
62
66
  return (
63
67
  <MapPopupContents
@@ -68,10 +72,10 @@ export const StationEntity = (): JSX.Element => {
68
72
  );
69
73
  };
70
74
 
71
- export const ScooterEntity = (): JSX.Element => {
75
+ export const FloatingVehicleEntity = (): JSX.Element => {
72
76
  return (
73
77
  <MapPopupContents
74
- entity={SCOOTER}
78
+ entity={FLOATING_VEHICLE}
75
79
  setLocation={action("setLocation")}
76
80
  setViewedStop={action("setViewedStop")}
77
81
  />
@@ -0,0 +1,2 @@
1
+ // Generic module definition for all YAML file imports.
2
+ declare module "*.yml";
package/src/index.tsx CHANGED
@@ -10,7 +10,6 @@ import { flatten } from "flat";
10
10
  import * as S from "./styled";
11
11
 
12
12
  // Load the default messages.
13
- // @ts-expect-error TODO: why is this failing?
14
13
  import defaultEnglishMessages from "../i18n/en-US.yml";
15
14
  import { makeDefaultGetEntityName } from "./util";
16
15
 
@@ -18,103 +17,111 @@ import { makeDefaultGetEntityName } from "./util";
18
17
  // the YAML loaders behave differently between webpack and our version of jest:
19
18
  // - the yaml loader for webpack returns a nested object,
20
19
  // - the yaml loader for jest returns messages with flattened ids.
21
- export const defaultMessages = flatten(defaultEnglishMessages);
20
+ export const defaultMessages: { [key: string]: string } = flatten(defaultEnglishMessages);
21
+
22
+
23
+ const generateLocation = (entity: Entity, name: string) => {
24
+ // @ts-expect-error some of these values may be null, but that's ok
25
+ const { lon: entityLon, lat: entityLat, x, y } = entity
26
+
27
+ const lat = entityLat || x
28
+ const lon = entityLon || y
29
+ if (!lat || !lon) return null
30
+
31
+ return { lat, lon, name };
32
+ }
33
+
34
+ const StationHubDetails = ({ station }: { station: Station }) => {
35
+ return (
36
+ <BaseMapStyled.PopupRow>
37
+ <div>
38
+ <FormattedMessage
39
+ defaultMessage={
40
+ defaultMessages["otpUi.MapPopup.availableBikes"]
41
+ }
42
+ description="Label text for the number of bikes available"
43
+ id="otpUi.MapPopup.availableBikes"
44
+ values={{ value: station.bikesAvailable }}
45
+ />
46
+ </div>
47
+ <div>
48
+ <FormattedMessage
49
+ defaultMessage={
50
+ defaultMessages["otpUi.MapPopup.availableDocks"]
51
+ }
52
+ description="Label text for the number of docks available"
53
+ id="otpUi.MapPopup.availableDocks"
54
+ values={{ value: station.spacesAvailable }}
55
+ />
56
+ </div>
57
+ </BaseMapStyled.PopupRow>
58
+ )
59
+ }
60
+
61
+ const StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: ({ stopId }: { stopId: string }) => void; }) => {
62
+ return (
63
+ <BaseMapStyled.PopupRow>
64
+ <strong>
65
+ <FormattedMessage
66
+ defaultMessage={defaultMessages["otpUi.MapPopup.stopId"]}
67
+ description="Displays the stop id"
68
+ id="otpUi.MapPopup.stopId"
69
+ values={{
70
+ stopId: id
71
+ }}
72
+ />
73
+ </strong>
74
+ <S.ViewStopButton onClick={() => setViewedStop({ stopId: id })}>
75
+ <FormattedMessage
76
+ defaultMessage={defaultMessages["otpUi.MapPopup.stopViewer"]}
77
+ description="Text for link that opens the stop viewer"
78
+ id="otpUi.MapPopup.stopViewer"
79
+ />
80
+ </S.ViewStopButton>
81
+ </BaseMapStyled.PopupRow>
82
+ )
83
+ }
22
84
 
23
85
  type Entity = Stop | Station
24
86
  type Props = {
25
87
  configCompanies?: ConfiguredCompany[];
88
+ entity: Entity
26
89
  getEntityName?: (entity: Entity, configCompanies: Company[],) => string;
27
-
28
90
  setLocation?: ({ location, locationType }: { location: Location, locationType: string }) => void;
29
91
  setViewedStop?: ({ stopId }: { stopId: string }) => void;
30
-
31
- entity: Entity
32
92
  };
33
93
 
34
94
  /**
35
95
  * Renders a map popup for a stop, scooter, or shared bike
36
96
  */
37
97
  export function MapPopup({ configCompanies, entity, getEntityName, setLocation, setViewedStop, }: Props): JSX.Element {
38
- if (!entity) return null
39
98
  const intl = useIntl()
99
+ if (!entity) return <></>
40
100
 
41
- const getNameFunc = getEntityName || makeDefaultGetEntityName(intl, defaultEnglishMessages);
101
+ const getNameFunc = getEntityName || makeDefaultGetEntityName(intl, defaultMessages);
42
102
  const name = getNameFunc(entity, configCompanies);
43
103
 
44
- const generateLocation = () => {
45
- // @ts-expect-error some of these values may be null, but that's ok
46
- const { lon: entityLon, lat: entityLat, x, y } = entity
47
-
48
- const lat = entityLat || x
49
- const lon = entityLon || y
50
- if (!lat || !lon) return null
51
104
 
52
- return { lat, lon, name };
53
- }
54
-
55
- const entityIsStationHub = "bikesAvailable" in entity && entity?.bikesAvailable !== undefined && !entity?.isFloatingBike;
56
- const entityIsStop = !("bikesAvailable" in entity)
105
+ const bikesAvailablePresent = "bikesAvailable" in entity
106
+ const entityIsStationHub = bikesAvailablePresent && entity?.bikesAvailable !== undefined && !entity?.isFloatingBike;
57
107
  // @ts-expect-error ts doesn't understand entityIsStop
58
- const stopId = entityIsStop && entity?.code || entity.id.split(":")[1] || entity.id
108
+ const stopId = !bikesAvailablePresent && entity?.code || entity.id.split(":")[1] || entity.id
59
109
 
60
110
  return (
61
111
  <BaseMapStyled.MapOverlayPopup>
62
112
  <BaseMapStyled.PopupTitle>{name}</BaseMapStyled.PopupTitle>
63
113
  {/* render dock info if it is available */}
64
- {entityIsStationHub && (
65
- <BaseMapStyled.PopupRow>
66
- <div>
67
- <FormattedMessage
68
- defaultMessage={
69
- defaultMessages["otpUi.MapPopup.availableBikes"]
70
- }
71
- description="Label text for the number of bikes available"
72
- id="otpUi.MapPopup.availableBikes"
73
- values={{ value: entity.bikesAvailable }}
74
- />
75
- </div>
76
- <div>
77
- <FormattedMessage
78
- defaultMessage={
79
- defaultMessages["otpUi.MapPopup.availableDocks"]
80
- }
81
- description="Label text for the number of docks available"
82
- id="otpUi.MapPopup.availableDocks"
83
- values={{ value: entity.spacesAvailable }}
84
- />
85
- </div>
86
- </BaseMapStyled.PopupRow>
87
- )}
114
+ {entityIsStationHub && <StationHubDetails station={entity} />}
88
115
 
89
116
  {/* render stop viewer link if available */}
90
- {setViewedStop && entityIsStop && <BaseMapStyled.PopupRow>
91
- <span>
92
- <strong>
93
- <FormattedMessage
94
- defaultMessage={defaultMessages["otpUi.MapPopup.stopId"]}
95
- description="Displays the stop id"
96
- id="otpUi.MapPopup.stopId"
97
- values={{
98
- stopId
99
- }}
100
- />
101
- </strong>
102
- </span>
103
- <S.ViewStopButton onClick={() => setViewedStop(stopId)}>
104
- <FormattedMessage
105
- defaultMessage={defaultMessages["otpUi.MapPopup.stopViewer"]}
106
- description="Text for link that opens the stop viewer"
107
- id="otpUi.MapPopup.stopViewer"
108
- />
109
- </S.ViewStopButton>
110
- </BaseMapStyled.PopupRow>}
117
+ {setViewedStop && !bikesAvailablePresent && <StopDetails id={stopId} setViewedStop={setViewedStop} />}
111
118
 
112
119
  {/* The "Set as [from/to]" ButtonGroup */}
113
120
  {setLocation && (
114
121
  <BaseMapStyled.PopupRow>
115
122
  <FromToLocationPicker
116
123
  label
117
- location={generateLocation()}
124
+ location={generateLocation(entity, name)}
118
125
  setLocation={setLocation}
119
126
  />
120
127
  </BaseMapStyled.PopupRow>
package/src/styled.ts CHANGED
@@ -5,13 +5,10 @@ export const ViewStopButton = styled.button`
5
5
  background: none;
6
6
  border-bottom: none;
7
7
  border-left: 1px solid #000;
8
- border-radius: 0;
9
8
  border-right: none;
10
9
  border-top: none;
11
10
  color: #008;
12
- height: 14px;
13
- line-height: 1;
11
+ font-family: inherit;
14
12
  margin-left: 5px;
15
- outline: none;
16
13
  padding-top: 0;
17
14
  `;
package/src/util.ts CHANGED
@@ -10,7 +10,7 @@ export function makeDefaultGetEntityName(
10
10
  return function defaultGetEntityName(
11
11
  entity: Station | Stop,
12
12
  configCompanies: Company[]
13
- ): string {
13
+ ): string | null {
14
14
  const stationNetworks =
15
15
  "networks" in entity &&
16
16
  (coreUtils.itinerary.getCompaniesLabelFromNetworks(
@@ -18,7 +18,7 @@ export function makeDefaultGetEntityName(
18
18
  configCompanies
19
19
  ) ||
20
20
  entity?.networks?.[0]);
21
- let stationName = entity.name || entity.id;
21
+ let stationName: string | null = entity.name || entity.id;
22
22
  // If the station name or id is a giant UUID (with more than 3 "-" characters)
23
23
  // best not to show that at all. The company name will still be shown.
24
24
  if ((stationName.match(/-/g) || []).length > 3) {