@finos/legend-query-builder 4.16.19 → 4.16.21
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/components/__test-utils__/QueryBuilderComponentTestUtils.d.ts +21 -1
- package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.d.ts.map +1 -1
- package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.js +16 -2
- package/lib/components/__test-utils__/QueryBuilderComponentTestUtils.js.map +1 -1
- package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.js +1 -1
- package/lib/components/fetch-structure/QueryBuilderPostFilterPanel.js.map +1 -1
- package/lib/components/filter/QueryBuilderFilterPanel.js +1 -1
- package/lib/components/filter/QueryBuilderFilterPanel.js.map +1 -1
- package/lib/components/shared/BasicValueSpecificationEditor.d.ts +155 -4
- package/lib/components/shared/BasicValueSpecificationEditor.d.ts.map +1 -1
- package/lib/components/shared/BasicValueSpecificationEditor.js +239 -158
- package/lib/components/shared/BasicValueSpecificationEditor.js.map +1 -1
- package/lib/components/shared/CustomDatePicker.d.ts +8 -55
- package/lib/components/shared/CustomDatePicker.d.ts.map +1 -1
- package/lib/components/shared/CustomDatePicker.js +31 -415
- package/lib/components/shared/CustomDatePicker.js.map +1 -1
- package/lib/components/shared/CustomDatePickerHelper.d.ts +145 -0
- package/lib/components/shared/CustomDatePickerHelper.d.ts.map +1 -0
- package/lib/components/shared/CustomDatePickerHelper.js +517 -0
- package/lib/components/shared/CustomDatePickerHelper.js.map +1 -0
- package/lib/components/shared/QueryBuilderVariableSelector.js +1 -1
- package/lib/components/shared/QueryBuilderVariableSelector.js.map +1 -1
- package/lib/components/shared/V1_BasicValueSpecificationEditor.d.ts +36 -0
- package/lib/components/shared/V1_BasicValueSpecificationEditor.d.ts.map +1 -0
- package/lib/components/shared/V1_BasicValueSpecificationEditor.js +166 -0
- package/lib/components/shared/V1_BasicValueSpecificationEditor.js.map +1 -0
- package/lib/index.css +16 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/package.json +1 -1
- package/lib/stores/shared/V1_ValueSpecificationEditorHelper.d.ts +23 -0
- package/lib/stores/shared/V1_ValueSpecificationEditorHelper.d.ts.map +1 -0
- package/lib/stores/shared/V1_ValueSpecificationEditorHelper.js +69 -0
- package/lib/stores/shared/V1_ValueSpecificationEditorHelper.js.map +1 -0
- package/lib/stores/shared/V1_ValueSpecificationModifierHelper.d.ts +20 -0
- package/lib/stores/shared/V1_ValueSpecificationModifierHelper.d.ts.map +1 -0
- package/lib/stores/shared/V1_ValueSpecificationModifierHelper.js +38 -0
- package/lib/stores/shared/V1_ValueSpecificationModifierHelper.js.map +1 -0
- package/lib/stores/shared/ValueSpecificationEditorHelper.d.ts +4 -1
- package/lib/stores/shared/ValueSpecificationEditorHelper.d.ts.map +1 -1
- package/lib/stores/shared/ValueSpecificationEditorHelper.js +23 -2
- package/lib/stores/shared/ValueSpecificationEditorHelper.js.map +1 -1
- package/package.json +5 -5
- package/src/components/__test-utils__/QueryBuilderComponentTestUtils.tsx +101 -12
- package/src/components/fetch-structure/QueryBuilderPostFilterPanel.tsx +1 -1
- package/src/components/filter/QueryBuilderFilterPanel.tsx +1 -1
- package/src/components/shared/BasicValueSpecificationEditor.tsx +1417 -1085
- package/src/components/shared/CustomDatePicker.tsx +136 -902
- package/src/components/shared/CustomDatePickerHelper.ts +984 -0
- package/src/components/shared/QueryBuilderVariableSelector.tsx +1 -1
- package/src/components/shared/V1_BasicValueSpecificationEditor.tsx +396 -0
- package/src/index.ts +5 -0
- package/src/stores/shared/V1_ValueSpecificationEditorHelper.ts +113 -0
- package/src/stores/shared/V1_ValueSpecificationModifierHelper.ts +76 -0
- package/src/stores/shared/ValueSpecificationEditorHelper.ts +71 -2
- package/tsconfig.json +4 -0
@@ -21,781 +21,62 @@ import {
|
|
21
21
|
CustomSelectorInput,
|
22
22
|
clsx,
|
23
23
|
} from '@finos/legend-art';
|
24
|
+
import { PRIMITIVE_TYPE } from '@finos/legend-graph';
|
24
25
|
import {
|
25
|
-
type PureModel,
|
26
|
-
type Enum,
|
27
|
-
type Type,
|
28
|
-
type ValueSpecification,
|
29
|
-
PRIMITIVE_TYPE,
|
30
|
-
SimpleFunctionExpression,
|
31
|
-
InstanceValue,
|
32
|
-
GenericType,
|
33
|
-
PrimitiveInstanceValue,
|
34
|
-
GenericTypeExplicitReference,
|
35
|
-
EnumValueExplicitReference,
|
36
|
-
EnumValueInstanceValue,
|
37
|
-
matchFunctionName,
|
38
|
-
type ObserverContext,
|
39
|
-
PrimitiveType,
|
40
|
-
} from '@finos/legend-graph';
|
41
|
-
import {
|
42
|
-
assertErrorThrown,
|
43
26
|
guaranteeNonNullable,
|
44
27
|
parseNumber,
|
45
28
|
returnUndefOnError,
|
46
|
-
UnsupportedOperationError,
|
47
29
|
} from '@finos/legend-shared';
|
48
30
|
import { useEffect, useRef, useState } from 'react';
|
31
|
+
import { useApplicationStore } from '@finos/legend-application';
|
32
|
+
import type {
|
33
|
+
PrimitiveInstanceValueEditorProps,
|
34
|
+
TypeCheckOption,
|
35
|
+
} from './BasicValueSpecificationEditor.js';
|
49
36
|
import {
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
ABSOLUTE_DATE = 'Absolute Date',
|
73
|
-
ABSOLUTE_TIME = 'Absolute Time',
|
74
|
-
TODAY = 'Today',
|
75
|
-
NOW = 'Now',
|
76
|
-
YESTERDAY = 'Yesterday',
|
77
|
-
ONE_YEAR_AGO = 'One Year Ago',
|
78
|
-
ONE_MONTH_AGO = 'One Month Ago',
|
79
|
-
ONE_WEEK_AGO = 'One Week Ago',
|
80
|
-
CUSTOM_DATE = 'Custom Date',
|
81
|
-
PREVIOUS_DAY_OF_WEEK = 'Previous ... of Week',
|
82
|
-
FIRST_DAY_OF = 'First day of...',
|
83
|
-
LATEST_DATE = 'Latest Date',
|
84
|
-
}
|
85
|
-
|
86
|
-
enum CUSTOM_DATE_OPTION_UNIT {
|
87
|
-
DAYS = 'Day(s)',
|
88
|
-
WEEKS = 'Week(s)',
|
89
|
-
MONTHS = 'Month(s)',
|
90
|
-
YEARS = 'Year(s)',
|
91
|
-
}
|
92
|
-
|
93
|
-
enum CUSTOM_DATE_FIRST_DAY_OF_UNIT {
|
94
|
-
WEEK = 'Week',
|
95
|
-
MONTH = 'Month',
|
96
|
-
QUARTER = 'Quarter',
|
97
|
-
YEAR = 'Year',
|
98
|
-
}
|
99
|
-
|
100
|
-
enum CUSTOM_DATE_DAY_OF_WEEK {
|
101
|
-
MONDAY = 'Monday',
|
102
|
-
TUESDAY = 'Tuesday',
|
103
|
-
WENDNESDAY = 'Wednesday',
|
104
|
-
THURSDAY = 'Thursday',
|
105
|
-
FRIDAY = 'Friday',
|
106
|
-
SATURDAY = 'Saturday',
|
107
|
-
SUNDAY = 'Sunday',
|
108
|
-
}
|
109
|
-
|
110
|
-
enum CUSTOM_DATE_OPTION_DIRECTION {
|
111
|
-
BEFORE = 'Before',
|
112
|
-
AFTER = 'After',
|
113
|
-
}
|
114
|
-
|
115
|
-
enum CUSTOM_DATE_OPTION_REFERENCE_MOMENT {
|
116
|
-
TODAY = 'Today',
|
117
|
-
NOW = 'Now',
|
118
|
-
FIRST_DAY_OF_THIS_YEAR = 'Start of Year',
|
119
|
-
FIRST_DAY_OF_QUARTER = 'Start of Quarter',
|
120
|
-
FIRST_DAY_OF_MONTH = 'Start of Month',
|
121
|
-
FIRST_DAY_OF_WEEK = 'Start of Week',
|
122
|
-
PERVIOUS_DAY_OF_WEEK = 'Previous Day of Week',
|
123
|
-
}
|
124
|
-
|
125
|
-
/**
|
126
|
-
* DatePickerOption is the base class being used to display and generate the corresponding pure date function.
|
127
|
-
*/
|
128
|
-
class DatePickerOption {
|
129
|
-
/**
|
130
|
-
* label is the text that shows up in the valueSpecification box.
|
131
|
-
*/
|
132
|
-
label: string;
|
133
|
-
/**
|
134
|
-
* value is the selected date option in date-dropdown.
|
135
|
-
*/
|
136
|
-
value: string;
|
137
|
-
|
138
|
-
constructor(label: string, value: string) {
|
139
|
-
this.label = label;
|
140
|
-
this.value = value;
|
141
|
-
}
|
142
|
-
}
|
143
|
-
|
144
|
-
class CustomDateOption extends DatePickerOption {
|
145
|
-
/**
|
146
|
-
* duration is the amount of time span that will be adjusted.
|
147
|
-
*/
|
148
|
-
duration: number;
|
149
|
-
/**
|
150
|
-
* unit represents the time duration unit, e.g. year, week, etc.
|
151
|
-
*/
|
152
|
-
unit: CUSTOM_DATE_OPTION_UNIT | undefined;
|
153
|
-
/**
|
154
|
-
* direction means the direction in which time adjustment will go to.
|
155
|
-
*/
|
156
|
-
direction: CUSTOM_DATE_OPTION_DIRECTION | undefined;
|
157
|
-
/**
|
158
|
-
* referenceMoment is the date which adjustment starts from.
|
159
|
-
*/
|
160
|
-
referenceMoment: CUSTOM_DATE_OPTION_REFERENCE_MOMENT | undefined;
|
161
|
-
|
162
|
-
constructor(
|
163
|
-
label: string,
|
164
|
-
value: string,
|
165
|
-
duration: number,
|
166
|
-
unit: CUSTOM_DATE_OPTION_UNIT | undefined,
|
167
|
-
direction: CUSTOM_DATE_OPTION_DIRECTION | undefined,
|
168
|
-
referenceMoment: CUSTOM_DATE_OPTION_REFERENCE_MOMENT | undefined,
|
169
|
-
) {
|
170
|
-
super(label, value);
|
171
|
-
this.duration = duration;
|
172
|
-
this.unit = unit;
|
173
|
-
this.direction = direction;
|
174
|
-
this.referenceMoment = referenceMoment;
|
175
|
-
}
|
176
|
-
|
177
|
-
generateDisplayLabel(): string {
|
178
|
-
return [
|
179
|
-
this.duration,
|
180
|
-
this.unit,
|
181
|
-
this.direction,
|
182
|
-
this.referenceMoment,
|
183
|
-
].join(' ');
|
184
|
-
}
|
185
|
-
|
186
|
-
updateLabel(): void {
|
187
|
-
this.label = this.generateDisplayLabel();
|
188
|
-
}
|
189
|
-
}
|
190
|
-
|
191
|
-
class CustomFirstDayOfOption extends DatePickerOption {
|
192
|
-
/**
|
193
|
-
* unit: time unit, e.g. Week, Month, etc.
|
194
|
-
*/
|
195
|
-
unit: CUSTOM_DATE_FIRST_DAY_OF_UNIT | undefined;
|
196
|
-
|
197
|
-
constructor(label: string, unit: CUSTOM_DATE_FIRST_DAY_OF_UNIT | undefined) {
|
198
|
-
super(label, CUSTOM_DATE_PICKER_OPTION.FIRST_DAY_OF);
|
199
|
-
this.unit = unit;
|
200
|
-
}
|
201
|
-
}
|
202
|
-
|
203
|
-
class CustomPreviousDayOfWeekOption extends DatePickerOption {
|
204
|
-
/**
|
205
|
-
* day: which day in the week will be selected.
|
206
|
-
*/
|
207
|
-
day: CUSTOM_DATE_DAY_OF_WEEK;
|
208
|
-
|
209
|
-
constructor(label: string, day: CUSTOM_DATE_DAY_OF_WEEK) {
|
210
|
-
super(label, CUSTOM_DATE_PICKER_OPTION.PREVIOUS_DAY_OF_WEEK);
|
211
|
-
this.day = day;
|
212
|
-
}
|
37
|
+
buildCustomDateOption,
|
38
|
+
buildDatePickerOption,
|
39
|
+
CUSTOM_DATE_DAY_OF_WEEK,
|
40
|
+
CUSTOM_DATE_FIRST_DAY_OF_UNIT,
|
41
|
+
CUSTOM_DATE_OPTION_DIRECTION,
|
42
|
+
CUSTOM_DATE_OPTION_REFERENCE_MOMENT,
|
43
|
+
CUSTOM_DATE_OPTION_UNIT,
|
44
|
+
CUSTOM_DATE_PICKER_OPTION,
|
45
|
+
CustomDateOption,
|
46
|
+
CustomFirstDayOfOption,
|
47
|
+
CustomPreviousDayOfWeekOption,
|
48
|
+
DatePickerOption,
|
49
|
+
reservedCustomDateOptions,
|
50
|
+
type CustomDatePickerUpdateValueSpecification,
|
51
|
+
type CustomDatePickerValueSpecification,
|
52
|
+
} from './CustomDatePickerHelper.js';
|
53
|
+
import type { V1_TypeCheckOption } from './V1_BasicValueSpecificationEditor.js';
|
54
|
+
|
55
|
+
interface AbsoluteDateValueSpecificationEditorProps<
|
56
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
57
|
+
> extends Omit<CustomDatePickerProps<T>, 'typeCheckOption'> {
|
58
|
+
setDatePickerOption: (datePickerOption: DatePickerOption) => void;
|
213
59
|
}
|
214
60
|
|
215
|
-
const
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
CUSTOM_DATE_OPTION_UNIT.DAYS,
|
221
|
-
CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
|
222
|
-
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
|
223
|
-
),
|
224
|
-
new CustomDateOption(
|
225
|
-
'One Week Ago',
|
226
|
-
CUSTOM_DATE_PICKER_OPTION.ONE_WEEK_AGO,
|
227
|
-
1,
|
228
|
-
CUSTOM_DATE_OPTION_UNIT.WEEKS,
|
229
|
-
CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
|
230
|
-
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
|
231
|
-
),
|
232
|
-
new CustomDateOption(
|
233
|
-
'One Month Ago',
|
234
|
-
CUSTOM_DATE_PICKER_OPTION.ONE_MONTH_AGO,
|
235
|
-
1,
|
236
|
-
CUSTOM_DATE_OPTION_UNIT.MONTHS,
|
237
|
-
CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
|
238
|
-
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
|
239
|
-
),
|
240
|
-
new CustomDateOption(
|
241
|
-
'One Year Ago',
|
242
|
-
CUSTOM_DATE_PICKER_OPTION.ONE_YEAR_AGO,
|
243
|
-
1,
|
244
|
-
CUSTOM_DATE_OPTION_UNIT.YEARS,
|
245
|
-
CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
|
246
|
-
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
|
247
|
-
),
|
248
|
-
];
|
249
|
-
|
250
|
-
const getSupportedDateFunctionFullPath = (
|
251
|
-
functionName: string,
|
252
|
-
): string | undefined =>
|
253
|
-
Object.values(QUERY_BUILDER_SUPPORTED_FUNCTIONS).find((_func) =>
|
254
|
-
matchFunctionName(functionName, _func),
|
255
|
-
);
|
256
|
-
|
257
|
-
/**
|
258
|
-
* Generate pure date functions based on the DatePickerOption.
|
259
|
-
*/
|
260
|
-
const buildPureDateFunctionExpression = (
|
261
|
-
datePickerOption: DatePickerOption,
|
262
|
-
graph: PureModel,
|
263
|
-
observerContext: ObserverContext,
|
264
|
-
): SimpleFunctionExpression => {
|
265
|
-
if (datePickerOption instanceof CustomPreviousDayOfWeekOption) {
|
266
|
-
const previousFridaySFE = new SimpleFunctionExpression(
|
267
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.PREVIOUS_DAY_OF_WEEK,
|
268
|
-
);
|
269
|
-
valueSpecification_setGenericType(
|
270
|
-
previousFridaySFE,
|
271
|
-
GenericTypeExplicitReference.create(new GenericType(PrimitiveType.DATE)),
|
272
|
-
);
|
273
|
-
const dayOfWeekEnumIntanceValue = new EnumValueInstanceValue(
|
274
|
-
GenericTypeExplicitReference.create(
|
275
|
-
new GenericType(graph.getType(QUERY_BUILDER_PURE_PATH.DAY_OF_WEEK)),
|
276
|
-
),
|
277
|
-
);
|
278
|
-
instanceValue_setValues(
|
279
|
-
dayOfWeekEnumIntanceValue,
|
280
|
-
[
|
281
|
-
...dayOfWeekEnumIntanceValue.values,
|
282
|
-
EnumValueExplicitReference.create(
|
283
|
-
guaranteeNonNullable(
|
284
|
-
graph
|
285
|
-
.getEnumeration(QUERY_BUILDER_PURE_PATH.DAY_OF_WEEK)
|
286
|
-
.values.filter((e) => e.name === datePickerOption.day)[0],
|
287
|
-
),
|
288
|
-
),
|
289
|
-
],
|
290
|
-
observerContext,
|
291
|
-
);
|
292
|
-
functionExpression_addParameterValue(
|
293
|
-
previousFridaySFE,
|
294
|
-
dayOfWeekEnumIntanceValue,
|
295
|
-
observerContext,
|
296
|
-
);
|
297
|
-
return previousFridaySFE;
|
298
|
-
} else if (datePickerOption instanceof CustomFirstDayOfOption) {
|
299
|
-
switch (datePickerOption.unit) {
|
300
|
-
case CUSTOM_DATE_FIRST_DAY_OF_UNIT.YEAR: {
|
301
|
-
const firstDayOfThisYearSFE = new SimpleFunctionExpression(
|
302
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_YEAR,
|
303
|
-
);
|
304
|
-
valueSpecification_setGenericType(
|
305
|
-
firstDayOfThisYearSFE,
|
306
|
-
GenericTypeExplicitReference.create(
|
307
|
-
new GenericType(PrimitiveType.DATE),
|
308
|
-
),
|
309
|
-
);
|
310
|
-
return firstDayOfThisYearSFE;
|
311
|
-
}
|
312
|
-
case CUSTOM_DATE_FIRST_DAY_OF_UNIT.QUARTER: {
|
313
|
-
const firstDayOfQuarterSFE = new SimpleFunctionExpression(
|
314
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER,
|
315
|
-
);
|
316
|
-
valueSpecification_setGenericType(
|
317
|
-
firstDayOfQuarterSFE,
|
318
|
-
GenericTypeExplicitReference.create(
|
319
|
-
new GenericType(PrimitiveType.STRICTDATE),
|
320
|
-
),
|
321
|
-
);
|
322
|
-
return firstDayOfQuarterSFE;
|
323
|
-
}
|
324
|
-
case CUSTOM_DATE_FIRST_DAY_OF_UNIT.MONTH: {
|
325
|
-
const firstDayOfMonthSFE = new SimpleFunctionExpression(
|
326
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_MONTH,
|
327
|
-
);
|
328
|
-
valueSpecification_setGenericType(
|
329
|
-
firstDayOfMonthSFE,
|
330
|
-
GenericTypeExplicitReference.create(
|
331
|
-
new GenericType(PrimitiveType.DATE),
|
332
|
-
),
|
333
|
-
);
|
334
|
-
return firstDayOfMonthSFE;
|
335
|
-
}
|
336
|
-
case CUSTOM_DATE_FIRST_DAY_OF_UNIT.WEEK: {
|
337
|
-
const firstDayOfWeekSFE = new SimpleFunctionExpression(
|
338
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK,
|
339
|
-
);
|
340
|
-
valueSpecification_setGenericType(
|
341
|
-
firstDayOfWeekSFE,
|
342
|
-
GenericTypeExplicitReference.create(
|
343
|
-
new GenericType(PrimitiveType.DATE),
|
344
|
-
),
|
345
|
-
);
|
346
|
-
return firstDayOfWeekSFE;
|
347
|
-
}
|
348
|
-
default:
|
349
|
-
throw new UnsupportedOperationError(
|
350
|
-
`Can't build expression for 'First Day Of ...' date picker option for unit '${datePickerOption.unit}'`,
|
351
|
-
);
|
352
|
-
}
|
353
|
-
} else {
|
354
|
-
switch (datePickerOption.value) {
|
355
|
-
case CUSTOM_DATE_PICKER_OPTION.TODAY: {
|
356
|
-
return createSupportedFunctionExpression(
|
357
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.TODAY,
|
358
|
-
PrimitiveType.STRICTDATE,
|
359
|
-
);
|
360
|
-
}
|
361
|
-
case CUSTOM_DATE_PICKER_OPTION.NOW: {
|
362
|
-
return createSupportedFunctionExpression(
|
363
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.NOW,
|
364
|
-
PrimitiveType.DATETIME,
|
365
|
-
);
|
366
|
-
}
|
367
|
-
case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_THIS_YEAR: {
|
368
|
-
const firstDayOfYearSFE = new SimpleFunctionExpression(
|
369
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_YEAR,
|
370
|
-
);
|
371
|
-
valueSpecification_setGenericType(
|
372
|
-
firstDayOfYearSFE,
|
373
|
-
GenericTypeExplicitReference.create(
|
374
|
-
new GenericType(PrimitiveType.DATE),
|
375
|
-
),
|
376
|
-
);
|
377
|
-
return firstDayOfYearSFE;
|
378
|
-
}
|
379
|
-
case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_QUARTER: {
|
380
|
-
const firstDayOfQuarterSFE = new SimpleFunctionExpression(
|
381
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER,
|
382
|
-
);
|
383
|
-
valueSpecification_setGenericType(
|
384
|
-
firstDayOfQuarterSFE,
|
385
|
-
GenericTypeExplicitReference.create(
|
386
|
-
new GenericType(PrimitiveType.STRICTDATE),
|
387
|
-
),
|
388
|
-
);
|
389
|
-
return firstDayOfQuarterSFE;
|
390
|
-
}
|
391
|
-
case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_MONTH: {
|
392
|
-
const firstDayOfMonthSFE = new SimpleFunctionExpression(
|
393
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_MONTH,
|
394
|
-
);
|
395
|
-
valueSpecification_setGenericType(
|
396
|
-
firstDayOfMonthSFE,
|
397
|
-
GenericTypeExplicitReference.create(
|
398
|
-
new GenericType(PrimitiveType.DATE),
|
399
|
-
),
|
400
|
-
);
|
401
|
-
return firstDayOfMonthSFE;
|
402
|
-
}
|
403
|
-
case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_WEEK: {
|
404
|
-
const firstDayOfWeekSFE = new SimpleFunctionExpression(
|
405
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK,
|
406
|
-
);
|
407
|
-
valueSpecification_setGenericType(
|
408
|
-
firstDayOfWeekSFE,
|
409
|
-
GenericTypeExplicitReference.create(
|
410
|
-
new GenericType(PrimitiveType.DATE),
|
411
|
-
),
|
412
|
-
);
|
413
|
-
return firstDayOfWeekSFE;
|
414
|
-
}
|
415
|
-
default:
|
416
|
-
throw new UnsupportedOperationError(
|
417
|
-
`Can't build expression for date picker option '${datePickerOption.value}'`,
|
418
|
-
);
|
419
|
-
}
|
420
|
-
}
|
421
|
-
};
|
422
|
-
|
423
|
-
/**
|
424
|
-
* Generate the enum value of type Pure Enum, DURATION_UNIT, based on the input string.
|
425
|
-
*/
|
426
|
-
const buildPureDurationEnumValue = (
|
427
|
-
unitString: string,
|
428
|
-
graph: PureModel,
|
429
|
-
): Enum => {
|
430
|
-
const durationUnitEnum = graph.getEnumeration(
|
431
|
-
QUERY_BUILDER_PURE_PATH.DURATION_UNIT,
|
432
|
-
);
|
433
|
-
const targetPureDurationEnumValue = durationUnitEnum.values.filter(
|
434
|
-
(e) =>
|
435
|
-
e.name ===
|
436
|
-
Object.keys(CUSTOM_DATE_OPTION_UNIT).filter(
|
437
|
-
(key) =>
|
438
|
-
CUSTOM_DATE_OPTION_UNIT[
|
439
|
-
key as keyof typeof CUSTOM_DATE_OPTION_UNIT
|
440
|
-
] === unitString,
|
441
|
-
)[0],
|
442
|
-
)[0];
|
443
|
-
return (
|
444
|
-
targetPureDurationEnumValue ??
|
445
|
-
guaranteeNonNullable(durationUnitEnum.values[0])
|
446
|
-
);
|
447
|
-
};
|
448
|
-
|
449
|
-
/**
|
450
|
-
* Generate the pure date adjust() function based on the CustomDateOption.
|
451
|
-
*/
|
452
|
-
const buildPureAdjustDateFunction = (
|
453
|
-
customDateOption: CustomDateOption,
|
454
|
-
graph: PureModel,
|
455
|
-
observerContext: ObserverContext,
|
456
|
-
): SimpleFunctionExpression => {
|
457
|
-
const dateAdjustSimpleFunctionExpression = new SimpleFunctionExpression(
|
458
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.ADJUST,
|
459
|
-
);
|
460
|
-
functionExpression_addParameterValue(
|
461
|
-
dateAdjustSimpleFunctionExpression,
|
462
|
-
buildPureDateFunctionExpression(
|
463
|
-
new DatePickerOption(
|
464
|
-
guaranteeNonNullable(customDateOption.referenceMoment),
|
465
|
-
guaranteeNonNullable(customDateOption.referenceMoment),
|
466
|
-
),
|
467
|
-
graph,
|
468
|
-
observerContext,
|
469
|
-
),
|
470
|
-
observerContext,
|
471
|
-
);
|
472
|
-
if (customDateOption.direction === CUSTOM_DATE_OPTION_DIRECTION.BEFORE) {
|
473
|
-
const minusFunc = new SimpleFunctionExpression(
|
474
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.MINUS,
|
475
|
-
);
|
476
|
-
functionExpression_addParameterValue(
|
477
|
-
minusFunc,
|
478
|
-
buildPrimitiveInstanceValue(
|
479
|
-
graph,
|
480
|
-
PRIMITIVE_TYPE.INTEGER,
|
481
|
-
customDateOption.duration,
|
482
|
-
observerContext,
|
483
|
-
),
|
484
|
-
observerContext,
|
485
|
-
);
|
486
|
-
functionExpression_addParameterValue(
|
487
|
-
dateAdjustSimpleFunctionExpression,
|
488
|
-
minusFunc,
|
489
|
-
observerContext,
|
490
|
-
);
|
491
|
-
} else {
|
492
|
-
functionExpression_addParameterValue(
|
493
|
-
dateAdjustSimpleFunctionExpression,
|
494
|
-
buildPrimitiveInstanceValue(
|
495
|
-
graph,
|
496
|
-
PRIMITIVE_TYPE.INTEGER,
|
497
|
-
customDateOption.duration,
|
498
|
-
observerContext,
|
499
|
-
),
|
500
|
-
observerContext,
|
501
|
-
);
|
502
|
-
}
|
503
|
-
const durationUnitEnumIntanceValue = new EnumValueInstanceValue(
|
504
|
-
GenericTypeExplicitReference.create(
|
505
|
-
new GenericType(graph.getType(QUERY_BUILDER_PURE_PATH.DURATION_UNIT)),
|
506
|
-
),
|
507
|
-
);
|
508
|
-
instanceValue_setValues(
|
509
|
-
durationUnitEnumIntanceValue,
|
510
|
-
[
|
511
|
-
...durationUnitEnumIntanceValue.values,
|
512
|
-
EnumValueExplicitReference.create(
|
513
|
-
guaranteeNonNullable(
|
514
|
-
buildPureDurationEnumValue(
|
515
|
-
guaranteeNonNullable(customDateOption.unit),
|
516
|
-
graph,
|
517
|
-
),
|
518
|
-
),
|
519
|
-
),
|
520
|
-
],
|
521
|
-
observerContext,
|
522
|
-
);
|
523
|
-
functionExpression_addParameterValue(
|
524
|
-
dateAdjustSimpleFunctionExpression,
|
525
|
-
durationUnitEnumIntanceValue,
|
526
|
-
observerContext,
|
527
|
-
);
|
528
|
-
valueSpecification_setGenericType(
|
529
|
-
dateAdjustSimpleFunctionExpression,
|
530
|
-
GenericTypeExplicitReference.create(new GenericType(PrimitiveType.DATE)),
|
531
|
-
);
|
532
|
-
return dateAdjustSimpleFunctionExpression;
|
533
|
-
};
|
534
|
-
|
535
|
-
/**
|
536
|
-
* Generate the value of CustomDateOption.duration from the pure date adjust() function.
|
537
|
-
*/
|
538
|
-
const buildCustomDateOptionDurationValue = (
|
539
|
-
pureDateAdjustFunction: SimpleFunctionExpression,
|
540
|
-
): number => {
|
541
|
-
const durationParam = pureDateAdjustFunction.parametersValues[1];
|
542
|
-
return durationParam instanceof PrimitiveInstanceValue
|
543
|
-
? (durationParam.values[0] as number)
|
544
|
-
: durationParam instanceof SimpleFunctionExpression &&
|
545
|
-
matchFunctionName(
|
546
|
-
durationParam.functionName,
|
547
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.MINUS,
|
548
|
-
)
|
549
|
-
? durationParam.parametersValues[0] instanceof PrimitiveInstanceValue
|
550
|
-
? (durationParam.parametersValues[0].values[0] as number)
|
551
|
-
: 0
|
552
|
-
: 0;
|
553
|
-
};
|
554
|
-
|
555
|
-
/**
|
556
|
-
* Generate the value of CustomDateOption.direction from the pure date adjust() function.
|
557
|
-
*/
|
558
|
-
const buildCustomDateOptionDirectionValue = (
|
559
|
-
pureDateAdjustFunction: SimpleFunctionExpression,
|
560
|
-
): CUSTOM_DATE_OPTION_DIRECTION =>
|
561
|
-
pureDateAdjustFunction.parametersValues[1] instanceof
|
562
|
-
SimpleFunctionExpression &&
|
563
|
-
matchFunctionName(
|
564
|
-
pureDateAdjustFunction.parametersValues[1].functionName,
|
565
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.MINUS,
|
566
|
-
)
|
567
|
-
? CUSTOM_DATE_OPTION_DIRECTION.BEFORE
|
568
|
-
: CUSTOM_DATE_OPTION_DIRECTION.AFTER;
|
569
|
-
|
570
|
-
/**
|
571
|
-
* Generate the value of CustomDateOption.unit from the pure date adjust() function.
|
572
|
-
*/
|
573
|
-
const buildCustomDateOptionUnitValue = (
|
574
|
-
valueSpecification: SimpleFunctionExpression,
|
575
|
-
): CUSTOM_DATE_OPTION_UNIT =>
|
576
|
-
guaranteeNonNullable(
|
577
|
-
Object.keys(CUSTOM_DATE_OPTION_UNIT)
|
578
|
-
.filter(
|
579
|
-
(key) =>
|
580
|
-
key ===
|
581
|
-
(valueSpecification.parametersValues[2] as EnumValueInstanceValue)
|
582
|
-
.values[0]?.value.name,
|
583
|
-
)
|
584
|
-
.map(
|
585
|
-
(key) =>
|
586
|
-
CUSTOM_DATE_OPTION_UNIT[key as keyof typeof CUSTOM_DATE_OPTION_UNIT],
|
587
|
-
)[0],
|
588
|
-
);
|
589
|
-
|
590
|
-
/**
|
591
|
-
* Generate the value of CustomDateOption.moment from the pure date adjust() function.
|
592
|
-
*/
|
593
|
-
const buildCustomDateOptionReferenceMomentValue = (
|
594
|
-
pureDateAjustFunction: SimpleFunctionExpression,
|
595
|
-
): CUSTOM_DATE_OPTION_REFERENCE_MOMENT => {
|
596
|
-
const funcName = (
|
597
|
-
pureDateAjustFunction.parametersValues[0] as SimpleFunctionExpression
|
598
|
-
).functionName;
|
599
|
-
switch (getSupportedDateFunctionFullPath(funcName)) {
|
600
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.TODAY:
|
601
|
-
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY;
|
602
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.NOW:
|
603
|
-
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.NOW;
|
604
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_YEAR:
|
605
|
-
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_THIS_YEAR;
|
606
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER:
|
607
|
-
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_QUARTER;
|
608
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_MONTH:
|
609
|
-
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_MONTH;
|
610
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK:
|
611
|
-
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_WEEK;
|
612
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.PREVIOUS_DAY_OF_WEEK:
|
613
|
-
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.PERVIOUS_DAY_OF_WEEK;
|
614
|
-
default:
|
615
|
-
throw new UnsupportedOperationError(
|
616
|
-
`Can't build custom date option reference moment '${funcName}'`,
|
617
|
-
);
|
618
|
-
}
|
619
|
-
};
|
620
|
-
|
621
|
-
/**
|
622
|
-
* Build CustomDateOption based on the pure date adjust() function.
|
623
|
-
* Transform CustomDateOption if it matches any preserved custom adjust date functions. e.g. One Month Ago..
|
624
|
-
*/
|
625
|
-
const buildCustomDateOption = (
|
626
|
-
valueSpecification: SimpleFunctionExpression | PrimitiveInstanceValue,
|
627
|
-
applicationStore: ApplicationStore<
|
628
|
-
LegendApplicationConfig,
|
629
|
-
LegendApplicationPluginManager<LegendApplicationPlugin>
|
630
|
-
>,
|
631
|
-
): CustomDateOption => {
|
632
|
-
if (
|
633
|
-
valueSpecification instanceof SimpleFunctionExpression &&
|
634
|
-
matchFunctionName(
|
635
|
-
valueSpecification.functionName,
|
636
|
-
QUERY_BUILDER_SUPPORTED_FUNCTIONS.ADJUST,
|
637
|
-
)
|
638
|
-
) {
|
639
|
-
try {
|
640
|
-
const customDateOption = new CustomDateOption(
|
641
|
-
'',
|
642
|
-
CUSTOM_DATE_PICKER_OPTION.CUSTOM_DATE,
|
643
|
-
buildCustomDateOptionDurationValue(valueSpecification),
|
644
|
-
buildCustomDateOptionUnitValue(valueSpecification),
|
645
|
-
buildCustomDateOptionDirectionValue(valueSpecification),
|
646
|
-
buildCustomDateOptionReferenceMomentValue(valueSpecification),
|
647
|
-
);
|
648
|
-
const matchedPreservedCustomAdjustDates =
|
649
|
-
reservedCustomDateOptions.filter(
|
650
|
-
(t) =>
|
651
|
-
t.generateDisplayLabel() ===
|
652
|
-
customDateOption.generateDisplayLabel(),
|
653
|
-
);
|
654
|
-
if (matchedPreservedCustomAdjustDates.length > 0) {
|
655
|
-
customDateOption.label = guaranteeNonNullable(
|
656
|
-
matchedPreservedCustomAdjustDates[0]?.label,
|
657
|
-
);
|
658
|
-
customDateOption.value = guaranteeNonNullable(
|
659
|
-
matchedPreservedCustomAdjustDates[0]?.value,
|
660
|
-
);
|
661
|
-
return customDateOption;
|
662
|
-
}
|
663
|
-
customDateOption.updateLabel();
|
664
|
-
return customDateOption;
|
665
|
-
} catch (error) {
|
666
|
-
assertErrorThrown(error);
|
667
|
-
applicationStore.notificationService.notifyError(error);
|
668
|
-
}
|
669
|
-
}
|
670
|
-
return new CustomDateOption('', '', 0, undefined, undefined, undefined);
|
671
|
-
};
|
672
|
-
|
673
|
-
/**
|
674
|
-
* Build DatePickerOption from pure date functions or PrimitiveInstanceValue
|
675
|
-
*/
|
676
|
-
export const buildDatePickerOption = (
|
677
|
-
valueSpecification: SimpleFunctionExpression | PrimitiveInstanceValue,
|
678
|
-
applicationStore: ApplicationStore<
|
679
|
-
LegendApplicationConfig,
|
680
|
-
LegendApplicationPluginManager<LegendApplicationPlugin>
|
681
|
-
>,
|
682
|
-
): DatePickerOption => {
|
683
|
-
if (valueSpecification instanceof SimpleFunctionExpression) {
|
684
|
-
switch (getSupportedDateFunctionFullPath(valueSpecification.functionName)) {
|
685
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.TODAY:
|
686
|
-
return new DatePickerOption(
|
687
|
-
CUSTOM_DATE_PICKER_OPTION.TODAY,
|
688
|
-
CUSTOM_DATE_PICKER_OPTION.TODAY,
|
689
|
-
);
|
690
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.NOW:
|
691
|
-
return new DatePickerOption(
|
692
|
-
CUSTOM_DATE_PICKER_OPTION.NOW,
|
693
|
-
CUSTOM_DATE_PICKER_OPTION.NOW,
|
694
|
-
);
|
695
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_YEAR:
|
696
|
-
return new CustomFirstDayOfOption(
|
697
|
-
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_THIS_YEAR,
|
698
|
-
CUSTOM_DATE_FIRST_DAY_OF_UNIT.YEAR,
|
699
|
-
);
|
700
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER:
|
701
|
-
return new CustomFirstDayOfOption(
|
702
|
-
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_QUARTER,
|
703
|
-
CUSTOM_DATE_FIRST_DAY_OF_UNIT.QUARTER,
|
704
|
-
);
|
705
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_THIS_MONTH:
|
706
|
-
return new CustomFirstDayOfOption(
|
707
|
-
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_MONTH,
|
708
|
-
CUSTOM_DATE_FIRST_DAY_OF_UNIT.MONTH,
|
709
|
-
);
|
710
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK:
|
711
|
-
return new CustomFirstDayOfOption(
|
712
|
-
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_WEEK,
|
713
|
-
CUSTOM_DATE_FIRST_DAY_OF_UNIT.WEEK,
|
714
|
-
);
|
715
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.PREVIOUS_DAY_OF_WEEK:
|
716
|
-
return new CustomPreviousDayOfWeekOption(
|
717
|
-
`Previous ${
|
718
|
-
(valueSpecification.parametersValues[0] as EnumValueInstanceValue)
|
719
|
-
.values[0]?.value.name
|
720
|
-
}`,
|
721
|
-
(valueSpecification.parametersValues[0] as EnumValueInstanceValue)
|
722
|
-
.values[0]?.value.name as CUSTOM_DATE_DAY_OF_WEEK,
|
723
|
-
);
|
724
|
-
case QUERY_BUILDER_SUPPORTED_FUNCTIONS.ADJUST:
|
725
|
-
return buildCustomDateOption(valueSpecification, applicationStore);
|
726
|
-
default:
|
727
|
-
return new DatePickerOption('', '');
|
728
|
-
}
|
729
|
-
} else {
|
730
|
-
return valueSpecification.genericType.value.rawType.path ===
|
731
|
-
PRIMITIVE_TYPE.LATESTDATE
|
732
|
-
? new DatePickerOption(
|
733
|
-
CUSTOM_DATE_PICKER_OPTION.LATEST_DATE,
|
734
|
-
CUSTOM_DATE_PICKER_OPTION.LATEST_DATE,
|
735
|
-
)
|
736
|
-
: new DatePickerOption(
|
737
|
-
(valueSpecification.values[0] ?? '') as string,
|
738
|
-
valueSpecification.values[0] === null
|
739
|
-
? ''
|
740
|
-
: valueSpecification.genericType.value.rawType.path ===
|
741
|
-
PRIMITIVE_TYPE.DATETIME
|
742
|
-
? CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_TIME
|
743
|
-
: CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_DATE,
|
744
|
-
);
|
745
|
-
}
|
746
|
-
};
|
747
|
-
|
748
|
-
const AbsoluteDateValueSpecificationEditor: React.FC<{
|
749
|
-
valueSpecification: SimpleFunctionExpression | PrimitiveInstanceValue;
|
750
|
-
graph: PureModel;
|
751
|
-
setValueSpecification: (val: ValueSpecification) => void;
|
752
|
-
setDatePickerOption: (datePickerOption: DatePickerOption) => void;
|
753
|
-
observerContext: ObserverContext;
|
754
|
-
}> = (props) => {
|
61
|
+
const AbsoluteDateValueSpecificationEditor = <
|
62
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
63
|
+
>(
|
64
|
+
props: AbsoluteDateValueSpecificationEditorProps<T>,
|
65
|
+
) => {
|
755
66
|
const {
|
756
67
|
valueSpecification,
|
757
|
-
|
758
|
-
|
68
|
+
valueSelector,
|
69
|
+
updateValueSpecification,
|
759
70
|
setDatePickerOption,
|
760
|
-
observerContext,
|
761
71
|
} = props;
|
762
72
|
const inputRef = useRef<HTMLInputElement>(null);
|
763
|
-
const absoluteDateValue =
|
764
|
-
valueSpecification instanceof SimpleFunctionExpression
|
765
|
-
? ''
|
766
|
-
: (valueSpecification.values[0] as string | null);
|
73
|
+
const absoluteDateValue = valueSelector(valueSpecification);
|
767
74
|
const updateAbsoluteDateValue: React.ChangeEventHandler<HTMLInputElement> = (
|
768
75
|
event,
|
769
76
|
) => {
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
graph,
|
774
|
-
PRIMITIVE_TYPE.STRICTDATE,
|
775
|
-
event.target.value,
|
776
|
-
observerContext,
|
777
|
-
),
|
778
|
-
);
|
779
|
-
} else if (valueSpecification instanceof InstanceValue) {
|
780
|
-
instanceValue_setValue(
|
781
|
-
valueSpecification,
|
782
|
-
event.target.value,
|
783
|
-
0,
|
784
|
-
observerContext,
|
785
|
-
);
|
786
|
-
if (
|
787
|
-
valueSpecification.genericType.value.rawType.path !==
|
788
|
-
PRIMITIVE_TYPE.STRICTDATE
|
789
|
-
) {
|
790
|
-
valueSpecification_setGenericType(
|
791
|
-
valueSpecification,
|
792
|
-
GenericTypeExplicitReference.create(
|
793
|
-
new GenericType(PrimitiveType.STRICTDATE),
|
794
|
-
),
|
795
|
-
);
|
796
|
-
}
|
797
|
-
setValueSpecification(valueSpecification);
|
798
|
-
}
|
77
|
+
updateValueSpecification(valueSpecification, event.target.value, {
|
78
|
+
primitiveTypeEnum: PRIMITIVE_TYPE.STRICTDATE,
|
79
|
+
});
|
799
80
|
setDatePickerOption(
|
800
81
|
new DatePickerOption(
|
801
82
|
event.target.value,
|
@@ -822,56 +103,34 @@ const AbsoluteDateValueSpecificationEditor: React.FC<{
|
|
822
103
|
);
|
823
104
|
};
|
824
105
|
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
setValueSpecification: (val: ValueSpecification) => void;
|
106
|
+
interface AbsoluteTimeValueSpecificationEditorProps<
|
107
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
108
|
+
> extends Omit<CustomDatePickerProps<T>, 'typeCheckOption'> {
|
829
109
|
setDatePickerOption: (datePickerOption: DatePickerOption) => void;
|
830
|
-
|
831
|
-
|
110
|
+
}
|
111
|
+
|
112
|
+
const AbsoluteTimeValueSpecificationEditor = <
|
113
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
114
|
+
>(
|
115
|
+
props: AbsoluteTimeValueSpecificationEditorProps<T>,
|
116
|
+
) => {
|
832
117
|
const {
|
833
118
|
valueSpecification,
|
834
|
-
|
835
|
-
|
119
|
+
valueSelector,
|
120
|
+
updateValueSpecification,
|
836
121
|
setDatePickerOption,
|
837
|
-
observerContext,
|
838
122
|
} = props;
|
839
123
|
const inputRef = useRef<HTMLInputElement>(null);
|
840
|
-
const absoluteTimeValue =
|
841
|
-
valueSpecification instanceof SimpleFunctionExpression
|
842
|
-
? ''
|
843
|
-
: (valueSpecification.values[0] as string | null);
|
124
|
+
const absoluteTimeValue = valueSelector(valueSpecification);
|
844
125
|
const updateAbsoluteTimeValue: React.ChangeEventHandler<HTMLInputElement> = (
|
845
126
|
event,
|
846
127
|
) => {
|
847
|
-
//
|
848
128
|
const value = new Date(event.target.value).getUTCSeconds()
|
849
129
|
? event.target.value
|
850
130
|
: `${event.target.value}:00`;
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
graph,
|
855
|
-
PRIMITIVE_TYPE.DATETIME,
|
856
|
-
value,
|
857
|
-
observerContext,
|
858
|
-
),
|
859
|
-
);
|
860
|
-
} else {
|
861
|
-
instanceValue_setValue(valueSpecification, value, 0, observerContext);
|
862
|
-
if (
|
863
|
-
valueSpecification.genericType.value.rawType.path !==
|
864
|
-
PRIMITIVE_TYPE.DATETIME
|
865
|
-
) {
|
866
|
-
valueSpecification_setGenericType(
|
867
|
-
valueSpecification,
|
868
|
-
GenericTypeExplicitReference.create(
|
869
|
-
new GenericType(PrimitiveType.DATETIME),
|
870
|
-
),
|
871
|
-
);
|
872
|
-
}
|
873
|
-
setValueSpecification(valueSpecification);
|
874
|
-
}
|
131
|
+
updateValueSpecification(valueSpecification, value, {
|
132
|
+
primitiveTypeEnum: PRIMITIVE_TYPE.DATETIME,
|
133
|
+
});
|
875
134
|
setDatePickerOption(
|
876
135
|
new DatePickerOption(
|
877
136
|
event.target.value,
|
@@ -903,19 +162,25 @@ const AbsoluteTimeValueSpecificationEditor: React.FC<{
|
|
903
162
|
);
|
904
163
|
};
|
905
164
|
|
906
|
-
|
165
|
+
interface CustomDateInstanceValueEditorProps<
|
166
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
167
|
+
> extends Omit<
|
168
|
+
CustomDatePickerProps<T>,
|
169
|
+
'typeCheckOption' | 'valueSpecification' | 'valueSelector'
|
170
|
+
> {
|
907
171
|
customDateOptionValue: CustomDateOption;
|
908
|
-
graph: PureModel;
|
909
|
-
observerContext: ObserverContext;
|
910
|
-
setValueSpecification: (val: ValueSpecification) => void;
|
911
172
|
setDatePickerOption: (datePickerOption: DatePickerOption) => void;
|
912
|
-
}
|
173
|
+
}
|
174
|
+
|
175
|
+
const CustomDateInstanceValueEditor = <
|
176
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
177
|
+
>(
|
178
|
+
props: CustomDateInstanceValueEditorProps<T>,
|
179
|
+
) => {
|
913
180
|
const {
|
914
181
|
customDateOptionValue,
|
915
|
-
|
916
|
-
setValueSpecification,
|
182
|
+
updateValueSpecification,
|
917
183
|
setDatePickerOption,
|
918
|
-
observerContext,
|
919
184
|
} = props;
|
920
185
|
const applicationStore = useApplicationStore();
|
921
186
|
const inputRef = useRef<HTMLInputElement>(null);
|
@@ -952,9 +217,7 @@ const CustomDateInstanceValueEditor: React.FC<{
|
|
952
217
|
latestDirectionValue as CUSTOM_DATE_OPTION_DIRECTION,
|
953
218
|
latestReferenceMomentValue as CUSTOM_DATE_OPTION_REFERENCE_MOMENT,
|
954
219
|
);
|
955
|
-
|
956
|
-
buildPureAdjustDateFunction(dateOption, graph, observerContext),
|
957
|
-
);
|
220
|
+
updateValueSpecification(undefined, dateOption);
|
958
221
|
const matchedPreservedCustomAdjustDates =
|
959
222
|
reservedCustomDateOptions.filter(
|
960
223
|
(t) => t.generateDisplayLabel() === dateOption.generateDisplayLabel(),
|
@@ -1069,18 +332,24 @@ const CustomDateInstanceValueEditor: React.FC<{
|
|
1069
332
|
);
|
1070
333
|
};
|
1071
334
|
|
1072
|
-
|
335
|
+
interface CustomFirstDayOfValueSpecificationEditorProps<
|
336
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
337
|
+
> extends Omit<
|
338
|
+
CustomDatePickerProps<T>,
|
339
|
+
'typeCheckOption' | 'valueSpecification' | 'valueSelector'
|
340
|
+
> {
|
1073
341
|
customDateAdjustOptionValue: DatePickerOption;
|
1074
|
-
graph: PureModel;
|
1075
|
-
observerContext: ObserverContext;
|
1076
|
-
setValueSpecification: (val: ValueSpecification) => void;
|
1077
342
|
setDatePickerOption: (datePickerOption: DatePickerOption) => void;
|
1078
|
-
}
|
343
|
+
}
|
344
|
+
|
345
|
+
const CustomFirstDayOfValueSpecificationEditor = <
|
346
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
347
|
+
>(
|
348
|
+
props: CustomFirstDayOfValueSpecificationEditorProps<T>,
|
349
|
+
) => {
|
1079
350
|
const {
|
1080
351
|
customDateAdjustOptionValue,
|
1081
|
-
|
1082
|
-
observerContext,
|
1083
|
-
setValueSpecification,
|
352
|
+
updateValueSpecification,
|
1084
353
|
setDatePickerOption,
|
1085
354
|
} = props;
|
1086
355
|
const applicationStore = useApplicationStore();
|
@@ -1102,13 +371,7 @@ const CustomFirstDayOfValueSpecificationEditor: React.FC<{
|
|
1102
371
|
latestUnitValue as CUSTOM_DATE_FIRST_DAY_OF_UNIT,
|
1103
372
|
)
|
1104
373
|
: new CustomFirstDayOfOption('', undefined);
|
1105
|
-
|
1106
|
-
buildPureDateFunctionExpression(
|
1107
|
-
startDayOfDateOption,
|
1108
|
-
graph,
|
1109
|
-
observerContext,
|
1110
|
-
),
|
1111
|
-
);
|
374
|
+
updateValueSpecification(undefined, startDayOfDateOption);
|
1112
375
|
setDatePickerOption(startDayOfDateOption);
|
1113
376
|
}
|
1114
377
|
};
|
@@ -1144,18 +407,24 @@ const CustomFirstDayOfValueSpecificationEditor: React.FC<{
|
|
1144
407
|
);
|
1145
408
|
};
|
1146
409
|
|
1147
|
-
|
410
|
+
interface CustomPreviousDayOfWeekValueSpecificationEditorProps<
|
411
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
412
|
+
> extends Omit<
|
413
|
+
CustomDatePickerProps<T>,
|
414
|
+
'typeCheckOption' | 'valueSpecification' | 'valueSelector'
|
415
|
+
> {
|
1148
416
|
customDateAdjustOptionValue: DatePickerOption;
|
1149
|
-
graph: PureModel;
|
1150
|
-
observerContext: ObserverContext;
|
1151
|
-
setValueSpecification: (val: ValueSpecification) => void;
|
1152
417
|
setDatePickerOption: (datePickerOption: DatePickerOption) => void;
|
1153
|
-
}
|
418
|
+
}
|
419
|
+
|
420
|
+
const CustomPreviousDayOfWeekValueSpecificationEditor = <
|
421
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
422
|
+
>(
|
423
|
+
props: CustomPreviousDayOfWeekValueSpecificationEditorProps<T>,
|
424
|
+
) => {
|
1154
425
|
const {
|
1155
426
|
customDateAdjustOptionValue,
|
1156
|
-
|
1157
|
-
observerContext,
|
1158
|
-
setValueSpecification,
|
427
|
+
updateValueSpecification,
|
1159
428
|
setDatePickerOption,
|
1160
429
|
} = props;
|
1161
430
|
const applicationStore = useApplicationStore();
|
@@ -1171,13 +440,7 @@ const CustomPreviousDayOfWeekValueSpecificationEditor: React.FC<{
|
|
1171
440
|
`Previous ${latestDurationUnitValue}`,
|
1172
441
|
latestDurationUnitValue as CUSTOM_DATE_DAY_OF_WEEK,
|
1173
442
|
);
|
1174
|
-
|
1175
|
-
buildPureDateFunctionExpression(
|
1176
|
-
previousDayOfWeekDateOption,
|
1177
|
-
graph,
|
1178
|
-
observerContext,
|
1179
|
-
),
|
1180
|
-
);
|
443
|
+
updateValueSpecification(undefined, previousDayOfWeekDateOption);
|
1181
444
|
setDatePickerOption(previousDayOfWeekDateOption);
|
1182
445
|
}
|
1183
446
|
};
|
@@ -1217,35 +480,28 @@ const CustomPreviousDayOfWeekValueSpecificationEditor: React.FC<{
|
|
1217
480
|
);
|
1218
481
|
};
|
1219
482
|
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
483
|
+
interface CustomDatePickerProps<
|
484
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
485
|
+
> extends Omit<
|
486
|
+
PrimitiveInstanceValueEditorProps<T, string | null>,
|
487
|
+
'updateValueSpecification' | 'resetValue'
|
488
|
+
> {
|
489
|
+
updateValueSpecification: CustomDatePickerUpdateValueSpecification<T>;
|
1224
490
|
hasError?: boolean;
|
1225
|
-
typeCheckOption:
|
1226
|
-
expectedType: Type;
|
1227
|
-
/**
|
1228
|
-
* Indicates if a strict type-matching will happen.
|
1229
|
-
* Sometimes, auto-boxing allow some rooms to wiggle,
|
1230
|
-
* for example we can assign a Float to an Integer, a
|
1231
|
-
* Date to a DateTime. With this flag set to `true`
|
1232
|
-
* we will not allow this.
|
1233
|
-
*
|
1234
|
-
* For example, if `match=true`, it means that options in the
|
1235
|
-
* date-capability-dropdown which are not returning type DateTime
|
1236
|
-
* will be filtered out.
|
1237
|
-
*/
|
1238
|
-
match?: boolean;
|
1239
|
-
};
|
491
|
+
typeCheckOption: TypeCheckOption | V1_TypeCheckOption;
|
1240
492
|
displayAsEditableValue?: boolean | undefined;
|
1241
|
-
setValueSpecification: (val: ValueSpecification) => void;
|
1242
493
|
handleBlur?: (() => void) | undefined;
|
1243
|
-
}
|
494
|
+
}
|
495
|
+
|
496
|
+
export const CustomDatePicker = <
|
497
|
+
T extends CustomDatePickerValueSpecification | undefined,
|
498
|
+
>(
|
499
|
+
props: CustomDatePickerProps<T>,
|
500
|
+
) => {
|
1244
501
|
const {
|
1245
502
|
valueSpecification,
|
1246
|
-
|
1247
|
-
|
1248
|
-
observerContext,
|
503
|
+
valueSelector,
|
504
|
+
updateValueSpecification,
|
1249
505
|
hasError,
|
1250
506
|
typeCheckOption,
|
1251
507
|
displayAsEditableValue,
|
@@ -1292,14 +548,9 @@ export const CustomDatePicker: React.FC<{
|
|
1292
548
|
if (
|
1293
549
|
CUSTOM_DATE_PICKER_OPTION.LATEST_DATE === chosenDatePickerOption.value
|
1294
550
|
) {
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
PRIMITIVE_TYPE.LATESTDATE,
|
1299
|
-
event.target.value,
|
1300
|
-
observerContext,
|
1301
|
-
),
|
1302
|
-
);
|
551
|
+
updateValueSpecification(undefined, event.target.value, {
|
552
|
+
primitiveTypeEnum: PRIMITIVE_TYPE.LATESTDATE,
|
553
|
+
});
|
1303
554
|
} else if (
|
1304
555
|
// Elements in this list will trigger children date components
|
1305
556
|
![
|
@@ -1314,21 +565,12 @@ export const CustomDatePicker: React.FC<{
|
|
1314
565
|
(d) => d.value === chosenDatePickerOption.value,
|
1315
566
|
);
|
1316
567
|
if (theReservedCustomDateOption.length > 0) {
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
graph,
|
1321
|
-
observerContext,
|
1322
|
-
),
|
568
|
+
updateValueSpecification(
|
569
|
+
undefined,
|
570
|
+
guaranteeNonNullable(theReservedCustomDateOption[0]),
|
1323
571
|
);
|
1324
572
|
} else {
|
1325
|
-
|
1326
|
-
buildPureDateFunctionExpression(
|
1327
|
-
chosenDatePickerOption,
|
1328
|
-
graph,
|
1329
|
-
observerContext,
|
1330
|
-
),
|
1331
|
-
);
|
573
|
+
updateValueSpecification(undefined, chosenDatePickerOption);
|
1332
574
|
}
|
1333
575
|
}
|
1334
576
|
setDatePickerOption(chosenDatePickerOption);
|
@@ -1337,60 +579,52 @@ export const CustomDatePicker: React.FC<{
|
|
1337
579
|
switch (datePickerOption.value) {
|
1338
580
|
case CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_DATE:
|
1339
581
|
return (
|
1340
|
-
<AbsoluteDateValueSpecificationEditor
|
1341
|
-
graph={graph}
|
582
|
+
<AbsoluteDateValueSpecificationEditor<T>
|
1342
583
|
valueSpecification={valueSpecification}
|
1343
|
-
|
584
|
+
valueSelector={valueSelector}
|
585
|
+
updateValueSpecification={updateValueSpecification}
|
1344
586
|
setDatePickerOption={setDatePickerOption}
|
1345
|
-
observerContext={observerContext}
|
1346
587
|
/>
|
1347
588
|
);
|
1348
589
|
case CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_TIME:
|
1349
590
|
return (
|
1350
|
-
<AbsoluteTimeValueSpecificationEditor
|
1351
|
-
graph={graph}
|
591
|
+
<AbsoluteTimeValueSpecificationEditor<T>
|
1352
592
|
valueSpecification={valueSpecification}
|
1353
|
-
|
593
|
+
valueSelector={valueSelector}
|
594
|
+
updateValueSpecification={updateValueSpecification}
|
1354
595
|
setDatePickerOption={setDatePickerOption}
|
1355
|
-
observerContext={observerContext}
|
1356
596
|
/>
|
1357
597
|
);
|
1358
598
|
case CUSTOM_DATE_PICKER_OPTION.CUSTOM_DATE:
|
1359
599
|
return (
|
1360
|
-
<CustomDateInstanceValueEditor
|
1361
|
-
graph={graph}
|
1362
|
-
observerContext={observerContext}
|
600
|
+
<CustomDateInstanceValueEditor<T>
|
1363
601
|
customDateOptionValue={buildCustomDateOption(
|
1364
602
|
valueSpecification,
|
1365
603
|
applicationStore,
|
1366
604
|
)}
|
1367
|
-
|
605
|
+
updateValueSpecification={updateValueSpecification}
|
1368
606
|
setDatePickerOption={setDatePickerOption}
|
1369
607
|
/>
|
1370
608
|
);
|
1371
609
|
case CUSTOM_DATE_PICKER_OPTION.FIRST_DAY_OF:
|
1372
610
|
return (
|
1373
|
-
<CustomFirstDayOfValueSpecificationEditor
|
1374
|
-
graph={graph}
|
1375
|
-
observerContext={observerContext}
|
611
|
+
<CustomFirstDayOfValueSpecificationEditor<T>
|
1376
612
|
customDateAdjustOptionValue={buildDatePickerOption(
|
1377
613
|
valueSpecification,
|
1378
614
|
applicationStore,
|
1379
615
|
)}
|
1380
|
-
|
616
|
+
updateValueSpecification={updateValueSpecification}
|
1381
617
|
setDatePickerOption={setDatePickerOption}
|
1382
618
|
/>
|
1383
619
|
);
|
1384
620
|
case CUSTOM_DATE_PICKER_OPTION.PREVIOUS_DAY_OF_WEEK:
|
1385
621
|
return (
|
1386
|
-
<CustomPreviousDayOfWeekValueSpecificationEditor
|
1387
|
-
graph={graph}
|
1388
|
-
observerContext={observerContext}
|
622
|
+
<CustomPreviousDayOfWeekValueSpecificationEditor<T>
|
1389
623
|
customDateAdjustOptionValue={buildDatePickerOption(
|
1390
624
|
valueSpecification,
|
1391
625
|
applicationStore,
|
1392
626
|
)}
|
1393
|
-
|
627
|
+
updateValueSpecification={updateValueSpecification}
|
1394
628
|
setDatePickerOption={setDatePickerOption}
|
1395
629
|
/>
|
1396
630
|
);
|