@finos/legend-query-builder 4.16.20 → 4.16.22

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 (59) hide show
  1. package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.d.ts +23 -1
  2. package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.d.ts.map +1 -1
  3. package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.js +16 -2
  4. package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.js.map +1 -1
  5. package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.js +1 -1
  6. package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.js.map +1 -1
  7. package/lib/components/filter/QueryBuilderFilterPanel.js +1 -1
  8. package/lib/components/filter/QueryBuilderFilterPanel.js.map +1 -1
  9. package/lib/components/shared/BasicValueSpecificationEditor.d.ts +162 -4
  10. package/lib/components/shared/BasicValueSpecificationEditor.d.ts.map +1 -1
  11. package/lib/components/shared/BasicValueSpecificationEditor.js +253 -172
  12. package/lib/components/shared/BasicValueSpecificationEditor.js.map +1 -1
  13. package/lib/components/shared/CustomDatePicker.d.ts +8 -55
  14. package/lib/components/shared/CustomDatePicker.d.ts.map +1 -1
  15. package/lib/components/shared/CustomDatePicker.js +33 -417
  16. package/lib/components/shared/CustomDatePicker.js.map +1 -1
  17. package/lib/components/shared/CustomDatePickerHelper.d.ts +145 -0
  18. package/lib/components/shared/CustomDatePickerHelper.d.ts.map +1 -0
  19. package/lib/components/shared/CustomDatePickerHelper.js +517 -0
  20. package/lib/components/shared/CustomDatePickerHelper.js.map +1 -0
  21. package/lib/components/shared/QueryBuilderVariableSelector.js +1 -1
  22. package/lib/components/shared/QueryBuilderVariableSelector.js.map +1 -1
  23. package/lib/components/shared/V1_BasicValueSpecificationEditor.d.ts +38 -0
  24. package/lib/components/shared/V1_BasicValueSpecificationEditor.d.ts.map +1 -0
  25. package/lib/components/shared/V1_BasicValueSpecificationEditor.js +166 -0
  26. package/lib/components/shared/V1_BasicValueSpecificationEditor.js.map +1 -0
  27. package/lib/index.css +2 -2
  28. package/lib/index.css.map +1 -1
  29. package/lib/index.d.ts +4 -0
  30. package/lib/index.d.ts.map +1 -1
  31. package/lib/index.js +4 -0
  32. package/lib/index.js.map +1 -1
  33. package/lib/package.json +1 -1
  34. package/lib/stores/shared/V1_ValueSpecificationEditorHelper.d.ts +23 -0
  35. package/lib/stores/shared/V1_ValueSpecificationEditorHelper.d.ts.map +1 -0
  36. package/lib/stores/shared/V1_ValueSpecificationEditorHelper.js +83 -0
  37. package/lib/stores/shared/V1_ValueSpecificationEditorHelper.js.map +1 -0
  38. package/lib/stores/shared/V1_ValueSpecificationModifierHelper.d.ts +20 -0
  39. package/lib/stores/shared/V1_ValueSpecificationModifierHelper.d.ts.map +1 -0
  40. package/lib/stores/shared/V1_ValueSpecificationModifierHelper.js +38 -0
  41. package/lib/stores/shared/V1_ValueSpecificationModifierHelper.js.map +1 -0
  42. package/lib/stores/shared/ValueSpecificationEditorHelper.d.ts +4 -1
  43. package/lib/stores/shared/ValueSpecificationEditorHelper.d.ts.map +1 -1
  44. package/lib/stores/shared/ValueSpecificationEditorHelper.js +23 -2
  45. package/lib/stores/shared/ValueSpecificationEditorHelper.js.map +1 -1
  46. package/package.json +10 -10
  47. package/src/components/__test-utils__/QueryBuilderComponentTestUtils.tsx +103 -12
  48. package/src/components/fetch-structure/QueryBuilderPostFilterPanel.tsx +1 -1
  49. package/src/components/filter/QueryBuilderFilterPanel.tsx +1 -1
  50. package/src/components/shared/BasicValueSpecificationEditor.tsx +1477 -1088
  51. package/src/components/shared/CustomDatePicker.tsx +146 -905
  52. package/src/components/shared/CustomDatePickerHelper.ts +984 -0
  53. package/src/components/shared/QueryBuilderVariableSelector.tsx +1 -1
  54. package/src/components/shared/V1_BasicValueSpecificationEditor.tsx +409 -0
  55. package/src/index.ts +7 -0
  56. package/src/stores/shared/V1_ValueSpecificationEditorHelper.ts +131 -0
  57. package/src/stores/shared/V1_ValueSpecificationModifierHelper.ts +76 -0
  58. package/src/stores/shared/ValueSpecificationEditorHelper.ts +71 -2
  59. package/tsconfig.json +4 -0
@@ -0,0 +1,984 @@
1
+ /**
2
+ * Copyright (c) 2020-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import {
18
+ type Enum,
19
+ type ObserverContext,
20
+ type PureModel,
21
+ type V1_CDate,
22
+ type V1_CStrictTime,
23
+ type V1_CString,
24
+ EnumValueExplicitReference,
25
+ EnumValueInstanceValue,
26
+ GenericType,
27
+ GenericTypeExplicitReference,
28
+ matchFunctionName,
29
+ PRIMITIVE_TYPE,
30
+ PrimitiveInstanceValue,
31
+ PrimitiveType,
32
+ SimpleFunctionExpression,
33
+ V1_AppliedFunction,
34
+ V1_AppliedProperty,
35
+ V1_CDateTime,
36
+ V1_CInteger,
37
+ V1_CLatestDate,
38
+ V1_CStrictDate,
39
+ } from '@finos/legend-graph';
40
+ import {
41
+ assertErrorThrown,
42
+ guaranteeNonNullable,
43
+ guaranteeType,
44
+ UnsupportedOperationError,
45
+ } from '@finos/legend-shared';
46
+ import {
47
+ buildPrimitiveInstanceValue,
48
+ createSupportedFunctionExpression,
49
+ } from '../../stores/shared/ValueSpecificationEditorHelper.js';
50
+ import {
51
+ functionExpression_addParameterValue,
52
+ instanceValue_setValues,
53
+ valueSpecification_setGenericType,
54
+ } from '../../stores/shared/ValueSpecificationModifierHelper.js';
55
+ import {
56
+ QUERY_BUILDER_PURE_PATH,
57
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS,
58
+ } from '../../graph/QueryBuilderMetaModelConst.js';
59
+ import {
60
+ type ApplicationStore,
61
+ type LegendApplicationConfig,
62
+ type LegendApplicationPlugin,
63
+ type LegendApplicationPluginManager,
64
+ } from '@finos/legend-application';
65
+ import {
66
+ _elementPtr,
67
+ _function,
68
+ _primitiveValue,
69
+ _property,
70
+ } from '@finos/legend-data-cube';
71
+
72
+ export type CustomDatePickerValueSpecification =
73
+ | SimpleFunctionExpression
74
+ | PrimitiveInstanceValue
75
+ | V1_AppliedFunction
76
+ | V1_CDate
77
+ | V1_CStrictTime
78
+ | V1_CString;
79
+
80
+ export type CustomDatePickerUpdateValueSpecification<T> = (
81
+ _valueSpecification: T | undefined,
82
+ value:
83
+ | string
84
+ | CustomDateOption
85
+ | CustomFirstDayOfOption
86
+ | CustomPreviousDayOfWeekOption
87
+ | DatePickerOption,
88
+ options?: {
89
+ primitiveTypeEnum?: PRIMITIVE_TYPE;
90
+ },
91
+ ) => void;
92
+
93
+ export enum CUSTOM_DATE_PICKER_OPTION {
94
+ ABSOLUTE_DATE = 'Absolute Date',
95
+ ABSOLUTE_TIME = 'Absolute Time',
96
+ TODAY = 'Today',
97
+ NOW = 'Now',
98
+ YESTERDAY = 'Yesterday',
99
+ ONE_YEAR_AGO = 'One Year Ago',
100
+ ONE_MONTH_AGO = 'One Month Ago',
101
+ ONE_WEEK_AGO = 'One Week Ago',
102
+ CUSTOM_DATE = 'Custom Date',
103
+ PREVIOUS_DAY_OF_WEEK = 'Previous ... of Week',
104
+ FIRST_DAY_OF = 'First day of...',
105
+ LATEST_DATE = 'Latest Date',
106
+ }
107
+
108
+ export enum CUSTOM_DATE_OPTION_UNIT {
109
+ DAYS = 'Day(s)',
110
+ WEEKS = 'Week(s)',
111
+ MONTHS = 'Month(s)',
112
+ YEARS = 'Year(s)',
113
+ }
114
+
115
+ export enum CUSTOM_DATE_FIRST_DAY_OF_UNIT {
116
+ WEEK = 'Week',
117
+ MONTH = 'Month',
118
+ QUARTER = 'Quarter',
119
+ YEAR = 'Year',
120
+ }
121
+
122
+ export enum CUSTOM_DATE_DAY_OF_WEEK {
123
+ MONDAY = 'Monday',
124
+ TUESDAY = 'Tuesday',
125
+ WENDNESDAY = 'Wednesday',
126
+ THURSDAY = 'Thursday',
127
+ FRIDAY = 'Friday',
128
+ SATURDAY = 'Saturday',
129
+ SUNDAY = 'Sunday',
130
+ }
131
+
132
+ export enum CUSTOM_DATE_OPTION_DIRECTION {
133
+ BEFORE = 'Before',
134
+ AFTER = 'After',
135
+ }
136
+
137
+ export enum CUSTOM_DATE_OPTION_REFERENCE_MOMENT {
138
+ TODAY = 'Today',
139
+ NOW = 'Now',
140
+ FIRST_DAY_OF_THIS_YEAR = 'Start of Year',
141
+ FIRST_DAY_OF_QUARTER = 'Start of Quarter',
142
+ FIRST_DAY_OF_MONTH = 'Start of Month',
143
+ FIRST_DAY_OF_WEEK = 'Start of Week',
144
+ PERVIOUS_DAY_OF_WEEK = 'Previous Day of Week',
145
+ }
146
+
147
+ /**
148
+ * DatePickerOption is the base class being used to display and generate the corresponding pure date function.
149
+ */
150
+ export class DatePickerOption {
151
+ /**
152
+ * label is the text that shows up in the valueSpecification box.
153
+ */
154
+ label: string;
155
+ /**
156
+ * value is the selected date option in date-dropdown.
157
+ */
158
+ value: string;
159
+
160
+ constructor(label: string, value: string) {
161
+ this.label = label;
162
+ this.value = value;
163
+ }
164
+ }
165
+
166
+ export class CustomDateOption extends DatePickerOption {
167
+ /**
168
+ * duration is the amount of time span that will be adjusted.
169
+ */
170
+ duration: number;
171
+ /**
172
+ * unit represents the time duration unit, e.g. year, week, etc.
173
+ */
174
+ unit: CUSTOM_DATE_OPTION_UNIT | undefined;
175
+ /**
176
+ * direction means the direction in which time adjustment will go to.
177
+ */
178
+ direction: CUSTOM_DATE_OPTION_DIRECTION | undefined;
179
+ /**
180
+ * referenceMoment is the date which adjustment starts from.
181
+ */
182
+ referenceMoment: CUSTOM_DATE_OPTION_REFERENCE_MOMENT | undefined;
183
+
184
+ constructor(
185
+ label: string,
186
+ value: string,
187
+ duration: number,
188
+ unit: CUSTOM_DATE_OPTION_UNIT | undefined,
189
+ direction: CUSTOM_DATE_OPTION_DIRECTION | undefined,
190
+ referenceMoment: CUSTOM_DATE_OPTION_REFERENCE_MOMENT | undefined,
191
+ ) {
192
+ super(label, value);
193
+ this.duration = duration;
194
+ this.unit = unit;
195
+ this.direction = direction;
196
+ this.referenceMoment = referenceMoment;
197
+ }
198
+
199
+ generateDisplayLabel(): string {
200
+ return [
201
+ this.duration,
202
+ this.unit,
203
+ this.direction,
204
+ this.referenceMoment,
205
+ ].join(' ');
206
+ }
207
+
208
+ updateLabel(): void {
209
+ this.label = this.generateDisplayLabel();
210
+ }
211
+ }
212
+
213
+ export class CustomFirstDayOfOption extends DatePickerOption {
214
+ /**
215
+ * unit: time unit, e.g. Week, Month, etc.
216
+ */
217
+ unit: CUSTOM_DATE_FIRST_DAY_OF_UNIT | undefined;
218
+
219
+ constructor(label: string, unit: CUSTOM_DATE_FIRST_DAY_OF_UNIT | undefined) {
220
+ super(label, CUSTOM_DATE_PICKER_OPTION.FIRST_DAY_OF);
221
+ this.unit = unit;
222
+ }
223
+ }
224
+
225
+ export class CustomPreviousDayOfWeekOption extends DatePickerOption {
226
+ /**
227
+ * day: which day in the week will be selected.
228
+ */
229
+ day: CUSTOM_DATE_DAY_OF_WEEK;
230
+
231
+ constructor(label: string, day: CUSTOM_DATE_DAY_OF_WEEK) {
232
+ super(label, CUSTOM_DATE_PICKER_OPTION.PREVIOUS_DAY_OF_WEEK);
233
+ this.day = day;
234
+ }
235
+ }
236
+
237
+ export const reservedCustomDateOptions: CustomDateOption[] = [
238
+ new CustomDateOption(
239
+ 'Yesterday',
240
+ CUSTOM_DATE_PICKER_OPTION.YESTERDAY,
241
+ 1,
242
+ CUSTOM_DATE_OPTION_UNIT.DAYS,
243
+ CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
244
+ CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
245
+ ),
246
+ new CustomDateOption(
247
+ 'One Week Ago',
248
+ CUSTOM_DATE_PICKER_OPTION.ONE_WEEK_AGO,
249
+ 1,
250
+ CUSTOM_DATE_OPTION_UNIT.WEEKS,
251
+ CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
252
+ CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
253
+ ),
254
+ new CustomDateOption(
255
+ 'One Month Ago',
256
+ CUSTOM_DATE_PICKER_OPTION.ONE_MONTH_AGO,
257
+ 1,
258
+ CUSTOM_DATE_OPTION_UNIT.MONTHS,
259
+ CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
260
+ CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
261
+ ),
262
+ new CustomDateOption(
263
+ 'One Year Ago',
264
+ CUSTOM_DATE_PICKER_OPTION.ONE_YEAR_AGO,
265
+ 1,
266
+ CUSTOM_DATE_OPTION_UNIT.YEARS,
267
+ CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
268
+ CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
269
+ ),
270
+ ];
271
+
272
+ const getSupportedDateFunctionFullPath = (
273
+ functionName: string,
274
+ ): string | undefined =>
275
+ Object.values(QUERY_BUILDER_SUPPORTED_FUNCTIONS).find((_func) =>
276
+ matchFunctionName(functionName, _func),
277
+ );
278
+
279
+ /**
280
+ * Generate pure date functions based on the DatePickerOption.
281
+ */
282
+ export const buildPureDateFunctionExpression = (
283
+ datePickerOption: DatePickerOption,
284
+ graph: PureModel,
285
+ observerContext: ObserverContext,
286
+ ): SimpleFunctionExpression => {
287
+ if (datePickerOption instanceof CustomPreviousDayOfWeekOption) {
288
+ const previousFridaySFE = new SimpleFunctionExpression(
289
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.PREVIOUS_DAY_OF_WEEK,
290
+ );
291
+ valueSpecification_setGenericType(
292
+ previousFridaySFE,
293
+ GenericTypeExplicitReference.create(new GenericType(PrimitiveType.DATE)),
294
+ );
295
+ const dayOfWeekEnumIntanceValue = new EnumValueInstanceValue(
296
+ GenericTypeExplicitReference.create(
297
+ new GenericType(graph.getType(QUERY_BUILDER_PURE_PATH.DAY_OF_WEEK)),
298
+ ),
299
+ );
300
+ instanceValue_setValues(
301
+ dayOfWeekEnumIntanceValue,
302
+ [
303
+ ...dayOfWeekEnumIntanceValue.values,
304
+ EnumValueExplicitReference.create(
305
+ guaranteeNonNullable(
306
+ graph
307
+ .getEnumeration(QUERY_BUILDER_PURE_PATH.DAY_OF_WEEK)
308
+ .values.filter((e) => e.name === datePickerOption.day)[0],
309
+ ),
310
+ ),
311
+ ],
312
+ observerContext,
313
+ );
314
+ functionExpression_addParameterValue(
315
+ previousFridaySFE,
316
+ dayOfWeekEnumIntanceValue,
317
+ observerContext,
318
+ );
319
+ return previousFridaySFE;
320
+ } else if (datePickerOption instanceof CustomFirstDayOfOption) {
321
+ switch (datePickerOption.unit) {
322
+ case CUSTOM_DATE_FIRST_DAY_OF_UNIT.YEAR: {
323
+ const firstDayOfThisYearSFE = new SimpleFunctionExpression(
324
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_YEAR,
325
+ );
326
+ valueSpecification_setGenericType(
327
+ firstDayOfThisYearSFE,
328
+ GenericTypeExplicitReference.create(
329
+ new GenericType(PrimitiveType.DATE),
330
+ ),
331
+ );
332
+ return firstDayOfThisYearSFE;
333
+ }
334
+ case CUSTOM_DATE_FIRST_DAY_OF_UNIT.QUARTER: {
335
+ const firstDayOfQuarterSFE = new SimpleFunctionExpression(
336
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER,
337
+ );
338
+ valueSpecification_setGenericType(
339
+ firstDayOfQuarterSFE,
340
+ GenericTypeExplicitReference.create(
341
+ new GenericType(PrimitiveType.STRICTDATE),
342
+ ),
343
+ );
344
+ return firstDayOfQuarterSFE;
345
+ }
346
+ case CUSTOM_DATE_FIRST_DAY_OF_UNIT.MONTH: {
347
+ const firstDayOfMonthSFE = new SimpleFunctionExpression(
348
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_MONTH,
349
+ );
350
+ valueSpecification_setGenericType(
351
+ firstDayOfMonthSFE,
352
+ GenericTypeExplicitReference.create(
353
+ new GenericType(PrimitiveType.DATE),
354
+ ),
355
+ );
356
+ return firstDayOfMonthSFE;
357
+ }
358
+ case CUSTOM_DATE_FIRST_DAY_OF_UNIT.WEEK: {
359
+ const firstDayOfWeekSFE = new SimpleFunctionExpression(
360
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK,
361
+ );
362
+ valueSpecification_setGenericType(
363
+ firstDayOfWeekSFE,
364
+ GenericTypeExplicitReference.create(
365
+ new GenericType(PrimitiveType.DATE),
366
+ ),
367
+ );
368
+ return firstDayOfWeekSFE;
369
+ }
370
+ default:
371
+ throw new UnsupportedOperationError(
372
+ `Can't build expression for 'First Day Of ...' date picker option for unit '${datePickerOption.unit}'`,
373
+ );
374
+ }
375
+ } else {
376
+ switch (datePickerOption.value) {
377
+ case CUSTOM_DATE_PICKER_OPTION.TODAY: {
378
+ return createSupportedFunctionExpression(
379
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.TODAY,
380
+ PrimitiveType.STRICTDATE,
381
+ );
382
+ }
383
+ case CUSTOM_DATE_PICKER_OPTION.NOW: {
384
+ return createSupportedFunctionExpression(
385
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.NOW,
386
+ PrimitiveType.DATETIME,
387
+ );
388
+ }
389
+ case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_THIS_YEAR: {
390
+ const firstDayOfYearSFE = new SimpleFunctionExpression(
391
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_YEAR,
392
+ );
393
+ valueSpecification_setGenericType(
394
+ firstDayOfYearSFE,
395
+ GenericTypeExplicitReference.create(
396
+ new GenericType(PrimitiveType.DATE),
397
+ ),
398
+ );
399
+ return firstDayOfYearSFE;
400
+ }
401
+ case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_QUARTER: {
402
+ const firstDayOfQuarterSFE = new SimpleFunctionExpression(
403
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER,
404
+ );
405
+ valueSpecification_setGenericType(
406
+ firstDayOfQuarterSFE,
407
+ GenericTypeExplicitReference.create(
408
+ new GenericType(PrimitiveType.STRICTDATE),
409
+ ),
410
+ );
411
+ return firstDayOfQuarterSFE;
412
+ }
413
+ case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_MONTH: {
414
+ const firstDayOfMonthSFE = new SimpleFunctionExpression(
415
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_MONTH,
416
+ );
417
+ valueSpecification_setGenericType(
418
+ firstDayOfMonthSFE,
419
+ GenericTypeExplicitReference.create(
420
+ new GenericType(PrimitiveType.DATE),
421
+ ),
422
+ );
423
+ return firstDayOfMonthSFE;
424
+ }
425
+ case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_WEEK: {
426
+ const firstDayOfWeekSFE = new SimpleFunctionExpression(
427
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK,
428
+ );
429
+ valueSpecification_setGenericType(
430
+ firstDayOfWeekSFE,
431
+ GenericTypeExplicitReference.create(
432
+ new GenericType(PrimitiveType.DATE),
433
+ ),
434
+ );
435
+ return firstDayOfWeekSFE;
436
+ }
437
+ default:
438
+ throw new UnsupportedOperationError(
439
+ `Can't build expression for date picker option '${datePickerOption.value}'`,
440
+ );
441
+ }
442
+ }
443
+ };
444
+
445
+ /**
446
+ * Generate pure date functions based on the DatePickerOption (for V1 protocol).
447
+ */
448
+ export const buildV1PureDateFunctionExpression = (
449
+ datePickerOption: DatePickerOption,
450
+ ): V1_AppliedFunction => {
451
+ if (datePickerOption instanceof CustomPreviousDayOfWeekOption) {
452
+ const dayOfWeekProperty = _property(datePickerOption.day, [
453
+ _elementPtr(QUERY_BUILDER_PURE_PATH.DAY_OF_WEEK),
454
+ ]);
455
+ const previousDayAF = _function(
456
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.PREVIOUS_DAY_OF_WEEK,
457
+ [dayOfWeekProperty],
458
+ { useFullFunctionPath: true },
459
+ );
460
+ return previousDayAF;
461
+ } else if (datePickerOption instanceof CustomFirstDayOfOption) {
462
+ switch (datePickerOption.unit) {
463
+ case CUSTOM_DATE_FIRST_DAY_OF_UNIT.YEAR: {
464
+ const firstDayOfThisYearAF = _function(
465
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_YEAR,
466
+ [],
467
+ { useFullFunctionPath: true },
468
+ );
469
+ return firstDayOfThisYearAF;
470
+ }
471
+ case CUSTOM_DATE_FIRST_DAY_OF_UNIT.QUARTER: {
472
+ const firstDayOfQuarterAF = _function(
473
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER,
474
+ [],
475
+ { useFullFunctionPath: true },
476
+ );
477
+ return firstDayOfQuarterAF;
478
+ }
479
+ case CUSTOM_DATE_FIRST_DAY_OF_UNIT.MONTH: {
480
+ const firstDayOfMonthAF = _function(
481
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_MONTH,
482
+ [],
483
+ { useFullFunctionPath: true },
484
+ );
485
+ return firstDayOfMonthAF;
486
+ }
487
+ case CUSTOM_DATE_FIRST_DAY_OF_UNIT.WEEK: {
488
+ const firstDayOfWeekAF = _function(
489
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK,
490
+ [],
491
+ { useFullFunctionPath: true },
492
+ );
493
+ return firstDayOfWeekAF;
494
+ }
495
+ default:
496
+ throw new UnsupportedOperationError(
497
+ `Can't build expression for 'First Day Of ...' date picker option for unit '${datePickerOption.unit}'`,
498
+ );
499
+ }
500
+ } else {
501
+ switch (datePickerOption.value) {
502
+ case CUSTOM_DATE_PICKER_OPTION.TODAY: {
503
+ return _function(QUERY_BUILDER_SUPPORTED_FUNCTIONS.TODAY, [], {
504
+ useFullFunctionPath: true,
505
+ });
506
+ }
507
+ case CUSTOM_DATE_PICKER_OPTION.NOW: {
508
+ return _function(QUERY_BUILDER_SUPPORTED_FUNCTIONS.NOW, [], {
509
+ useFullFunctionPath: true,
510
+ });
511
+ }
512
+ case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_THIS_YEAR: {
513
+ return _function(
514
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_YEAR,
515
+ [],
516
+ { useFullFunctionPath: true },
517
+ );
518
+ }
519
+ case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_QUARTER: {
520
+ return _function(
521
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER,
522
+ [],
523
+ { useFullFunctionPath: true },
524
+ );
525
+ }
526
+ case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_MONTH: {
527
+ return _function(
528
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_MONTH,
529
+ [],
530
+ { useFullFunctionPath: true },
531
+ );
532
+ }
533
+ case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_WEEK: {
534
+ return _function(
535
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK,
536
+ [],
537
+ { useFullFunctionPath: true },
538
+ );
539
+ }
540
+ default:
541
+ throw new UnsupportedOperationError(
542
+ `Can't build expression for date picker option '${datePickerOption.value}'`,
543
+ );
544
+ }
545
+ }
546
+ };
547
+
548
+ /**
549
+ * Generate the enum value of type Pure Enum, DURATION_UNIT, based on the input string.
550
+ */
551
+ const buildPureDurationEnumValue = (
552
+ unitString: string,
553
+ graph: PureModel,
554
+ ): Enum => {
555
+ const durationUnitEnum = graph.getEnumeration(
556
+ QUERY_BUILDER_PURE_PATH.DURATION_UNIT,
557
+ );
558
+ const targetPureDurationEnumValue = durationUnitEnum.values.filter(
559
+ (e) =>
560
+ e.name ===
561
+ Object.keys(CUSTOM_DATE_OPTION_UNIT).filter(
562
+ (key) =>
563
+ CUSTOM_DATE_OPTION_UNIT[
564
+ key as keyof typeof CUSTOM_DATE_OPTION_UNIT
565
+ ] === unitString,
566
+ )[0],
567
+ )[0];
568
+ return (
569
+ targetPureDurationEnumValue ??
570
+ guaranteeNonNullable(durationUnitEnum.values[0])
571
+ );
572
+ };
573
+
574
+ /**
575
+ * Generate the pure date adjust() function based on the CustomDateOption.
576
+ */
577
+ export const buildPureAdjustDateFunction = (
578
+ customDateOption: CustomDateOption,
579
+ graph: PureModel,
580
+ observerContext: ObserverContext,
581
+ ): SimpleFunctionExpression => {
582
+ const dateAdjustSimpleFunctionExpression = new SimpleFunctionExpression(
583
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.ADJUST,
584
+ );
585
+ functionExpression_addParameterValue(
586
+ dateAdjustSimpleFunctionExpression,
587
+ buildPureDateFunctionExpression(
588
+ new DatePickerOption(
589
+ guaranteeNonNullable(customDateOption.referenceMoment),
590
+ guaranteeNonNullable(customDateOption.referenceMoment),
591
+ ),
592
+ graph,
593
+ observerContext,
594
+ ),
595
+ observerContext,
596
+ );
597
+ if (customDateOption.direction === CUSTOM_DATE_OPTION_DIRECTION.BEFORE) {
598
+ const minusFunc = new SimpleFunctionExpression(
599
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.MINUS,
600
+ );
601
+ functionExpression_addParameterValue(
602
+ minusFunc,
603
+ buildPrimitiveInstanceValue(
604
+ graph,
605
+ PRIMITIVE_TYPE.INTEGER,
606
+ customDateOption.duration,
607
+ observerContext,
608
+ ),
609
+ observerContext,
610
+ );
611
+ functionExpression_addParameterValue(
612
+ dateAdjustSimpleFunctionExpression,
613
+ minusFunc,
614
+ observerContext,
615
+ );
616
+ } else {
617
+ functionExpression_addParameterValue(
618
+ dateAdjustSimpleFunctionExpression,
619
+ buildPrimitiveInstanceValue(
620
+ graph,
621
+ PRIMITIVE_TYPE.INTEGER,
622
+ customDateOption.duration,
623
+ observerContext,
624
+ ),
625
+ observerContext,
626
+ );
627
+ }
628
+ const durationUnitEnumIntanceValue = new EnumValueInstanceValue(
629
+ GenericTypeExplicitReference.create(
630
+ new GenericType(graph.getType(QUERY_BUILDER_PURE_PATH.DURATION_UNIT)),
631
+ ),
632
+ );
633
+ instanceValue_setValues(
634
+ durationUnitEnumIntanceValue,
635
+ [
636
+ ...durationUnitEnumIntanceValue.values,
637
+ EnumValueExplicitReference.create(
638
+ guaranteeNonNullable(
639
+ buildPureDurationEnumValue(
640
+ guaranteeNonNullable(customDateOption.unit),
641
+ graph,
642
+ ),
643
+ ),
644
+ ),
645
+ ],
646
+ observerContext,
647
+ );
648
+ functionExpression_addParameterValue(
649
+ dateAdjustSimpleFunctionExpression,
650
+ durationUnitEnumIntanceValue,
651
+ observerContext,
652
+ );
653
+ valueSpecification_setGenericType(
654
+ dateAdjustSimpleFunctionExpression,
655
+ GenericTypeExplicitReference.create(new GenericType(PrimitiveType.DATE)),
656
+ );
657
+ return dateAdjustSimpleFunctionExpression;
658
+ };
659
+
660
+ /**
661
+ * Generate the pure date adjust() function based on the CustomDateOption (for V1 protocol).
662
+ */
663
+ export const buildV1PureAdjustDateFunction = (
664
+ customDateOption: CustomDateOption,
665
+ ): V1_AppliedFunction => {
666
+ // Starting point function
667
+ const startingPointAF = buildV1PureDateFunctionExpression(
668
+ new DatePickerOption(
669
+ guaranteeNonNullable(customDateOption.referenceMoment),
670
+ guaranteeNonNullable(customDateOption.referenceMoment),
671
+ ),
672
+ );
673
+ // Direction and duration
674
+ const directionDuration =
675
+ customDateOption.direction === CUSTOM_DATE_OPTION_DIRECTION.BEFORE
676
+ ? _function(
677
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.MINUS,
678
+ [_primitiveValue(PRIMITIVE_TYPE.INTEGER, customDateOption.duration)],
679
+ { useFullFunctionPath: true },
680
+ )
681
+ : _primitiveValue(PRIMITIVE_TYPE.INTEGER, customDateOption.duration);
682
+ // Unit property
683
+ const durationUnitProperty = _property(
684
+ guaranteeNonNullable(customDateOption.unit),
685
+ [_elementPtr(QUERY_BUILDER_PURE_PATH.DURATION_UNIT)],
686
+ );
687
+
688
+ return _function(
689
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.ADJUST,
690
+ [startingPointAF, directionDuration, durationUnitProperty],
691
+ { useFullFunctionPath: true },
692
+ );
693
+ };
694
+
695
+ /**
696
+ * Generate the value of CustomDateOption.duration from the pure date adjust() function.
697
+ */
698
+ const buildCustomDateOptionDurationValue = (
699
+ pureDateAdjustFunction: SimpleFunctionExpression | V1_AppliedFunction,
700
+ ): number => {
701
+ if (pureDateAdjustFunction instanceof SimpleFunctionExpression) {
702
+ const durationParam = pureDateAdjustFunction.parametersValues[1];
703
+ return durationParam instanceof PrimitiveInstanceValue
704
+ ? (durationParam.values[0] as number)
705
+ : durationParam instanceof SimpleFunctionExpression &&
706
+ matchFunctionName(
707
+ durationParam.functionName,
708
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.MINUS,
709
+ )
710
+ ? durationParam.parametersValues[0] instanceof PrimitiveInstanceValue
711
+ ? (durationParam.parametersValues[0].values[0] as number)
712
+ : 0
713
+ : 0;
714
+ } else {
715
+ const durationParam = pureDateAdjustFunction.parameters[1];
716
+ return durationParam instanceof V1_CInteger
717
+ ? durationParam.value
718
+ : durationParam instanceof V1_AppliedFunction &&
719
+ matchFunctionName(
720
+ durationParam.function,
721
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.MINUS,
722
+ )
723
+ ? durationParam.parameters[0] instanceof V1_CInteger
724
+ ? durationParam.parameters[0].value
725
+ : 0
726
+ : 0;
727
+ }
728
+ };
729
+
730
+ /**
731
+ * Generate the value of CustomDateOption.direction from the pure date adjust() function.
732
+ */
733
+ const buildCustomDateOptionDirectionValue = (
734
+ pureDateAdjustFunction: SimpleFunctionExpression | V1_AppliedFunction,
735
+ ): CUSTOM_DATE_OPTION_DIRECTION => {
736
+ if (pureDateAdjustFunction instanceof SimpleFunctionExpression) {
737
+ return pureDateAdjustFunction.parametersValues[1] instanceof
738
+ SimpleFunctionExpression &&
739
+ matchFunctionName(
740
+ pureDateAdjustFunction.parametersValues[1].functionName,
741
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.MINUS,
742
+ )
743
+ ? CUSTOM_DATE_OPTION_DIRECTION.BEFORE
744
+ : CUSTOM_DATE_OPTION_DIRECTION.AFTER;
745
+ } else {
746
+ return pureDateAdjustFunction.parameters[1] instanceof V1_AppliedFunction &&
747
+ matchFunctionName(
748
+ pureDateAdjustFunction.parameters[1].function,
749
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.MINUS,
750
+ )
751
+ ? CUSTOM_DATE_OPTION_DIRECTION.BEFORE
752
+ : CUSTOM_DATE_OPTION_DIRECTION.AFTER;
753
+ }
754
+ };
755
+
756
+ /**
757
+ * Generate the value of CustomDateOption.unit from the pure date adjust() function.
758
+ */
759
+ const buildCustomDateOptionUnitValue = (
760
+ valueSpecification: SimpleFunctionExpression | V1_AppliedFunction,
761
+ ): CUSTOM_DATE_OPTION_UNIT => {
762
+ if (valueSpecification instanceof SimpleFunctionExpression) {
763
+ return guaranteeNonNullable(
764
+ Object.keys(CUSTOM_DATE_OPTION_UNIT)
765
+ .filter(
766
+ (key) =>
767
+ key ===
768
+ (valueSpecification.parametersValues[2] as EnumValueInstanceValue)
769
+ .values[0]?.value.name,
770
+ )
771
+ .map(
772
+ (key) =>
773
+ CUSTOM_DATE_OPTION_UNIT[
774
+ key as keyof typeof CUSTOM_DATE_OPTION_UNIT
775
+ ],
776
+ )[0],
777
+ );
778
+ } else {
779
+ return guaranteeNonNullable(
780
+ Object.values(CUSTOM_DATE_OPTION_UNIT).filter(
781
+ (value) =>
782
+ value ===
783
+ guaranteeType(valueSpecification.parameters[2], V1_AppliedProperty)
784
+ .property,
785
+ )[0],
786
+ );
787
+ }
788
+ };
789
+
790
+ /**
791
+ * Generate the value of CustomDateOption.moment from the pure date adjust() function.
792
+ */
793
+ const buildCustomDateOptionReferenceMomentValue = (
794
+ pureDateAjustFunction: SimpleFunctionExpression | V1_AppliedFunction,
795
+ ): CUSTOM_DATE_OPTION_REFERENCE_MOMENT => {
796
+ const funcName =
797
+ pureDateAjustFunction instanceof SimpleFunctionExpression
798
+ ? (pureDateAjustFunction.parametersValues[0] as SimpleFunctionExpression)
799
+ .functionName
800
+ : (pureDateAjustFunction.parameters[0] as V1_AppliedFunction).function;
801
+ switch (getSupportedDateFunctionFullPath(funcName)) {
802
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.TODAY:
803
+ return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY;
804
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.NOW:
805
+ return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.NOW;
806
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_YEAR:
807
+ return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_THIS_YEAR;
808
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER:
809
+ return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_QUARTER;
810
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_MONTH:
811
+ return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_MONTH;
812
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK:
813
+ return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_WEEK;
814
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.PREVIOUS_DAY_OF_WEEK:
815
+ return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.PERVIOUS_DAY_OF_WEEK;
816
+ default:
817
+ throw new UnsupportedOperationError(
818
+ `Can't build custom date option reference moment '${funcName}'`,
819
+ );
820
+ }
821
+ };
822
+
823
+ /**
824
+ * Build CustomDateOption based on the pure date adjust() function.
825
+ * Transform CustomDateOption if it matches any preserved custom adjust date functions. e.g. One Month Ago..
826
+ */
827
+ export const buildCustomDateOption = (
828
+ valueSpecification: CustomDatePickerValueSpecification | undefined,
829
+ applicationStore: ApplicationStore<
830
+ LegendApplicationConfig,
831
+ LegendApplicationPluginManager<LegendApplicationPlugin>
832
+ >,
833
+ ): CustomDateOption => {
834
+ if (
835
+ (valueSpecification instanceof SimpleFunctionExpression &&
836
+ matchFunctionName(
837
+ valueSpecification.functionName,
838
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.ADJUST,
839
+ )) ||
840
+ (valueSpecification instanceof V1_AppliedFunction &&
841
+ matchFunctionName(
842
+ valueSpecification.function,
843
+ QUERY_BUILDER_SUPPORTED_FUNCTIONS.ADJUST,
844
+ ))
845
+ ) {
846
+ try {
847
+ const customDateOption = new CustomDateOption(
848
+ '',
849
+ CUSTOM_DATE_PICKER_OPTION.CUSTOM_DATE,
850
+ buildCustomDateOptionDurationValue(valueSpecification),
851
+ buildCustomDateOptionUnitValue(valueSpecification),
852
+ buildCustomDateOptionDirectionValue(valueSpecification),
853
+ buildCustomDateOptionReferenceMomentValue(valueSpecification),
854
+ );
855
+ const matchedPreservedCustomAdjustDates =
856
+ reservedCustomDateOptions.filter(
857
+ (t) =>
858
+ t.generateDisplayLabel() ===
859
+ customDateOption.generateDisplayLabel(),
860
+ );
861
+ if (matchedPreservedCustomAdjustDates.length > 0) {
862
+ customDateOption.label = guaranteeNonNullable(
863
+ matchedPreservedCustomAdjustDates[0]?.label,
864
+ );
865
+ customDateOption.value = guaranteeNonNullable(
866
+ matchedPreservedCustomAdjustDates[0]?.value,
867
+ );
868
+ return customDateOption;
869
+ }
870
+ customDateOption.updateLabel();
871
+ return customDateOption;
872
+ } catch (error) {
873
+ assertErrorThrown(error);
874
+ applicationStore.notificationService.notifyError(error);
875
+ }
876
+ }
877
+ return new CustomDateOption('', '', 0, undefined, undefined, undefined);
878
+ };
879
+
880
+ /**
881
+ * Build DatePickerOption from pure date functions or PrimitiveInstanceValue
882
+ */
883
+ export const buildDatePickerOption = (
884
+ valueSpecification: CustomDatePickerValueSpecification | undefined,
885
+ applicationStore: ApplicationStore<
886
+ LegendApplicationConfig,
887
+ LegendApplicationPluginManager<LegendApplicationPlugin>
888
+ >,
889
+ ): DatePickerOption => {
890
+ if (
891
+ valueSpecification instanceof SimpleFunctionExpression ||
892
+ valueSpecification instanceof V1_AppliedFunction
893
+ ) {
894
+ const functionName =
895
+ valueSpecification instanceof SimpleFunctionExpression
896
+ ? valueSpecification.functionName
897
+ : valueSpecification.function;
898
+ switch (getSupportedDateFunctionFullPath(functionName)) {
899
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.TODAY:
900
+ return new DatePickerOption(
901
+ CUSTOM_DATE_PICKER_OPTION.TODAY,
902
+ CUSTOM_DATE_PICKER_OPTION.TODAY,
903
+ );
904
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.NOW:
905
+ return new DatePickerOption(
906
+ CUSTOM_DATE_PICKER_OPTION.NOW,
907
+ CUSTOM_DATE_PICKER_OPTION.NOW,
908
+ );
909
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_YEAR:
910
+ return new CustomFirstDayOfOption(
911
+ CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_THIS_YEAR,
912
+ CUSTOM_DATE_FIRST_DAY_OF_UNIT.YEAR,
913
+ );
914
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER:
915
+ return new CustomFirstDayOfOption(
916
+ CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_QUARTER,
917
+ CUSTOM_DATE_FIRST_DAY_OF_UNIT.QUARTER,
918
+ );
919
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_MONTH:
920
+ return new CustomFirstDayOfOption(
921
+ CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_MONTH,
922
+ CUSTOM_DATE_FIRST_DAY_OF_UNIT.MONTH,
923
+ );
924
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK:
925
+ return new CustomFirstDayOfOption(
926
+ CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_WEEK,
927
+ CUSTOM_DATE_FIRST_DAY_OF_UNIT.WEEK,
928
+ );
929
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.PREVIOUS_DAY_OF_WEEK:
930
+ const dayOfWeek =
931
+ valueSpecification instanceof SimpleFunctionExpression
932
+ ? (valueSpecification.parametersValues[0] as EnumValueInstanceValue)
933
+ .values[0]?.value.name
934
+ : guaranteeType(
935
+ valueSpecification.parameters[0],
936
+ V1_AppliedProperty,
937
+ ).property;
938
+ return new CustomPreviousDayOfWeekOption(
939
+ `Previous ${dayOfWeek}`,
940
+ dayOfWeek as CUSTOM_DATE_DAY_OF_WEEK,
941
+ );
942
+ case QUERY_BUILDER_SUPPORTED_FUNCTIONS.ADJUST:
943
+ return buildCustomDateOption(valueSpecification, applicationStore);
944
+ default:
945
+ return new DatePickerOption('', '');
946
+ }
947
+ } else if (valueSpecification instanceof PrimitiveInstanceValue) {
948
+ return valueSpecification.genericType.value.rawType.path ===
949
+ PRIMITIVE_TYPE.LATESTDATE
950
+ ? new DatePickerOption(
951
+ CUSTOM_DATE_PICKER_OPTION.LATEST_DATE,
952
+ CUSTOM_DATE_PICKER_OPTION.LATEST_DATE,
953
+ )
954
+ : new DatePickerOption(
955
+ (valueSpecification.values[0] ?? '') as string,
956
+ valueSpecification.values[0] === null
957
+ ? ''
958
+ : valueSpecification.genericType.value.rawType.path ===
959
+ PRIMITIVE_TYPE.DATETIME
960
+ ? CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_TIME
961
+ : CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_DATE,
962
+ );
963
+ } else {
964
+ if (valueSpecification instanceof V1_CLatestDate) {
965
+ return new DatePickerOption(
966
+ CUSTOM_DATE_PICKER_OPTION.LATEST_DATE,
967
+ CUSTOM_DATE_PICKER_OPTION.LATEST_DATE,
968
+ );
969
+ } else if (valueSpecification instanceof V1_CStrictDate) {
970
+ return new DatePickerOption(
971
+ valueSpecification.value,
972
+ CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_DATE,
973
+ );
974
+ } else if (valueSpecification instanceof V1_CDateTime) {
975
+ return new DatePickerOption(
976
+ valueSpecification.value,
977
+ CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_TIME,
978
+ );
979
+ }
980
+ throw new Error(
981
+ `Unexpected date V1_ValueSpecification: ${valueSpecification}`,
982
+ );
983
+ }
984
+ };