@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.
Files changed (60) hide show
  1. package/addon/components/eui-field-text/index.hbs +1 -0
  2. package/addon/components/eui-global-toast-list/index.ts +1 -1
  3. package/addon/components/eui-i18n/index.ts +9 -41
  4. package/addon/components/eui-super-date-picker/date-popover/absolute-tab.hbs +42 -0
  5. package/addon/components/eui-super-date-picker/date-popover/absolute-tab.ts +79 -0
  6. package/addon/components/eui-super-date-picker/date-popover/datetime-picker.hbs +125 -0
  7. package/addon/components/eui-super-date-picker/date-popover/datetime-picker.ts +258 -0
  8. package/addon/components/eui-super-date-picker/date-popover/eui-date-popover-button.hbs +49 -0
  9. package/addon/components/eui-super-date-picker/date-popover/eui-date-popover-button.ts +49 -0
  10. package/addon/components/eui-super-date-picker/date-popover/eui-date-popover-content.hbs +42 -0
  11. package/addon/components/eui-super-date-picker/date-popover/eui-date-popover-content.ts +73 -0
  12. package/addon/components/eui-super-date-picker/date-popover/now-tab.hbs +45 -0
  13. package/addon/components/eui-super-date-picker/date-popover/relative-tab.hbs +47 -0
  14. package/addon/components/eui-super-date-picker/date-popover/relative-tab.ts +89 -0
  15. package/addon/components/eui-super-date-picker/eui-date-picker-range.hbs +22 -0
  16. package/addon/components/eui-super-date-picker/eui-quick-select-popover/eui-commonly-used-time-ranges.hbs +42 -0
  17. package/addon/components/eui-super-date-picker/eui-quick-select-popover/eui-quick-select.hbs +154 -0
  18. package/addon/components/eui-super-date-picker/eui-quick-select-popover/eui-quick-select.ts +103 -0
  19. package/addon/components/eui-super-date-picker/eui-quick-select-popover/eui-recently-used.hbs +48 -0
  20. package/addon/components/eui-super-date-picker/eui-quick-select-popover/index.hbs +60 -0
  21. package/addon/components/eui-super-date-picker/eui-quick-select-popover/index.ts +34 -0
  22. package/addon/components/eui-super-date-picker/eui-super-update-button.hbs +43 -0
  23. package/addon/components/eui-super-date-picker/index.hbs +123 -0
  24. package/addon/components/eui-super-date-picker/index.ts +220 -0
  25. package/addon/components/eui-super-date-picker/types/global.d.ts +52 -0
  26. package/addon/components/eui-super-date-picker/utils/date-utils.ts +59 -0
  27. package/addon/components/eui-super-date-picker/utils/index.ts +181 -0
  28. package/addon/components/eui-super-date-picker/utils/pretty-duration.ts +131 -0
  29. package/addon/components/eui-super-date-picker/utils/quick-select.ts +75 -0
  30. package/addon/components/eui-super-date-picker/utils/time-options.ts +216 -0
  31. package/addon/components/text-block/index.hbs +25 -21
  32. package/addon/{components/eui-i18n → i18n}/util.ts +1 -6
  33. package/addon/services/eui-i18n.ts +89 -0
  34. package/addon/utils/markdown/markdown-unified-plugins.d.ts +0 -14
  35. package/app/components/eui-super-date-picker/date-popover/absolute-tab.js +1 -0
  36. package/app/components/eui-super-date-picker/date-popover/datetime-picker.js +1 -0
  37. package/app/components/eui-super-date-picker/date-popover/eui-date-popover-button.js +1 -0
  38. package/app/components/eui-super-date-picker/date-popover/eui-date-popover-content.js +1 -0
  39. package/app/components/eui-super-date-picker/date-popover/now-tab.js +1 -0
  40. package/app/components/eui-super-date-picker/date-popover/relative-tab.js +1 -0
  41. package/app/components/eui-super-date-picker/eui-date-picker-range.js +1 -0
  42. package/app/components/eui-super-date-picker/eui-quick-select-popover/eui-commonly-used-time-ranges.js +1 -0
  43. package/app/components/eui-super-date-picker/eui-quick-select-popover/eui-quick-select.js +1 -0
  44. package/app/components/eui-super-date-picker/eui-quick-select-popover/eui-recently-used.js +1 -0
  45. package/app/components/eui-super-date-picker/eui-quick-select-popover/index.js +1 -0
  46. package/app/components/eui-super-date-picker/eui-super-update-button.js +1 -0
  47. package/app/components/eui-super-date-picker/index.js +1 -0
  48. package/app/services/eui-i18n.js +1 -0
  49. package/docs/forms/super-date-picker/demo/d01-picker.md +90 -0
  50. package/docs/forms/super-date-picker/index.md +16 -0
  51. package/package.json +6 -3
  52. package/tsconfig.json +1 -0
  53. package/addon/i18n/index.ts +0 -8
  54. package/app/i18n/index.js +0 -1
  55. package/docs/templates/super-date-picker/demo/d01-update-button.md +0 -10
  56. package/docs/templates/super-date-picker/demo/d02-quick-select-panels.md +0 -10
  57. package/docs/templates/super-date-picker/demo/d03-sizing.md +0 -10
  58. package/docs/templates/super-date-picker/demo/d04-auto-refresh.md +0 -11
  59. package/docs/templates/super-date-picker/demo/d05-elastic-pattern-with-kql.md +0 -10
  60. package/docs/templates/super-date-picker/index.md +0 -12
@@ -0,0 +1,48 @@
1
+ {{#let (unique-id) as |legendId|}}
2
+ <fieldset>
3
+ <EuiTitle
4
+ id={{legendId}}
5
+ @tagName="legend"
6
+ @size="xxxs"
7
+ >
8
+ <EuiI18n
9
+ @token="euiRecentlyUsed.legend"
10
+ @default="Recently used date ranges"
11
+ as |Token|
12
+ >
13
+ <Token as |value|>
14
+ {{value}}
15
+ </Token>
16
+ </EuiI18n>
17
+ </EuiTitle>
18
+ <div class="euiQuickSelectPopover__section">
19
+ <EuiFlexGrid
20
+ aria-labelledby={{legendId}}
21
+ @gutterSize="s"
22
+ @columns="2"
23
+ @direction="column"
24
+ @responsive={{false}}
25
+ @tagName="ul"
26
+ >
27
+ {{#each @recentlyUsedRanges as |range|}}
28
+ <EuiFlexItem
29
+ class="euiQuickSelectPopover__sectionItem"
30
+ @tagName="li"
31
+ >
32
+ <EuiLink
33
+ {{on "click" (fn @applyTime (hash start=range.start end=range.end))}}
34
+ >
35
+ {{!-- <PrettyDuration
36
+ timeFrom={start}
37
+ timeTo={end}
38
+ @quickRanges={{@commonlyUsedRanges}}
39
+ @dateFormat={{@dateFormat}}
40
+ /> --}}
41
+ {{range.label}}
42
+ </EuiLink>
43
+ </EuiFlexItem>
44
+ {{/each}}
45
+ </EuiFlexGrid>
46
+ </div>
47
+ </fieldset>
48
+ {{/let}}
@@ -0,0 +1,60 @@
1
+ <EuiPopover
2
+ @isOpen={{this.isOpen}}
3
+ @closePopover={{set this "isOpen" false}}
4
+ @anchorPosition="downLeft"
5
+ @anchorClassName="euiQuickSelectPopover__anchor"
6
+ >
7
+ <:button>
8
+ <EuiButtonEmpty
9
+ class="euiFormControlLayout__prepend"
10
+ @textClasses="euiQuickSelectPopover__buttonText"
11
+ @size="xs"
12
+ @iconType="arrowDown"
13
+ @iconSide="right"
14
+ @isDisabled={{@isDisabled}}
15
+ {{on "click" (set this "isOpen" (not this.isOpen))}}
16
+ >
17
+ <EuiIcon @type="calendar" />
18
+ </EuiButtonEmpty>
19
+ </:button>
20
+
21
+ <:content>
22
+ <div
23
+ class="euiQuickSelectPopover__content"
24
+ >
25
+ <EuiSuperDatePicker::EuiQuickSelectPopover::EuiQuickSelect
26
+ @applyTime={{this.applyTime}}
27
+ @start={{@start}}
28
+ @end={{@end}}
29
+ @timeOptions={{@timeOptions}}
30
+ {{!-- prevQuickSelect={prevQuickSelect} --}}
31
+ />
32
+
33
+ {{#if (gt @commonlyUsedRanges.length 0)}}
34
+ <EuiHorizontalRule @margin="s" />
35
+ <EuiSuperDatePicker::EuiQuickSelectPopover::EuiCommonlyUsedTimeRanges
36
+ @applyTime={{this.applyTime}}
37
+ @commonlyUsedRanges={{@commonlyUsedRanges}}
38
+ />
39
+ {{/if}}
40
+
41
+ {{#if (gt @recentlyUsedRanges.length 0)}}
42
+ <EuiHorizontalRule @margin="s" />
43
+ <EuiSuperDatePicker::EuiQuickSelectPopover::EuiRecentlyUsed
44
+ @applyTime={{this.applyTime}}
45
+ @commonlyUsedRanges={{@commonlyUsedRanges}}
46
+ @dateFormat={{@dateFormat}}
47
+ @recentlyUsedRanges={{@recentlyUsedRanges}}
48
+ />
49
+ {{/if}}
50
+
51
+ {{!-- {this.renderCustomQuickSelectPanels()} --}}
52
+ {{!-- <EuiHorizontalRule @margin="s" />
53
+ <EuiRefreshInterval
54
+ onRefreshChange={applyRefreshInterval}
55
+ isPaused={isPaused}
56
+ refreshInterval={refreshInterval}
57
+ /> --}}
58
+ </div>
59
+ </:content>
60
+ </EuiPopover>
@@ -0,0 +1,34 @@
1
+ import { action } from '@ember/object';
2
+ import Component from '@glimmer/component';
3
+ import { tracked } from '@glimmer/tracking';
4
+ import { ApplyTime } from '../types/global';
5
+
6
+ interface EuiQuickSelectPopoverArgs {
7
+ applyTime: ApplyTime;
8
+ }
9
+
10
+ export default class EuiQuickSelectPopover extends Component<EuiQuickSelectPopoverArgs> {
11
+ @tracked isOpen = false;
12
+
13
+ @action applyTime({
14
+ start,
15
+ end,
16
+ keepPopoverOpen = false
17
+ }: {
18
+ start: string;
19
+ end: string;
20
+ quickSelect?: { timeTense: string; timeValue: number; timeUnits: string };
21
+ keepPopoverOpen?: boolean;
22
+ }) {
23
+ this.args.applyTime({
24
+ start,
25
+ end
26
+ });
27
+ // if (quickSelect) {
28
+ // this.setState({ prevQuickSelect: quickSelect });
29
+ // }
30
+ if (!keepPopoverOpen) {
31
+ this.isOpen = false;
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,43 @@
1
+ {{#if @iconOnly}}
2
+ <EuiButtonIcon
3
+ class={{class-names
4
+ "euiSuperUpdateButton"
5
+ @className
6
+ }}
7
+ @display={{if @fill "fill"}}
8
+ @color={{if (or @needsUpdate @isLoading) "success" "primary"}}
9
+ @iconType={{if (or @needsUpdate @isLoading) "kqlFunction" "refresh"}}
10
+ @isDisabled={{@isDisabled}}
11
+ @isLoading={{@isLoading}}
12
+ @size={{@size}}
13
+ {{style minWidth="0px"}}
14
+ {{on "click" @onClick}}
15
+ ...attributes
16
+ />
17
+ {{else}}
18
+ <EuiButton
19
+ class={{class-names
20
+ "euiSuperUpdateButton"
21
+ @className
22
+ }}
23
+ @fill={{@fill}}
24
+ @textClasses={{@textClasses}}
25
+ @color={{if (or @needsUpdate @isLoading) "success" "primary"}}
26
+ @iconType={{if (or @needsUpdate @isLoading) "kqlFunction" "refresh"}}
27
+ @isDisabled={{@isDisabled}}
28
+ @isLoading={{@isLoading}}
29
+ @size={{@size}}
30
+ {{on "click" @onClick}}
31
+ ...attributes
32
+ >
33
+ {{#if (or @needsUpdate @isLoading)}}
34
+ {{#if @isLoading}}
35
+ Updating
36
+ {{else}}
37
+ Update
38
+ {{/if}}
39
+ {{else}}
40
+ Refresh
41
+ {{/if}}
42
+ </EuiButton>
43
+ {{/if}}
@@ -0,0 +1,123 @@
1
+ <EuiFlexGroup
2
+ @gutterSize="s"
3
+ @responsive={{false}}
4
+ class={{class-names
5
+ "euiSuperDatePicker__flexWrapper"
6
+ (unless this.showUpdateButton "euiSuperDatePicker__flexWrapper--noUpdateButton")
7
+ (if this.isAutoRefreshOnly "euiSuperDatePicker__flexWrapper--isAutoRefreshOnly")
8
+ (if @isQuickSelectOnly "euiSuperDatePicker__flexWrapper--isQuickSelectOnly")
9
+ (if (eq this.width "full") "euiSuperDatePicker__flexWrapper--fullWidth")
10
+ (if (eq this.width "auto") "euiSuperDatePicker__flexWrapper--autoWidth")
11
+ }}
12
+ >
13
+ <EuiFlexItem>
14
+ <EuiFormControlLayout
15
+ class="euiSuperDatePicker"
16
+ @compressed={{@compressed}}
17
+ @isDisabled={{@isDisabled}}
18
+ @useGroup={{true}}
19
+ {{!-- @fullWidth={{this.fullWidth}} --}}
20
+ {{!-- @readOnly={{@readOnly}} --}}
21
+ >
22
+ <:prepend>
23
+ <EuiSuperDatePicker::EuiQuickSelectPopover
24
+ @start={{this.start}}
25
+ @end={{this.end}}
26
+ @applyTime={{this.applyQuickTime}}
27
+ @timeOptions={{this.timeOptions}}
28
+ @isDisabled={{@isDisabled}}
29
+ @dateFormat={{this.dateFormat}}
30
+ @commonlyUsedRanges={{arg-or-default
31
+ @commonlyUsedRanges
32
+ this.timeOptions.commonDurationRanges
33
+ }}
34
+ {{!-- @applyRefreshInterval={{if @onRefreshChange this.onRefreshChange}} --}}
35
+ {{!-- commonlyUsedRanges={commonlyUsedRanges}
36
+ customQuickSelectPanels={customQuickSelectPanels}
37
+ isPaused={isPaused}
38
+ recentlyUsedRanges={recentlyUsedRanges}
39
+ refreshInterval={refreshInterval} --}}
40
+ />
41
+ </:prepend>
42
+
43
+ <:field>
44
+ <EuiSuperDatePicker::EuiDatePickerRange
45
+ @className="euiDatePickerRange--inGroup"
46
+ @iconType={{false}}
47
+ @isInvalid={{this.isInvalid}}
48
+ @disabled={{@isDisabled}}
49
+ @isCustom={{true}}
50
+ >
51
+ <:startDateControl>
52
+ <EuiSuperDatePicker::DatePopover::EuiDatePopoverButton
53
+ @className="euiSuperDatePicker__startPopoverButton"
54
+ @value={{this.start}}
55
+ @compressed={{@compressed}}
56
+ @position="start"
57
+ @isDisabled={{@isDisabled}}
58
+ @dateFormat={{this.dateFormat}}
59
+ @onChange={{this.setStart}}
60
+ @isInvalid={{this.isInvalid}}
61
+ @timeOptions={{this.timeOptions}}
62
+ @needsUpdating={{this.hasChanged}}
63
+ @locale={{@locale}}
64
+ {{!--
65
+ isInvalid={isInvalid}
66
+ utcOffset={utcOffset}
67
+ timeFormat={timeFormat}
68
+ isOpen={this.state.isStartDatePopoverOpen}
69
+ onPopoverToggle={this.onStartDatePopoverToggle}
70
+ onPopoverClose={this.onStartDatePopoverClose}
71
+ --}}
72
+ />
73
+ </:startDateControl>
74
+
75
+ <:endDateControl>
76
+ <EuiSuperDatePicker::DatePopover::EuiDatePopoverButton
77
+ @className="euiSuperDatePicker__startPopoverButton"
78
+ @value={{this.end}}
79
+ @compressed={{@compressed}}
80
+ @position="end"
81
+ @isDisabled={{@isDisabled}}
82
+ @dateFormat={{this.dateFormat}}
83
+ @onChange={{this.setEnd}}
84
+ @isInvalid={{this.isInvalid}}
85
+ @timeOptions={{this.timeOptions}}
86
+ @roundUp={{true}}
87
+ @needsUpdating={{this.hasChanged}}
88
+ @locale={{@locale}}
89
+ {{!--
90
+ utcOffset={utcOffset}
91
+ timeFormat={timeFormat}
92
+ isOpen={this.state.isStartDatePopoverOpen}
93
+ onPopoverToggle={this.onStartDatePopoverToggle}
94
+ onPopoverClose={this.onStartDatePopoverClose}
95
+ --}}
96
+ />
97
+ </:endDateControl>
98
+ </EuiSuperDatePicker::EuiDatePickerRange>
99
+ </:field>
100
+ </EuiFormControlLayout>
101
+ </EuiFlexItem>
102
+
103
+ {{#if this.showUpdateButton}}
104
+ <EuiFlexItem @grow={{false}}>
105
+ <EuiSuperDatePicker::EuiSuperUpdateButton
106
+ @size={{if @compressed "s" "m"}}
107
+ @onClick={{this.handleClickUpdateButton}}
108
+ @isLoading={{@isLoading}}
109
+ @isDisabled={{or @isDisabled this.isInvalid}}
110
+ @needsUpdate={{this.hasChanged}}
111
+ @fill={{true}}
112
+ @iconOnly={{eq this.showUpdateButton "iconOnly"}}
113
+ {{!--
114
+ showTooltip={
115
+ !this.state.isStartDatePopoverOpen &&
116
+ !this.state.isEndDatePopoverOpen
117
+ }
118
+ responsive
119
+ --}}
120
+ />
121
+ </EuiFlexItem>
122
+ {{/if}}
123
+ </EuiFlexGroup>
@@ -0,0 +1,220 @@
1
+ import { action } from '@ember/object';
2
+ import Component from '@glimmer/component';
3
+ import { tracked } from '@glimmer/tracking';
4
+ import { argOrDefaultDecorator as argOrDefault } from '../../helpers/arg-or-default';
5
+ import { LocaleSpecifier } from 'moment';
6
+ import {
7
+ ApplyRefreshInterval,
8
+ DurationRange,
9
+ Milliseconds,
10
+ ShortDate
11
+ } from './types/global';
12
+ import { isRangeInvalid } from './utils';
13
+ import { useI18nTimeOptions } from './utils/time-options';
14
+ import { OnRefreshProps, OnTimeChangeProps } from '@elastic/eui';
15
+ import type EuiI18n from '../../services/eui-i18n';
16
+ import { inject as service } from '@ember/service';
17
+
18
+ interface EuiSuperDatePickerArgs {
19
+ commonlyUsedRanges?: DurationRange[];
20
+ // customQuickSelectPanels?: QuickSelectPanel[];
21
+ /**
22
+ * Specifies the formatted used when displaying dates and/or datetimes
23
+ */
24
+ dateFormat?: string;
25
+ /**
26
+ * Set isAutoRefreshOnly to true to limit the component to only display auto refresh content.
27
+ */
28
+ isAutoRefreshOnly?: boolean;
29
+ isDisabled?: boolean;
30
+ isLoading?: boolean;
31
+ isPaused?: boolean;
32
+ /**
33
+ * Sets the overall width by adding sensible min and max widths.
34
+ * - `auto`: fits width to internal content / time string.
35
+ * - `restricted`: static width that fits the longest possible time string.
36
+ * - `full`: expands to 100% of the container.
37
+ */
38
+ width?: 'restricted' | 'full' | 'auto';
39
+ /**
40
+ * Reduces overall height to compressed form size
41
+ */
42
+ compressed?: boolean;
43
+ /**
44
+ * Used to localize e.g. month names, passed to `moment`
45
+ */
46
+ locale?: LocaleSpecifier;
47
+ /**
48
+ * Callback for when the refresh interval is fired.
49
+ * EuiSuperDatePicker will only manage a refresh interval timer when onRefresh callback is supplied
50
+ * If a promise is returned, the next refresh interval will not start until the promise has resolved.
51
+ * If the promise rejects the refresh interval will stop and the error thrown
52
+ */
53
+ onRefresh?: (props: OnRefreshProps) => void;
54
+ /**
55
+ * Callback for when the refresh interval changes.
56
+ * Supply onRefreshChange to show refresh interval inputs in quick select popover
57
+ */
58
+ onRefreshChange?: ApplyRefreshInterval;
59
+ /**
60
+ * Callback for when the time changes.
61
+ */
62
+ onTimeChange: (props: OnTimeChangeProps) => void;
63
+ // recentlyUsedRanges?: DurationRange[];
64
+ /**
65
+ * Refresh interval in milliseconds
66
+ */
67
+ refreshInterval?: Milliseconds;
68
+ start?: ShortDate;
69
+ end?: ShortDate;
70
+ /**
71
+ * Specifies the formatted used when displaying times
72
+ */
73
+ timeFormat?: string;
74
+ utcOffset?: number;
75
+ /**
76
+ * Set showUpdateButton to false to immediately invoke onTimeChange for all start and end changes.
77
+ */
78
+ showUpdateButton?: boolean | 'iconOnly';
79
+ /**
80
+ * Hides the actual input reducing to just the quick select button.
81
+ */
82
+ isQuickSelectOnly?: boolean;
83
+ /**
84
+ * Props passed to the update button #EuiSuperUpdateButtonProps
85
+ */
86
+ // updateButtonProps?: EuiSuperUpdateButtonProps;
87
+ }
88
+
89
+ export default class EuiSuperDatePicker extends Component<EuiSuperDatePickerArgs> {
90
+ @argOrDefault('MMM D, YYYY @ HH:mm:ss.SSS') dateFormat!: string;
91
+ @argOrDefault('HH:mm') timeFormat!: string;
92
+ // @argOrDefault('now-15m') start!: ShortDate;
93
+ // @argOrDefault('now') end!: ShortDate;
94
+ @argOrDefault(false) isAutoRefreshOnly!: boolean;
95
+ @argOrDefault(false) isDisabled!: boolean;
96
+ @argOrDefault(true) isPaused!: boolean;
97
+ @argOrDefault(true) showUpdateButton!: boolean;
98
+ @argOrDefault('restricted') width!: string;
99
+ // recentlyUsedRanges: [],
100
+ @argOrDefault(1000) refreshInterval!: Milliseconds;
101
+
102
+ @service declare euiI18n: EuiI18n;
103
+
104
+ @tracked start: ShortDate;
105
+ @tracked end: ShortDate;
106
+ @tracked isInvalid = false;
107
+ @tracked hasChanged = false;
108
+
109
+ constructor(owner: any, args: EuiSuperDatePickerArgs) {
110
+ super(owner, args);
111
+
112
+ this.start = this.args.start ?? 'now-15m';
113
+ this.end = this.args.end ?? 'now';
114
+
115
+ // if (this.args.start === undefined || this.args.end === undefined) {
116
+ // this.setTime({
117
+ // start: this.args.start ?? 'now-15m',
118
+ // end: this.args.end ?? 'now'
119
+ // });
120
+ // }
121
+ }
122
+
123
+ get timeOptions() {
124
+ return useI18nTimeOptions(this.euiI18n);
125
+ }
126
+
127
+ setTime({ start, end }: DurationRange) {
128
+ this.hasChanged = !(this.start === start && this.end === end);
129
+ this.start = start;
130
+ this.end = end;
131
+ this.isInvalid = isRangeInvalid(start, end);
132
+
133
+ if (!this.showUpdateButton) {
134
+ this.args.onTimeChange({
135
+ start,
136
+ end,
137
+ isQuickSelection: false,
138
+ isInvalid: this.isInvalid
139
+ } as OnTimeChangeProps);
140
+ }
141
+ }
142
+
143
+ applyTime() {
144
+ this.args.onTimeChange({
145
+ start: this.start,
146
+ end: this.end,
147
+ isQuickSelection: false,
148
+ isInvalid: false
149
+ });
150
+ }
151
+
152
+ // stopInterval() {
153
+ // if (this.asyncInterval) {
154
+ // this.asyncInterval.stop();
155
+ // }
156
+ // }
157
+
158
+ // startInterval(refreshInterval: number) {
159
+ // if (this.args.onRefresh) {
160
+ // const handler = () => {
161
+ // const { start, end } = this.props;
162
+ // this.args.onRefresh({ start, end, refreshInterval });
163
+ // };
164
+ // this.asyncInterval = new AsyncInterval(handler, refreshInterval);
165
+ // }
166
+ // }
167
+
168
+ @action applyQuickTime({ start, end }: DurationRange) {
169
+ // this.setState({
170
+ // showPrettyDuration: showPrettyDuration(
171
+ // start,
172
+ // end,
173
+ // this.props.commonlyUsedRanges
174
+ // )
175
+ // });
176
+
177
+ // Update the internal state
178
+ this.start = start;
179
+ this.end = end;
180
+
181
+ this.args.onTimeChange({
182
+ start,
183
+ end,
184
+ isQuickSelection: true,
185
+ isInvalid: false
186
+ });
187
+ }
188
+
189
+ @action setStart(start: ShortDate) {
190
+ this.setTime({ start, end: this.end });
191
+ }
192
+
193
+ @action setEnd(end: ShortDate) {
194
+ this.setTime({ start: this.start, end });
195
+ }
196
+
197
+ @action handleClickUpdateButton() {
198
+ if (!this.hasChanged && this.args.onRefresh) {
199
+ // const { start, end, refreshInterval } = this.args;
200
+ this.args.onRefresh({
201
+ start: this.start,
202
+ end: this.end,
203
+ refreshInterval: this.refreshInterval
204
+ });
205
+ } else {
206
+ this.applyTime();
207
+ }
208
+ this.hasChanged = false;
209
+ }
210
+
211
+ // @action onRefreshChange({ refreshInterval, isPaused }) {
212
+ // this.stopInterval();
213
+ // if (!isPaused) {
214
+ // this.startInterval(refreshInterval);
215
+ // }
216
+ // if (this.props.onRefreshChange) {
217
+ // this.props.onRefreshChange({ refreshInterval, isPaused });
218
+ // }
219
+ // }
220
+ }
@@ -0,0 +1,52 @@
1
+ import { Moment } from 'moment';
2
+
3
+ export interface DurationRange {
4
+ end: ShortDate;
5
+ label?: string;
6
+ start: ShortDate;
7
+ }
8
+
9
+ export type ShortDate = NowDateMode | string;
10
+
11
+ export type NowDateMode = 'now';
12
+
13
+ export type TimeUnitId = 's' | 'm' | 'h' | 'd' | 'w' | 'M' | 'y';
14
+
15
+ export type TimeUnitFromNowId = 's+' | 'm+' | 'h+' | 'd+' | 'w+' | 'M+' | 'y+';
16
+
17
+ export interface RelativeParts {
18
+ count: number;
19
+ round: boolean;
20
+ roundUnit?: TimeUnitId;
21
+ unit: string;
22
+ }
23
+
24
+ export type Milliseconds = number;
25
+
26
+ export interface RelativeOption {
27
+ text: string;
28
+ value: TimeUnitAllId;
29
+ }
30
+
31
+ export type TimeUnitAllId = TimeUnitId | TimeUnitFromNowId;
32
+
33
+ export type OnRefreshChangeArgs = {
34
+ isPaused: boolean;
35
+ refreshInterval: number;
36
+ };
37
+
38
+ export type ApplyRefreshInterval = (args: OnRefreshChangeArgs) => void;
39
+
40
+ interface ApplyTimeArgs extends DurationRange {
41
+ start: string;
42
+ end: string;
43
+ keepPopoverOpen?: boolean;
44
+ quickSelect?: QuickSelect;
45
+ }
46
+ export type ApplyTime = (args: ApplyTimeArgs) => void;
47
+
48
+ export interface QuickSelect {
49
+ timeTense: string;
50
+ timeValue: number;
51
+ timeUnits: TimeUnitId;
52
+ }
@@ -0,0 +1,59 @@
1
+ import { Moment } from 'moment';
2
+
3
+ export function isSameDay(moment1: Moment, moment2: Moment) {
4
+ if (moment1 && moment2) {
5
+ return moment1.isSame(moment2, 'day');
6
+ } else {
7
+ return !moment1 && !moment2;
8
+ }
9
+ }
10
+
11
+ export function isSameTime(moment1: Moment, moment2: Moment) {
12
+ if (moment1 && moment2) {
13
+ return moment1.isSame(moment2, 'second');
14
+ } else {
15
+ return !moment1 && !moment2;
16
+ }
17
+ }
18
+
19
+ export function isDayDisabled(
20
+ day: Moment,
21
+ {
22
+ minDate,
23
+ maxDate,
24
+ excludeDates,
25
+ includeDates,
26
+ filterDate
27
+ }: {
28
+ minDate?: Moment;
29
+ maxDate?: Moment;
30
+ excludeDates?: Moment[];
31
+ includeDates?: Moment[];
32
+ filterDate?: (day: Moment) => boolean;
33
+ } = {}
34
+ ) {
35
+ return (
36
+ (minDate && day.isBefore(minDate, 'day')) ||
37
+ (maxDate && day.isAfter(maxDate, 'day')) ||
38
+ (excludeDates &&
39
+ excludeDates.some((excludeDate: Moment) =>
40
+ isSameDay(day, excludeDate)
41
+ )) ||
42
+ (includeDates &&
43
+ !includeDates.some((includeDate: Moment) =>
44
+ isSameDay(day, includeDate)
45
+ )) ||
46
+ (filterDate && !filterDate(day.clone())) ||
47
+ false
48
+ );
49
+ }
50
+
51
+ export function isOutOfBounds(
52
+ day: Moment,
53
+ { minDate, maxDate }: { minDate?: Moment; maxDate?: Moment } = {}
54
+ ) {
55
+ return (
56
+ (minDate && day.isBefore(minDate, 'day')) ||
57
+ (maxDate && day.isAfter(maxDate, 'day'))
58
+ );
59
+ }