@finos/legend-application 3.0.2 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/application/LegendApplication.d.ts +2 -2
- package/lib/application/LegendApplication.d.ts.map +1 -1
- package/lib/application/LegendApplication.js +4 -4
- package/lib/application/LegendApplication.js.map +1 -1
- package/lib/application/LegendApplicationPluginManager.d.ts +3 -3
- package/lib/application/LegendApplicationPluginManager.d.ts.map +1 -1
- package/lib/components/ActionAlert.d.ts +1 -1
- package/lib/components/ActionAlert.js +3 -3
- package/lib/components/ActionAlert.js.map +1 -1
- package/lib/components/ApplicationStoreProvider.d.ts +3 -3
- package/lib/components/ApplicationStoreProvider.d.ts.map +1 -1
- package/lib/components/ApplicationStoreProvider.js +2 -2
- package/lib/components/ApplicationStoreProvider.js.map +1 -1
- package/lib/components/ApplicationStoreProviderTestUtils.d.ts +5 -5
- package/lib/components/ApplicationStoreProviderTestUtils.d.ts.map +1 -1
- package/lib/components/ApplicationStoreProviderTestUtils.js +5 -4
- package/lib/components/ApplicationStoreProviderTestUtils.js.map +1 -1
- package/lib/components/ApplicationTestID.js +1 -1
- package/lib/components/ApplicationTestID.js.map +1 -1
- package/lib/components/BasicValueSpecificationEditor.d.ts +44 -0
- package/lib/components/BasicValueSpecificationEditor.d.ts.map +1 -0
- package/lib/components/BasicValueSpecificationEditor.js +276 -0
- package/lib/components/BasicValueSpecificationEditor.js.map +1 -0
- package/lib/components/BlockingAlert.d.ts +1 -1
- package/lib/components/BlockingAlert.js +1 -1
- package/lib/components/BlockingAlert.js.map +1 -1
- package/lib/components/CustomDatePicker.d.ts +38 -0
- package/lib/components/CustomDatePicker.d.ts.map +1 -0
- package/lib/components/CustomDatePicker.js +592 -0
- package/lib/components/CustomDatePicker.js.map +1 -0
- package/lib/components/DocumentationLink.d.ts +1 -1
- package/lib/components/DocumentationLink.js +2 -2
- package/lib/components/DocumentationLink.js.map +1 -1
- package/lib/components/LambdaEditor.d.ts +2 -2
- package/lib/components/LambdaEditor.d.ts.map +1 -1
- package/lib/components/LambdaEditor.js +3 -3
- package/lib/components/LambdaEditor.js.map +1 -1
- package/lib/components/LambdaParameterValuesEditor.d.ts +25 -0
- package/lib/components/LambdaParameterValuesEditor.d.ts.map +1 -0
- package/lib/components/LambdaParameterValuesEditor.js +52 -0
- package/lib/components/LambdaParameterValuesEditor.js.map +1 -0
- package/lib/components/LegendApplicationComponentFrameworkProvider.d.ts +1 -1
- package/lib/components/LegendApplicationComponentFrameworkProvider.js +3 -3
- package/lib/components/LegendApplicationComponentFrameworkProvider.js.map +1 -1
- package/lib/components/LegendApplicationNavigationContextServiceUtils.d.ts +32 -0
- package/lib/components/LegendApplicationNavigationContextServiceUtils.d.ts.map +1 -0
- package/lib/components/LegendApplicationNavigationContextServiceUtils.js +57 -0
- package/lib/components/LegendApplicationNavigationContextServiceUtils.js.map +1 -0
- package/lib/components/NotificationManager.d.ts +1 -1
- package/lib/components/NotificationManager.js +2 -2
- package/lib/components/NotificationManager.js.map +1 -1
- package/lib/components/TextInputEditor.d.ts +2 -2
- package/lib/components/TextInputEditor.d.ts.map +1 -1
- package/lib/components/TextInputEditor.js +2 -2
- package/lib/components/TextInputEditor.js.map +1 -1
- package/lib/components/{AppHeader.d.ts → VirtualAssistant.d.ts} +5 -5
- package/lib/components/VirtualAssistant.d.ts.map +1 -0
- package/lib/components/VirtualAssistant.js +171 -0
- package/lib/components/VirtualAssistant.js.map +1 -0
- package/lib/components/WebApplicationNavigatorProvider.d.ts +2 -2
- package/lib/components/WebApplicationNavigatorProvider.d.ts.map +1 -1
- package/lib/components/WebApplicationNavigatorProvider.js +1 -1
- package/lib/components/WebApplicationNavigatorProvider.js.map +1 -1
- package/lib/components/WebApplicationNavigatorProviderTestUtils.d.ts +2 -2
- package/lib/components/WebApplicationNavigatorProviderTestUtils.d.ts.map +1 -1
- package/lib/components/WebApplicationNavigatorProviderTestUtils.js +3 -2
- package/lib/components/WebApplicationNavigatorProviderTestUtils.js.map +1 -1
- package/lib/const.js +2 -2
- package/lib/const.js.map +1 -1
- package/lib/index.css +2 -2
- package/lib/index.css.map +1 -1
- package/lib/index.d.ts +30 -22
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +32 -22
- package/lib/index.js.map +1 -1
- package/lib/stores/ApplicationEvent.d.ts +9 -7
- package/lib/stores/ApplicationEvent.d.ts.map +1 -1
- package/lib/stores/ApplicationEvent.js +10 -8
- package/lib/stores/ApplicationEvent.js.map +1 -1
- package/lib/stores/ApplicationStore.d.ts +16 -10
- package/lib/stores/ApplicationStore.d.ts.map +1 -1
- package/lib/stores/ApplicationStore.js +28 -23
- package/lib/stores/ApplicationStore.js.map +1 -1
- package/lib/stores/ApplicationStoreTestUtils.d.ts +3 -3
- package/lib/stores/ApplicationStoreTestUtils.d.ts.map +1 -1
- package/lib/stores/ApplicationStoreTestUtils.js +2 -2
- package/lib/stores/ApplicationStoreTestUtils.js.map +1 -1
- package/lib/stores/ApplicationTelemetry.d.ts +1 -1
- package/lib/stores/ApplicationTelemetry.d.ts.map +1 -1
- package/lib/stores/ApplicationTelemetry.js +2 -2
- package/lib/stores/ApplicationTelemetry.js.map +1 -1
- package/lib/stores/CJS__Fuse.cjs +35 -0
- package/lib/stores/CJS__Fuse.cjs.map +1 -0
- package/lib/stores/CJS__Fuse.d.cts +28 -0
- package/lib/stores/CJS__Fuse.d.cts.map +1 -0
- package/lib/stores/LambdaEditorState.d.ts +1 -1
- package/lib/stores/LambdaEditorState.d.ts.map +1 -1
- package/lib/stores/LambdaEditorState.js +2 -2
- package/lib/stores/LambdaEditorState.js.map +1 -1
- package/lib/stores/LambdaParameterState.d.ts +59 -0
- package/lib/stores/LambdaParameterState.d.ts.map +1 -0
- package/lib/stores/LambdaParameterState.js +184 -0
- package/lib/stores/LambdaParameterState.js.map +1 -0
- package/lib/stores/LegendApplicationAssistantService.d.ts +63 -0
- package/lib/stores/LegendApplicationAssistantService.d.ts.map +1 -0
- package/lib/stores/LegendApplicationAssistantService.js +167 -0
- package/lib/stores/LegendApplicationAssistantService.js.map +1 -0
- package/lib/stores/LegendApplicationConfig.d.ts +5 -4
- package/lib/stores/LegendApplicationConfig.d.ts.map +1 -1
- package/lib/stores/LegendApplicationConfig.js +8 -3
- package/lib/stores/LegendApplicationConfig.js.map +1 -1
- package/lib/stores/LegendApplicationDocumentationService.d.ts +70 -0
- package/lib/stores/LegendApplicationDocumentationService.d.ts.map +1 -0
- package/lib/stores/LegendApplicationDocumentationService.js +152 -0
- package/lib/stores/LegendApplicationDocumentationService.js.map +1 -0
- package/lib/stores/LegendApplicationEventService.d.ts +22 -0
- package/lib/stores/LegendApplicationEventService.d.ts.map +1 -0
- package/lib/stores/LegendApplicationEventService.js +25 -0
- package/lib/stores/LegendApplicationEventService.js.map +1 -0
- package/lib/stores/LegendApplicationNavigationContextService.d.ts +74 -0
- package/lib/stores/LegendApplicationNavigationContextService.d.ts.map +1 -0
- package/lib/stores/LegendApplicationNavigationContextService.js +118 -0
- package/lib/stores/LegendApplicationNavigationContextService.js.map +1 -0
- package/lib/stores/LegendApplicationPlugin.d.ts +6 -2
- package/lib/stores/LegendApplicationPlugin.d.ts.map +1 -1
- package/lib/stores/LegendApplicationPlugin.js.map +1 -1
- package/lib/stores/PureLanguageSupport.d.ts.map +1 -1
- package/lib/stores/PureLanguageSupport.js +8 -2
- package/lib/stores/PureLanguageSupport.js.map +1 -1
- package/lib/stores/ValueSpecificationModifierHelper.d.ts +27 -0
- package/lib/stores/ValueSpecificationModifierHelper.d.ts.map +1 -0
- package/lib/stores/ValueSpecificationModifierHelper.js +49 -0
- package/lib/stores/ValueSpecificationModifierHelper.js.map +1 -0
- package/package.json +26 -20
- package/src/application/LegendApplication.tsx +6 -6
- package/src/application/LegendApplicationPluginManager.tsx +3 -3
- package/src/components/ActionAlert.tsx +3 -3
- package/src/components/ApplicationStoreProvider.tsx +4 -4
- package/src/components/ApplicationStoreProviderTestUtils.tsx +7 -6
- package/src/components/BasicValueSpecificationEditor.tsx +703 -0
- package/src/components/BlockingAlert.tsx +1 -1
- package/src/components/CustomDatePicker.tsx +1235 -0
- package/src/components/DocumentationLink.tsx +2 -2
- package/src/components/LambdaEditor.tsx +4 -4
- package/src/components/LambdaParameterValuesEditor.tsx +114 -0
- package/src/components/LegendApplicationComponentFrameworkProvider.tsx +3 -3
- package/src/components/LegendApplicationNavigationContextServiceUtils.tsx +63 -0
- package/src/components/NotificationManager.tsx +2 -2
- package/src/components/TextInputEditor.tsx +2 -2
- package/src/components/VirtualAssistant.tsx +600 -0
- package/src/components/WebApplicationNavigatorProvider.tsx +1 -1
- package/src/components/WebApplicationNavigatorProviderTestUtils.tsx +3 -2
- package/src/index.ts +39 -28
- package/src/stores/ApplicationEvent.ts +11 -7
- package/src/stores/ApplicationStore.ts +31 -29
- package/src/stores/ApplicationStoreTestUtils.ts +4 -4
- package/src/stores/ApplicationTelemetry.ts +2 -2
- package/src/stores/CJS__Fuse.cts +28 -0
- package/src/stores/LambdaEditorState.ts +5 -5
- package/src/stores/LambdaParameterState.ts +314 -0
- package/src/stores/LegendApplicationAssistantService.ts +218 -0
- package/src/stores/LegendApplicationConfig.ts +20 -6
- package/src/stores/LegendApplicationDocumentationService.ts +276 -0
- package/src/stores/LegendApplicationEventService.ts +32 -0
- package/src/stores/LegendApplicationNavigationContextService.ts +131 -0
- package/src/stores/LegendApplicationPlugin.ts +10 -2
- package/src/stores/PureLanguageSupport.ts +8 -2
- package/src/stores/ValueSpecificationModifierHelper.ts +104 -0
- package/tsconfig.json +18 -12
- package/lib/components/AppHeader.d.ts.map +0 -1
- package/lib/components/AppHeader.js +0 -26
- package/lib/components/AppHeader.js.map +0 -1
- package/lib/stores/LegendApplicationDocumentationRegistry.d.ts +0 -36
- package/lib/stores/LegendApplicationDocumentationRegistry.d.ts.map +0 -1
- package/lib/stores/LegendApplicationDocumentationRegistry.js +0 -47
- package/lib/stores/LegendApplicationDocumentationRegistry.js.map +0 -1
- package/src/components/AppHeader.tsx +0 -49
- package/src/stores/LegendApplicationDocumentationRegistry.ts +0 -81
|
@@ -0,0 +1,1235 @@
|
|
|
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
|
+
BasePopover,
|
|
19
|
+
BaseRadioGroup,
|
|
20
|
+
CustomSelectorInput,
|
|
21
|
+
} from '@finos/legend-art';
|
|
22
|
+
import {
|
|
23
|
+
type PureModel,
|
|
24
|
+
type Enum,
|
|
25
|
+
type Type,
|
|
26
|
+
type ValueSpecification,
|
|
27
|
+
PRIMITIVE_TYPE,
|
|
28
|
+
SimpleFunctionExpression,
|
|
29
|
+
InstanceValue,
|
|
30
|
+
GenericType,
|
|
31
|
+
PrimitiveInstanceValue,
|
|
32
|
+
GenericTypeExplicitReference,
|
|
33
|
+
EnumValueExplicitReference,
|
|
34
|
+
EnumValueInstanceValue,
|
|
35
|
+
matchFunctionName,
|
|
36
|
+
TYPICAL_MULTIPLICITY_TYPE,
|
|
37
|
+
SUPPORTED_FUNCTIONS,
|
|
38
|
+
DAY_OF_WEEK,
|
|
39
|
+
buildPrimitiveInstanceValue,
|
|
40
|
+
DURATION_UNIT,
|
|
41
|
+
} from '@finos/legend-graph';
|
|
42
|
+
import {
|
|
43
|
+
guaranteeNonNullable,
|
|
44
|
+
UnsupportedOperationError,
|
|
45
|
+
} from '@finos/legend-shared';
|
|
46
|
+
import { useEffect, useState } from 'react';
|
|
47
|
+
import {
|
|
48
|
+
genericType_setRawType,
|
|
49
|
+
instanceValue_changeValue,
|
|
50
|
+
} from '../stores/ValueSpecificationModifierHelper.js';
|
|
51
|
+
|
|
52
|
+
enum CUSTOM_DATE_PICKER_OPTION {
|
|
53
|
+
ABSOLUTE_DATE = 'Absolute Date',
|
|
54
|
+
ABSOLUTE_TIME = 'Absolute Time',
|
|
55
|
+
TODAY = 'Today',
|
|
56
|
+
NOW = 'Now',
|
|
57
|
+
YESTERDAY = 'Yesterday',
|
|
58
|
+
ONE_YEAR_AGO = 'One Year Ago',
|
|
59
|
+
ONE_MONTH_AGO = 'One Month Ago',
|
|
60
|
+
ONE_WEEK_AGO = 'One Week Ago',
|
|
61
|
+
CUSTOM_DATE = 'Custom Date',
|
|
62
|
+
PREVIOUS_DAY_OF_WEEK = 'Previous ... of Week',
|
|
63
|
+
FIRST_DAY_OF = 'First day of...',
|
|
64
|
+
LATEST_DATE = 'Latest Date',
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
enum CUSTOM_DATE_OPTION_UNIT {
|
|
68
|
+
DAYS = 'Day(s)',
|
|
69
|
+
WEEKS = 'Week(s)',
|
|
70
|
+
MONTHS = 'Month(s)',
|
|
71
|
+
YEARS = 'Year(s)',
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
enum CUSTOM_DATE_FIRST_DAY_OF_UNIT {
|
|
75
|
+
WEEK = 'Week',
|
|
76
|
+
MONTH = 'Month',
|
|
77
|
+
QUARTER = 'Quarter',
|
|
78
|
+
YEAR = 'Year',
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
enum CUSTOM_DATE_DAY_OF_WEEK {
|
|
82
|
+
MONDAY = 'Monday',
|
|
83
|
+
TUESDAY = 'Tuesday',
|
|
84
|
+
WENDNESDAY = 'Wednesday',
|
|
85
|
+
THURSDAY = 'Thursday',
|
|
86
|
+
FRIDAY = 'Friday',
|
|
87
|
+
SATURDAY = 'Saturday',
|
|
88
|
+
SUNDAY = 'Sunday',
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
enum CUSTOM_DATE_OPTION_DIRECTION {
|
|
92
|
+
BEFORE = 'Before',
|
|
93
|
+
AFTER = 'After',
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
enum CUSTOM_DATE_OPTION_REFERENCE_MOMENT {
|
|
97
|
+
TODAY = 'Today',
|
|
98
|
+
NOW = 'Now',
|
|
99
|
+
FIRST_DAY_OF_YEAR = 'Start of Year',
|
|
100
|
+
FIRST_DAY_OF_QUARTER = 'Start of Quarter',
|
|
101
|
+
FIRST_DAY_OF_MONTH = 'Start of Month',
|
|
102
|
+
FIRST_DAY_OF_WEEK = 'Start of Week',
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* DatePickerOption is the base class being used to display and generate the corresponding pure date function.
|
|
107
|
+
*/
|
|
108
|
+
class DatePickerOption {
|
|
109
|
+
/**
|
|
110
|
+
* label is the text that shows up in the valueSpecification box.
|
|
111
|
+
*/
|
|
112
|
+
label: string;
|
|
113
|
+
/**
|
|
114
|
+
* value is the selected date option in date-dropdown.
|
|
115
|
+
*/
|
|
116
|
+
value: string;
|
|
117
|
+
|
|
118
|
+
constructor(label: string, value: string) {
|
|
119
|
+
this.label = label;
|
|
120
|
+
this.value = value;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
class CustomDateOption extends DatePickerOption {
|
|
125
|
+
/**
|
|
126
|
+
* duration is the amount of time span that will be adjusted.
|
|
127
|
+
*/
|
|
128
|
+
duration: number;
|
|
129
|
+
/**
|
|
130
|
+
* unit represents the time duration unit, e.g. year, week, etc.
|
|
131
|
+
*/
|
|
132
|
+
unit: CUSTOM_DATE_OPTION_UNIT | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* direction means the direction in which time adjustment will go to.
|
|
135
|
+
*/
|
|
136
|
+
direction: CUSTOM_DATE_OPTION_DIRECTION | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* referenceMoment is the date which adjustment starts from.
|
|
139
|
+
*/
|
|
140
|
+
referenceMoment: CUSTOM_DATE_OPTION_REFERENCE_MOMENT | undefined;
|
|
141
|
+
|
|
142
|
+
constructor(
|
|
143
|
+
label: string,
|
|
144
|
+
value: string,
|
|
145
|
+
duration: number,
|
|
146
|
+
unit: CUSTOM_DATE_OPTION_UNIT | undefined,
|
|
147
|
+
direction: CUSTOM_DATE_OPTION_DIRECTION | undefined,
|
|
148
|
+
referenceMoment: CUSTOM_DATE_OPTION_REFERENCE_MOMENT | undefined,
|
|
149
|
+
) {
|
|
150
|
+
super(label, value);
|
|
151
|
+
this.duration = duration;
|
|
152
|
+
this.unit = unit;
|
|
153
|
+
this.direction = direction;
|
|
154
|
+
this.referenceMoment = referenceMoment;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
generateDisplayLabel(): string {
|
|
158
|
+
return [
|
|
159
|
+
this.duration,
|
|
160
|
+
this.unit,
|
|
161
|
+
this.direction,
|
|
162
|
+
this.referenceMoment,
|
|
163
|
+
].join(' ');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
updateLabel(): void {
|
|
167
|
+
this.label = this.generateDisplayLabel();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
class CustomFirstDayOfOption extends DatePickerOption {
|
|
172
|
+
/**
|
|
173
|
+
* unit: time unit, e.g. Week, Month, etc.
|
|
174
|
+
*/
|
|
175
|
+
unit: CUSTOM_DATE_FIRST_DAY_OF_UNIT | undefined;
|
|
176
|
+
|
|
177
|
+
constructor(label: string, unit: CUSTOM_DATE_FIRST_DAY_OF_UNIT | undefined) {
|
|
178
|
+
super(label, CUSTOM_DATE_PICKER_OPTION.FIRST_DAY_OF);
|
|
179
|
+
this.unit = unit;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
class CustomPreviousDayOfWeekOption extends DatePickerOption {
|
|
184
|
+
/**
|
|
185
|
+
* day: which day in the week will be selected.
|
|
186
|
+
*/
|
|
187
|
+
day: CUSTOM_DATE_DAY_OF_WEEK;
|
|
188
|
+
|
|
189
|
+
constructor(label: string, day: CUSTOM_DATE_DAY_OF_WEEK) {
|
|
190
|
+
super(label, CUSTOM_DATE_PICKER_OPTION.PREVIOUS_DAY_OF_WEEK);
|
|
191
|
+
this.day = day;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const reservedCustomDateOptions: CustomDateOption[] = [
|
|
196
|
+
new CustomDateOption(
|
|
197
|
+
'Yesterday',
|
|
198
|
+
CUSTOM_DATE_PICKER_OPTION.YESTERDAY,
|
|
199
|
+
1,
|
|
200
|
+
CUSTOM_DATE_OPTION_UNIT.DAYS,
|
|
201
|
+
CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
|
|
202
|
+
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
|
|
203
|
+
),
|
|
204
|
+
new CustomDateOption(
|
|
205
|
+
'One Week Ago',
|
|
206
|
+
CUSTOM_DATE_PICKER_OPTION.ONE_WEEK_AGO,
|
|
207
|
+
1,
|
|
208
|
+
CUSTOM_DATE_OPTION_UNIT.WEEKS,
|
|
209
|
+
CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
|
|
210
|
+
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
|
|
211
|
+
),
|
|
212
|
+
new CustomDateOption(
|
|
213
|
+
'One Month Ago',
|
|
214
|
+
CUSTOM_DATE_PICKER_OPTION.ONE_MONTH_AGO,
|
|
215
|
+
1,
|
|
216
|
+
CUSTOM_DATE_OPTION_UNIT.MONTHS,
|
|
217
|
+
CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
|
|
218
|
+
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
|
|
219
|
+
),
|
|
220
|
+
new CustomDateOption(
|
|
221
|
+
'One Year Ago',
|
|
222
|
+
CUSTOM_DATE_PICKER_OPTION.ONE_YEAR_AGO,
|
|
223
|
+
1,
|
|
224
|
+
CUSTOM_DATE_OPTION_UNIT.YEARS,
|
|
225
|
+
CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
|
|
226
|
+
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
|
|
227
|
+
),
|
|
228
|
+
];
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Generate pure date functions based on the DatePickerOption.
|
|
232
|
+
*/
|
|
233
|
+
const buildPureDateFunctionExpression = (
|
|
234
|
+
datePickerOption: DatePickerOption,
|
|
235
|
+
graph: PureModel,
|
|
236
|
+
): SimpleFunctionExpression => {
|
|
237
|
+
const multiplicityOne = graph.getTypicalMultiplicity(
|
|
238
|
+
TYPICAL_MULTIPLICITY_TYPE.ONE,
|
|
239
|
+
);
|
|
240
|
+
const strictDate = graph.getPrimitiveType(PRIMITIVE_TYPE.STRICTDATE);
|
|
241
|
+
const date = graph.getPrimitiveType(PRIMITIVE_TYPE.DATE);
|
|
242
|
+
const dateTime = graph.getPrimitiveType(PRIMITIVE_TYPE.DATETIME);
|
|
243
|
+
if (datePickerOption instanceof CustomPreviousDayOfWeekOption) {
|
|
244
|
+
const previousFridaySFE = new SimpleFunctionExpression(
|
|
245
|
+
SUPPORTED_FUNCTIONS.PREVIOUS_DAY_OF_WEEK,
|
|
246
|
+
multiplicityOne,
|
|
247
|
+
);
|
|
248
|
+
previousFridaySFE.genericType = GenericTypeExplicitReference.create(
|
|
249
|
+
new GenericType(date),
|
|
250
|
+
);
|
|
251
|
+
const dayOfWeekEnumIntanceValue = new EnumValueInstanceValue(
|
|
252
|
+
GenericTypeExplicitReference.create(
|
|
253
|
+
new GenericType(graph.getType(DAY_OF_WEEK)),
|
|
254
|
+
),
|
|
255
|
+
multiplicityOne,
|
|
256
|
+
);
|
|
257
|
+
dayOfWeekEnumIntanceValue.values.push(
|
|
258
|
+
EnumValueExplicitReference.create(
|
|
259
|
+
guaranteeNonNullable(
|
|
260
|
+
graph
|
|
261
|
+
.getEnumeration(DAY_OF_WEEK)
|
|
262
|
+
.values.filter((e) => e.name === datePickerOption.day)[0],
|
|
263
|
+
),
|
|
264
|
+
),
|
|
265
|
+
);
|
|
266
|
+
previousFridaySFE.parametersValues.push(dayOfWeekEnumIntanceValue);
|
|
267
|
+
return previousFridaySFE;
|
|
268
|
+
} else if (datePickerOption instanceof CustomFirstDayOfOption) {
|
|
269
|
+
switch (datePickerOption.unit) {
|
|
270
|
+
case CUSTOM_DATE_FIRST_DAY_OF_UNIT.YEAR: {
|
|
271
|
+
const firstDayOfYearSFE = new SimpleFunctionExpression(
|
|
272
|
+
SUPPORTED_FUNCTIONS.FIRST_DAY_OF_YEAR,
|
|
273
|
+
multiplicityOne,
|
|
274
|
+
);
|
|
275
|
+
firstDayOfYearSFE.genericType = GenericTypeExplicitReference.create(
|
|
276
|
+
new GenericType(date),
|
|
277
|
+
);
|
|
278
|
+
return firstDayOfYearSFE;
|
|
279
|
+
}
|
|
280
|
+
case CUSTOM_DATE_FIRST_DAY_OF_UNIT.QUARTER: {
|
|
281
|
+
const firstDayOfQuarterSFE = new SimpleFunctionExpression(
|
|
282
|
+
SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER,
|
|
283
|
+
multiplicityOne,
|
|
284
|
+
);
|
|
285
|
+
firstDayOfQuarterSFE.genericType = GenericTypeExplicitReference.create(
|
|
286
|
+
new GenericType(strictDate),
|
|
287
|
+
);
|
|
288
|
+
return firstDayOfQuarterSFE;
|
|
289
|
+
}
|
|
290
|
+
case CUSTOM_DATE_FIRST_DAY_OF_UNIT.MONTH: {
|
|
291
|
+
const firstDayOfMonthSFE = new SimpleFunctionExpression(
|
|
292
|
+
SUPPORTED_FUNCTIONS.FIRST_DAY_OF_MONTH,
|
|
293
|
+
multiplicityOne,
|
|
294
|
+
);
|
|
295
|
+
firstDayOfMonthSFE.genericType = GenericTypeExplicitReference.create(
|
|
296
|
+
new GenericType(date),
|
|
297
|
+
);
|
|
298
|
+
return firstDayOfMonthSFE;
|
|
299
|
+
}
|
|
300
|
+
case CUSTOM_DATE_FIRST_DAY_OF_UNIT.WEEK: {
|
|
301
|
+
const firstDayOfWeekSFE = new SimpleFunctionExpression(
|
|
302
|
+
SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK,
|
|
303
|
+
multiplicityOne,
|
|
304
|
+
);
|
|
305
|
+
firstDayOfWeekSFE.genericType = GenericTypeExplicitReference.create(
|
|
306
|
+
new GenericType(date),
|
|
307
|
+
);
|
|
308
|
+
return firstDayOfWeekSFE;
|
|
309
|
+
}
|
|
310
|
+
default:
|
|
311
|
+
throw new UnsupportedOperationError(
|
|
312
|
+
`Can't build expression for 'First Day Of ...' date picker option for unit '${datePickerOption.unit}'`,
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
switch (datePickerOption.value) {
|
|
317
|
+
case CUSTOM_DATE_PICKER_OPTION.TODAY: {
|
|
318
|
+
const todaySFE = new SimpleFunctionExpression(
|
|
319
|
+
SUPPORTED_FUNCTIONS.TODAY,
|
|
320
|
+
multiplicityOne,
|
|
321
|
+
);
|
|
322
|
+
todaySFE.genericType = GenericTypeExplicitReference.create(
|
|
323
|
+
new GenericType(strictDate),
|
|
324
|
+
);
|
|
325
|
+
return todaySFE;
|
|
326
|
+
}
|
|
327
|
+
case CUSTOM_DATE_PICKER_OPTION.NOW: {
|
|
328
|
+
const nowSFE = new SimpleFunctionExpression(
|
|
329
|
+
SUPPORTED_FUNCTIONS.NOW,
|
|
330
|
+
multiplicityOne,
|
|
331
|
+
);
|
|
332
|
+
nowSFE.genericType = GenericTypeExplicitReference.create(
|
|
333
|
+
new GenericType(dateTime),
|
|
334
|
+
);
|
|
335
|
+
return nowSFE;
|
|
336
|
+
}
|
|
337
|
+
case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_YEAR: {
|
|
338
|
+
const firstDayOfYearSFE = new SimpleFunctionExpression(
|
|
339
|
+
SUPPORTED_FUNCTIONS.FIRST_DAY_OF_YEAR,
|
|
340
|
+
multiplicityOne,
|
|
341
|
+
);
|
|
342
|
+
firstDayOfYearSFE.genericType = GenericTypeExplicitReference.create(
|
|
343
|
+
new GenericType(date),
|
|
344
|
+
);
|
|
345
|
+
return firstDayOfYearSFE;
|
|
346
|
+
}
|
|
347
|
+
case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_QUARTER: {
|
|
348
|
+
const firstDayOfQuarterSFE = new SimpleFunctionExpression(
|
|
349
|
+
SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER,
|
|
350
|
+
multiplicityOne,
|
|
351
|
+
);
|
|
352
|
+
firstDayOfQuarterSFE.genericType = GenericTypeExplicitReference.create(
|
|
353
|
+
new GenericType(strictDate),
|
|
354
|
+
);
|
|
355
|
+
return firstDayOfQuarterSFE;
|
|
356
|
+
}
|
|
357
|
+
case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_MONTH: {
|
|
358
|
+
const firstDayOfMonthSFE = new SimpleFunctionExpression(
|
|
359
|
+
SUPPORTED_FUNCTIONS.FIRST_DAY_OF_MONTH,
|
|
360
|
+
multiplicityOne,
|
|
361
|
+
);
|
|
362
|
+
firstDayOfMonthSFE.genericType = GenericTypeExplicitReference.create(
|
|
363
|
+
new GenericType(date),
|
|
364
|
+
);
|
|
365
|
+
return firstDayOfMonthSFE;
|
|
366
|
+
}
|
|
367
|
+
case CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_WEEK: {
|
|
368
|
+
const firstDayOfWeekSFE = new SimpleFunctionExpression(
|
|
369
|
+
SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK,
|
|
370
|
+
multiplicityOne,
|
|
371
|
+
);
|
|
372
|
+
firstDayOfWeekSFE.genericType = GenericTypeExplicitReference.create(
|
|
373
|
+
new GenericType(date),
|
|
374
|
+
);
|
|
375
|
+
return firstDayOfWeekSFE;
|
|
376
|
+
}
|
|
377
|
+
default:
|
|
378
|
+
throw new UnsupportedOperationError(
|
|
379
|
+
`Can't build expression for date picker option '${datePickerOption.value}'`,
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Generate the enum value of type Pure Enum, DURATION_UNIT, based on the input string.
|
|
387
|
+
*/
|
|
388
|
+
const buildPureDurationEnumValue = (
|
|
389
|
+
unitString: string,
|
|
390
|
+
graph: PureModel,
|
|
391
|
+
): Enum => {
|
|
392
|
+
const durationUnitEnum = graph.getEnumeration(DURATION_UNIT);
|
|
393
|
+
const targetPureDurationEnumValue = durationUnitEnum.values.filter(
|
|
394
|
+
(e) =>
|
|
395
|
+
e.name ===
|
|
396
|
+
Object.keys(CUSTOM_DATE_OPTION_UNIT).filter(
|
|
397
|
+
(key) =>
|
|
398
|
+
CUSTOM_DATE_OPTION_UNIT[
|
|
399
|
+
key as keyof typeof CUSTOM_DATE_OPTION_UNIT
|
|
400
|
+
] === unitString,
|
|
401
|
+
)[0],
|
|
402
|
+
)[0];
|
|
403
|
+
return (
|
|
404
|
+
targetPureDurationEnumValue ??
|
|
405
|
+
guaranteeNonNullable(durationUnitEnum.values[0])
|
|
406
|
+
);
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Generate the pure date ajust() function based on the CustomDateOption.
|
|
411
|
+
*/
|
|
412
|
+
const buildPureAdjustDateFunction = (
|
|
413
|
+
customDateOption: CustomDateOption,
|
|
414
|
+
graph: PureModel,
|
|
415
|
+
): SimpleFunctionExpression => {
|
|
416
|
+
const multiplicityOne = graph.getTypicalMultiplicity(
|
|
417
|
+
TYPICAL_MULTIPLICITY_TYPE.ONE,
|
|
418
|
+
);
|
|
419
|
+
const dateAdjustSimpleFunctionExpression = new SimpleFunctionExpression(
|
|
420
|
+
SUPPORTED_FUNCTIONS.ADJUST,
|
|
421
|
+
multiplicityOne,
|
|
422
|
+
);
|
|
423
|
+
dateAdjustSimpleFunctionExpression.parametersValues.push(
|
|
424
|
+
buildPureDateFunctionExpression(
|
|
425
|
+
new DatePickerOption(
|
|
426
|
+
guaranteeNonNullable(customDateOption.referenceMoment),
|
|
427
|
+
guaranteeNonNullable(customDateOption.referenceMoment),
|
|
428
|
+
),
|
|
429
|
+
graph,
|
|
430
|
+
),
|
|
431
|
+
);
|
|
432
|
+
if (customDateOption.direction === CUSTOM_DATE_OPTION_DIRECTION.BEFORE) {
|
|
433
|
+
const minusFunc = new SimpleFunctionExpression(
|
|
434
|
+
SUPPORTED_FUNCTIONS.MINUS,
|
|
435
|
+
multiplicityOne,
|
|
436
|
+
);
|
|
437
|
+
minusFunc.parametersValues.push(
|
|
438
|
+
buildPrimitiveInstanceValue(
|
|
439
|
+
graph,
|
|
440
|
+
PRIMITIVE_TYPE.INTEGER,
|
|
441
|
+
customDateOption.duration,
|
|
442
|
+
),
|
|
443
|
+
);
|
|
444
|
+
dateAdjustSimpleFunctionExpression.parametersValues.push(minusFunc);
|
|
445
|
+
} else {
|
|
446
|
+
const adjustmentInstanceValue = buildPrimitiveInstanceValue(
|
|
447
|
+
graph,
|
|
448
|
+
PRIMITIVE_TYPE.INTEGER,
|
|
449
|
+
customDateOption.duration,
|
|
450
|
+
);
|
|
451
|
+
dateAdjustSimpleFunctionExpression.parametersValues.push(
|
|
452
|
+
adjustmentInstanceValue,
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
const durationUnitEnumIntanceValue = new EnumValueInstanceValue(
|
|
456
|
+
GenericTypeExplicitReference.create(
|
|
457
|
+
new GenericType(graph.getType(DURATION_UNIT)),
|
|
458
|
+
),
|
|
459
|
+
multiplicityOne,
|
|
460
|
+
);
|
|
461
|
+
durationUnitEnumIntanceValue.values.push(
|
|
462
|
+
EnumValueExplicitReference.create(
|
|
463
|
+
guaranteeNonNullable(
|
|
464
|
+
buildPureDurationEnumValue(
|
|
465
|
+
guaranteeNonNullable(customDateOption.unit),
|
|
466
|
+
graph,
|
|
467
|
+
),
|
|
468
|
+
),
|
|
469
|
+
),
|
|
470
|
+
);
|
|
471
|
+
dateAdjustSimpleFunctionExpression.parametersValues.push(
|
|
472
|
+
durationUnitEnumIntanceValue,
|
|
473
|
+
);
|
|
474
|
+
dateAdjustSimpleFunctionExpression.genericType =
|
|
475
|
+
GenericTypeExplicitReference.create(
|
|
476
|
+
new GenericType(graph.getPrimitiveType(PRIMITIVE_TYPE.DATE)),
|
|
477
|
+
);
|
|
478
|
+
return dateAdjustSimpleFunctionExpression;
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Generate the value of CustomDateOption.duration from the pure date adjust() function.
|
|
483
|
+
*/
|
|
484
|
+
const buildCustomDateOptionDurationValue = (
|
|
485
|
+
pureDateAdjustFunction: SimpleFunctionExpression,
|
|
486
|
+
): number => {
|
|
487
|
+
const durationParam = pureDateAdjustFunction.parametersValues[1];
|
|
488
|
+
return durationParam instanceof PrimitiveInstanceValue
|
|
489
|
+
? (durationParam.values[0] as number)
|
|
490
|
+
: durationParam instanceof SimpleFunctionExpression &&
|
|
491
|
+
matchFunctionName(durationParam.functionName, SUPPORTED_FUNCTIONS.MINUS)
|
|
492
|
+
? durationParam.parametersValues[0] instanceof PrimitiveInstanceValue
|
|
493
|
+
? (durationParam.parametersValues[0].values[0] as number)
|
|
494
|
+
: 0
|
|
495
|
+
: 0;
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Generate the value of CustomDateOption.direction from the pure date adjust() function.
|
|
500
|
+
*/
|
|
501
|
+
const buildCustomDateOptionDirectionValue = (
|
|
502
|
+
pureDateAdjustFunction: SimpleFunctionExpression,
|
|
503
|
+
): CUSTOM_DATE_OPTION_DIRECTION =>
|
|
504
|
+
pureDateAdjustFunction.parametersValues[1] instanceof
|
|
505
|
+
SimpleFunctionExpression &&
|
|
506
|
+
matchFunctionName(
|
|
507
|
+
pureDateAdjustFunction.parametersValues[1].functionName,
|
|
508
|
+
SUPPORTED_FUNCTIONS.MINUS,
|
|
509
|
+
)
|
|
510
|
+
? CUSTOM_DATE_OPTION_DIRECTION.BEFORE
|
|
511
|
+
: CUSTOM_DATE_OPTION_DIRECTION.AFTER;
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Generate the value of CustomDateOption.unit from the pure date adjust() function.
|
|
515
|
+
*/
|
|
516
|
+
const buildCustomDateOptionUnitValue = (
|
|
517
|
+
valueSpecification: SimpleFunctionExpression,
|
|
518
|
+
): CUSTOM_DATE_OPTION_UNIT =>
|
|
519
|
+
guaranteeNonNullable(
|
|
520
|
+
Object.keys(CUSTOM_DATE_OPTION_UNIT)
|
|
521
|
+
.filter(
|
|
522
|
+
(key) =>
|
|
523
|
+
key ===
|
|
524
|
+
(valueSpecification.parametersValues[2] as EnumValueInstanceValue)
|
|
525
|
+
.values[0]?.value.name,
|
|
526
|
+
)
|
|
527
|
+
.map(
|
|
528
|
+
(key) =>
|
|
529
|
+
CUSTOM_DATE_OPTION_UNIT[key as keyof typeof CUSTOM_DATE_OPTION_UNIT],
|
|
530
|
+
)[0],
|
|
531
|
+
);
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Generate the value of CustomDateOption.moment from the pure date adjust() function.
|
|
535
|
+
*/
|
|
536
|
+
const buildCustomDateOptionReferenceMomentValue = (
|
|
537
|
+
pureDateAjustFunction: SimpleFunctionExpression,
|
|
538
|
+
): CUSTOM_DATE_OPTION_REFERENCE_MOMENT => {
|
|
539
|
+
const funcName = (
|
|
540
|
+
pureDateAjustFunction.parametersValues[0] as SimpleFunctionExpression
|
|
541
|
+
).functionName;
|
|
542
|
+
switch (funcName) {
|
|
543
|
+
case SUPPORTED_FUNCTIONS.TODAY:
|
|
544
|
+
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY;
|
|
545
|
+
case SUPPORTED_FUNCTIONS.NOW:
|
|
546
|
+
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.NOW;
|
|
547
|
+
case SUPPORTED_FUNCTIONS.FIRST_DAY_OF_YEAR:
|
|
548
|
+
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_YEAR;
|
|
549
|
+
case SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER:
|
|
550
|
+
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_QUARTER;
|
|
551
|
+
case SUPPORTED_FUNCTIONS.FIRST_DAY_OF_MONTH:
|
|
552
|
+
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_MONTH;
|
|
553
|
+
case SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK:
|
|
554
|
+
return CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_WEEK;
|
|
555
|
+
default:
|
|
556
|
+
throw new UnsupportedOperationError(
|
|
557
|
+
`Can't build custom date option reference moment '${funcName}'`,
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Build CustomDateOption based on the pure date adjust() function.
|
|
564
|
+
* Transform CustomDateOption if it matches any preserved custom adjust date functions. e.g. One Month Ago..
|
|
565
|
+
*/
|
|
566
|
+
const buildCustomDateOption = (
|
|
567
|
+
valueSpecification: SimpleFunctionExpression | PrimitiveInstanceValue,
|
|
568
|
+
): CustomDateOption => {
|
|
569
|
+
if (
|
|
570
|
+
valueSpecification instanceof SimpleFunctionExpression &&
|
|
571
|
+
matchFunctionName(
|
|
572
|
+
valueSpecification.functionName,
|
|
573
|
+
SUPPORTED_FUNCTIONS.ADJUST,
|
|
574
|
+
)
|
|
575
|
+
) {
|
|
576
|
+
const customDateOption = new CustomDateOption(
|
|
577
|
+
'',
|
|
578
|
+
CUSTOM_DATE_PICKER_OPTION.CUSTOM_DATE,
|
|
579
|
+
buildCustomDateOptionDurationValue(valueSpecification),
|
|
580
|
+
buildCustomDateOptionUnitValue(valueSpecification),
|
|
581
|
+
buildCustomDateOptionDirectionValue(valueSpecification),
|
|
582
|
+
buildCustomDateOptionReferenceMomentValue(valueSpecification),
|
|
583
|
+
);
|
|
584
|
+
const matchedPreservedCustomAdjustDates = reservedCustomDateOptions.filter(
|
|
585
|
+
(t) =>
|
|
586
|
+
t.generateDisplayLabel() === customDateOption.generateDisplayLabel(),
|
|
587
|
+
);
|
|
588
|
+
if (matchedPreservedCustomAdjustDates.length > 0) {
|
|
589
|
+
customDateOption.label = guaranteeNonNullable(
|
|
590
|
+
matchedPreservedCustomAdjustDates[0]?.label,
|
|
591
|
+
);
|
|
592
|
+
customDateOption.value = guaranteeNonNullable(
|
|
593
|
+
matchedPreservedCustomAdjustDates[0]?.value,
|
|
594
|
+
);
|
|
595
|
+
return customDateOption;
|
|
596
|
+
}
|
|
597
|
+
customDateOption.updateLabel();
|
|
598
|
+
return customDateOption;
|
|
599
|
+
}
|
|
600
|
+
return new CustomDateOption('', '', 0, undefined, undefined, undefined);
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Build DatePickerOption from pure date functions or PrimitiveInstanceValue
|
|
605
|
+
*/
|
|
606
|
+
const buildDatePickerOption = (
|
|
607
|
+
valueSpecification: SimpleFunctionExpression | PrimitiveInstanceValue,
|
|
608
|
+
): DatePickerOption => {
|
|
609
|
+
if (valueSpecification instanceof SimpleFunctionExpression) {
|
|
610
|
+
switch (valueSpecification.functionName) {
|
|
611
|
+
case SUPPORTED_FUNCTIONS.TODAY:
|
|
612
|
+
return new DatePickerOption(
|
|
613
|
+
CUSTOM_DATE_PICKER_OPTION.TODAY,
|
|
614
|
+
CUSTOM_DATE_PICKER_OPTION.TODAY,
|
|
615
|
+
);
|
|
616
|
+
case SUPPORTED_FUNCTIONS.NOW:
|
|
617
|
+
return new DatePickerOption(
|
|
618
|
+
CUSTOM_DATE_PICKER_OPTION.NOW,
|
|
619
|
+
CUSTOM_DATE_PICKER_OPTION.NOW,
|
|
620
|
+
);
|
|
621
|
+
case SUPPORTED_FUNCTIONS.FIRST_DAY_OF_YEAR:
|
|
622
|
+
return new CustomFirstDayOfOption(
|
|
623
|
+
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_YEAR,
|
|
624
|
+
CUSTOM_DATE_FIRST_DAY_OF_UNIT.YEAR,
|
|
625
|
+
);
|
|
626
|
+
case SUPPORTED_FUNCTIONS.FIRST_DAY_OF_QUARTER:
|
|
627
|
+
return new CustomFirstDayOfOption(
|
|
628
|
+
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_QUARTER,
|
|
629
|
+
CUSTOM_DATE_FIRST_DAY_OF_UNIT.QUARTER,
|
|
630
|
+
);
|
|
631
|
+
case SUPPORTED_FUNCTIONS.FIRST_DAY_OF_MONTH:
|
|
632
|
+
return new CustomFirstDayOfOption(
|
|
633
|
+
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_MONTH,
|
|
634
|
+
CUSTOM_DATE_FIRST_DAY_OF_UNIT.MONTH,
|
|
635
|
+
);
|
|
636
|
+
case SUPPORTED_FUNCTIONS.FIRST_DAY_OF_WEEK:
|
|
637
|
+
return new CustomFirstDayOfOption(
|
|
638
|
+
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.FIRST_DAY_OF_WEEK,
|
|
639
|
+
CUSTOM_DATE_FIRST_DAY_OF_UNIT.WEEK,
|
|
640
|
+
);
|
|
641
|
+
case SUPPORTED_FUNCTIONS.PREVIOUS_DAY_OF_WEEK:
|
|
642
|
+
return new CustomPreviousDayOfWeekOption(
|
|
643
|
+
`Previous ${
|
|
644
|
+
(valueSpecification.parametersValues[0] as EnumValueInstanceValue)
|
|
645
|
+
.values[0]?.value.name
|
|
646
|
+
}`,
|
|
647
|
+
(valueSpecification.parametersValues[0] as EnumValueInstanceValue)
|
|
648
|
+
.values[0]?.value.name as CUSTOM_DATE_DAY_OF_WEEK,
|
|
649
|
+
);
|
|
650
|
+
|
|
651
|
+
case SUPPORTED_FUNCTIONS.ADJUST:
|
|
652
|
+
return buildCustomDateOption(valueSpecification);
|
|
653
|
+
default:
|
|
654
|
+
return new DatePickerOption('', '');
|
|
655
|
+
}
|
|
656
|
+
} else {
|
|
657
|
+
return valueSpecification.genericType.value.rawType.path ===
|
|
658
|
+
PRIMITIVE_TYPE.LATESTDATE
|
|
659
|
+
? new DatePickerOption(
|
|
660
|
+
CUSTOM_DATE_PICKER_OPTION.LATEST_DATE,
|
|
661
|
+
CUSTOM_DATE_PICKER_OPTION.LATEST_DATE,
|
|
662
|
+
)
|
|
663
|
+
: new DatePickerOption(
|
|
664
|
+
valueSpecification.values[0] as string,
|
|
665
|
+
valueSpecification.genericType.value.rawType.path ===
|
|
666
|
+
PRIMITIVE_TYPE.DATETIME
|
|
667
|
+
? CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_TIME
|
|
668
|
+
: CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_DATE,
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
const AbsoluteDateValueSpecificationEditor: React.FC<{
|
|
674
|
+
valueSpecification: SimpleFunctionExpression | PrimitiveInstanceValue;
|
|
675
|
+
graph: PureModel;
|
|
676
|
+
updateValue: (val: ValueSpecification) => void;
|
|
677
|
+
setDatePickerOption: (datePickerOption: DatePickerOption) => void;
|
|
678
|
+
}> = (props) => {
|
|
679
|
+
const { valueSpecification, graph, updateValue, setDatePickerOption } = props;
|
|
680
|
+
const absoluteDateValue =
|
|
681
|
+
valueSpecification instanceof SimpleFunctionExpression
|
|
682
|
+
? ''
|
|
683
|
+
: (valueSpecification.values[0] as string);
|
|
684
|
+
const updateAbsoluteDateValue: React.ChangeEventHandler<HTMLInputElement> = (
|
|
685
|
+
event,
|
|
686
|
+
) => {
|
|
687
|
+
if (valueSpecification instanceof SimpleFunctionExpression) {
|
|
688
|
+
updateValue(
|
|
689
|
+
buildPrimitiveInstanceValue(
|
|
690
|
+
graph,
|
|
691
|
+
PRIMITIVE_TYPE.STRICTDATE,
|
|
692
|
+
event.target.value,
|
|
693
|
+
),
|
|
694
|
+
);
|
|
695
|
+
} else if (valueSpecification instanceof InstanceValue) {
|
|
696
|
+
instanceValue_changeValue(valueSpecification, event.target.value, 0);
|
|
697
|
+
if (
|
|
698
|
+
valueSpecification.genericType.value.rawType.path !==
|
|
699
|
+
PRIMITIVE_TYPE.STRICTDATE
|
|
700
|
+
) {
|
|
701
|
+
genericType_setRawType(
|
|
702
|
+
valueSpecification.genericType.value,
|
|
703
|
+
graph.getPrimitiveType(PRIMITIVE_TYPE.STRICTDATE),
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
setDatePickerOption(
|
|
708
|
+
new DatePickerOption(
|
|
709
|
+
event.target.value,
|
|
710
|
+
CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_DATE,
|
|
711
|
+
),
|
|
712
|
+
);
|
|
713
|
+
};
|
|
714
|
+
return (
|
|
715
|
+
<div className="value-spec-editor__date-picker__absolute-date">
|
|
716
|
+
<input
|
|
717
|
+
className="panel__content__form__section__input value-spec-editor__date-picker__absolute-date__input input--dark"
|
|
718
|
+
type="date"
|
|
719
|
+
spellCheck={false}
|
|
720
|
+
value={absoluteDateValue}
|
|
721
|
+
onChange={updateAbsoluteDateValue}
|
|
722
|
+
/>
|
|
723
|
+
</div>
|
|
724
|
+
);
|
|
725
|
+
};
|
|
726
|
+
|
|
727
|
+
const AbsoluteTimeValueSpecificationEditor: React.FC<{
|
|
728
|
+
valueSpecification: SimpleFunctionExpression | PrimitiveInstanceValue;
|
|
729
|
+
graph: PureModel;
|
|
730
|
+
updateValue: (val: ValueSpecification) => void;
|
|
731
|
+
setDatePickerOption: (datePickerOption: DatePickerOption) => void;
|
|
732
|
+
}> = (props) => {
|
|
733
|
+
const { valueSpecification, graph, updateValue, setDatePickerOption } = props;
|
|
734
|
+
const absoluteTimeValue =
|
|
735
|
+
valueSpecification instanceof SimpleFunctionExpression
|
|
736
|
+
? ''
|
|
737
|
+
: (valueSpecification.values[0] as string);
|
|
738
|
+
const updateAbsoluteTimeValue: React.ChangeEventHandler<HTMLInputElement> = (
|
|
739
|
+
event,
|
|
740
|
+
) => {
|
|
741
|
+
if (valueSpecification instanceof SimpleFunctionExpression) {
|
|
742
|
+
updateValue(
|
|
743
|
+
buildPrimitiveInstanceValue(
|
|
744
|
+
graph,
|
|
745
|
+
PRIMITIVE_TYPE.DATETIME,
|
|
746
|
+
event.target.value,
|
|
747
|
+
),
|
|
748
|
+
);
|
|
749
|
+
} else {
|
|
750
|
+
instanceValue_changeValue(valueSpecification, event.target.value, 0);
|
|
751
|
+
if (
|
|
752
|
+
valueSpecification.genericType.value.rawType.path !==
|
|
753
|
+
PRIMITIVE_TYPE.DATETIME
|
|
754
|
+
) {
|
|
755
|
+
genericType_setRawType(
|
|
756
|
+
valueSpecification.genericType.value,
|
|
757
|
+
graph.getPrimitiveType(PRIMITIVE_TYPE.DATETIME),
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
setDatePickerOption(
|
|
762
|
+
new DatePickerOption(
|
|
763
|
+
event.target.value,
|
|
764
|
+
CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_TIME,
|
|
765
|
+
),
|
|
766
|
+
);
|
|
767
|
+
};
|
|
768
|
+
return (
|
|
769
|
+
<div className="value-spec-editor__date-picker__absolute-date">
|
|
770
|
+
<input
|
|
771
|
+
className="panel__content__form__section__input value-spec-editor__date-picker__absolute-date__input input--dark"
|
|
772
|
+
// Despite its name this would actually allow us to register time in UTC
|
|
773
|
+
// See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local#setting_timezones
|
|
774
|
+
type="datetime-local"
|
|
775
|
+
spellCheck={false}
|
|
776
|
+
value={absoluteTimeValue}
|
|
777
|
+
onChange={updateAbsoluteTimeValue}
|
|
778
|
+
/>
|
|
779
|
+
</div>
|
|
780
|
+
);
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
const CustomDateInstanceValueEditor: React.FC<{
|
|
784
|
+
customDateOptionValue: CustomDateOption;
|
|
785
|
+
graph: PureModel;
|
|
786
|
+
updateValue: (val: ValueSpecification) => void;
|
|
787
|
+
setDatePickerOption: (datePickerOption: DatePickerOption) => void;
|
|
788
|
+
}> = (props) => {
|
|
789
|
+
const { customDateOptionValue, graph, updateValue, setDatePickerOption } =
|
|
790
|
+
props;
|
|
791
|
+
const [durationValue, setDurationValue] = useState(
|
|
792
|
+
customDateOptionValue.duration,
|
|
793
|
+
);
|
|
794
|
+
const [unitValue, setUnitValue] = useState(
|
|
795
|
+
customDateOptionValue.unit ?? CUSTOM_DATE_OPTION_UNIT.DAYS,
|
|
796
|
+
);
|
|
797
|
+
const [directionValue, setDirectionValue] = useState(
|
|
798
|
+
customDateOptionValue.direction ?? CUSTOM_DATE_OPTION_DIRECTION.BEFORE,
|
|
799
|
+
);
|
|
800
|
+
const [referenceMomentValue, setReferenceMomentValueValue] = useState(
|
|
801
|
+
customDateOptionValue.referenceMoment ??
|
|
802
|
+
CUSTOM_DATE_OPTION_REFERENCE_MOMENT.TODAY,
|
|
803
|
+
);
|
|
804
|
+
const changeValue = (
|
|
805
|
+
latestDurationValue: number,
|
|
806
|
+
latestUnitValue: string,
|
|
807
|
+
latestDirectionValue: string,
|
|
808
|
+
latestReferenceMomentValue: string,
|
|
809
|
+
): void => {
|
|
810
|
+
if (
|
|
811
|
+
latestDurationValue !== 0 &&
|
|
812
|
+
latestUnitValue !== '' &&
|
|
813
|
+
latestDirectionValue !== '' &&
|
|
814
|
+
latestReferenceMomentValue !== ''
|
|
815
|
+
) {
|
|
816
|
+
const dateOption = new CustomDateOption(
|
|
817
|
+
CUSTOM_DATE_PICKER_OPTION.CUSTOM_DATE,
|
|
818
|
+
CUSTOM_DATE_PICKER_OPTION.CUSTOM_DATE,
|
|
819
|
+
latestDurationValue,
|
|
820
|
+
latestUnitValue as CUSTOM_DATE_OPTION_UNIT,
|
|
821
|
+
latestDirectionValue as CUSTOM_DATE_OPTION_DIRECTION,
|
|
822
|
+
latestReferenceMomentValue as CUSTOM_DATE_OPTION_REFERENCE_MOMENT,
|
|
823
|
+
);
|
|
824
|
+
updateValue(buildPureAdjustDateFunction(dateOption, graph));
|
|
825
|
+
const matchedPreservedCustomAdjustDates =
|
|
826
|
+
reservedCustomDateOptions.filter(
|
|
827
|
+
(t) => t.generateDisplayLabel() === dateOption.generateDisplayLabel(),
|
|
828
|
+
);
|
|
829
|
+
if (matchedPreservedCustomAdjustDates.length > 0) {
|
|
830
|
+
dateOption.label = guaranteeNonNullable(
|
|
831
|
+
matchedPreservedCustomAdjustDates[0]?.label,
|
|
832
|
+
);
|
|
833
|
+
dateOption.value = guaranteeNonNullable(
|
|
834
|
+
matchedPreservedCustomAdjustDates[0]?.value,
|
|
835
|
+
);
|
|
836
|
+
} else {
|
|
837
|
+
dateOption.updateLabel();
|
|
838
|
+
}
|
|
839
|
+
setDatePickerOption(dateOption);
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
const changeDurationValue: React.ChangeEventHandler<HTMLInputElement> = (
|
|
843
|
+
event,
|
|
844
|
+
) => {
|
|
845
|
+
const duration =
|
|
846
|
+
event.target.value !== '' ? parseInt(event.target.value) : 0;
|
|
847
|
+
setDurationValue(duration);
|
|
848
|
+
changeValue(duration, unitValue, directionValue, referenceMomentValue);
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
return (
|
|
852
|
+
<div className="value-spec-editor__date-picker__custom-date">
|
|
853
|
+
<div className="value-spec-editor__date-picker__custom-date__input">
|
|
854
|
+
<input
|
|
855
|
+
className="value-spec-editor__date-picker__custom-date__input-text-editor input--dark"
|
|
856
|
+
spellCheck={false}
|
|
857
|
+
value={durationValue}
|
|
858
|
+
type="number"
|
|
859
|
+
onChange={changeDurationValue}
|
|
860
|
+
/>
|
|
861
|
+
</div>
|
|
862
|
+
<div className="value-spec-editor__date-picker__custom-date__input">
|
|
863
|
+
<CustomSelectorInput
|
|
864
|
+
placeholder="Unit"
|
|
865
|
+
className="value-spec-editor__date-picker__custom-date__input-dropdown"
|
|
866
|
+
options={Object.values(CUSTOM_DATE_OPTION_UNIT).map((t) => ({
|
|
867
|
+
value: t.toString(),
|
|
868
|
+
label: t.toString(),
|
|
869
|
+
}))}
|
|
870
|
+
onChange={(val: {
|
|
871
|
+
label: string;
|
|
872
|
+
value: CUSTOM_DATE_OPTION_UNIT;
|
|
873
|
+
}): void => {
|
|
874
|
+
setUnitValue(val.value);
|
|
875
|
+
changeValue(
|
|
876
|
+
durationValue,
|
|
877
|
+
val.value,
|
|
878
|
+
directionValue,
|
|
879
|
+
referenceMomentValue,
|
|
880
|
+
);
|
|
881
|
+
}}
|
|
882
|
+
value={{ value: unitValue, label: unitValue }}
|
|
883
|
+
darkMode={true}
|
|
884
|
+
/>
|
|
885
|
+
</div>
|
|
886
|
+
<div className="value-spec-editor__date-picker__custom-date__input">
|
|
887
|
+
<CustomSelectorInput
|
|
888
|
+
className="value-spec-editor__date-picker__custom-date__input-dropdown"
|
|
889
|
+
options={Object.values(CUSTOM_DATE_OPTION_DIRECTION).map((t) => ({
|
|
890
|
+
value: t.toString(),
|
|
891
|
+
label: t.toString(),
|
|
892
|
+
}))}
|
|
893
|
+
onChange={(val: {
|
|
894
|
+
label: string;
|
|
895
|
+
value: CUSTOM_DATE_OPTION_DIRECTION;
|
|
896
|
+
}): void => {
|
|
897
|
+
setDirectionValue(val.value);
|
|
898
|
+
changeValue(
|
|
899
|
+
durationValue,
|
|
900
|
+
unitValue,
|
|
901
|
+
val.value,
|
|
902
|
+
referenceMomentValue,
|
|
903
|
+
);
|
|
904
|
+
}}
|
|
905
|
+
value={{ value: directionValue, label: directionValue }}
|
|
906
|
+
darkMode={true}
|
|
907
|
+
/>
|
|
908
|
+
</div>
|
|
909
|
+
<div className="value-spec-editor__date-picker__custom-date__input">
|
|
910
|
+
<CustomSelectorInput
|
|
911
|
+
className="value-spec-editor__date-picker__custom-date__input-dropdown"
|
|
912
|
+
options={Object.values(CUSTOM_DATE_OPTION_REFERENCE_MOMENT).map(
|
|
913
|
+
(t) => ({
|
|
914
|
+
value: t.toString(),
|
|
915
|
+
label: t.toString(),
|
|
916
|
+
}),
|
|
917
|
+
)}
|
|
918
|
+
onChange={(val: {
|
|
919
|
+
label: string;
|
|
920
|
+
value: CUSTOM_DATE_OPTION_REFERENCE_MOMENT;
|
|
921
|
+
}): void => {
|
|
922
|
+
setReferenceMomentValueValue(val.value);
|
|
923
|
+
changeValue(durationValue, unitValue, directionValue, val.value);
|
|
924
|
+
}}
|
|
925
|
+
value={{ value: referenceMomentValue, label: referenceMomentValue }}
|
|
926
|
+
darkMode={true}
|
|
927
|
+
/>
|
|
928
|
+
</div>
|
|
929
|
+
</div>
|
|
930
|
+
);
|
|
931
|
+
};
|
|
932
|
+
|
|
933
|
+
const CustomFirstDayOfValueSpecificationEditor: React.FC<{
|
|
934
|
+
customDateAdjustOptionValue: DatePickerOption;
|
|
935
|
+
graph: PureModel;
|
|
936
|
+
updateValue: (val: ValueSpecification) => void;
|
|
937
|
+
setDatePickerOption: (datePickerOption: DatePickerOption) => void;
|
|
938
|
+
}> = (props) => {
|
|
939
|
+
const {
|
|
940
|
+
customDateAdjustOptionValue,
|
|
941
|
+
graph,
|
|
942
|
+
updateValue,
|
|
943
|
+
setDatePickerOption,
|
|
944
|
+
} = props;
|
|
945
|
+
const [unitValue, setUnitValue] = useState(
|
|
946
|
+
customDateAdjustOptionValue instanceof CustomFirstDayOfOption
|
|
947
|
+
? (customDateAdjustOptionValue.unit as string)
|
|
948
|
+
: null,
|
|
949
|
+
);
|
|
950
|
+
const changeValue = (latestUnitValue: string): void => {
|
|
951
|
+
if (latestUnitValue !== '') {
|
|
952
|
+
const targetUnitValue = Object.values(
|
|
953
|
+
CUSTOM_DATE_OPTION_REFERENCE_MOMENT,
|
|
954
|
+
).filter((moment) => moment.toString().includes(latestUnitValue));
|
|
955
|
+
const startDayOfDateOption =
|
|
956
|
+
targetUnitValue.length > 0
|
|
957
|
+
? new CustomFirstDayOfOption(
|
|
958
|
+
guaranteeNonNullable(targetUnitValue[0]?.toString()),
|
|
959
|
+
latestUnitValue as CUSTOM_DATE_FIRST_DAY_OF_UNIT,
|
|
960
|
+
)
|
|
961
|
+
: new CustomFirstDayOfOption('', undefined);
|
|
962
|
+
updateValue(buildPureDateFunctionExpression(startDayOfDateOption, graph));
|
|
963
|
+
setDatePickerOption(startDayOfDateOption);
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
return (
|
|
968
|
+
<div className="value-spec-editor__date-picker__custom-date">
|
|
969
|
+
<div className="value-spec-editor__date-picker__custom-date__input">
|
|
970
|
+
<CustomSelectorInput
|
|
971
|
+
placeholder="Choose a unit..."
|
|
972
|
+
className="value-spec-editor__date-picker__custom-date__input-dropdown value-spec-editor__date-picker__custom-date__input-dropdown--full"
|
|
973
|
+
options={Object.values(CUSTOM_DATE_FIRST_DAY_OF_UNIT).map((t) => ({
|
|
974
|
+
value: t.toString(),
|
|
975
|
+
label: t.toString(),
|
|
976
|
+
}))}
|
|
977
|
+
onChange={(val: { label: string; value: string } | null): void => {
|
|
978
|
+
if (val) {
|
|
979
|
+
setUnitValue(val.value);
|
|
980
|
+
changeValue(val.value);
|
|
981
|
+
}
|
|
982
|
+
}}
|
|
983
|
+
value={unitValue ? { value: unitValue, label: unitValue } : null}
|
|
984
|
+
darkMode={true}
|
|
985
|
+
/>
|
|
986
|
+
</div>
|
|
987
|
+
</div>
|
|
988
|
+
);
|
|
989
|
+
};
|
|
990
|
+
|
|
991
|
+
const CustomPreviousDayOfWeekValueSpecificationEditor: React.FC<{
|
|
992
|
+
customDateAdjustOptionValue: DatePickerOption;
|
|
993
|
+
graph: PureModel;
|
|
994
|
+
updateValue: (val: ValueSpecification) => void;
|
|
995
|
+
setDatePickerOption: (datePickerOption: DatePickerOption) => void;
|
|
996
|
+
}> = (props) => {
|
|
997
|
+
const {
|
|
998
|
+
customDateAdjustOptionValue,
|
|
999
|
+
graph,
|
|
1000
|
+
updateValue,
|
|
1001
|
+
setDatePickerOption,
|
|
1002
|
+
} = props;
|
|
1003
|
+
const [dayOfWeekValue, setDayOfWeekValue] = useState(
|
|
1004
|
+
customDateAdjustOptionValue instanceof CustomPreviousDayOfWeekOption
|
|
1005
|
+
? (customDateAdjustOptionValue.day as string)
|
|
1006
|
+
: null,
|
|
1007
|
+
);
|
|
1008
|
+
const changeValue = (latestDurationUnitValue: string): void => {
|
|
1009
|
+
if (latestDurationUnitValue !== '') {
|
|
1010
|
+
const previousDayOfWeekDateOption = new CustomPreviousDayOfWeekOption(
|
|
1011
|
+
`Previous ${latestDurationUnitValue}`,
|
|
1012
|
+
latestDurationUnitValue as CUSTOM_DATE_DAY_OF_WEEK,
|
|
1013
|
+
);
|
|
1014
|
+
updateValue(
|
|
1015
|
+
buildPureDateFunctionExpression(previousDayOfWeekDateOption, graph),
|
|
1016
|
+
);
|
|
1017
|
+
setDatePickerOption(previousDayOfWeekDateOption);
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
return (
|
|
1022
|
+
<div className="value-spec-editor__date-picker__custom-date">
|
|
1023
|
+
<div className="value-spec-editor__date-picker__custom-date__input">
|
|
1024
|
+
<CustomSelectorInput
|
|
1025
|
+
placeholder="Choose a day..."
|
|
1026
|
+
className="value-spec-editor__date-picker__custom-date__input-dropdown value-spec-editor__date-picker__custom-date__input-dropdown--full"
|
|
1027
|
+
options={Object.values(CUSTOM_DATE_DAY_OF_WEEK).map((t) => ({
|
|
1028
|
+
value: t.toString(),
|
|
1029
|
+
label: t.toString(),
|
|
1030
|
+
}))}
|
|
1031
|
+
onChange={(val: { label: string; value: string } | null): void => {
|
|
1032
|
+
if (val) {
|
|
1033
|
+
setDayOfWeekValue(val.value);
|
|
1034
|
+
changeValue(val.value);
|
|
1035
|
+
}
|
|
1036
|
+
}}
|
|
1037
|
+
value={
|
|
1038
|
+
dayOfWeekValue
|
|
1039
|
+
? { value: dayOfWeekValue, label: dayOfWeekValue }
|
|
1040
|
+
: null
|
|
1041
|
+
}
|
|
1042
|
+
darkMode={true}
|
|
1043
|
+
/>
|
|
1044
|
+
</div>
|
|
1045
|
+
</div>
|
|
1046
|
+
);
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
export const CustomDatePicker: React.FC<{
|
|
1050
|
+
valueSpecification: PrimitiveInstanceValue | SimpleFunctionExpression;
|
|
1051
|
+
graph: PureModel;
|
|
1052
|
+
typeCheckOption: {
|
|
1053
|
+
expectedType: Type;
|
|
1054
|
+
/**
|
|
1055
|
+
* Indicates if a strict type-matching will happen.
|
|
1056
|
+
* Sometimes, auto-boxing allow some rooms to wiggle,
|
|
1057
|
+
* for example we can assign a Float to an Integer, a
|
|
1058
|
+
* Date to a DateTime. With this flag set to `true`
|
|
1059
|
+
* we will not allow this.
|
|
1060
|
+
*
|
|
1061
|
+
* For example, if `match=true`, it means that options in the
|
|
1062
|
+
* date-capability-dropdown which are not returning type DateTime
|
|
1063
|
+
* will be filtered out.
|
|
1064
|
+
*/
|
|
1065
|
+
match?: boolean;
|
|
1066
|
+
};
|
|
1067
|
+
updateValue: (val: ValueSpecification) => void;
|
|
1068
|
+
}> = (props) => {
|
|
1069
|
+
const { valueSpecification, updateValue, graph, typeCheckOption } = props;
|
|
1070
|
+
// For some cases where types need to be matched strictly.
|
|
1071
|
+
// Some options need to be filtered out for DateTime.
|
|
1072
|
+
const targetDateOptionsEnum = typeCheckOption.match
|
|
1073
|
+
? Object.values([
|
|
1074
|
+
CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_TIME,
|
|
1075
|
+
CUSTOM_DATE_PICKER_OPTION.NOW,
|
|
1076
|
+
])
|
|
1077
|
+
: Object.values(CUSTOM_DATE_PICKER_OPTION);
|
|
1078
|
+
const [datePickerOption, setDatePickerOption] = useState(
|
|
1079
|
+
buildDatePickerOption(valueSpecification),
|
|
1080
|
+
);
|
|
1081
|
+
|
|
1082
|
+
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
|
|
1083
|
+
const openCustomDatePickerPopover = (
|
|
1084
|
+
event: React.MouseEvent<HTMLButtonElement>,
|
|
1085
|
+
): void => {
|
|
1086
|
+
setAnchorEl(event.currentTarget);
|
|
1087
|
+
};
|
|
1088
|
+
const handleEnter = (): void => {
|
|
1089
|
+
setDatePickerOption(buildDatePickerOption(valueSpecification));
|
|
1090
|
+
};
|
|
1091
|
+
const closeCustomDatePickerPopover = (): void => {
|
|
1092
|
+
setDatePickerOption(buildDatePickerOption(valueSpecification));
|
|
1093
|
+
setAnchorEl(null);
|
|
1094
|
+
};
|
|
1095
|
+
const handleDatePickerOptionChange = (
|
|
1096
|
+
event: React.ChangeEvent<HTMLInputElement>,
|
|
1097
|
+
): void => {
|
|
1098
|
+
const chosenDatePickerOption = new DatePickerOption(
|
|
1099
|
+
(event.target as HTMLInputElement).value,
|
|
1100
|
+
(event.target as HTMLInputElement).value,
|
|
1101
|
+
);
|
|
1102
|
+
if (
|
|
1103
|
+
CUSTOM_DATE_PICKER_OPTION.LATEST_DATE === chosenDatePickerOption.value
|
|
1104
|
+
) {
|
|
1105
|
+
updateValue(
|
|
1106
|
+
buildPrimitiveInstanceValue(
|
|
1107
|
+
graph,
|
|
1108
|
+
PRIMITIVE_TYPE.LATESTDATE,
|
|
1109
|
+
event.target.value,
|
|
1110
|
+
),
|
|
1111
|
+
);
|
|
1112
|
+
} else if (
|
|
1113
|
+
// Elements in this list will trigger children date components
|
|
1114
|
+
![
|
|
1115
|
+
CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_DATE,
|
|
1116
|
+
CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_TIME,
|
|
1117
|
+
CUSTOM_DATE_PICKER_OPTION.CUSTOM_DATE,
|
|
1118
|
+
CUSTOM_DATE_PICKER_OPTION.FIRST_DAY_OF,
|
|
1119
|
+
CUSTOM_DATE_PICKER_OPTION.PREVIOUS_DAY_OF_WEEK,
|
|
1120
|
+
].includes(chosenDatePickerOption.value as CUSTOM_DATE_PICKER_OPTION)
|
|
1121
|
+
) {
|
|
1122
|
+
const theReservedCustomDateOption = reservedCustomDateOptions.filter(
|
|
1123
|
+
(d) => d.value === chosenDatePickerOption.value,
|
|
1124
|
+
);
|
|
1125
|
+
theReservedCustomDateOption.length > 0
|
|
1126
|
+
? updateValue(
|
|
1127
|
+
buildPureAdjustDateFunction(
|
|
1128
|
+
guaranteeNonNullable(theReservedCustomDateOption[0]),
|
|
1129
|
+
graph,
|
|
1130
|
+
),
|
|
1131
|
+
)
|
|
1132
|
+
: updateValue(
|
|
1133
|
+
buildPureDateFunctionExpression(chosenDatePickerOption, graph),
|
|
1134
|
+
);
|
|
1135
|
+
}
|
|
1136
|
+
setDatePickerOption(chosenDatePickerOption);
|
|
1137
|
+
};
|
|
1138
|
+
const renderChildrenDateComponents = (): React.ReactNode => {
|
|
1139
|
+
switch (datePickerOption.value) {
|
|
1140
|
+
case CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_DATE:
|
|
1141
|
+
return (
|
|
1142
|
+
<AbsoluteDateValueSpecificationEditor
|
|
1143
|
+
graph={graph}
|
|
1144
|
+
valueSpecification={valueSpecification}
|
|
1145
|
+
updateValue={updateValue}
|
|
1146
|
+
setDatePickerOption={setDatePickerOption}
|
|
1147
|
+
/>
|
|
1148
|
+
);
|
|
1149
|
+
case CUSTOM_DATE_PICKER_OPTION.ABSOLUTE_TIME:
|
|
1150
|
+
return (
|
|
1151
|
+
<AbsoluteTimeValueSpecificationEditor
|
|
1152
|
+
graph={graph}
|
|
1153
|
+
valueSpecification={valueSpecification}
|
|
1154
|
+
updateValue={updateValue}
|
|
1155
|
+
setDatePickerOption={setDatePickerOption}
|
|
1156
|
+
/>
|
|
1157
|
+
);
|
|
1158
|
+
case CUSTOM_DATE_PICKER_OPTION.CUSTOM_DATE:
|
|
1159
|
+
return (
|
|
1160
|
+
<CustomDateInstanceValueEditor
|
|
1161
|
+
graph={graph}
|
|
1162
|
+
customDateOptionValue={buildCustomDateOption(valueSpecification)}
|
|
1163
|
+
updateValue={updateValue}
|
|
1164
|
+
setDatePickerOption={setDatePickerOption}
|
|
1165
|
+
/>
|
|
1166
|
+
);
|
|
1167
|
+
case CUSTOM_DATE_PICKER_OPTION.FIRST_DAY_OF:
|
|
1168
|
+
return (
|
|
1169
|
+
<CustomFirstDayOfValueSpecificationEditor
|
|
1170
|
+
graph={graph}
|
|
1171
|
+
customDateAdjustOptionValue={buildDatePickerOption(
|
|
1172
|
+
valueSpecification,
|
|
1173
|
+
)}
|
|
1174
|
+
updateValue={updateValue}
|
|
1175
|
+
setDatePickerOption={setDatePickerOption}
|
|
1176
|
+
/>
|
|
1177
|
+
);
|
|
1178
|
+
case CUSTOM_DATE_PICKER_OPTION.PREVIOUS_DAY_OF_WEEK:
|
|
1179
|
+
return (
|
|
1180
|
+
<CustomPreviousDayOfWeekValueSpecificationEditor
|
|
1181
|
+
graph={graph}
|
|
1182
|
+
customDateAdjustOptionValue={buildDatePickerOption(
|
|
1183
|
+
valueSpecification,
|
|
1184
|
+
)}
|
|
1185
|
+
updateValue={updateValue}
|
|
1186
|
+
setDatePickerOption={setDatePickerOption}
|
|
1187
|
+
/>
|
|
1188
|
+
);
|
|
1189
|
+
default:
|
|
1190
|
+
return null;
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
|
|
1194
|
+
// make sure the date picker label is updated when the value is reset or changed somehow
|
|
1195
|
+
useEffect(() => {
|
|
1196
|
+
setDatePickerOption(buildDatePickerOption(valueSpecification));
|
|
1197
|
+
}, [valueSpecification]);
|
|
1198
|
+
|
|
1199
|
+
return (
|
|
1200
|
+
<>
|
|
1201
|
+
<button
|
|
1202
|
+
className="value-spec-editor__date-picker__trigger"
|
|
1203
|
+
title="Click to edit and pick from more date options"
|
|
1204
|
+
onClick={openCustomDatePickerPopover}
|
|
1205
|
+
>
|
|
1206
|
+
{datePickerOption.label}
|
|
1207
|
+
</button>
|
|
1208
|
+
<BasePopover
|
|
1209
|
+
open={Boolean(anchorEl)}
|
|
1210
|
+
TransitionProps={{
|
|
1211
|
+
onEnter: handleEnter,
|
|
1212
|
+
}}
|
|
1213
|
+
anchorEl={anchorEl}
|
|
1214
|
+
onClose={closeCustomDatePickerPopover}
|
|
1215
|
+
anchorOrigin={{
|
|
1216
|
+
vertical: 'bottom',
|
|
1217
|
+
horizontal: 'center',
|
|
1218
|
+
}}
|
|
1219
|
+
transformOrigin={{
|
|
1220
|
+
vertical: 'top',
|
|
1221
|
+
horizontal: 'center',
|
|
1222
|
+
}}
|
|
1223
|
+
>
|
|
1224
|
+
<BaseRadioGroup
|
|
1225
|
+
value={datePickerOption.value}
|
|
1226
|
+
onChange={handleDatePickerOptionChange}
|
|
1227
|
+
row={true}
|
|
1228
|
+
options={targetDateOptionsEnum}
|
|
1229
|
+
size={2}
|
|
1230
|
+
/>
|
|
1231
|
+
{renderChildrenDateComponents()}
|
|
1232
|
+
</BasePopover>
|
|
1233
|
+
</>
|
|
1234
|
+
);
|
|
1235
|
+
};
|