@antscorp/antsomi-ui 1.3.3-beta.74 → 1.3.3-beta.76
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/es/components/common/ConfigProvider/GlobalStyle.js +4 -0
- package/es/components/molecules/DatePicker/components/AdvancedPicker/AdvancedPicker.js +68 -229
- package/es/components/molecules/DatePicker/components/AdvancedPicker/constants.d.ts +20 -8
- package/es/components/molecules/DatePicker/components/AdvancedPicker/constants.js +36 -22
- package/es/components/molecules/DatePicker/components/AdvancedPicker/styled.js +1 -1
- package/es/components/molecules/DatePicker/components/AdvancedPicker/utils.d.ts +5 -1
- package/es/components/molecules/DatePicker/components/AdvancedPicker/utils.js +70 -38
- package/es/components/molecules/DatePicker/components/DropdownLabel/DropdownLabel.d.ts +13 -0
- package/es/components/molecules/DatePicker/components/DropdownLabel/DropdownLabel.js +82 -0
- package/es/components/molecules/DatePicker/components/ErrorMessage/ErrorMessage.d.ts +6 -0
- package/es/components/molecules/DatePicker/components/ErrorMessage/ErrorMessage.js +12 -0
- package/package.json +1 -1
|
@@ -312,6 +312,10 @@ export const GlobalStyle = () => {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
.antsomi-picker-time-panel {
|
|
315
|
+
.antsomi-picker-time-panel-column:after {
|
|
316
|
+
height: 8px;
|
|
317
|
+
}
|
|
318
|
+
|
|
315
319
|
.antsomi-picker-time-panel-cell-selected {
|
|
316
320
|
background-color: ${(_8 = THEME.token) === null || _8 === void 0 ? void 0 : _8.colorPrimary};
|
|
317
321
|
color: #fff;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable react/no-unused-prop-types */
|
|
2
2
|
// Libraries
|
|
3
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
4
|
-
import { Tooltip, theme } from 'antd';
|
|
3
|
+
import React, { useEffect, useMemo, useCallback, useState } from 'react';
|
|
4
|
+
import { Tooltip, theme, DatePicker } from 'antd';
|
|
5
5
|
import dayjs from 'dayjs';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
// Hooks
|
|
@@ -9,20 +9,19 @@ import { useDeepCompareEffect } from '../../../../../hooks';
|
|
|
9
9
|
// Icons
|
|
10
10
|
import Icon from '@antscorp/icons';
|
|
11
11
|
import { EventIcon } from '../../../../icons';
|
|
12
|
-
//
|
|
12
|
+
// Components
|
|
13
13
|
import { Input, InputNumber, Divider, Space, Button, Typography, } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
14
|
-
|
|
15
|
-
import {
|
|
14
|
+
import { Select, Dropdown } from '@antscorp/antsomi-ui/es/components';
|
|
15
|
+
import { ErrorMessage } from '../ErrorMessage/ErrorMessage';
|
|
16
|
+
import { DropdownLabel } from '../DropdownLabel/DropdownLabel';
|
|
16
17
|
// Utils
|
|
17
18
|
import { handleError, reorder } from '@antscorp/antsomi-ui/es/utils';
|
|
18
|
-
import { calculationDateAdvanced, getCellRender,
|
|
19
|
+
import { calculationDateAdvanced, getCellRender, getFormatDisplay, getPickerRender, getTimePickerRender, } from './utils';
|
|
19
20
|
// Styled
|
|
20
21
|
import { DatePickerCustomInput, DatePickerHeader, DropdownContent, DropdownHeader, DatePickerFooter, DropdownFooter, CalendarIconWrapper, } from './styled';
|
|
21
22
|
// Constants
|
|
22
|
-
import { CALCULATION_DATES, CALCULATION_TYPES, DATE_TYPES, DEFAULT_DATE_FORMAT, VALUE_TYPES, ADVANCED_PICKER_TYPE, WEEK_ARR, QUARTER_PLACEHOLDER, WEEK_PLACEHOLDER, DAY_LABEL_SHORT,
|
|
23
|
-
import { THEME } from '
|
|
24
|
-
// Instance
|
|
25
|
-
import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
|
|
23
|
+
import { CALCULATION_DATES, CALCULATION_TYPES, DATE_TYPES, DEFAULT_DATE_FORMAT, VALUE_TYPES, ADVANCED_PICKER_TYPE, WEEK_ARR, QUARTER_PLACEHOLDER, WEEK_PLACEHOLDER, DAY_LABEL_SHORT, MONTH_LABEL_FULL, DAY_OF_MONTH, ANCHOR_LEAP_YEAR, GRANULARITY_MAPPING, } from './constants';
|
|
24
|
+
import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
26
25
|
const PATH = '@antscorp/antsomi-ui/es/components/molecules/DatePicker/components/Advanced/DatePickerAdvanced.tsx';
|
|
27
26
|
const { useToken } = theme;
|
|
28
27
|
const { Text } = Typography;
|
|
@@ -44,83 +43,8 @@ export const AdvancedPicker = props => {
|
|
|
44
43
|
}
|
|
45
44
|
return DATE_TYPES;
|
|
46
45
|
}, [dateTypeKeysShow, defaultDateTypeKey]);
|
|
47
|
-
const newCalculationDates = useMemo(() =>
|
|
48
|
-
|
|
49
|
-
return CALCULATION_DATES.filter(calculationDate => granularityKey.includes(calculationDate.value));
|
|
50
|
-
}, [valueType]);
|
|
51
|
-
const [formatDisplay, timeFormatDisplay] = useMemo(() => {
|
|
52
|
-
let formatDisplay = '';
|
|
53
|
-
let timeFormatDisplay = '';
|
|
54
|
-
let isStartDate = false;
|
|
55
|
-
// Handle detect day is start or end
|
|
56
|
-
if (operatorKey === 'between') {
|
|
57
|
-
isStartDate = type === 'startDate';
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
isStartDate = operatorKey === 'after';
|
|
61
|
-
}
|
|
62
|
-
switch (valueType) {
|
|
63
|
-
case 'YEAR':
|
|
64
|
-
formatDisplay = 'YYYY';
|
|
65
|
-
break;
|
|
66
|
-
case 'YEAR_QUARTER':
|
|
67
|
-
formatDisplay = `${QUARTER_PLACEHOLDER}Q, YYYY`;
|
|
68
|
-
break;
|
|
69
|
-
case 'YEAR_MONTH':
|
|
70
|
-
formatDisplay = 'MMMM, YYYY';
|
|
71
|
-
break;
|
|
72
|
-
case 'YEAR_WEEK':
|
|
73
|
-
formatDisplay = `${WEEK_PLACEHOLDER}W, YYYY`;
|
|
74
|
-
break;
|
|
75
|
-
case 'YEAR_MONTH_DAY':
|
|
76
|
-
formatDisplay = 'MMMM DD, YYYY';
|
|
77
|
-
break;
|
|
78
|
-
case 'YEAR_MONTH_DAY_HOUR':
|
|
79
|
-
formatDisplay = `MMMM DD, YYYY ${isStartDate ? 'HH:00:00' : 'HH:59:59'}`;
|
|
80
|
-
timeFormatDisplay = isStartDate ? 'HH:00:00' : 'HH:59:59';
|
|
81
|
-
break;
|
|
82
|
-
case 'YEAR_MONTH_DAY_MINUTE':
|
|
83
|
-
formatDisplay = `MMMM DD, YYYY ${isStartDate ? 'HH:mm:00' : 'HH:mm:59'}`;
|
|
84
|
-
timeFormatDisplay = isStartDate ? 'HH:mm:00' : 'HH:mm:59';
|
|
85
|
-
break;
|
|
86
|
-
case 'YEAR_MONTH_DAY_SECOND':
|
|
87
|
-
formatDisplay = 'MMMM DD, YYYY HH:mm:ss';
|
|
88
|
-
timeFormatDisplay = 'HH:mm:ss';
|
|
89
|
-
break;
|
|
90
|
-
case 'QUARTER':
|
|
91
|
-
formatDisplay = `${QUARTER_PLACEHOLDER}Q`;
|
|
92
|
-
break;
|
|
93
|
-
case 'MONTH':
|
|
94
|
-
formatDisplay = 'MMMM';
|
|
95
|
-
break;
|
|
96
|
-
case 'WEEK':
|
|
97
|
-
formatDisplay = `${WEEK_PLACEHOLDER}W`;
|
|
98
|
-
break;
|
|
99
|
-
case 'MONTH_DAY':
|
|
100
|
-
formatDisplay = 'MMMM DD';
|
|
101
|
-
break;
|
|
102
|
-
case 'DAY_OF_WEEK':
|
|
103
|
-
formatDisplay = 'dddd';
|
|
104
|
-
break;
|
|
105
|
-
case 'DAY':
|
|
106
|
-
formatDisplay = 'DD';
|
|
107
|
-
break;
|
|
108
|
-
case 'HOUR':
|
|
109
|
-
formatDisplay = 'HH';
|
|
110
|
-
break;
|
|
111
|
-
case 'MINUTE':
|
|
112
|
-
formatDisplay = 'mm';
|
|
113
|
-
break;
|
|
114
|
-
default:
|
|
115
|
-
formatDisplay = `DD/MM/YYYY - ${isStartDate ? '00:00:00' : '23:59:59'}`;
|
|
116
|
-
timeFormatDisplay = isStartDate ? '00:00:00' : '23:59:59';
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
if (formatInputDisplay) {
|
|
120
|
-
formatDisplay = formatInputDisplay;
|
|
121
|
-
}
|
|
122
|
-
return [formatDisplay, timeFormatDisplay];
|
|
123
|
-
}, [valueType, operatorKey, type, formatInputDisplay]);
|
|
46
|
+
const newCalculationDates = useMemo(() => CALCULATION_DATES.filter(calculationDate => GRANULARITY_MAPPING[valueType].includes(calculationDate.value)), [valueType]);
|
|
47
|
+
const { formatDisplay } = getFormatDisplay(operatorKey, type, valueType, formatInputDisplay);
|
|
124
48
|
// State
|
|
125
49
|
const [state, setState] = useState({
|
|
126
50
|
isOpen: false,
|
|
@@ -140,7 +64,12 @@ export const AdvancedPicker = props => {
|
|
|
140
64
|
dateDisplay: dayjs().format(DEFAULT_DATE_FORMAT),
|
|
141
65
|
});
|
|
142
66
|
const { isOpen, option, date, dateDisplay } = state;
|
|
143
|
-
const
|
|
67
|
+
const currDate = dayjs(date, format);
|
|
68
|
+
const currWeek = currDate.isoWeek();
|
|
69
|
+
const currDay = currDate.day();
|
|
70
|
+
const currDayOfMonth = currDate.date();
|
|
71
|
+
const currMonth = currDate.month();
|
|
72
|
+
const [currMonthSelected, setCurrMonthSelected] = useState(currMonth);
|
|
144
73
|
const newCalculationTypes = useMemo(() => {
|
|
145
74
|
var _a;
|
|
146
75
|
if (calculationTypeKeysShow && calculationTypeKeysShow.length) {
|
|
@@ -161,13 +90,28 @@ export const AdvancedPicker = props => {
|
|
|
161
90
|
}, [calculationTypeKeysShow, showCalculationTypeCondition, option.dateType]);
|
|
162
91
|
// Hooks
|
|
163
92
|
const { token } = useToken();
|
|
164
|
-
const { t } = i18nInstance;
|
|
165
93
|
// Variables
|
|
166
94
|
const contentStyle = {
|
|
167
95
|
backgroundColor: token.colorBgElevated,
|
|
168
96
|
borderRadius: token.borderRadius,
|
|
169
97
|
boxShadow: token.boxShadowSecondary,
|
|
170
98
|
};
|
|
99
|
+
const selectedDateTitle = useMemo(() => dayjs(dateDisplay, format)
|
|
100
|
+
.format(formatDisplay)
|
|
101
|
+
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
102
|
+
.replace(WEEK_PLACEHOLDER, 'Week '), [dateDisplay, format, formatDisplay]);
|
|
103
|
+
const onChangeOption = (params) => {
|
|
104
|
+
try {
|
|
105
|
+
setState(state => (Object.assign(Object.assign({}, state), { option: Object.assign(Object.assign({}, state.option), params) })));
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
handleError(error, {
|
|
109
|
+
path: PATH,
|
|
110
|
+
name: 'onChangeOption',
|
|
111
|
+
args: {},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
};
|
|
171
115
|
// Effects
|
|
172
116
|
useEffect(() => {
|
|
173
117
|
try {
|
|
@@ -205,7 +149,8 @@ export const AdvancedPicker = props => {
|
|
|
205
149
|
const newDateTypes = DATE_TYPES;
|
|
206
150
|
const newDateType = newDateTypes.find(dType => dType.value === dateType);
|
|
207
151
|
const newCalculationType = CALCULATION_TYPES.find(calType => calType.value === calculationType);
|
|
208
|
-
const newCalculationDate = newCalculationDates.find(calDate => calDate.value === calculationDate)
|
|
152
|
+
const newCalculationDate = newCalculationDates.find(calDate => calDate.value === calculationDate) ||
|
|
153
|
+
newCalculationDates[0];
|
|
209
154
|
let newDate = '';
|
|
210
155
|
if (newDateType) {
|
|
211
156
|
if (newDateType.value === 'fixed') {
|
|
@@ -240,75 +185,12 @@ export const AdvancedPicker = props => {
|
|
|
240
185
|
});
|
|
241
186
|
}
|
|
242
187
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
243
|
-
}, [propsOption, propsDate, format]);
|
|
188
|
+
}, [propsOption, newCalculationDates, propsDate, format]);
|
|
244
189
|
// Handlers
|
|
245
190
|
const disableDate = current => current > dayjs(disableAfterDate, format) || current < dayjs(disableBeforeDate, format);
|
|
246
|
-
const
|
|
247
|
-
let formatLabel = 'dddd, MMMM DD, YYYY';
|
|
248
|
-
let subLabel = '';
|
|
249
|
-
switch (valueType) {
|
|
250
|
-
case 'YEAR':
|
|
251
|
-
formatLabel = 'YYYY';
|
|
252
|
-
break;
|
|
253
|
-
case 'YEAR_QUARTER':
|
|
254
|
-
formatLabel = `${QUARTER_PLACEHOLDER}Q, YYYY`;
|
|
255
|
-
subLabel = getLabelQuarterRange(date, format || DEFAULT_DATE_FORMAT, locale);
|
|
256
|
-
break;
|
|
257
|
-
case 'YEAR_MONTH':
|
|
258
|
-
formatLabel = 'MMMM, YYYY';
|
|
259
|
-
break;
|
|
260
|
-
case 'YEAR_WEEK': {
|
|
261
|
-
const dayObj = dayjs(date || new Date(), format).locale(locale || 'en');
|
|
262
|
-
formatLabel = `${WEEK_PLACEHOLDER}W, YYYY`;
|
|
263
|
-
subLabel = `${dayjs(dayObj).day(0).format('MMMM DD, YYYY')} - ${dayjs(dayObj)
|
|
264
|
-
.day(6)
|
|
265
|
-
.format('MMMM DD, YYYY')}`;
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
case 'YEAR_MONTH_DAY_HOUR':
|
|
269
|
-
formatLabel = 'dddd, MMMM DD, YYYY';
|
|
270
|
-
break;
|
|
271
|
-
case 'QUARTER':
|
|
272
|
-
formatLabel = `${QUARTER_PLACEHOLDER}Q`;
|
|
273
|
-
break;
|
|
274
|
-
case 'MONTH':
|
|
275
|
-
formatLabel = 'MMMM';
|
|
276
|
-
break;
|
|
277
|
-
case 'WEEK':
|
|
278
|
-
formatLabel = `${WEEK_PLACEHOLDER}W`;
|
|
279
|
-
break;
|
|
280
|
-
case 'MONTH_DAY':
|
|
281
|
-
formatLabel = 'MMMM DD';
|
|
282
|
-
break;
|
|
283
|
-
case 'DAY_OF_WEEK':
|
|
284
|
-
formatLabel = 'dddd';
|
|
285
|
-
break;
|
|
286
|
-
case 'DAY':
|
|
287
|
-
formatLabel = 'DD';
|
|
288
|
-
break;
|
|
289
|
-
case 'HOUR':
|
|
290
|
-
formatLabel = 'HH:00:00';
|
|
291
|
-
break;
|
|
292
|
-
case 'MINUTE':
|
|
293
|
-
formatLabel = '00:mm:00';
|
|
294
|
-
break;
|
|
295
|
-
default:
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
return (React.createElement(React.Fragment, null,
|
|
299
|
-
React.createElement("div", { style: { fontWeight: 'bold' } }, dayjs(date || new Date(), format)
|
|
300
|
-
.locale(locale || 'en')
|
|
301
|
-
.format(formatLabel)
|
|
302
|
-
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
303
|
-
.replace(WEEK_PLACEHOLDER, 'Week ')),
|
|
304
|
-
subLabel ? React.createElement("div", null, subLabel) : null,
|
|
305
|
-
!HIDE_TIME_LABEL_ARR.includes(valueType || '') && showTime && !subLabel ? (React.createElement("div", { style: { fontWeight: 'bold' } }, dayjs(date || new Date(), format)
|
|
306
|
-
.locale(locale || 'en')
|
|
307
|
-
.format(timeFormatDisplay))) : null));
|
|
308
|
-
};
|
|
309
|
-
const toggleOpenDropdown = (isOpen) => {
|
|
191
|
+
const toggleOpenDropdown = () => {
|
|
310
192
|
try {
|
|
311
|
-
setState(() => (Object.assign(Object.assign({}, state), { isOpen:
|
|
193
|
+
setState(() => (Object.assign(Object.assign({}, state), { isOpen: !state.isOpen })));
|
|
312
194
|
}
|
|
313
195
|
catch (error) {
|
|
314
196
|
handleError(error, {
|
|
@@ -318,18 +200,6 @@ export const AdvancedPicker = props => {
|
|
|
318
200
|
});
|
|
319
201
|
}
|
|
320
202
|
};
|
|
321
|
-
const onChangeOption = (params) => {
|
|
322
|
-
try {
|
|
323
|
-
setState(state => (Object.assign(Object.assign({}, state), { option: Object.assign(Object.assign({}, state.option), params) })));
|
|
324
|
-
}
|
|
325
|
-
catch (error) {
|
|
326
|
-
handleError(error, {
|
|
327
|
-
path: PATH,
|
|
328
|
-
name: 'onChangeOption',
|
|
329
|
-
args: {},
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
203
|
const onClickApply = () => {
|
|
334
204
|
try {
|
|
335
205
|
const draftOption = {
|
|
@@ -370,46 +240,29 @@ export const AdvancedPicker = props => {
|
|
|
370
240
|
});
|
|
371
241
|
}
|
|
372
242
|
};
|
|
373
|
-
const renderDropdownLabel = () => {
|
|
374
|
-
var _a;
|
|
375
|
-
const title = (_a = Object.values(ADVANCED_PICKER_TYPE).find(({ value }) => value === type)) === null || _a === void 0 ? void 0 : _a.label;
|
|
376
|
-
return (React.createElement("div", { style: { textAlign: 'center' } },
|
|
377
|
-
title && operatorKey === 'between' && (React.createElement(Text, { className: "__title", style: { color: '#666666' } }, t(title))),
|
|
378
|
-
renderLabel(date, 'en')));
|
|
379
|
-
};
|
|
380
243
|
const renderDropdownFooter = () => (React.createElement(React.Fragment, null,
|
|
381
244
|
React.createElement(Divider, null),
|
|
382
245
|
React.createElement(DropdownFooter, null,
|
|
383
246
|
React.createElement(Space, null,
|
|
384
247
|
React.createElement(Button, { type: "primary", onClick: () => onClickApply() }, "Apply"),
|
|
385
|
-
React.createElement(Button, { type: "default", onClick: () => toggleOpenDropdown(
|
|
248
|
+
React.createElement(Button, { type: "default", onClick: () => toggleOpenDropdown() }, "Cancel")),
|
|
386
249
|
option.dateType.value === 'fixed' && React.createElement(Button, { onClick: () => onClickNow() }, "Now"))));
|
|
387
|
-
const renderDateTypeOptions = () => (React.createElement(Select, {
|
|
250
|
+
const renderDateTypeOptions = () => (React.createElement(Select, { options: newDateTypes, value: option.dateType.value, onChange: value => {
|
|
388
251
|
const dateType = newDateTypes.find(dateType => dateType.value === value);
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}
|
|
252
|
+
onChangeOption({ dateType });
|
|
253
|
+
// toggleOpenDropdown(true);
|
|
254
|
+
// setTimeout(() => {
|
|
255
|
+
// onChangeOption({ dateType });
|
|
256
|
+
// }, 100);
|
|
393
257
|
} }));
|
|
394
|
-
const renderErrorMessage = () => {
|
|
395
|
-
var _a;
|
|
396
|
-
return errorMessage ? (React.createElement("div", { style: { display: 'flex', alignItems: 'center', gap: 5 } },
|
|
397
|
-
React.createElement(Icon, { type: "icon-ants-remove-circle", style: { color: (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.colorError } }),
|
|
398
|
-
React.createElement(Text, { type: "danger" }, errorMessage))) : null;
|
|
399
|
-
};
|
|
400
258
|
// NOTE: valueType: 'WEEK'; 'DAY_OF_WEEK'; 'MONTH_DAY'; 'DAY'
|
|
401
|
-
const customPickerArr =
|
|
259
|
+
const customPickerArr = {
|
|
402
260
|
WEEK: WEEK_ARR,
|
|
403
261
|
DAY_OF_WEEK: DAY_LABEL_SHORT,
|
|
404
262
|
MONTH_DAY: DAY_OF_MONTH[currMonthSelected],
|
|
405
263
|
DAY: DAY_OF_MONTH[0],
|
|
406
|
-
}
|
|
264
|
+
};
|
|
407
265
|
const dropdownRender = () => {
|
|
408
|
-
// const customPickerArr = valueType === 'WEEK' ? WEEK_ARR : DAY_LABEL_SHORT;
|
|
409
|
-
const currWeek = dayjs(date, format).isoWeek();
|
|
410
|
-
const currDay = dayjs(date, format).day();
|
|
411
|
-
const currDayOfMonth = dayjs(date, format).date();
|
|
412
|
-
const currMonth = dayjs(date, format).month();
|
|
413
266
|
const getCellSelected = (item, index) => {
|
|
414
267
|
switch (valueType) {
|
|
415
268
|
case 'WEEK':
|
|
@@ -439,7 +292,8 @@ export const AdvancedPicker = props => {
|
|
|
439
292
|
}
|
|
440
293
|
};
|
|
441
294
|
return (React.createElement("div", { style: contentStyle },
|
|
442
|
-
React.createElement(DropdownHeader, { className: "dropdown-header" },
|
|
295
|
+
React.createElement(DropdownHeader, { className: "dropdown-header" },
|
|
296
|
+
React.createElement(DropdownLabel, { valueType: valueType, date: date, format: format, type: type, showTime: showTime, operatorKey: operatorKey, formatInputDisplay: formatInputDisplay })),
|
|
443
297
|
React.createElement(DropdownContent, { className: "dropdown-content" },
|
|
444
298
|
renderDateTypeOptions(),
|
|
445
299
|
option.dateType.value === 'fixed' ? (React.createElement(React.Fragment, null,
|
|
@@ -447,28 +301,25 @@ export const AdvancedPicker = props => {
|
|
|
447
301
|
React.createElement(Icon, { type: "icon-ants-angle-left", style: { fontSize: '14px', color: '#D2D2D2' }, onClick: () => setCurrMonthSelected(prev => (prev === 0 ? 11 : prev - 1)) }),
|
|
448
302
|
MONTH_LABEL_FULL[currMonthSelected],
|
|
449
303
|
React.createElement(Icon, { type: "icon-ants-angle-right", style: { fontSize: '14px', color: '#D2D2D2' }, onClick: () => setCurrMonthSelected(prev => (prev === 11 ? 0 : prev + 1)) }))) : null,
|
|
450
|
-
React.createElement("div", { className: `custom-picker-content${['MONTH_DAY', 'DAY'].includes(valueType
|
|
304
|
+
React.createElement("div", { className: `custom-picker-content${['MONTH_DAY', 'DAY'].includes(valueType) ? ' day-of-month-container' : ''}` }, customPickerArr[valueType].map((item, index) => (React.createElement("div", { key: `day_${item}`, className: clsx('custom-picker-item', {
|
|
451
305
|
'custom-picker-item-selected': getCellSelected(item, index),
|
|
452
306
|
}), onClick: () => {
|
|
453
307
|
const newDate = getNewDate(item, index);
|
|
454
308
|
setState(state => (Object.assign(Object.assign({}, state), { date: dayjs(newDate).format(format) })));
|
|
455
309
|
} }, item)))))) : (React.createElement(React.Fragment, null,
|
|
456
|
-
React.createElement(Select, { getPopupContainer: triggerNode => triggerNode.parentNode, options: newCalculationTypes.
|
|
457
|
-
value,
|
|
458
|
-
label: t(label),
|
|
459
|
-
})), value: option.calculationType.value, onChange: value => {
|
|
310
|
+
React.createElement(Select, { getPopupContainer: triggerNode => triggerNode.parentNode, options: newCalculationTypes, value: option.calculationType.value, onChange: value => {
|
|
460
311
|
const calculationType = CALCULATION_TYPES.find(calculationType => calculationType.value === value);
|
|
461
312
|
onChangeOption({ calculationType });
|
|
462
313
|
} }),
|
|
463
|
-
React.createElement(InputNumber, { value: option.value, style: { width: '100%' }, min: 0, showHandler: false, onChange: value => onChangeOption({ value }) }),
|
|
464
|
-
React.createElement(Select, { getPopupContainer: triggerNode => triggerNode.parentNode, options: newCalculationDates
|
|
314
|
+
React.createElement(InputNumber, { value: option.value, style: { width: '100%' }, min: 0, showHandler: false, onChange: value => onChangeOption({ value: Math.floor(value) }) }),
|
|
315
|
+
React.createElement(Select, { getPopupContainer: triggerNode => triggerNode.parentNode, options: newCalculationDates, value: option.calculationDate.value, onChange: value => {
|
|
465
316
|
const calculationDate = newCalculationDates.find(calculationDate => calculationDate.value === value);
|
|
466
317
|
onChangeOption({ calculationDate });
|
|
467
318
|
} }))),
|
|
468
|
-
|
|
319
|
+
React.createElement(ErrorMessage, { errorMessage: errorMessage })),
|
|
469
320
|
renderDropdownFooter()));
|
|
470
321
|
};
|
|
471
|
-
const cellRender =
|
|
322
|
+
const cellRender = useCallback((current, info) => {
|
|
472
323
|
const onChangeDatePicker = (value) => {
|
|
473
324
|
try {
|
|
474
325
|
setState(state => (Object.assign(Object.assign({}, state), { date: dayjs(value).format(format) })));
|
|
@@ -505,58 +356,46 @@ export const AdvancedPicker = props => {
|
|
|
505
356
|
}
|
|
506
357
|
if (info.type === 'decade' ||
|
|
507
358
|
(info.type === 'year' && valueType !== 'YEAR') ||
|
|
508
|
-
(info.type === 'month' &&
|
|
509
|
-
!['MONTH', 'YEAR_MONTH'].includes(valueType || 'YEAR_MONTH_DAY')))
|
|
359
|
+
(info.type === 'month' && !['MONTH', 'YEAR_MONTH'].includes(valueType)))
|
|
510
360
|
return;
|
|
511
361
|
e.preventDefault();
|
|
512
362
|
e.stopPropagation();
|
|
513
363
|
onChangeDatePicker(current);
|
|
514
|
-
} }, getCellRender(current, valueType
|
|
364
|
+
} }, getCellRender(current, valueType, info)));
|
|
515
365
|
}, [valueType, format, date]);
|
|
516
366
|
return (React.createElement(Space, { direction: "vertical", size: 5, className: "antsomi-advanced-picker-container" },
|
|
517
367
|
!!label && typeof label === 'string' ? (React.createElement(Text, { style: { color: '#666666' } }, label)) : (label),
|
|
518
368
|
option.dateType.value === 'fixed' &&
|
|
519
|
-
!['WEEK', 'DAY_OF_WEEK', 'MONTH_DAY', 'DAY'].includes(valueType
|
|
520
|
-
|
|
521
|
-
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
522
|
-
.replace(WEEK_PLACEHOLDER, 'Week ') },
|
|
523
|
-
React.createElement(DatePicker, { disabled: disabled, open: !disabled && isOpen, allowClear: false, inputReadOnly: true, status: errorMessage ? 'error' : '', inputRender: () => (React.createElement(DatePickerCustomInput, { readOnly: true, placeholder: "Select Date", value: dayjs(dateDisplay, format)
|
|
524
|
-
.format(formatDisplay)
|
|
525
|
-
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
526
|
-
.replace(WEEK_PLACEHOLDER, 'Week '), onClick: () => toggleOpenDropdown() })), value: dayjs(date, format), style: {
|
|
369
|
+
!['WEEK', 'DAY_OF_WEEK', 'MONTH_DAY', 'DAY'].includes(valueType) ? (React.createElement(Tooltip, { title: selectedDateTitle },
|
|
370
|
+
React.createElement(DatePicker, { disabled: disabled, open: !disabled && isOpen, allowClear: false, inputReadOnly: true, status: errorMessage ? 'error' : '', inputRender: () => (React.createElement(DatePickerCustomInput, { readOnly: true, placeholder: "Select Date", value: selectedDateTitle, onClick: () => toggleOpenDropdown() })), value: currDate, style: {
|
|
527
371
|
width: 120,
|
|
528
372
|
}, disabledDate: disableDate, format: formatDisplay, showToday: false, popupClassName: clsx('antsomi-picker-dropdown__advanced', {
|
|
529
373
|
'--error': errorMessage,
|
|
530
|
-
'hide-picker-header': ['QUARTER', 'MONTH'].includes(valueType
|
|
531
|
-
'only-show-time-picker': ['HOUR', 'MINUTE'].includes(valueType
|
|
374
|
+
'hide-picker-header': ['QUARTER', 'MONTH'].includes(valueType),
|
|
375
|
+
'only-show-time-picker': ['HOUR', 'MINUTE'].includes(valueType),
|
|
532
376
|
'is-minutes-picker': valueType === 'MINUTE',
|
|
533
377
|
'is-hours-picker': valueType === 'HOUR',
|
|
534
378
|
}), renderExtraFooter: () => (React.createElement(React.Fragment, null,
|
|
535
379
|
React.createElement(DatePickerHeader, null,
|
|
536
|
-
|
|
380
|
+
React.createElement(DropdownLabel, { valueType: valueType, date: date, format: format, type: type, showTime: showTime, operatorKey: operatorKey, formatInputDisplay: formatInputDisplay }),
|
|
537
381
|
renderDateTypeOptions()),
|
|
538
382
|
React.createElement(DatePickerFooter, null,
|
|
539
|
-
React.createElement("div", { style: { padding: '0 10px' } },
|
|
383
|
+
React.createElement("div", { style: { padding: '0 10px' } },
|
|
384
|
+
React.createElement(ErrorMessage, { errorMessage: errorMessage })),
|
|
540
385
|
renderDropdownFooter()),
|
|
541
|
-
React.createElement(Divider, null))), picker: getPickerRender(valueType
|
|
386
|
+
React.createElement(Divider, null))), picker: getPickerRender(valueType), showTime: getTimePickerRender(valueType)
|
|
542
387
|
? {
|
|
543
|
-
format: getTimePickerRender(valueType
|
|
388
|
+
format: getTimePickerRender(valueType),
|
|
544
389
|
}
|
|
545
390
|
: undefined, suffixIcon: React.createElement(CalendarIconWrapper, { style: {
|
|
546
391
|
pointerEvents: disabled ? 'none' : 'all',
|
|
547
392
|
}, onClick: () => toggleOpenDropdown() },
|
|
548
393
|
React.createElement(EventIcon, { width: 20, height: 20, fill: errorMessage ? (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.colorError : (_b = THEME.token) === null || _b === void 0 ? void 0 : _b.bw10 })), cellRender: cellRender, onOpenChange: () => toggleOpenDropdown() }))) : (React.createElement(Dropdown, { disabled: disabled, open: !disabled && isOpen, dropdownRender: dropdownRender, trigger: ['click'], onOpenChange: () => toggleOpenDropdown(), overlayStyle: { width: 'fit-content', minWidth: 'auto' } },
|
|
549
|
-
React.createElement(Tooltip, { title:
|
|
550
|
-
.format(formatDisplay)
|
|
551
|
-
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
552
|
-
.replace(WEEK_PLACEHOLDER, 'Week ') },
|
|
394
|
+
React.createElement(Tooltip, { title: selectedDateTitle },
|
|
553
395
|
React.createElement(Input, { disabled: disabled, onClick: () => toggleOpenDropdown(), readOnly: true, suffix: React.createElement(CalendarIconWrapper, { style: {
|
|
554
396
|
pointerEvents: disabled ? 'none' : 'all',
|
|
555
397
|
}, onClick: () => toggleOpenDropdown() },
|
|
556
|
-
React.createElement(EventIcon, { width: 19, height: 19 })), style: inputStyle, value:
|
|
557
|
-
.format(formatDisplay)
|
|
558
|
-
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
559
|
-
.replace(WEEK_PLACEHOLDER, 'Week '), status: errorMessage ? 'error' : '' }))))));
|
|
398
|
+
React.createElement(EventIcon, { width: 19, height: 19 })), style: inputStyle, value: selectedDateTitle, status: errorMessage ? 'error' : '' }))))));
|
|
560
399
|
};
|
|
561
400
|
AdvancedPicker.defaultProps = {
|
|
562
401
|
label: '',
|
|
@@ -3,34 +3,46 @@ export declare const DATE_TYPES: {
|
|
|
3
3
|
value: string;
|
|
4
4
|
label: string;
|
|
5
5
|
}[];
|
|
6
|
+
export declare const DATE_TYPE_MAPPING: {
|
|
7
|
+
first_day_of_week_mon_sun: string;
|
|
8
|
+
first_day_of_week_sun_sat: string;
|
|
9
|
+
first_day_of_month: string;
|
|
10
|
+
first_day_of_quarter: string;
|
|
11
|
+
first_day_of_year: string;
|
|
12
|
+
last_day_of_week_mon_sun: string;
|
|
13
|
+
last_day_of_week_sun_sat: string;
|
|
14
|
+
last_day_of_month: string;
|
|
15
|
+
last_day_of_quarter: string;
|
|
16
|
+
last_day_of_year: string;
|
|
17
|
+
};
|
|
6
18
|
export declare const CALCULATION_TYPES: {
|
|
7
19
|
value: string;
|
|
8
20
|
label: string;
|
|
9
21
|
}[];
|
|
10
22
|
export declare const CALCULATION_DATES: readonly [{
|
|
11
23
|
readonly value: "seconds";
|
|
12
|
-
readonly label:
|
|
24
|
+
readonly label: string;
|
|
13
25
|
}, {
|
|
14
26
|
readonly value: "minutes";
|
|
15
|
-
readonly label:
|
|
27
|
+
readonly label: string;
|
|
16
28
|
}, {
|
|
17
29
|
readonly value: "hours";
|
|
18
|
-
readonly label:
|
|
30
|
+
readonly label: string;
|
|
19
31
|
}, {
|
|
20
32
|
readonly value: "days";
|
|
21
|
-
readonly label:
|
|
33
|
+
readonly label: string;
|
|
22
34
|
}, {
|
|
23
35
|
readonly value: "weeks";
|
|
24
|
-
readonly label:
|
|
36
|
+
readonly label: string;
|
|
25
37
|
}, {
|
|
26
38
|
readonly value: "months";
|
|
27
|
-
readonly label:
|
|
39
|
+
readonly label: string;
|
|
28
40
|
}, {
|
|
29
41
|
readonly value: "quarters";
|
|
30
|
-
readonly label:
|
|
42
|
+
readonly label: string;
|
|
31
43
|
}, {
|
|
32
44
|
readonly value: "years";
|
|
33
|
-
readonly label:
|
|
45
|
+
readonly label: string;
|
|
34
46
|
}];
|
|
35
47
|
type CalculationDateValues = (typeof CALCULATION_DATES)[number]['value'];
|
|
36
48
|
export declare const VALUE_TYPES: {
|
|
@@ -1,30 +1,44 @@
|
|
|
1
|
+
import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
|
|
2
|
+
const { t } = i18nInstance;
|
|
1
3
|
export const DATE_TYPES = [
|
|
2
|
-
{ value: 'today', label: 'datePicker.dateTypes.today' },
|
|
3
|
-
{ value: 'first_day_of_week_mon_sun', label: 'datePicker.dateTypes.firstDayOfWeekMonSun' },
|
|
4
|
-
{ value: 'first_day_of_week_sun_sat', label: 'datePicker.dateTypes.firstDayOfWeekSunSat' },
|
|
5
|
-
{ value: 'first_day_of_month', label: 'datePicker.dateTypes.firstDayOfMonth' },
|
|
6
|
-
{ value: 'first_day_of_quarter', label: 'datePicker.dateTypes.firstDayOfQuarter' },
|
|
7
|
-
{ value: 'first_day_of_year', label: 'datePicker.dateTypes.firstDayOfYear' },
|
|
8
|
-
{ value: 'last_day_of_week_mon_sun', label: 'datePicker.dateTypes.lastDayOfWeekMonSun' },
|
|
9
|
-
{ value: 'last_day_of_week_sun_sat', label: 'datePicker.dateTypes.lastDayOfWeekSunSat' },
|
|
10
|
-
{ value: 'last_day_of_month', label: 'datePicker.dateTypes.lastDayOfMonth' },
|
|
11
|
-
{ value: 'last_day_of_quarter', label: 'datePicker.dateTypes.lastDayOfQuarter' },
|
|
12
|
-
{ value: 'last_day_of_year', label: 'datePicker.dateTypes.lastDayOfYear' },
|
|
13
|
-
{ value: 'fixed', label: 'datePicker.dateTypes.fixed' },
|
|
4
|
+
{ value: 'today', label: t('datePicker.dateTypes.today') },
|
|
5
|
+
{ value: 'first_day_of_week_mon_sun', label: t('datePicker.dateTypes.firstDayOfWeekMonSun') },
|
|
6
|
+
{ value: 'first_day_of_week_sun_sat', label: t('datePicker.dateTypes.firstDayOfWeekSunSat') },
|
|
7
|
+
{ value: 'first_day_of_month', label: t('datePicker.dateTypes.firstDayOfMonth') },
|
|
8
|
+
{ value: 'first_day_of_quarter', label: t('datePicker.dateTypes.firstDayOfQuarter') },
|
|
9
|
+
{ value: 'first_day_of_year', label: t('datePicker.dateTypes.firstDayOfYear') },
|
|
10
|
+
{ value: 'last_day_of_week_mon_sun', label: t('datePicker.dateTypes.lastDayOfWeekMonSun') },
|
|
11
|
+
{ value: 'last_day_of_week_sun_sat', label: t('datePicker.dateTypes.lastDayOfWeekSunSat') },
|
|
12
|
+
{ value: 'last_day_of_month', label: t('datePicker.dateTypes.lastDayOfMonth') },
|
|
13
|
+
{ value: 'last_day_of_quarter', label: t('datePicker.dateTypes.lastDayOfQuarter') },
|
|
14
|
+
{ value: 'last_day_of_year', label: t('datePicker.dateTypes.lastDayOfYear') },
|
|
15
|
+
{ value: 'fixed', label: t('datePicker.dateTypes.fixed') },
|
|
14
16
|
];
|
|
17
|
+
export const DATE_TYPE_MAPPING = {
|
|
18
|
+
first_day_of_week_mon_sun: 'isoWeek',
|
|
19
|
+
first_day_of_week_sun_sat: 'week',
|
|
20
|
+
first_day_of_month: 'month',
|
|
21
|
+
first_day_of_quarter: 'quarter',
|
|
22
|
+
first_day_of_year: 'year',
|
|
23
|
+
last_day_of_week_mon_sun: 'isoWeek',
|
|
24
|
+
last_day_of_week_sun_sat: 'week',
|
|
25
|
+
last_day_of_month: 'month',
|
|
26
|
+
last_day_of_quarter: 'quarter',
|
|
27
|
+
last_day_of_year: 'year',
|
|
28
|
+
};
|
|
15
29
|
export const CALCULATION_TYPES = [
|
|
16
|
-
{ value: 'minus', label: 'global.minus' },
|
|
17
|
-
{ value: 'plus', label: 'global.plus' },
|
|
30
|
+
{ value: 'minus', label: t('global.minus') },
|
|
31
|
+
{ value: 'plus', label: t('global.plus') },
|
|
18
32
|
];
|
|
19
33
|
export const CALCULATION_DATES = [
|
|
20
|
-
{ value: 'seconds', label: 'datePicker.seconds' },
|
|
21
|
-
{ value: 'minutes', label: 'datePicker.minutes' },
|
|
22
|
-
{ value: 'hours', label: 'datePicker.hours' },
|
|
23
|
-
{ value: 'days', label: 'datePicker.days' },
|
|
24
|
-
{ value: 'weeks', label: 'datePicker.weeks' },
|
|
25
|
-
{ value: 'months', label: 'datePicker.months' },
|
|
26
|
-
{ value: 'quarters', label: 'datePicker.quarters' },
|
|
27
|
-
{ value: 'years', label: 'datePicker.years' },
|
|
34
|
+
{ value: 'seconds', label: t('datePicker.seconds') },
|
|
35
|
+
{ value: 'minutes', label: t('datePicker.minutes') },
|
|
36
|
+
{ value: 'hours', label: t('datePicker.hours') },
|
|
37
|
+
{ value: 'days', label: t('datePicker.days') },
|
|
38
|
+
{ value: 'weeks', label: t('datePicker.weeks') },
|
|
39
|
+
{ value: 'months', label: t('datePicker.months') },
|
|
40
|
+
{ value: 'quarters', label: t('datePicker.quarters') },
|
|
41
|
+
{ value: 'years', label: t('datePicker.years') },
|
|
28
42
|
];
|
|
29
43
|
export const VALUE_TYPES = {
|
|
30
44
|
INPUT_TEXT: 'INPUT_TEXT',
|
|
@@ -3,7 +3,7 @@ var _a, _b, _c, _d, _e;
|
|
|
3
3
|
import { THEME } from '../../../../../constants';
|
|
4
4
|
import styled from 'styled-components';
|
|
5
5
|
export const DropdownContent = styled.div `
|
|
6
|
-
width:
|
|
6
|
+
width: 250px;
|
|
7
7
|
padding: 10px 10px 0px 10px;
|
|
8
8
|
display: flex;
|
|
9
9
|
flex-direction: column;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Dayjs } from 'dayjs';
|
|
2
2
|
import type { CellRenderInfo } from 'rc-picker/es/interface';
|
|
3
|
-
import { ValueTypes } from './types';
|
|
3
|
+
import { TAdvancedType, TOperatorKey, ValueTypes } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Calculates a new date based on the given parameters.
|
|
6
6
|
* @param {string} [dateTypeKey='today'] - Key to determine the type of date to be used as the starting point.
|
|
@@ -33,3 +33,7 @@ export declare const getPickerRender: (valueType: ValueTypes) => 'date' | 'week'
|
|
|
33
33
|
export declare const getTimePickerRender: (valueType: ValueTypes) => "HH" | "HHmm" | "HHmmss" | "mm" | undefined;
|
|
34
34
|
export declare function getLabelQuarterRange(day: string, format: string, locale: string, showYear?: boolean): string;
|
|
35
35
|
export declare function getLabelQuarterRange(quarter: number, year?: number): string;
|
|
36
|
+
export declare const getFormatDisplay: (operatorKey?: TOperatorKey, type?: TAdvancedType, valueType?: ValueTypes, formatInputDisplay?: string) => {
|
|
37
|
+
formatDisplay: string;
|
|
38
|
+
timeFormatDisplay: string;
|
|
39
|
+
};
|
|
@@ -4,7 +4,7 @@ import dayjs from 'dayjs';
|
|
|
4
4
|
import isoWeek from 'dayjs/plugin/isoWeek';
|
|
5
5
|
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
|
|
6
6
|
// Constants
|
|
7
|
-
import { DEFAULT_DATE_FORMAT, MONTH_LABEL_SHORT } from './constants';
|
|
7
|
+
import { DATE_TYPE_MAPPING, DEFAULT_DATE_FORMAT, MONTH_LABEL_SHORT, QUARTER_PLACEHOLDER, WEEK_PLACEHOLDER, } from './constants';
|
|
8
8
|
dayjs.extend(isoWeek);
|
|
9
9
|
dayjs.extend(quarterOfYear);
|
|
10
10
|
/**
|
|
@@ -23,43 +23,12 @@ dayjs.extend(quarterOfYear);
|
|
|
23
23
|
*/
|
|
24
24
|
export const calculationDateAdvanced = (dateTypeKey = 'today', calculationTypeKey = 'minus', calculationDateKey = 'days', value = 0, dateFormat = DEFAULT_DATE_FORMAT) => {
|
|
25
25
|
let date = dayjs();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
date
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
break;
|
|
33
|
-
case 'first_day_of_week_sun_sat':
|
|
34
|
-
date = dayjs().startOf('week');
|
|
35
|
-
break;
|
|
36
|
-
case 'first_day_of_month':
|
|
37
|
-
date = dayjs().startOf('month');
|
|
38
|
-
break;
|
|
39
|
-
case 'first_day_of_quarter':
|
|
40
|
-
date = dayjs().startOf('quarter');
|
|
41
|
-
break;
|
|
42
|
-
case 'first_day_of_year':
|
|
43
|
-
date = dayjs().startOf('year');
|
|
44
|
-
break;
|
|
45
|
-
case 'last_day_of_week_mon_sun':
|
|
46
|
-
date = dayjs().endOf('isoWeek');
|
|
47
|
-
break;
|
|
48
|
-
case 'last_day_of_week_sun_sat':
|
|
49
|
-
date = dayjs().endOf('week');
|
|
50
|
-
break;
|
|
51
|
-
case 'last_day_of_month':
|
|
52
|
-
date = dayjs().endOf('month');
|
|
53
|
-
break;
|
|
54
|
-
case 'last_day_of_quarter':
|
|
55
|
-
date = dayjs().endOf('quarter');
|
|
56
|
-
break;
|
|
57
|
-
case 'last_day_of_year':
|
|
58
|
-
date = dayjs().endOf('year');
|
|
59
|
-
break;
|
|
60
|
-
default:
|
|
61
|
-
date = dayjs();
|
|
62
|
-
break;
|
|
26
|
+
if (DATE_TYPE_MAPPING[dateTypeKey]) {
|
|
27
|
+
date = dateTypeKey.includes('first_day')
|
|
28
|
+
? date.startOf(DATE_TYPE_MAPPING[dateTypeKey])
|
|
29
|
+
: dateTypeKey.includes('last_day')
|
|
30
|
+
? date.endOf(DATE_TYPE_MAPPING[dateTypeKey])
|
|
31
|
+
: dayjs();
|
|
63
32
|
}
|
|
64
33
|
let newDate = '';
|
|
65
34
|
newDate =
|
|
@@ -171,3 +140,66 @@ export function getLabelQuarterRange(quarterOrDay, yearOrFormat, locale, showYea
|
|
|
171
140
|
? `${startMonthQuarter[currQuarter]} 01, ${currYear} - ${endMonthQuarter[currQuarter]} ${endDayQuarter[currQuarter]}, ${currYear}`
|
|
172
141
|
: `${startMonthQuarter[currQuarter]} 01 - ${endMonthQuarter[currQuarter]} ${endDayQuarter[currQuarter]}`;
|
|
173
142
|
}
|
|
143
|
+
export const getFormatDisplay = (operatorKey, type, valueType, formatInputDisplay) => {
|
|
144
|
+
let formatDisplay = '';
|
|
145
|
+
let timeFormatDisplay = '';
|
|
146
|
+
const isStartDate = operatorKey === 'between' ? type === 'startDate' : operatorKey === 'after';
|
|
147
|
+
switch (valueType) {
|
|
148
|
+
case 'YEAR':
|
|
149
|
+
formatDisplay = 'YYYY';
|
|
150
|
+
break;
|
|
151
|
+
case 'YEAR_QUARTER':
|
|
152
|
+
formatDisplay = `${QUARTER_PLACEHOLDER}Q, YYYY`;
|
|
153
|
+
break;
|
|
154
|
+
case 'YEAR_MONTH':
|
|
155
|
+
formatDisplay = 'MMMM, YYYY';
|
|
156
|
+
break;
|
|
157
|
+
case 'YEAR_WEEK':
|
|
158
|
+
formatDisplay = `${WEEK_PLACEHOLDER}W, YYYY`;
|
|
159
|
+
break;
|
|
160
|
+
case 'YEAR_MONTH_DAY':
|
|
161
|
+
formatDisplay = 'MMMM DD, YYYY';
|
|
162
|
+
break;
|
|
163
|
+
case 'YEAR_MONTH_DAY_HOUR':
|
|
164
|
+
formatDisplay = `MMMM DD, YYYY ${isStartDate ? 'HH:00:00' : 'HH:59:59'}`;
|
|
165
|
+
timeFormatDisplay = isStartDate ? 'HH:00:00' : 'HH:59:59';
|
|
166
|
+
break;
|
|
167
|
+
case 'YEAR_MONTH_DAY_MINUTE':
|
|
168
|
+
formatDisplay = `MMMM DD, YYYY ${isStartDate ? 'HH:mm:00' : 'HH:mm:59'}`;
|
|
169
|
+
timeFormatDisplay = isStartDate ? 'HH:mm:00' : 'HH:mm:59';
|
|
170
|
+
break;
|
|
171
|
+
case 'YEAR_MONTH_DAY_SECOND':
|
|
172
|
+
formatDisplay = 'MMMM DD, YYYY HH:mm:ss';
|
|
173
|
+
timeFormatDisplay = 'HH:mm:ss';
|
|
174
|
+
break;
|
|
175
|
+
case 'QUARTER':
|
|
176
|
+
formatDisplay = `${QUARTER_PLACEHOLDER}Q`;
|
|
177
|
+
break;
|
|
178
|
+
case 'MONTH':
|
|
179
|
+
formatDisplay = 'MMMM';
|
|
180
|
+
break;
|
|
181
|
+
case 'WEEK':
|
|
182
|
+
formatDisplay = `${WEEK_PLACEHOLDER}W`;
|
|
183
|
+
break;
|
|
184
|
+
case 'MONTH_DAY':
|
|
185
|
+
formatDisplay = 'MMMM DD';
|
|
186
|
+
break;
|
|
187
|
+
case 'DAY_OF_WEEK':
|
|
188
|
+
formatDisplay = 'dddd';
|
|
189
|
+
break;
|
|
190
|
+
case 'DAY':
|
|
191
|
+
formatDisplay = 'DD';
|
|
192
|
+
break;
|
|
193
|
+
case 'HOUR':
|
|
194
|
+
formatDisplay = 'HH';
|
|
195
|
+
break;
|
|
196
|
+
case 'MINUTE':
|
|
197
|
+
formatDisplay = 'mm';
|
|
198
|
+
break;
|
|
199
|
+
default:
|
|
200
|
+
formatDisplay = `DD/MM/YYYY - ${isStartDate ? '00:00:00' : '23:59:59'}`;
|
|
201
|
+
timeFormatDisplay = isStartDate ? '00:00:00' : '23:59:59';
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
return { formatDisplay: formatInputDisplay || formatDisplay, timeFormatDisplay };
|
|
205
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TAdvancedType, TOperatorKey, ValueTypes } from '../AdvancedPicker/types';
|
|
3
|
+
interface DropdownLabelProps {
|
|
4
|
+
valueType?: ValueTypes;
|
|
5
|
+
date?: string;
|
|
6
|
+
format?: string;
|
|
7
|
+
type?: TAdvancedType;
|
|
8
|
+
showTime?: boolean;
|
|
9
|
+
operatorKey?: TOperatorKey;
|
|
10
|
+
formatInputDisplay?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const DropdownLabel: React.FC<DropdownLabelProps>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
// Components
|
|
5
|
+
import { Typography } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
6
|
+
// Constants
|
|
7
|
+
import { ADVANCED_PICKER_TYPE, DEFAULT_DATE_FORMAT, HIDE_TIME_LABEL_ARR, QUARTER_PLACEHOLDER, WEEK_PLACEHOLDER, } from '../AdvancedPicker/constants';
|
|
8
|
+
// Instance
|
|
9
|
+
import i18nInstance from '@antscorp/antsomi-ui/es/locales/i18n';
|
|
10
|
+
import { getFormatDisplay, getLabelQuarterRange } from '../AdvancedPicker/utils';
|
|
11
|
+
export const DropdownLabel = React.memo(({ valueType, date, format, type, showTime, operatorKey, formatInputDisplay }) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const { t } = i18nInstance;
|
|
14
|
+
const title = (_a = Object.values(ADVANCED_PICKER_TYPE).find(({ value }) => value === type)) === null || _a === void 0 ? void 0 : _a.label;
|
|
15
|
+
const { timeFormatDisplay } = getFormatDisplay(operatorKey, type, valueType, formatInputDisplay);
|
|
16
|
+
let formatLabel = 'dddd, MMMM DD, YYYY';
|
|
17
|
+
let subLabel = '';
|
|
18
|
+
switch (valueType) {
|
|
19
|
+
case 'YEAR':
|
|
20
|
+
formatLabel = 'YYYY';
|
|
21
|
+
break;
|
|
22
|
+
case 'YEAR_QUARTER':
|
|
23
|
+
formatLabel = `${QUARTER_PLACEHOLDER}Q, YYYY`;
|
|
24
|
+
subLabel = getLabelQuarterRange(date, format || DEFAULT_DATE_FORMAT, 'en');
|
|
25
|
+
// subLabel = getLabelQuarterRange(date!, format || DEFAULT_DATE_FORMAT, locale);
|
|
26
|
+
break;
|
|
27
|
+
case 'YEAR_MONTH':
|
|
28
|
+
formatLabel = 'MMMM, YYYY';
|
|
29
|
+
break;
|
|
30
|
+
case 'YEAR_WEEK': {
|
|
31
|
+
const dayObj = dayjs(date || new Date(), format).locale('en');
|
|
32
|
+
// const dayObj = dayjs(date || new Date(), format).locale(locale || 'en');
|
|
33
|
+
formatLabel = `${WEEK_PLACEHOLDER}W, YYYY`;
|
|
34
|
+
subLabel = `${dayjs(dayObj).day(0).format('MMMM DD, YYYY')} - ${dayjs(dayObj)
|
|
35
|
+
.day(6)
|
|
36
|
+
.format('MMMM DD, YYYY')}`;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case 'YEAR_MONTH_DAY_HOUR':
|
|
40
|
+
formatLabel = 'dddd, MMMM DD, YYYY';
|
|
41
|
+
break;
|
|
42
|
+
case 'QUARTER':
|
|
43
|
+
formatLabel = `${QUARTER_PLACEHOLDER}Q`;
|
|
44
|
+
break;
|
|
45
|
+
case 'MONTH':
|
|
46
|
+
formatLabel = 'MMMM';
|
|
47
|
+
break;
|
|
48
|
+
case 'WEEK':
|
|
49
|
+
formatLabel = `${WEEK_PLACEHOLDER}W`;
|
|
50
|
+
break;
|
|
51
|
+
case 'MONTH_DAY':
|
|
52
|
+
formatLabel = 'MMMM DD';
|
|
53
|
+
break;
|
|
54
|
+
case 'DAY_OF_WEEK':
|
|
55
|
+
formatLabel = 'dddd';
|
|
56
|
+
break;
|
|
57
|
+
case 'DAY':
|
|
58
|
+
formatLabel = 'DD';
|
|
59
|
+
break;
|
|
60
|
+
case 'HOUR':
|
|
61
|
+
formatLabel = 'HH:00:00';
|
|
62
|
+
break;
|
|
63
|
+
case 'MINUTE':
|
|
64
|
+
formatLabel = '00:mm:00';
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
return (React.createElement("div", { style: { textAlign: 'center' } },
|
|
70
|
+
title && operatorKey === 'between' && (React.createElement(Typography.Text, { className: "__title", style: { color: '#666666' } }, t(title))),
|
|
71
|
+
React.createElement("div", { style: { fontWeight: 'bold' } }, dayjs(date || new Date(), format)
|
|
72
|
+
.locale('en')
|
|
73
|
+
// .locale(locale || 'en')
|
|
74
|
+
.format(formatLabel)
|
|
75
|
+
.replace(QUARTER_PLACEHOLDER, 'Quarter ')
|
|
76
|
+
.replace(WEEK_PLACEHOLDER, 'Week ')),
|
|
77
|
+
subLabel ? React.createElement("div", null, subLabel) : null,
|
|
78
|
+
!HIDE_TIME_LABEL_ARR.includes(valueType || '') && showTime && !subLabel ? (React.createElement("div", { style: { fontWeight: 'bold' } }, dayjs(date || new Date(), format)
|
|
79
|
+
.locale('en')
|
|
80
|
+
// .locale(locale || 'en')
|
|
81
|
+
.format(timeFormatDisplay))) : null));
|
|
82
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Icon from '@antscorp/icons';
|
|
3
|
+
import { Typography } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
4
|
+
import { THEME } from '@antscorp/antsomi-ui/es/constants';
|
|
5
|
+
export const ErrorMessage = React.memo(({ errorMessage }) => {
|
|
6
|
+
var _a;
|
|
7
|
+
if (!errorMessage)
|
|
8
|
+
return null;
|
|
9
|
+
return (React.createElement("div", { style: { display: 'flex', alignItems: 'center', gap: 5 } },
|
|
10
|
+
React.createElement(Icon, { type: "icon-ants-remove-circle", style: { color: (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.colorError } }),
|
|
11
|
+
React.createElement(Typography.Text, { type: "danger" }, errorMessage)));
|
|
12
|
+
});
|