@opentripplanner/map-popup 7.0.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/lib/util.js CHANGED
@@ -1,59 +1,60 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getNetwork = getNetwork;
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
- return "network" in entity && (_coreUtils.default.itinerary.getCompaniesLabelFromNetworks([entity.network] || [], configCompanies) || entity.network);
9
+ return ("network" in entity &&
10
+ (core_utils_1.default.itinerary.getCompaniesLabelFromNetworks([entity.network], configCompanies) ||
11
+ entity.network));
12
12
  }
13
-
13
+ exports.getNetwork = getNetwork;
14
14
  // eslint-disable-next-line import/prefer-default-export
15
15
  function makeDefaultGetEntityName(intl, defaultEnglishMessages) {
16
- return function defaultGetEntityName(entity, configCompanies, feedName) {
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 || stationName === "Default vehicle type") {
22
- stationName = null;
23
- }
24
- if ("isFloatingBike" in entity && entity.isFloatingBike) {
25
- stationName = intl.formatMessage({
26
- defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingBike"],
27
- description: "Popup title for a free-floating bike",
28
- id: "otpUi.MapPopup.floatingBike"
29
- }, {
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
- } else if ("isFloatingVehicle" in entity && entity.isFloatingVehicle) {
45
- // assumes that all floating vehicles are E-scooters
46
- stationName = intl.formatMessage({
47
- defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingEScooter"],
48
- description: "Popup title for a free-floating e-scooter",
49
- id: "otpUi.MapPopup.floatingEScooter"
50
- }, {
51
- name: stationName
52
- });
53
- } else if (feedName && "code" in entity) {
54
- stationName = `${stationName} (${feedName} ${entity.code})`;
55
- }
56
- return stationName;
57
- };
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
+ };
58
58
  }
59
+ exports.makeDefaultGetEntityName = makeDefaultGetEntityName;
59
60
  //# sourceMappingURL=util.js.map
package/lib/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","names":["_coreUtils","_interopRequireDefault","require","getNetwork","entity","configCompanies","coreUtils","itinerary","getCompaniesLabelFromNetworks","network","makeDefaultGetEntityName","intl","defaultEnglishMessages","defaultGetEntityName","feedName","stationName","name","id","match","length","isFloatingBike","formatMessage","defaultMessage","description","isFloatingCar","stationNetwork","company","isFloatingVehicle","code"],"sources":["../src/util.ts"],"sourcesContent":["import {\n Agency,\n Company,\n Station,\n Stop,\n TileLayerStation\n} from \"@opentripplanner/types\";\nimport { IntlShape } from \"react-intl\";\nimport coreUtils from \"@opentripplanner/core-utils\";\n\nexport type StopIdAgencyMap = Record<string, Agency>;\nexport type Entity = Station | Stop | TileLayerStation;\n\nexport function getNetwork(entity: Entity, configCompanies: Company[]): string {\n return (\n \"network\" in entity &&\n (coreUtils.itinerary.getCompaniesLabelFromNetworks(\n [entity.network] || [],\n configCompanies\n ) ||\n entity.network)\n );\n}\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: Entity,\n configCompanies: Company[],\n feedName?: string\n ): string | null {\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 // Also ignore \"Default Vehicle Type\"\n if (\n (stationName.match(/-/g) || []).length > 3 ||\n stationName === \"Default vehicle type\"\n ) {\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 }\n );\n } else if (\"isFloatingCar\" in entity && entity.isFloatingCar) {\n // TODO: Stop generating this / passing it to the car string? Is it needed?\n // In English we say \"Car: \" instead\n const stationNetwork = getNetwork(entity, configCompanies);\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: stationNetwork,\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 }\n );\n } else if (feedName && \"code\" in entity) {\n stationName = `${stationName} (${feedName} ${entity.code})`;\n }\n return stationName;\n };\n}\n"],"mappings":";;;;;;;;AAQA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKO,SAASC,UAAUA,CAACC,MAAc,EAAEC,eAA0B,EAAU;EAC7E,OACE,SAAS,IAAID,MAAM,KAClBE,kBAAS,CAACC,SAAS,CAACC,6BAA6B,CAChD,CAACJ,MAAM,CA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A6B,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": "7.0.0",
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",
@@ -12,13 +12,13 @@
12
12
  "private": false,
13
13
  "dependencies": {
14
14
  "flat": "^5.0.2",
15
- "@opentripplanner/base-map": "6.0.0",
16
15
  "@opentripplanner/building-blocks": "3.0.1",
17
- "@opentripplanner/core-utils": "13.0.1",
16
+ "@opentripplanner/base-map": "6.0.0",
17
+ "@opentripplanner/core-utils": "14.0.0",
18
18
  "@opentripplanner/from-to-location-picker": "4.0.1"
19
19
  },
20
20
  "devDependencies": {
21
- "@opentripplanner/types": "7.0.0"
21
+ "@opentripplanner/types": "8.0.0"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "react": "^18.2.0",
@@ -1,9 +1,9 @@
1
1
  import React from "react";
2
- import { action } from "@storybook/addon-actions";
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
@@ -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 &amp; SW 2nd (TriMet 9526)
395
+ W Burnside &amp; 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
@@ -74,7 +74,7 @@ const StationHubDetails = ({ station }: { station: TileLayerStation }) => {
74
74
  )
75
75
  }
76
76
 
77
- const StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => void; }) => {
77
+ const StopDetails = ({ id, feedName, setViewedStop }: { id: string, feedName?: string, setViewedStop: () => void; }) => {
78
78
  return (
79
79
  <Styled.PopupRow>
80
80
  {id &&
@@ -84,6 +84,7 @@ const StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => v
84
84
  description="Displays the stop id"
85
85
  id="otpUi.MapPopup.stopId"
86
86
  values={{
87
+ feedName,
87
88
  stopId: id
88
89
  }}
89
90
  />
@@ -103,7 +104,7 @@ type Props = {
103
104
  closePopup?: (arg?: boolean) => void
104
105
  configCompanies?: ConfiguredCompany[];
105
106
  entity: Entity
106
- getEntityName?: (entity: Entity, configCompanies: Company[], feedName?: string) => string;
107
+ getEntityName?: (entity: Entity, configCompanies: Company[], feedName?: string, includeParenthetical?: boolean) => string;
107
108
  getEntityPrefix?: (entity: Entity) => JSX.Element
108
109
  feeds?: Feed[]
109
110
  setLocation?: ({ location, locationType }: { location: Location, locationType: string }) => void;
@@ -142,6 +143,7 @@ export function MapPopup({
142
143
  }
143
144
 
144
145
  const name = getNameFunc(entity, configCompanies, feedName);
146
+ const titleName = getNameFunc(entity, configCompanies, feedName, false);
145
147
 
146
148
  const stationNetwork = getNetwork(entity, configCompanies);
147
149
 
@@ -159,7 +161,7 @@ export function MapPopup({
159
161
  defaultMessage={defaultMessages["otpUi.MapPopup.popupTitle"]}
160
162
  description="Text for title of the popup, contains an optional company name"
161
163
  id="otpUi.MapPopup.popupTitle"
162
- values={{ name, stationNetwork }}
164
+ values={{ name: titleName, stationNetwork }}
163
165
  />
164
166
  </Styled.PopupTitle>
165
167
  {/* render dock info if it is available */}
@@ -169,6 +171,7 @@ export function MapPopup({
169
171
  {setViewedStop && !bikesAvailablePresent && (
170
172
  <StopDetails
171
173
  id={stopId}
174
+ feedName={feedName}
172
175
  setViewedStop={useCallback(() => setViewedStop(entity as Stop), [entity])}
173
176
  />
174
177
  )}
package/src/util.ts CHANGED
@@ -15,7 +15,7 @@ export function getNetwork(entity: Entity, configCompanies: Company[]): string {
15
15
  return (
16
16
  "network" in entity &&
17
17
  (coreUtils.itinerary.getCompaniesLabelFromNetworks(
18
- [entity.network] || [],
18
+ [entity.network],
19
19
  configCompanies
20
20
  ) ||
21
21
  entity.network)
@@ -30,7 +30,8 @@ export function makeDefaultGetEntityName(
30
30
  return function defaultGetEntityName(
31
31
  entity: Entity,
32
32
  configCompanies: Company[],
33
- feedName?: string
33
+ feedName?: string,
34
+ includeParenthetical = true
34
35
  ): string | null {
35
36
  let stationName: string | null = entity.name || entity.id;
36
37
  // If the station name or id is a giant UUID (with more than 3 "-" characters)
@@ -78,7 +79,7 @@ export function makeDefaultGetEntityName(
78
79
  },
79
80
  { name: stationName }
80
81
  );
81
- } else if (feedName && "code" in entity) {
82
+ } else if (includeParenthetical && feedName && "code" in entity) {
82
83
  stationName = `${stationName} (${feedName} ${entity.code})`;
83
84
  }
84
85
  return stationName;