@opentripplanner/core-utils 13.0.0-alpha.3 → 13.0.0-alpha.4

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.
@@ -1,893 +0,0 @@
1
- // TODO: Remove this entire file, as it is deprecated in favor of i18n-queryParams within
2
- // the SettingsSelector package
3
-
4
- // This is only used within stories
5
- import cloneDeep from "lodash.clonedeep";
6
- import React from "react";
7
- import { Wheelchair } from "@styled-icons/foundation/Wheelchair";
8
-
9
- import {
10
- isTransit,
11
- isAccessMode,
12
- isCar,
13
- hasTransit,
14
- hasBike,
15
- hasMicromobility
16
- } from "./itinerary";
17
- import { getItem } from "./storage";
18
- import { getCurrentDate, getCurrentTime } from "./time";
19
-
20
- /**
21
- * name: the default name of the parameter used for internal reference and API calls
22
- *
23
- * routingTypes: array of routing type(s) (ITINERARY, PROFILE, or both) this param applies to
24
- *
25
- * applicable: an optional function (accepting the current full query as a
26
- * parameter) indicating whether this query parameter is applicable to the query.
27
- * (Applicability is assumed if this function is not provided.)
28
- *
29
- * default: the default value for this parameter. The default can be also be a
30
- * function that gets executed when accessing the default value.
31
- *
32
- * itineraryRewrite: an optional function for translating the key and/or value
33
- * for ITINERARY mode only (e.g. 'to' is rewritten as 'toPlace'). Accepts the
34
- * initial internal value as a function parameter.
35
- *
36
- * profileRewrite: an optional function for translating the value for PROFILE mode
37
- *
38
- * label: a text label for for onscreen display. May either be a text string or a
39
- * function (accepting the current full query as a parameter) returning a string
40
- *
41
- * selector: the default type of UI selector to use in the form. Can be one of:
42
- * - DROPDOWN: a standard drop-down menu selector
43
- *
44
- * options: an array of text/value pairs used with a dropdown selector
45
- *
46
- * TODO: validation system for rewrite functions and/or better user documentation
47
- * TODO: alphabetize below list
48
- */
49
-
50
- // FIXME: Use for parsing URL values?
51
- // const stringToLocation = string => {
52
- // const split = string.split(',')
53
- // return split.length === 2
54
- // ? {lat: split[0], lon: split[1]}
55
- // : {lat: null, lon: null}
56
- // }
57
-
58
- /**
59
- * Format location object as string for use in fromPlace or toPlace query param.
60
- */
61
- export function formatPlace(location, alternateName) {
62
- if (!location) return null;
63
- const name =
64
- location.name ||
65
- `${alternateName ? `${alternateName} ` : ""}(${location.lat},${
66
- location.lon
67
- })`;
68
- // This string is not language-specific
69
- return `${name}::${location.lat},${location.lon}`;
70
- }
71
-
72
- // Load stored default query settings from local storage
73
- const storedSettings = getItem("defaultQuery", {});
74
-
75
- const queryParams = [
76
- {
77
- /* from - the trip origin. stored internally as a location (lat/lon/name) object */
78
- name: "from",
79
- routingTypes: ["ITINERARY", "PROFILE"],
80
- default: null,
81
- itineraryRewrite: value => ({ fromPlace: formatPlace(value) }),
82
- profileRewrite: value => ({ from: { lat: value.lat, lon: value.lon } })
83
- // FIXME: Use for parsing URL values?
84
- // fromURL: stringToLocation
85
- },
86
-
87
- {
88
- /* to - the trip destination. stored internally as a location (lat/lon/name) object */
89
- name: "to",
90
- routingTypes: ["ITINERARY", "PROFILE"],
91
- default: null,
92
- itineraryRewrite: value => ({ toPlace: formatPlace(value) }),
93
- profileRewrite: value => ({ to: { lat: value.lat, lon: value.lon } })
94
- // FIXME: Use for parsing URL values?
95
- // fromURL: stringToLocation
96
- },
97
-
98
- {
99
- /* date - the date of travel, in MM-DD-YYYY format */
100
- name: "date",
101
- routingTypes: ["ITINERARY", "PROFILE"],
102
- default: getCurrentDate
103
- },
104
-
105
- {
106
- /* time - the arrival/departure time for an itinerary trip, in HH:mm format */
107
- name: "time",
108
- routingTypes: ["ITINERARY"],
109
- default: getCurrentTime
110
- },
111
-
112
- {
113
- /* departArrive - whether this is a depart-at, arrive-by, or leave-now trip */
114
- name: "departArrive",
115
- routingTypes: ["ITINERARY"],
116
- default: "NOW",
117
- itineraryRewrite: value => ({ arriveBy: value === "ARRIVE" })
118
- },
119
-
120
- {
121
- /* startTime - the start time for a profile trip, in HH:mm format */
122
- name: "startTime",
123
- routingTypes: ["PROFILE"],
124
- default: "07:00"
125
- },
126
-
127
- {
128
- /* endTime - the end time for a profile trip, in HH:mm format */
129
- name: "endTime",
130
- routingTypes: ["PROFILE"],
131
- default: "09:00"
132
- },
133
-
134
- {
135
- /* mode - the allowed modes for a trip, as a comma-separated list */
136
- name: "mode",
137
- routingTypes: ["ITINERARY", "PROFILE"],
138
- default: "WALK,TRANSIT", // TODO: make this dependent on routingType?
139
- profileRewrite: value => {
140
- const accessModes = [];
141
- const directModes = [];
142
- const transitModes = [];
143
-
144
- if (value && value.length > 0) {
145
- value.split(",").forEach(m => {
146
- if (isTransit(m)) transitModes.push(m);
147
- if (isAccessMode(m)) {
148
- accessModes.push(m);
149
- // TODO: make configurable whether direct-driving is considered
150
- if (!isCar(m)) directModes.push(m);
151
- }
152
- });
153
- }
154
-
155
- return { accessModes, directModes, transitModes };
156
- }
157
- },
158
-
159
- {
160
- /* showIntermediateStops - whether response should include intermediate stops for transit legs */
161
- name: "showIntermediateStops",
162
- routingTypes: ["ITINERARY"],
163
- default: true
164
- },
165
-
166
- {
167
- /* maxWalkDistance - the maximum distance in meters the user will walk to transit. */
168
- name: "maxWalkDistance",
169
- routingTypes: ["ITINERARY"],
170
- applicable: query =>
171
- /* Since this query variable isn't in this list, it's not included in the generated query
172
- * It does however allow us to determine if we should show the OTP1 max walk distance
173
- * dropdown or the OTP2 walk reluctance slider
174
- */
175
- !query.otp2 &&
176
- query.mode &&
177
- hasTransit(query.mode) &&
178
- query.mode.indexOf("WALK") !== -1,
179
- default: 1609, // 1 mi.
180
- selector: "DROPDOWN",
181
- label: "Maximum Walk",
182
- options: [
183
- {
184
- text: "1/10 mile",
185
- value: 160.9
186
- },
187
- {
188
- text: "1/4 mile",
189
- value: 402.3
190
- },
191
- {
192
- text: "1/2 mile",
193
- value: 804.7
194
- },
195
- {
196
- text: "3/4 mile",
197
- value: 1207
198
- },
199
- {
200
- text: "1 mile",
201
- value: 1609
202
- },
203
- {
204
- text: "2 miles",
205
- value: 3219
206
- },
207
- {
208
- text: "5 miles",
209
- value: 8047
210
- }
211
- ]
212
- },
213
-
214
- {
215
- /* maxBikeDistance - the maximum distance in meters the user will bike. Not
216
- * actually an OTP parameter (maxWalkDistance doubles for biking) but we
217
- * store it separately internally in order to allow different default values,
218
- * options, etc. Translated to 'maxWalkDistance' via the rewrite function.
219
- */
220
- name: "maxBikeDistance",
221
- routingTypes: ["ITINERARY"],
222
- applicable: query =>
223
- query.mode &&
224
- hasTransit(query.mode) &&
225
- query.mode.indexOf("BICYCLE") !== -1,
226
- default: 4828, // 3 mi.
227
- selector: "DROPDOWN",
228
- label: "Maximum Bike",
229
- options: [
230
- {
231
- text: "1/4 mile",
232
- value: 402.3
233
- },
234
- {
235
- text: "1/2 mile",
236
- value: 804.7
237
- },
238
- {
239
- text: "3/4 mile",
240
- value: 1207
241
- },
242
- {
243
- text: "1 mile",
244
- value: 1609
245
- },
246
- {
247
- text: "2 miles",
248
- value: 3219
249
- },
250
- {
251
- text: "3 miles",
252
- value: 4828
253
- },
254
- {
255
- text: "5 miles",
256
- value: 8047
257
- },
258
- {
259
- text: "10 miles",
260
- value: 16093
261
- },
262
- {
263
- text: "20 miles",
264
- value: 32187
265
- },
266
- {
267
- text: "30 miles",
268
- value: 48280
269
- }
270
- ],
271
- itineraryRewrite: value => ({
272
- maxWalkDistance: value,
273
- // ensures that the value is repopulated when loaded from URL params
274
- maxBikeDistance: value
275
- })
276
- },
277
-
278
- {
279
- /* optimize -- how to optimize a trip (non-bike, non-micromobility trips) */
280
- name: "optimize",
281
- // This parameter doesn't seem to do anything
282
- applicable: () => false,
283
- routingTypes: ["ITINERARY"],
284
- default: "QUICK",
285
- selector: "DROPDOWN",
286
- label: "Optimize for",
287
- options: [
288
- {
289
- text: "Speed",
290
- value: "QUICK"
291
- },
292
- {
293
- text: "Fewest Transfers",
294
- value: "TRANSFERS"
295
- }
296
- ]
297
- },
298
-
299
- {
300
- /* optimizeBike -- how to optimize an bike-based trip */
301
- name: "optimizeBike",
302
- applicable: query => !query.otp2 && hasBike(query.mode),
303
- routingTypes: ["ITINERARY"],
304
- default: "SAFE",
305
- selector: "DROPDOWN",
306
- label: "Optimize for",
307
- options: () => {
308
- const opts = [
309
- {
310
- text: "Speed",
311
- value: "QUICK"
312
- },
313
- {
314
- text: "Bike-Friendly Trip",
315
- value: "SAFE"
316
- },
317
- {
318
- text: "Flat Trip",
319
- value: "FLAT"
320
- }
321
- ];
322
-
323
- return opts;
324
- },
325
- itineraryRewrite: value => ({ optimize: value })
326
- },
327
-
328
- {
329
- /* maxWalkTime -- the maximum time the user will spend walking in minutes */
330
- name: "maxWalkTime",
331
- routingTypes: ["PROFILE"],
332
- default: 15,
333
- selector: "DROPDOWN",
334
- label: "Max Walk Time",
335
- applicable: query =>
336
- query.mode && hasTransit(query.mode) && query.mode.indexOf("WALK") !== -1,
337
- options: [
338
- {
339
- text: "5 minutes",
340
- value: 5
341
- },
342
- {
343
- text: "10 minutes",
344
- value: 10
345
- },
346
- {
347
- text: "15 minutes",
348
- value: 15
349
- },
350
- {
351
- text: "20 minutes",
352
- value: 20
353
- },
354
- {
355
- text: "30 minutes",
356
- value: 30
357
- },
358
- {
359
- text: "45 minutes",
360
- value: 45
361
- },
362
- {
363
- text: "1 hour",
364
- value: 60
365
- }
366
- ]
367
- },
368
- {
369
- name: "walkReluctance",
370
- routingTypes: ["ITINERARY", "PROFILE"],
371
- selector: "SLIDER",
372
- low: 1,
373
- high: 10,
374
- step: 0.5,
375
- label: "walk reluctance",
376
- labelLow: "More Walking",
377
- labelHigh: "More Transit",
378
- applicable: query =>
379
- /* Since this query variable isn't in this list, it's not included in the generated query
380
- * It does however allow us to determine if we should show the OTP1 max walk distance
381
- * dropdown or the OTP2 walk reluctance slider
382
- */
383
- !!query.otp2 && query.mode && query.mode.indexOf("WALK") !== -1
384
- },
385
- {
386
- /* maxBikeTime -- the maximum time the user will spend biking in minutes */
387
- name: "maxBikeTime",
388
- routingTypes: ["PROFILE"],
389
- default: 20,
390
- selector: "DROPDOWN",
391
- label: "Max Bike Time",
392
- applicable: query =>
393
- query.mode &&
394
- hasTransit(query.mode) &&
395
- query.mode.indexOf("BICYCLE") !== -1,
396
- options: [
397
- {
398
- text: "5 minutes",
399
- value: 5
400
- },
401
- {
402
- text: "10 minutes",
403
- value: 10
404
- },
405
- {
406
- text: "15 minutes",
407
- value: 15
408
- },
409
- {
410
- text: "20 minutes",
411
- value: 20
412
- },
413
- {
414
- text: "30 minutes",
415
- value: 30
416
- },
417
- {
418
- text: "45 minutes",
419
- value: 45
420
- },
421
- {
422
- text: "1 hour",
423
- value: 60
424
- }
425
- ]
426
- },
427
-
428
- {
429
- /* bikeSpeed -- the user's bikeSpeed speed in m/s */
430
- name: "bikeSpeed",
431
- routingTypes: ["ITINERARY", "PROFILE"],
432
- default: 3.58,
433
- selector: "DROPDOWN",
434
- label: "Bicycle Speed",
435
- applicable: query => query.mode && query.mode.indexOf("BICYCLE") !== -1,
436
- options: [
437
- {
438
- text: "6 MPH",
439
- value: 2.68
440
- },
441
- {
442
- text: "8 MPH",
443
- value: 3.58
444
- },
445
- {
446
- text: "10 MPH",
447
- value: 4.47
448
- },
449
- {
450
- text: "12 MPH",
451
- value: 5.36
452
- }
453
- ]
454
- },
455
-
456
- {
457
- /* maxEScooterDistance - the maximum distance in meters the user will ride
458
- * an E-scooter. Not actually an OTP parameter (maxWalkDistance doubles for
459
- * any non-transit mode except for car) but we store it separately
460
- * internally in order to allow different default values, options, etc.
461
- * Translated to 'maxWalkDistance' via the rewrite function.
462
- */
463
- name: "maxEScooterDistance",
464
- routingTypes: ["ITINERARY"],
465
- applicable: query =>
466
- query.mode && hasTransit(query.mode) && hasMicromobility(query.mode),
467
- default: 4828, // 3 mi.
468
- selector: "DROPDOWN",
469
- label: "Maximum E-scooter Distance",
470
- options: [
471
- {
472
- text: "1/4 mile",
473
- value: 402.3
474
- },
475
- {
476
- text: "1/2 mile",
477
- value: 804.7
478
- },
479
- {
480
- text: "3/4 mile",
481
- value: 1207
482
- },
483
- {
484
- text: "1 mile",
485
- value: 1609
486
- },
487
- {
488
- text: "2 miles",
489
- value: 3219
490
- },
491
- {
492
- text: "3 miles",
493
- value: 4828
494
- },
495
- {
496
- text: "5 miles",
497
- value: 8047
498
- },
499
- {
500
- text: "10 miles",
501
- value: 16093
502
- },
503
- {
504
- text: "20 miles",
505
- value: 32187
506
- },
507
- {
508
- text: "30 miles",
509
- value: 48280
510
- }
511
- ],
512
- itineraryRewrite: value => ({
513
- maxWalkDistance: value,
514
- // ensures that the value is repopulated when loaded from URL params
515
- maxEScooterDistance: value
516
- })
517
- },
518
-
519
- {
520
- /* bikeSpeed -- the user's bikeSpeed speed in m/s */
521
- name: "watts",
522
- routingTypes: ["ITINERARY", "PROFILE"],
523
- default: 250,
524
- selector: "DROPDOWN",
525
- label: "E-scooter Power",
526
- // this configuration should only be allowed for personal E-scooters as these
527
- // settings will be defined by the vehicle type of an E-scooter being rented
528
- applicable: query =>
529
- query.mode &&
530
- query.mode.indexOf("MICROMOBILITY") !== -1 &&
531
- query.mode.indexOf("MICROMOBILITY_RENT") === -1 &&
532
- query.mode.indexOf("SCOOTER") === -1,
533
- options: [
534
- {
535
- text: "Kid's hoverboard (6mph)",
536
- value: 125
537
- },
538
- {
539
- text: "Entry-level scooter (11mph)",
540
- value: 250
541
- },
542
- {
543
- text: "Robust E-scooter (18mph)",
544
- value: 500
545
- },
546
- {
547
- text: "Powerful E-scooter (24mph)",
548
- value: 1500
549
- }
550
- ],
551
- // rewrite a few other values to add some baseline assumptions about the
552
- // vehicle
553
- itineraryRewrite: value => {
554
- const watts = value;
555
- // the maximum cruising and downhill speed. Units in m/s
556
- let maximumMicromobilitySpeed;
557
- let weight;
558
- // see https://en.wikipedia.org/wiki/Human_body_weight#Average_weight_around_the_world
559
- // estimate is for an average North American human with clothes and stuff
560
- // units are in kg
561
- const TYPICAL_RIDER_WEIGHT = 90;
562
- switch (watts) {
563
- case 125:
564
- // exemplar: Swagtron Turbo 5 hoverboard (https://swagtron.com/product/recertified-swagtron-turbo-five-hoverboard-classic/)
565
- maximumMicromobilitySpeed = 2.8; // ~= 6mph
566
- weight = TYPICAL_RIDER_WEIGHT + 9;
567
- break;
568
- case 250:
569
- // exemplar: Xiaomi M365 (https://www.gearbest.com/skateboard/pp_596618.html)
570
- maximumMicromobilitySpeed = 5; // ~= 11.5mph
571
- weight = TYPICAL_RIDER_WEIGHT + 12.5;
572
- break;
573
- case 500:
574
- // exemplar: Razor EcoSmart Metro (https://www.amazon.com/Razor-EcoSmart-Metro-Electric-Scooter/dp/B002ZDAEIS?SubscriptionId=AKIAJMXJ2YFJTEDLQMUQ&tag=digitren08-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B002ZDAEIS&ascsubtag=15599460143449ocb)
575
- maximumMicromobilitySpeed = 8; // ~= 18mph
576
- weight = TYPICAL_RIDER_WEIGHT + 30;
577
- break;
578
- case 1000:
579
- // exemplar: Boosted Rev (https://boostedboards.com/vehicles/scooters/boosted-rev)
580
- maximumMicromobilitySpeed = 11; // ~= 24mph
581
- weight = TYPICAL_RIDER_WEIGHT + 21;
582
- break;
583
- default:
584
- break;
585
- }
586
- return { maximumMicromobilitySpeed, watts, weight };
587
- }
588
- },
589
-
590
- {
591
- /* ignoreRealtimeUpdates -- if true, do not use realtime updates in routing */
592
- name: "ignoreRealtimeUpdates",
593
- routingTypes: ["ITINERARY"],
594
- default: false
595
- },
596
-
597
- {
598
- /* companies -- tnc companies to query */
599
- name: "companies",
600
- routingTypes: ["ITINERARY"]
601
- },
602
-
603
- {
604
- /* wheelchair -- whether the user requires a wheelchair-accessible trip */
605
- name: "wheelchair",
606
- routingTypes: ["ITINERARY", "PROFILE"],
607
- default: false,
608
- selector: "CHECKBOX",
609
- label: "Prefer Wheelchair Accessible Routes",
610
- icon: <Wheelchair />,
611
- applicable: (query, config) => {
612
- if (!query.mode || !config.modes) return false;
613
- const configModes = (config.modes.accessModes || []).concat(
614
- config.modes.transitModes || []
615
- );
616
- return query.mode.split(",").some(mode => {
617
- const configMode = configModes.find(m => m.mode === mode);
618
- if (!configMode || !configMode.showWheelchairSetting) return false;
619
- if (
620
- configMode.company &&
621
- (!query.companies ||
622
- !query.companies.split(",").includes(configMode.company))
623
- )
624
- return false;
625
- return true;
626
- });
627
- }
628
- },
629
-
630
- {
631
- name: "bannedRoutes",
632
- routingTypes: ["ITINERARY"]
633
- },
634
- {
635
- name: "numItineraries",
636
- routingTypes: ["ITINERARY"],
637
- default: 3
638
- },
639
- {
640
- name: "intermediatePlaces",
641
- default: [],
642
- routingTypes: ["ITINERARY"],
643
- itineraryRewrite: places =>
644
- Array.isArray(places) && places.length > 0
645
- ? {
646
- intermediatePlaces: places.map(place => formatPlace(place))
647
- }
648
- : undefined
649
- },
650
- {
651
- // Time penalty in seconds the requester is willing to accept in order to
652
- // complete journey on preferred route. I.e., number of seconds that we are
653
- // willing to wait for the preferred route.
654
- name: "otherThanPreferredRoutesPenalty",
655
- default: 15 * 60, // 15 minutes
656
- routingTypes: ["ITINERARY"]
657
- },
658
- // Below are less commonly used query params included so that in case they are
659
- // passed in a query parameter they do not get filtered out from the ultimate
660
- // API request.
661
- {
662
- name: "preferredRoutes",
663
- routingTypes: ["ITINERARY"]
664
- },
665
- {
666
- name: "maxPreTransitTime",
667
- routingTypes: ["ITINERARY"]
668
- },
669
- {
670
- name: "waitReluctance",
671
- routingTypes: ["ITINERARY"]
672
- },
673
- {
674
- name: "driveDistanceReluctance",
675
- routingTypes: ["ITINERARY"]
676
- },
677
- {
678
- name: "driveTimeReluctance",
679
- routingTypes: ["ITINERARY"]
680
- },
681
- {
682
- name: "waitAtBeginningFactor",
683
- routingTypes: ["ITINERARY"]
684
- },
685
- {
686
- name: "bikeSwitchTime",
687
- routingTypes: ["ITINERARY"]
688
- },
689
- {
690
- name: "bikeSwitchCost",
691
- routingTypes: ["ITINERARY"]
692
- },
693
- {
694
- name: "minTransferTime",
695
- routingTypes: ["ITINERARY"]
696
- },
697
- {
698
- name: "preferredAgencies",
699
- routingTypes: ["ITINERARY"]
700
- },
701
- {
702
- name: "unpreferredRoutes",
703
- routingTypes: ["ITINERARY"]
704
- },
705
- {
706
- name: "unpreferredAgencies",
707
- routingTypes: ["ITINERARY"]
708
- },
709
- {
710
- name: "walkBoardCost",
711
- routingTypes: ["ITINERARY"]
712
- },
713
- {
714
- name: "bikeBoardCost",
715
- routingTypes: ["ITINERARY"]
716
- },
717
- {
718
- name: "whiteListedRoutes",
719
- routingTypes: ["ITINERARY"]
720
- },
721
- {
722
- name: "bannedAgencies",
723
- routingTypes: ["ITINERARY"]
724
- },
725
- {
726
- name: "whiteListedAgencies",
727
- routingTypes: ["ITINERARY"]
728
- },
729
- {
730
- name: "bannedTrips",
731
- routingTypes: ["ITINERARY"]
732
- },
733
- {
734
- name: "bannedStops",
735
- routingTypes: ["ITINERARY"]
736
- },
737
- {
738
- name: "bannedStopsHard",
739
- routingTypes: ["ITINERARY"]
740
- },
741
- {
742
- name: "transferPenalty",
743
- routingTypes: ["ITINERARY"]
744
- },
745
- {
746
- name: "nonpreferredTransferPenalty",
747
- routingTypes: ["ITINERARY"]
748
- },
749
- {
750
- name: "maxTransfers",
751
- routingTypes: ["ITINERARY"]
752
- },
753
- {
754
- name: "batch",
755
- routingTypes: ["ITINERARY"]
756
- },
757
- {
758
- name: "startTransitStopId",
759
- routingTypes: ["ITINERARY"]
760
- },
761
- {
762
- name: "startTransitTripId",
763
- routingTypes: ["ITINERARY"]
764
- },
765
- {
766
- name: "clampInitialWait",
767
- routingTypes: ["ITINERARY"]
768
- },
769
- {
770
- name: "reverseOptimizeOnTheFly",
771
- routingTypes: ["ITINERARY"]
772
- },
773
- {
774
- name: "boardSlack",
775
- routingTypes: ["ITINERARY"]
776
- },
777
- {
778
- name: "alightSlack",
779
- routingTypes: ["ITINERARY"]
780
- },
781
- {
782
- name: "locale",
783
- routingTypes: ["ITINERARY"]
784
- },
785
- {
786
- name: "disableRemainingWeightHeuristic",
787
- routingTypes: ["ITINERARY"]
788
- },
789
- {
790
- name: "flexFlagStopBufferSize",
791
- routingTypes: ["ITINERARY"]
792
- },
793
- {
794
- name: "flexUseReservationServices",
795
- routingTypes: ["ITINERARY"]
796
- },
797
- {
798
- name: "flexUseEligibilityServices",
799
- routingTypes: ["ITINERARY"]
800
- },
801
- {
802
- name: "flexIgnoreDrtAdvanceBookMin",
803
- routingTypes: ["ITINERARY"]
804
- },
805
- {
806
- name: "maxHours",
807
- routingTypes: ["ITINERARY"]
808
- },
809
- {
810
- name: "useRequestedDateTimeInMaxHours",
811
- routingTypes: ["ITINERARY"]
812
- },
813
- {
814
- name: "disableAlertFiltering",
815
- routingTypes: ["ITINERARY"]
816
- },
817
- {
818
- name: "geoidElevation",
819
- routingTypes: ["ITINERARY"]
820
- },
821
- {
822
- name: "invalidDateStrategy",
823
- routingTypes: ["ITINERARY"]
824
- },
825
- {
826
- name: "minTransitDistance",
827
- routingTypes: ["ITINERARY"]
828
- },
829
- {
830
- name: "searchTimeout",
831
- routingTypes: ["ITINERARY"]
832
- },
833
- {
834
- name: "pathComparator",
835
- routingTypes: ["ITINERARY"]
836
- },
837
- {
838
- name: "onlyTransitTrips",
839
- routingTypes: ["ITINERARY"]
840
- },
841
- {
842
- name: "minimumMicromobilitySpeed",
843
- routingTypes: ["ITINERARY"]
844
- }
845
- ];
846
- // Iterate over stored settings and update query param defaults.
847
- // FIXME: this does not get updated if the user defaults are cleared
848
- queryParams.forEach(param => {
849
- if (param.name in storedSettings) {
850
- param.default = storedSettings[param.name];
851
- param.userDefaultOverride = true;
852
- }
853
- });
854
-
855
- export default queryParams;
856
-
857
- /**
858
- * You can customize the queryParams labels and options, and labels and values for each option.
859
- * @param customizations The optional customizations to apply: an object whose fields
860
- * correspond to the items in queryParams with the corresponding name,
861
- * the value for those fields being an object which fields (label, options...)
862
- * will override the originals.
863
- * Example:
864
- * {
865
- * // Matches the name param
866
- * maxWalkDistance: {
867
- * // Any fields that should be overridden go here
868
- * options: [
869
- * // ...new options
870
- * ],
871
- * default: 500,
872
- * label: "max walk dist"
873
- * }
874
- * }
875
- * @returns A copy of the default queryParams that has the given customizations applied.
876
- * If no customizations parameter is provided, returns the queryParams object itself.
877
- */
878
- export function getCustomQueryParams(customizations) {
879
- if (!customizations) return queryParams;
880
-
881
- const clonedParams = cloneDeep(queryParams);
882
- Object.keys(customizations).forEach(k => {
883
- // Merge fields into the cloned object
884
- const paramIndex = clonedParams.findIndex(param => param.name === k);
885
- if (paramIndex !== -1) {
886
- clonedParams[paramIndex] = {
887
- ...clonedParams[paramIndex],
888
- ...customizations[k]
889
- };
890
- }
891
- });
892
- return clonedParams;
893
- }