@digitransit-search-util/digitransit-search-util-execute-search-immidiate 2.0.2 → 3.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.
Files changed (2) hide show
  1. package/index.js +54 -62
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -25,7 +25,10 @@ function getStopsFromGeocoding(stops, URL_PELIAS_PLACE) {
25
25
  gids += `${gid},`;
26
26
  return { ...stop, gid };
27
27
  });
28
- const stopStationMap = stopsWithGids.reduce(function (map, stopOrStation) {
28
+ const stopStationMap = stopsWithGids.reduce(function redu(
29
+ map,
30
+ stopOrStation,
31
+ ) {
29
32
  // eslint-disable-next-line no-param-reassign
30
33
  map[stopOrStation.gid] = stopOrStation;
31
34
  return map;
@@ -164,9 +167,12 @@ function getBackSuggestion() {
164
167
  ]);
165
168
  }
166
169
 
167
- function filterFavouriteStops(stopsAndStations, input) {
168
- return stopsAndStations.then(stops => {
169
- return filterMatchingToInput(stops, input, [
170
+ function filterFavouriteStops(stopsAndStations, input, useStops, useStations) {
171
+ return stopsAndStations.then(stopsStations => {
172
+ const candidates = stopsStations.filter(s =>
173
+ s.type === 'stop' ? useStops : useStations,
174
+ );
175
+ return filterMatchingToInput(candidates, input, [
170
176
  'properties.name',
171
177
  'properties.name',
172
178
  'properties.address',
@@ -226,9 +232,12 @@ const routeLayers = [
226
232
  'route-FERRY',
227
233
  'route-SUBWAY',
228
234
  'route-AIRPLANE',
235
+ 'route-FUNICULAR',
229
236
  ];
230
- const locationLayers = ['favouritePlace', 'venue', 'address', 'street'];
237
+ const locationLayers = ['venue', 'address', 'street'];
231
238
  const parkingLayers = ['carpark', 'bikepark'];
239
+ const stopLayers = ['stop', 'station'];
240
+
232
241
  /**
233
242
  * Executes the search
234
243
  *
@@ -320,7 +329,7 @@ export function getSearchResults(
320
329
  }
321
330
 
322
331
  if (allSources || sources.includes('Datasource')) {
323
- const geocodingLayers = ['station', 'venue', 'address', 'street'];
332
+ const geocodingLayers = ['venue', 'address', 'street'];
324
333
  const feedis = feedIDs.map(v => `gtfs${v}`);
325
334
  const geosources = geocodingSources.concat(feedis).join(',');
326
335
  searchComponents.push(
@@ -338,18 +347,10 @@ export function getSearchResults(
338
347
  }
339
348
  if (allSources || sources.includes('History')) {
340
349
  const locationHistory = getOldSearches(context, 'endpoint');
341
- const dropLayers = [
342
- 'currentPosition',
343
- 'selectFromMap',
344
- 'futureRoute',
345
- 'ownLocations',
346
- 'vehicleRentalStation',
347
- 'bikepark',
348
- 'carpark',
349
- 'stop',
350
- 'back',
351
- ];
350
+ const dropLayers = ['bikestation'];
351
+ dropLayers.push(...stopLayers);
352
352
  dropLayers.push(...routeLayers);
353
+ dropLayers.push(...parkingLayers);
353
354
  searchComponents.push(
354
355
  filterOldSearches(locationHistory, input, dropLayers),
355
356
  );
@@ -383,25 +384,18 @@ export function getSearchResults(
383
384
  }
384
385
  if (allSources || sources.includes('History')) {
385
386
  const history = getOldSearches(context);
386
- const dropLayers = [
387
- 'currentPosition',
388
- 'selectFromMap',
389
- 'futureRoute',
390
- 'ownLocations',
391
- 'favouritePlace',
392
- 'bikestation',
393
- 'vehicleRentalStation',
394
- 'back',
395
- 'stop',
396
- 'station',
397
- ];
387
+ const dropLayers = ['bikestation'];
388
+ dropLayers.push(...stopLayers);
398
389
  dropLayers.push(...routeLayers);
399
390
  dropLayers.push(...locationLayers);
400
391
  searchComponents.push(filterOldSearches(history, input, dropLayers));
401
392
  }
402
393
  }
403
394
 
404
- if (allTargets || targets.includes('Stops')) {
395
+ const useStops = targets.includes('Stops');
396
+ const useStations = targets.includes('Stations');
397
+
398
+ if (allTargets || useStops || useStations) {
405
399
  if (sources.includes('Favourite')) {
406
400
  const favouriteStops = getFavouriteStops(context);
407
401
  let stopsAndStations;
@@ -427,10 +421,18 @@ export function getSearchResults(
427
421
  return results;
428
422
  });
429
423
  }
430
- searchComponents.push(filterFavouriteStops(stopsAndStations, input));
424
+ searchComponents.push(
425
+ filterFavouriteStops(stopsAndStations, input, useStops, useStations),
426
+ );
431
427
  }
432
428
  if (allSources || sources.includes('Datasource')) {
433
- const geocodingLayers = ['stop', 'station'];
429
+ const geocodingLayers = [];
430
+ if (useStops) {
431
+ geocodingLayers.push('stop');
432
+ }
433
+ if (useStations) {
434
+ geocodingLayers.push('station');
435
+ }
434
436
  const searchParams =
435
437
  geocodingSize && geocodingSize !== 10 ? { size: geocodingSize } : {};
436
438
  if (geocodingSearchParams && geocodingSearchParams['boundary.country']) {
@@ -468,23 +470,17 @@ export function getSearchResults(
468
470
  }
469
471
  return true;
470
472
  });
471
- const dropLayers = [
472
- 'currentPosition',
473
- 'selectFromMap',
474
- 'futureRoute',
475
- 'ownLocations',
476
- 'favouritePlace',
477
- 'vehicleRentalStation',
478
- 'back',
479
- ];
473
+ const dropLayers = ['bikestation'];
480
474
  dropLayers.push(...routeLayers);
481
475
  dropLayers.push(...locationLayers);
482
476
  dropLayers.push(...parkingLayers);
477
+ if (!useStops) {
478
+ dropLayers.push('stop');
479
+ }
480
+ if (!useStations) {
481
+ dropLayers.push('station');
482
+ }
483
483
  if (transportMode) {
484
- if (transportMode !== 'route-CITYBIKE') {
485
- dropLayers.push('vehicleRentalStation');
486
- dropLayers.push('bikestation');
487
- }
488
484
  searchComponents.push(
489
485
  filterOldSearches(stopHistory, input, dropLayers).then(result =>
490
486
  filterResults ? filterResults(result, mode) : result,
@@ -497,7 +493,6 @@ export function getSearchResults(
497
493
  }
498
494
  }
499
495
  }
500
-
501
496
  if (allTargets || targets.includes('Routes')) {
502
497
  if (sources.includes('Favourite')) {
503
498
  const favouriteRoutes = getFavouriteRoutes(context);
@@ -515,26 +510,14 @@ export function getSearchResults(
515
510
  );
516
511
  if (allSources || sources.includes('History')) {
517
512
  const routeHistory = getOldSearches(context);
518
- const dropLayers = [
519
- 'currentPosition',
520
- 'selectFromMap',
521
- 'futureRoute',
522
- 'favouritePlace',
523
- 'stop',
524
- 'station',
525
- 'bikepark',
526
- 'carpark',
527
- 'ownLocations',
528
- 'back',
529
- ];
513
+ const dropLayers = ['bikestation'];
530
514
  if (transportMode) {
531
- if (transportMode !== 'route-CITYBIKE') {
532
- dropLayers.push('vehicleRentalStation');
533
- dropLayers.push('bikestation');
534
- }
535
515
  dropLayers.push(...routeLayers.filter(i => !(i === transportMode)));
536
516
  }
517
+ dropLayers.push(...stopLayers);
537
518
  dropLayers.push(...locationLayers);
519
+ dropLayers.push(...parkingLayers);
520
+
538
521
  searchComponents.push(
539
522
  filterOldSearches(routeHistory, input, dropLayers).then(results =>
540
523
  filterResults ? filterResults(results, mode, 'Routes') : results,
@@ -575,6 +558,15 @@ export function getSearchResults(
575
558
  }),
576
559
  );
577
560
  }
561
+ if (allSources || sources.includes('History')) {
562
+ const history = getOldSearches(context);
563
+ const dropLayers = [...stopLayers];
564
+ dropLayers.push(...routeLayers);
565
+ dropLayers.push(...locationLayers);
566
+ dropLayers.push(...parkingLayers);
567
+
568
+ searchComponents.push(filterOldSearches(history, input, dropLayers));
569
+ }
578
570
  }
579
571
 
580
572
  const searchResultsPromise = Promise.all(searchComponents)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitransit-search-util/digitransit-search-util-execute-search-immidiate",
3
- "version": "2.0.2",
3
+ "version": "3.0.0",
4
4
  "description": "digitransit-search-util execute-search-immidiate module",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -27,5 +27,5 @@
27
27
  "@digitransit-search-util/digitransit-search-util-helpers": "2.0.0",
28
28
  "lodash": "4.17.21"
29
29
  },
30
- "gitHead": "c8934e8828fac7ab01168e9224d0f4099dcd63e3"
30
+ "gitHead": "f4f89d869a32e89ee2212589c8f1f286d20f34e4"
31
31
  }