@ember-eui/core 5.8.5 → 5.9.2
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/addon/components/eui-field-text/index.hbs +1 -0
- package/addon/components/eui-global-toast-list/index.ts +1 -1
- package/addon/components/eui-i18n/index.ts +9 -41
- package/addon/components/eui-super-date-picker/date-popover/absolute-tab.hbs +42 -0
- package/addon/components/eui-super-date-picker/date-popover/absolute-tab.ts +79 -0
- package/addon/components/eui-super-date-picker/date-popover/datetime-picker.hbs +125 -0
- package/addon/components/eui-super-date-picker/date-popover/datetime-picker.ts +258 -0
- package/addon/components/eui-super-date-picker/date-popover/eui-date-popover-button.hbs +49 -0
- package/addon/components/eui-super-date-picker/date-popover/eui-date-popover-button.ts +49 -0
- package/addon/components/eui-super-date-picker/date-popover/eui-date-popover-content.hbs +42 -0
- package/addon/components/eui-super-date-picker/date-popover/eui-date-popover-content.ts +73 -0
- package/addon/components/eui-super-date-picker/date-popover/now-tab.hbs +45 -0
- package/addon/components/eui-super-date-picker/date-popover/relative-tab.hbs +47 -0
- package/addon/components/eui-super-date-picker/date-popover/relative-tab.ts +89 -0
- package/addon/components/eui-super-date-picker/eui-date-picker-range.hbs +22 -0
- package/addon/components/eui-super-date-picker/eui-quick-select-popover/eui-commonly-used-time-ranges.hbs +42 -0
- package/addon/components/eui-super-date-picker/eui-quick-select-popover/eui-quick-select.hbs +154 -0
- package/addon/components/eui-super-date-picker/eui-quick-select-popover/eui-quick-select.ts +103 -0
- package/addon/components/eui-super-date-picker/eui-quick-select-popover/eui-recently-used.hbs +48 -0
- package/addon/components/eui-super-date-picker/eui-quick-select-popover/index.hbs +60 -0
- package/addon/components/eui-super-date-picker/eui-quick-select-popover/index.ts +34 -0
- package/addon/components/eui-super-date-picker/eui-super-update-button.hbs +43 -0
- package/addon/components/eui-super-date-picker/index.hbs +123 -0
- package/addon/components/eui-super-date-picker/index.ts +220 -0
- package/addon/components/eui-super-date-picker/types/global.d.ts +52 -0
- package/addon/components/eui-super-date-picker/utils/date-utils.ts +59 -0
- package/addon/components/eui-super-date-picker/utils/index.ts +181 -0
- package/addon/components/eui-super-date-picker/utils/pretty-duration.ts +131 -0
- package/addon/components/eui-super-date-picker/utils/quick-select.ts +75 -0
- package/addon/components/eui-super-date-picker/utils/time-options.ts +216 -0
- package/addon/components/text-block/index.hbs +25 -21
- package/addon/{components/eui-i18n → i18n}/util.ts +1 -6
- package/addon/services/eui-i18n.ts +89 -0
- package/addon/utils/markdown/markdown-unified-plugins.d.ts +0 -14
- package/app/components/eui-super-date-picker/date-popover/absolute-tab.js +1 -0
- package/app/components/eui-super-date-picker/date-popover/datetime-picker.js +1 -0
- package/app/components/eui-super-date-picker/date-popover/eui-date-popover-button.js +1 -0
- package/app/components/eui-super-date-picker/date-popover/eui-date-popover-content.js +1 -0
- package/app/components/eui-super-date-picker/date-popover/now-tab.js +1 -0
- package/app/components/eui-super-date-picker/date-popover/relative-tab.js +1 -0
- package/app/components/eui-super-date-picker/eui-date-picker-range.js +1 -0
- package/app/components/eui-super-date-picker/eui-quick-select-popover/eui-commonly-used-time-ranges.js +1 -0
- package/app/components/eui-super-date-picker/eui-quick-select-popover/eui-quick-select.js +1 -0
- package/app/components/eui-super-date-picker/eui-quick-select-popover/eui-recently-used.js +1 -0
- package/app/components/eui-super-date-picker/eui-quick-select-popover/index.js +1 -0
- package/app/components/eui-super-date-picker/eui-super-update-button.js +1 -0
- package/app/components/eui-super-date-picker/index.js +1 -0
- package/app/services/eui-i18n.js +1 -0
- package/docs/forms/super-date-picker/demo/d01-picker.md +90 -0
- package/docs/forms/super-date-picker/index.md +16 -0
- package/package.json +6 -3
- package/tsconfig.json +1 -0
- package/addon/i18n/index.ts +0 -8
- package/app/i18n/index.js +0 -1
- package/docs/templates/super-date-picker/demo/d01-update-button.md +0 -10
- package/docs/templates/super-date-picker/demo/d02-quick-select-panels.md +0 -10
- package/docs/templates/super-date-picker/demo/d03-sizing.md +0 -10
- package/docs/templates/super-date-picker/demo/d04-auto-refresh.md +0 -11
- package/docs/templates/super-date-picker/demo/d05-elastic-pattern-with-kql.md +0 -10
- package/docs/templates/super-date-picker/index.md +0 -12
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
4
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
5
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
6
|
+
* Side Public License, v 1.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import moment, { LocaleSpecifier } from 'moment';
|
|
10
|
+
import dateMath from '@elastic/datemath';
|
|
11
|
+
import { RelativeParts, ShortDate } from '../types/global';
|
|
12
|
+
import type EuiI18n from '../../../services/eui-i18n';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Reusable format time string util
|
|
16
|
+
*/
|
|
17
|
+
export const ISO_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
|
|
18
|
+
export const INVALID_DATE = 'invalid_date';
|
|
19
|
+
export const ROUND_DELIMETER = '/';
|
|
20
|
+
export const relativeUnitsFromLargestToSmallest = [
|
|
21
|
+
'y',
|
|
22
|
+
'M',
|
|
23
|
+
'w',
|
|
24
|
+
'd',
|
|
25
|
+
'h',
|
|
26
|
+
'm',
|
|
27
|
+
's'
|
|
28
|
+
];
|
|
29
|
+
export type AbsoluteDateMode = 'absolute';
|
|
30
|
+
export type RelativeDateMode = 'relative';
|
|
31
|
+
export type NowDateMode = 'now';
|
|
32
|
+
export type DateMode = AbsoluteDateMode | RelativeDateMode | NowDateMode;
|
|
33
|
+
export const DATE_MODES: {
|
|
34
|
+
ABSOLUTE: AbsoluteDateMode;
|
|
35
|
+
RELATIVE: RelativeDateMode;
|
|
36
|
+
NOW: NowDateMode;
|
|
37
|
+
} = {
|
|
38
|
+
ABSOLUTE: 'absolute',
|
|
39
|
+
RELATIVE: 'relative',
|
|
40
|
+
NOW: 'now'
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const useFormatTimeString = (
|
|
44
|
+
timeString: string,
|
|
45
|
+
dateFormat: string,
|
|
46
|
+
roundUp = false,
|
|
47
|
+
locale: LocaleSpecifier = 'en',
|
|
48
|
+
euiI18nService: EuiI18n
|
|
49
|
+
): string => {
|
|
50
|
+
let lookupToken = euiI18nService.lookupToken;
|
|
51
|
+
|
|
52
|
+
// i18n'd strings
|
|
53
|
+
const nowDisplay = lookupToken('euiPrettyDuration.now', 'now');
|
|
54
|
+
const invalidDateDisplay = lookupToken(
|
|
55
|
+
'euiPrettyDuration.invalid',
|
|
56
|
+
'Invalid date'
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const timeAsMoment = moment(timeString, ISO_FORMAT, true);
|
|
60
|
+
if (timeAsMoment.isValid()) {
|
|
61
|
+
return timeAsMoment.locale(locale).format(dateFormat);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (timeString === 'now') {
|
|
65
|
+
return nowDisplay as string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const tryParse = dateMath.parse(timeString, { roundUp: roundUp });
|
|
69
|
+
if (!moment(tryParse).isValid()) {
|
|
70
|
+
return invalidDateDisplay as string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (moment.isMoment(tryParse)) {
|
|
74
|
+
return `~ ${tryParse.locale(locale).fromNow()}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return timeString;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export function toAbsoluteString(value: string, roundUp: boolean = false) {
|
|
81
|
+
const valueAsMoment = dateMath.parse(value, { roundUp });
|
|
82
|
+
if (!valueAsMoment) {
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
if (!moment(valueAsMoment).isValid()) {
|
|
86
|
+
return INVALID_DATE;
|
|
87
|
+
}
|
|
88
|
+
return valueAsMoment.toISOString();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function parseRelativeParts(value: string): {
|
|
92
|
+
count: number;
|
|
93
|
+
unit: string;
|
|
94
|
+
round: boolean;
|
|
95
|
+
roundUnit?: string;
|
|
96
|
+
} {
|
|
97
|
+
const matches =
|
|
98
|
+
typeof value === 'string' &&
|
|
99
|
+
value.match(/now(([-+])([0-9]+)([smhdwMy])(\/[smhdwMy])?)?/);
|
|
100
|
+
|
|
101
|
+
const operator = matches && matches[2];
|
|
102
|
+
const count = matches && matches[3];
|
|
103
|
+
const unit = matches && matches[4];
|
|
104
|
+
const roundBy = matches && matches[5];
|
|
105
|
+
|
|
106
|
+
if (count && unit) {
|
|
107
|
+
const isRounded = roundBy ? true : false;
|
|
108
|
+
const roundUnit =
|
|
109
|
+
isRounded && roundBy ? roundBy.replace(ROUND_DELIMETER, '') : undefined;
|
|
110
|
+
return {
|
|
111
|
+
count: parseInt(count, 10),
|
|
112
|
+
unit: operator === '+' ? `${unit}+` : unit,
|
|
113
|
+
round: isRounded,
|
|
114
|
+
...(roundUnit ? { roundUnit } : {})
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const results = { count: 0, unit: 's', round: false };
|
|
119
|
+
const duration = moment.duration(moment().diff(dateMath.parse(value)));
|
|
120
|
+
let unitOp = '';
|
|
121
|
+
for (let i = 0; i < relativeUnitsFromLargestToSmallest.length; i++) {
|
|
122
|
+
// @ts-expect-error this is a string with the accepted time units
|
|
123
|
+
const asRelative = duration.as(relativeUnitsFromLargestToSmallest[i]);
|
|
124
|
+
if (asRelative < 0) unitOp = '+';
|
|
125
|
+
if (Math.abs(asRelative) > 1) {
|
|
126
|
+
results.count = Math.round(Math.abs(asRelative));
|
|
127
|
+
results.unit = relativeUnitsFromLargestToSmallest[i] + unitOp;
|
|
128
|
+
results.round = false;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return results;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function toRelativeStringFromParts(relativeParts: RelativeParts) {
|
|
136
|
+
const count = relativeParts.count ?? 0;
|
|
137
|
+
const isRounded = relativeParts.round ?? false;
|
|
138
|
+
|
|
139
|
+
if (count === 0 && !isRounded) {
|
|
140
|
+
return 'now';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const matches = (relativeParts.unit ?? 's').match(/([smhdwMy])(\+)?/);
|
|
144
|
+
const unit = matches?.[1];
|
|
145
|
+
const operator = matches && matches[2] ? matches[2] : '-';
|
|
146
|
+
const round = isRounded ? `${ROUND_DELIMETER}${unit}` : '';
|
|
147
|
+
|
|
148
|
+
return `now${operator}${count}${unit}${round}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function isRangeInvalid(start: ShortDate, end: ShortDate) {
|
|
152
|
+
if (start === 'now' && end === 'now') {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const startMoment = dateMath.parse(start);
|
|
157
|
+
const endMoment = dateMath.parse(end, { roundUp: true });
|
|
158
|
+
|
|
159
|
+
const isInvalid =
|
|
160
|
+
!startMoment ||
|
|
161
|
+
!endMoment ||
|
|
162
|
+
!startMoment.isValid() ||
|
|
163
|
+
!endMoment.isValid() ||
|
|
164
|
+
!moment(startMoment).isValid() ||
|
|
165
|
+
!moment(endMoment).isValid() ||
|
|
166
|
+
startMoment.isAfter(endMoment);
|
|
167
|
+
|
|
168
|
+
return isInvalid;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function getDateMode(value: ShortDate) {
|
|
172
|
+
if (value === 'now') {
|
|
173
|
+
return DATE_MODES.NOW;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (value.includes('now')) {
|
|
177
|
+
return DATE_MODES.RELATIVE;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return DATE_MODES.ABSOLUTE;
|
|
181
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type EuiI18n from '../../../services/eui-i18n';
|
|
2
|
+
import { DATE_MODES, getDateMode } from '.';
|
|
3
|
+
import { DurationRange, ShortDate } from '../types/global';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Pretty duration i18n strings
|
|
7
|
+
* Units should not be simply concatenated because different languages
|
|
8
|
+
* will have different grammar/positions for time than English
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const useRelativeDurationI18n = <T extends number = number>(
|
|
12
|
+
duration: T,
|
|
13
|
+
euiI18n: EuiI18n
|
|
14
|
+
) => {
|
|
15
|
+
const lookupToken = euiI18n.lookupToken;
|
|
16
|
+
return {
|
|
17
|
+
s: lookupToken(
|
|
18
|
+
'euiPrettyDuration.lastDurationSeconds',
|
|
19
|
+
({ duration }: { duration: T }) =>
|
|
20
|
+
`Last ${duration} second${duration === 1 ? '' : 's'}`,
|
|
21
|
+
{ duration }
|
|
22
|
+
),
|
|
23
|
+
's+': lookupToken(
|
|
24
|
+
'euiPrettyDuration.nextDurationSeconds',
|
|
25
|
+
({ duration }: { duration: T }) =>
|
|
26
|
+
`Next ${duration} second${duration === 1 ? '' : 's'}`,
|
|
27
|
+
{ duration }
|
|
28
|
+
),
|
|
29
|
+
m: lookupToken(
|
|
30
|
+
'euiPrettyDuration.lastDurationMinutes',
|
|
31
|
+
({ duration }: { duration: T }) =>
|
|
32
|
+
`Last ${duration} minute${duration === 1 ? '' : 's'}`,
|
|
33
|
+
{ duration }
|
|
34
|
+
),
|
|
35
|
+
'm+': lookupToken(
|
|
36
|
+
'euiPrettyDuration.nextDurationMinutes',
|
|
37
|
+
({ duration }: { duration: T }) =>
|
|
38
|
+
`Next ${duration} minute${duration === 1 ? '' : 's'}`,
|
|
39
|
+
{ duration }
|
|
40
|
+
),
|
|
41
|
+
h: lookupToken(
|
|
42
|
+
'euiPrettyDuration.lastDurationHours',
|
|
43
|
+
({ duration }: { duration: T }) =>
|
|
44
|
+
`Last ${duration} hour${duration === 1 ? '' : 's'}`,
|
|
45
|
+
{ duration }
|
|
46
|
+
),
|
|
47
|
+
'h+': lookupToken(
|
|
48
|
+
'euiPrettyDuration.nextDurationHours',
|
|
49
|
+
({ duration }: { duration: T }) =>
|
|
50
|
+
`Next ${duration} hour${duration === 1 ? '' : 's'}`,
|
|
51
|
+
{ duration }
|
|
52
|
+
),
|
|
53
|
+
d: lookupToken(
|
|
54
|
+
'euiPrettyDuration.lastDurationDays',
|
|
55
|
+
({ duration }: { duration: T }) =>
|
|
56
|
+
`Last ${duration} day${duration === 1 ? '' : 's'}`,
|
|
57
|
+
{ duration }
|
|
58
|
+
),
|
|
59
|
+
'd+': lookupToken(
|
|
60
|
+
'euiPrettyDuration.nexttDurationDays',
|
|
61
|
+
({ duration }: { duration: T }) =>
|
|
62
|
+
`Next ${duration} day${duration === 1 ? '' : 's'}`,
|
|
63
|
+
{ duration }
|
|
64
|
+
),
|
|
65
|
+
w: lookupToken(
|
|
66
|
+
'euiPrettyDuration.lastDurationWeeks',
|
|
67
|
+
({ duration }: { duration: T }) =>
|
|
68
|
+
`Last ${duration} week${duration === 1 ? '' : 's'}`,
|
|
69
|
+
{ duration }
|
|
70
|
+
),
|
|
71
|
+
'w+': lookupToken(
|
|
72
|
+
'euiPrettyDuration.nextDurationWeeks',
|
|
73
|
+
({ duration }: { duration: T }) =>
|
|
74
|
+
`Next ${duration} week${duration === 1 ? '' : 's'}`,
|
|
75
|
+
{ duration }
|
|
76
|
+
),
|
|
77
|
+
M: lookupToken(
|
|
78
|
+
'euiPrettyDuration.lastDurationMonths',
|
|
79
|
+
({ duration }: { duration: T }) =>
|
|
80
|
+
`Last ${duration} month${duration === 1 ? '' : 's'}`,
|
|
81
|
+
{ duration }
|
|
82
|
+
),
|
|
83
|
+
'M+': lookupToken(
|
|
84
|
+
'euiPrettyDuration.nextDurationMonths',
|
|
85
|
+
({ duration }: { duration: T }) =>
|
|
86
|
+
`Next ${duration} month${duration === 1 ? '' : 's'}`,
|
|
87
|
+
{ duration }
|
|
88
|
+
),
|
|
89
|
+
y: lookupToken(
|
|
90
|
+
'euiPrettyDuration.lastDurationYears',
|
|
91
|
+
({ duration }: { duration: T }) =>
|
|
92
|
+
`Last ${duration} year${duration === 1 ? '' : 's'}`,
|
|
93
|
+
{ duration }
|
|
94
|
+
),
|
|
95
|
+
'y+': lookupToken(
|
|
96
|
+
'euiPrettyDuration.nextDurationYears',
|
|
97
|
+
({ duration }: { duration: T }) =>
|
|
98
|
+
`Next ${duration} year${duration === 1 ? '' : 's'}`,
|
|
99
|
+
{ duration }
|
|
100
|
+
)
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const hasRangeMatch = (
|
|
105
|
+
timeFrom: ShortDate,
|
|
106
|
+
timeTo: ShortDate,
|
|
107
|
+
ranges: DurationRange[]
|
|
108
|
+
) => {
|
|
109
|
+
return ranges.find(({ start, end }) => timeFrom === start && timeTo === end);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const isRelativeToNow = (timeFrom: ShortDate, timeTo: ShortDate): boolean => {
|
|
113
|
+
const fromDateMode = getDateMode(timeFrom);
|
|
114
|
+
const toDateMode = getDateMode(timeTo);
|
|
115
|
+
const isLast =
|
|
116
|
+
fromDateMode === DATE_MODES.RELATIVE && toDateMode === DATE_MODES.NOW;
|
|
117
|
+
const isNext =
|
|
118
|
+
fromDateMode === DATE_MODES.NOW && toDateMode === DATE_MODES.RELATIVE;
|
|
119
|
+
return isLast || isNext;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export const showPrettyDuration = (
|
|
123
|
+
timeFrom: ShortDate,
|
|
124
|
+
timeTo: ShortDate,
|
|
125
|
+
quickRanges: DurationRange[]
|
|
126
|
+
): boolean => {
|
|
127
|
+
if (hasRangeMatch(timeFrom, timeTo, quickRanges)) {
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return isRelativeToNow(timeFrom, timeTo);
|
|
131
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
4
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
5
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
6
|
+
* Side Public License, v 1.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import moment from 'moment';
|
|
10
|
+
import dateMath from '@elastic/datemath';
|
|
11
|
+
import { LAST, NEXT } from './time-options';
|
|
12
|
+
import { DATE_MODES, relativeUnitsFromLargestToSmallest } from '.';
|
|
13
|
+
import { QuickSelect, TimeUnitId } from '../types/global';
|
|
14
|
+
|
|
15
|
+
const isNow = (value: string) => value === DATE_MODES.NOW;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This function returns time value, time unit and time tense for a given time string.
|
|
19
|
+
*
|
|
20
|
+
* For example: for `now-40m` it will parse output as time value to `40` time unit to `m` and time unit to `last`.
|
|
21
|
+
*
|
|
22
|
+
* If given a datetime string it will return a default value.
|
|
23
|
+
*
|
|
24
|
+
* If the given string is in the format such as `now/d` it will parse the string to moment object and find the time value, time unit and time tense using moment
|
|
25
|
+
*
|
|
26
|
+
* This function accepts two strings start and end time. I the start value is now then it uses the end value to parse.
|
|
27
|
+
*/
|
|
28
|
+
export const parseTimeParts = (start: string, end: string): QuickSelect => {
|
|
29
|
+
const results: QuickSelect = {
|
|
30
|
+
timeTense: LAST,
|
|
31
|
+
timeUnits: 'm',
|
|
32
|
+
timeValue: 15
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const value = isNow(start) ? end : start;
|
|
36
|
+
|
|
37
|
+
const matches =
|
|
38
|
+
typeof value === 'string' &&
|
|
39
|
+
value.match(/now(([-+])(\d+)([smhdwMy])(\/[smhdwMy])?)?/);
|
|
40
|
+
|
|
41
|
+
if (!matches) {
|
|
42
|
+
return results;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const operator = matches[2];
|
|
46
|
+
const matchedTimeValue = matches[3];
|
|
47
|
+
const timeUnits = matches[4] as TimeUnitId;
|
|
48
|
+
|
|
49
|
+
if (matchedTimeValue && timeUnits && operator) {
|
|
50
|
+
return {
|
|
51
|
+
timeTense: operator === '+' ? NEXT : LAST,
|
|
52
|
+
timeUnits,
|
|
53
|
+
timeValue: parseInt(matchedTimeValue, 10)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const duration = moment.duration(moment().diff(dateMath.parse(value)));
|
|
58
|
+
let unitOp = '';
|
|
59
|
+
for (let i = 0; i < relativeUnitsFromLargestToSmallest.length; i++) {
|
|
60
|
+
// @ts-expect-error this is a string with the accepted time units
|
|
61
|
+
const as = duration.as(relativeUnitsFromLargestToSmallest[i]);
|
|
62
|
+
if (as < 0) {
|
|
63
|
+
unitOp = '+';
|
|
64
|
+
}
|
|
65
|
+
if (Math.abs(as) > 1) {
|
|
66
|
+
return {
|
|
67
|
+
timeValue: Math.round(Math.abs(as)),
|
|
68
|
+
timeUnits: relativeUnitsFromLargestToSmallest[i] as TimeUnitId,
|
|
69
|
+
timeTense: unitOp === '+' ? NEXT : LAST
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return results;
|
|
75
|
+
};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
|
+
* or more contributor license agreements. Licensed under the Elastic License
|
|
4
|
+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
5
|
+
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
6
|
+
* Side Public License, v 1.
|
|
7
|
+
*/
|
|
8
|
+
import { EuiSelectOption } from '@elastic/eui';
|
|
9
|
+
import type EuiI18n from '../../../services/eui-i18n';
|
|
10
|
+
|
|
11
|
+
import { TimeUnitId, RelativeOption, DurationRange } from '../types/global';
|
|
12
|
+
|
|
13
|
+
export const LAST = 'last';
|
|
14
|
+
export const NEXT = 'next';
|
|
15
|
+
|
|
16
|
+
export type TimeOptions = {
|
|
17
|
+
timeTenseOptions: EuiSelectOption[];
|
|
18
|
+
timeUnitsOptions: EuiSelectOption[];
|
|
19
|
+
relativeOptions: RelativeOption[];
|
|
20
|
+
relativeRoundingLabels: { [id in TimeUnitId]: string };
|
|
21
|
+
refreshUnitsOptions: EuiSelectOption[];
|
|
22
|
+
commonDurationRanges: DurationRange[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* i18n'd time options, mostly used in EuiSelects (except for a few cases)
|
|
27
|
+
* used in EuiSuperDatePicker child sub-components
|
|
28
|
+
*/
|
|
29
|
+
export const useI18nTimeOptions = (euiI18nService: EuiI18n): TimeOptions => {
|
|
30
|
+
let lookupToken = euiI18nService.lookupToken;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Quick select panel
|
|
34
|
+
*/
|
|
35
|
+
const timeTenseOptions = [
|
|
36
|
+
{ value: LAST, text: lookupToken('euiTimeOptions.last', 'Last') },
|
|
37
|
+
{ value: NEXT, text: lookupToken('euiTimeOptions.next', 'Next') }
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
const timeUnitsOptions = [
|
|
41
|
+
{ value: 's', text: lookupToken('euiTimeOptions.seconds', 'Seconds') },
|
|
42
|
+
{ value: 'm', text: lookupToken('euiTimeOptions.minutes', 'Minutes') },
|
|
43
|
+
{ value: 'h', text: lookupToken('euiTimeOptions.hours', 'Hours') },
|
|
44
|
+
{ value: 'd', text: lookupToken('euiTimeOptions.days', 'Days') },
|
|
45
|
+
{ value: 'w', text: lookupToken('euiTimeOptions.weeks', 'Weeks') },
|
|
46
|
+
{ value: 'M', text: lookupToken('euiTimeOptions.months', 'Months') },
|
|
47
|
+
{ value: 'y', text: lookupToken('euiTimeOptions.years', 'Years') }
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Relative tab
|
|
52
|
+
*/
|
|
53
|
+
const relativeOptions: RelativeOption[] = [
|
|
54
|
+
{
|
|
55
|
+
text: lookupToken('euiTimeOptions.secondsAgo', 'Seconds ago') as string,
|
|
56
|
+
value: 's'
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
text: lookupToken('euiTimeOptions.minutesAgo', 'Minutes ago') as string,
|
|
60
|
+
value: 'm'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
text: lookupToken('euiTimeOptions.hoursAgo', 'Hours ago') as string,
|
|
64
|
+
value: 'h'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
text: lookupToken('euiTimeOptions.daysAgo', 'Days ago') as string,
|
|
68
|
+
value: 'd'
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
text: lookupToken('euiTimeOptions.weeksAgo', 'Weeks ago') as string,
|
|
72
|
+
value: 'w'
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
text: lookupToken('euiTimeOptions.monthsAgo', 'Months ago') as string,
|
|
76
|
+
value: 'M'
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
text: lookupToken('euiTimeOptions.yearsAgo', 'Years ago') as string,
|
|
80
|
+
value: 'y'
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
text: lookupToken(
|
|
84
|
+
'euiTimeOptions.secondsFromNow',
|
|
85
|
+
'Seconds from now'
|
|
86
|
+
) as string,
|
|
87
|
+
value: 's+'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
text: lookupToken(
|
|
91
|
+
'euiTimeOptions.minutesFromNow',
|
|
92
|
+
'Minutes from now'
|
|
93
|
+
) as string,
|
|
94
|
+
value: 'm+'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
text: lookupToken(
|
|
98
|
+
'euiTimeOptions.hoursFromNow',
|
|
99
|
+
'Hours from now'
|
|
100
|
+
) as string,
|
|
101
|
+
value: 'h+'
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
text: lookupToken(
|
|
105
|
+
'euiTimeOptions.daysFromNow',
|
|
106
|
+
'Days from now'
|
|
107
|
+
) as string,
|
|
108
|
+
value: 'd+'
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
text: lookupToken(
|
|
112
|
+
'euiTimeOptions.weeksFromNow',
|
|
113
|
+
'Weeks from now'
|
|
114
|
+
) as string,
|
|
115
|
+
value: 'w+'
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
text: lookupToken(
|
|
119
|
+
'euiTimeOptions.monthsFromNow',
|
|
120
|
+
'Months from now'
|
|
121
|
+
) as string,
|
|
122
|
+
value: 'M+'
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
text: lookupToken(
|
|
126
|
+
'euiTimeOptions.yearsFromNow',
|
|
127
|
+
'Years from now'
|
|
128
|
+
) as string,
|
|
129
|
+
value: 'y+'
|
|
130
|
+
}
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
const relativeRoundingLabels = {
|
|
134
|
+
s: lookupToken(
|
|
135
|
+
'euiTimeOptions.roundToSecond',
|
|
136
|
+
'Round to the second'
|
|
137
|
+
) as string,
|
|
138
|
+
m: lookupToken(
|
|
139
|
+
'euiTimeOptions.roundToMinute',
|
|
140
|
+
'Round to the minute'
|
|
141
|
+
) as string,
|
|
142
|
+
h: lookupToken('euiTimeOptions.roundToHour', 'Round to the hour') as string,
|
|
143
|
+
d: lookupToken('euiTimeOptions.roundToDay', 'Round to the day') as string,
|
|
144
|
+
w: lookupToken('euiTimeOptions.roundToWeek', 'Round to the week') as string,
|
|
145
|
+
M: lookupToken(
|
|
146
|
+
'euiTimeOptions.roundToMonth',
|
|
147
|
+
'Round to the month'
|
|
148
|
+
) as string,
|
|
149
|
+
y: lookupToken('euiTimeOptions.roundToYear', 'Round to the year') as string
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Auto Refresh
|
|
154
|
+
*/
|
|
155
|
+
const refreshUnitsOptions = timeUnitsOptions.filter(
|
|
156
|
+
({ value }) => value === 'h' || value === 'm' || value === 's'
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Used by both Quick Select ('Commonly used') and by PrettyDuration
|
|
161
|
+
*/
|
|
162
|
+
const commonDurationRanges = [
|
|
163
|
+
{
|
|
164
|
+
start: 'now/d',
|
|
165
|
+
end: 'now/d',
|
|
166
|
+
label: lookupToken('euiTimeOptions.today', 'Today') as string
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
start: 'now/w',
|
|
170
|
+
end: 'now/w',
|
|
171
|
+
label: lookupToken('euiTimeOptions.thisWeek', 'This week') as string
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
start: 'now/M',
|
|
175
|
+
end: 'now/M',
|
|
176
|
+
label: lookupToken('euiTimeOptions.thisMonth', 'This month') as string
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
start: 'now/y',
|
|
180
|
+
end: 'now/y',
|
|
181
|
+
label: lookupToken('euiTimeOptions.thisYear', 'This year') as string
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
start: 'now-1d/d',
|
|
185
|
+
end: 'now-1d/d',
|
|
186
|
+
label: lookupToken('euiTimeOptions.yesterday', 'Yesterday') as string
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
start: 'now/w',
|
|
190
|
+
end: 'now',
|
|
191
|
+
label: lookupToken('euiTimeOptions.weekToDate', 'Week to date') as string
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
start: 'now/M',
|
|
195
|
+
end: 'now',
|
|
196
|
+
label: lookupToken(
|
|
197
|
+
'euiTimeOptions.monthToDate',
|
|
198
|
+
'Month to date'
|
|
199
|
+
) as string
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
start: 'now/y',
|
|
203
|
+
end: 'now',
|
|
204
|
+
label: lookupToken('euiTimeOptions.yearToDate', 'Year to date') as string
|
|
205
|
+
}
|
|
206
|
+
];
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
timeTenseOptions,
|
|
210
|
+
timeUnitsOptions,
|
|
211
|
+
relativeOptions,
|
|
212
|
+
relativeRoundingLabels,
|
|
213
|
+
refreshUnitsOptions,
|
|
214
|
+
commonDurationRanges
|
|
215
|
+
};
|
|
216
|
+
};
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
{{#if (eq @tagName "h1")}}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
<h1 ...attributes>
|
|
3
|
+
{{yield}}
|
|
4
|
+
</h1>
|
|
5
5
|
{{else if (eq @tagName "h2")}}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
<h2 ...attributes>
|
|
7
|
+
{{yield}}
|
|
8
|
+
</h2>
|
|
9
9
|
{{else if (eq @tagName "h3")}}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
<h3 ...attributes>
|
|
11
|
+
{{yield}}
|
|
12
|
+
</h3>
|
|
13
13
|
{{else if (eq @tagName "h4")}}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
<h4 ...attributes>
|
|
15
|
+
{{yield}}
|
|
16
|
+
</h4>
|
|
17
17
|
{{else if (eq @tagName "h5")}}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
<h5 ...attributes>
|
|
19
|
+
{{yield}}
|
|
20
|
+
</h5>
|
|
21
21
|
{{else if (eq @tagName "h6")}}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
<h6 ...attributes>
|
|
23
|
+
{{yield}}
|
|
24
|
+
</h6>
|
|
25
25
|
{{else if (eq @tagName "p")}}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
<p ...attributes>
|
|
27
|
+
{{yield}}
|
|
28
|
+
</p>
|
|
29
|
+
{{else if (eq @tagName "legend")}}
|
|
30
|
+
<legend ...attributes>
|
|
31
|
+
{{yield}}
|
|
32
|
+
</legend>
|
|
29
33
|
{{/if}}
|
|
@@ -6,12 +6,7 @@
|
|
|
6
6
|
* Side Public License, v 1.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
isBoolean,
|
|
11
|
-
isString,
|
|
12
|
-
isNumber,
|
|
13
|
-
isUndefined
|
|
14
|
-
} from '../../utils/predicate';
|
|
9
|
+
import { isBoolean, isString, isNumber, isUndefined } from '../utils/predicate';
|
|
15
10
|
import { get } from '@ember/object';
|
|
16
11
|
import { assert } from '@ember/debug';
|
|
17
12
|
|