-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiSuperDatePicker] add showRefreshOnly prop (#1412)
* [EuiSuperDatePicker] add showRefreshOnly prop * showRefreshOnly design updates (#4) * rename showRefreshOnly to isAutoRefreshOnly, add description for prop * changelog
- Loading branch information
Showing
14 changed files
with
364 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/components/date_picker/super_date_picker/pretty_interval.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
const MS_IN_SECOND = 1000; | ||
const MS_IN_MINUTE = 60 * MS_IN_SECOND; | ||
const MS_IN_HOUR = 60 * MS_IN_MINUTE; | ||
const MS_IN_DAY = 24 * MS_IN_HOUR; | ||
|
||
export function prettyInterval(isPaused, intervalInMs) { | ||
if (isPaused || intervalInMs === 0) { | ||
return 'Off'; | ||
} else if (intervalInMs < MS_IN_MINUTE) { | ||
const intervalInSeconds = Math.round(intervalInMs / MS_IN_SECOND); | ||
const units = intervalInSeconds > 1 ? 'seconds' : 'second'; | ||
return `${intervalInSeconds} ${units}`; | ||
} else if (intervalInMs < MS_IN_HOUR) { | ||
const intervalInMinutes = Math.round(intervalInMs / MS_IN_MINUTE); | ||
const units = intervalInMinutes > 1 ? 'minutes' : 'minute'; | ||
return `${intervalInMinutes} ${units}`; | ||
} else if (intervalInMs < MS_IN_DAY) { | ||
const intervalInHours = Math.round(intervalInMs / MS_IN_HOUR); | ||
const units = intervalInHours > 1 ? 'hours' : 'hour'; | ||
return `${intervalInHours} ${units}`; | ||
} | ||
|
||
const intervalInDays = Math.round(intervalInMs / MS_IN_DAY); | ||
const units = intervalInDays > 1 ? 'days' : 'day'; | ||
return `${intervalInDays} ${units}`; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/components/date_picker/super_date_picker/pretty_interval.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
import { prettyInterval } from './pretty_interval'; | ||
|
||
const IS_NOT_PAUSED = false; | ||
const IS_PAUSED = true; | ||
|
||
test('Off', () => { | ||
expect(prettyInterval(IS_NOT_PAUSED, 0)).toBe('Off'); | ||
expect(prettyInterval(IS_PAUSED, 1000)).toBe('Off'); | ||
}); | ||
|
||
test('seconds', () => { | ||
expect(prettyInterval(IS_NOT_PAUSED, 1000)).toBe('1 second'); | ||
expect(prettyInterval(IS_NOT_PAUSED, 15000)).toBe('15 seconds'); | ||
}); | ||
|
||
test('minutes', () => { | ||
expect(prettyInterval(IS_NOT_PAUSED, 60000)).toBe('1 minute'); | ||
expect(prettyInterval(IS_NOT_PAUSED, 1800000)).toBe('30 minutes'); | ||
}); | ||
|
||
test('hours', () => { | ||
expect(prettyInterval(IS_NOT_PAUSED, 3600000)).toBe('1 hour'); | ||
expect(prettyInterval(IS_NOT_PAUSED, 43200000)).toBe('12 hours'); | ||
}); | ||
|
||
test('days', () => { | ||
expect(prettyInterval(IS_NOT_PAUSED, 86400000)).toBe('1 day'); | ||
expect(prettyInterval(IS_NOT_PAUSED, 86400000 * 2)).toBe('2 days'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...er/super_date_picker/quick_select_popover/__snapshots__/quick_select_popover.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`EuiQuickSelectPopover is rendered 1`] = ` | ||
<EuiPopover | ||
anchorPosition="downLeft" | ||
button={ | ||
<EuiButtonEmpty | ||
aria-label="Date quick select" | ||
className="euiFormControlLayout__prepend" | ||
color="primary" | ||
data-test-subj="superDatePickerToggleQuickMenuButton" | ||
iconSide="right" | ||
iconType="arrowDown" | ||
onClick={[Function]} | ||
size="xs" | ||
textProps={ | ||
Object { | ||
"className": "euiQuickSelectPopover__buttonText", | ||
} | ||
} | ||
type="button" | ||
> | ||
<EuiIcon | ||
size="m" | ||
type="calendar" | ||
/> | ||
</EuiButtonEmpty> | ||
} | ||
closePopover={[Function]} | ||
hasArrow={true} | ||
id="QuickSelectPopover" | ||
isOpen={false} | ||
ownFocus={true} | ||
panelPaddingSize="m" | ||
> | ||
<div | ||
className="euiQuickSelectPopover__content" | ||
data-test-subj="superDatePickerQuickMenu" | ||
> | ||
<React.Fragment> | ||
<EuiQuickSelect | ||
applyTime={[Function]} | ||
end="now" | ||
prevQuickSelect={Object {}} | ||
start="now-15m" | ||
/> | ||
<EuiCommonlyUsedTimeRanges | ||
applyTime={[Function]} | ||
commonlyUsedRanges={ | ||
Array [ | ||
Object { | ||
"end": "now/d", | ||
"label": "Today", | ||
"start": "now/d", | ||
}, | ||
] | ||
} | ||
/> | ||
<EuiRecentlyUsed | ||
applyTime={[Function]} | ||
commonlyUsedRanges={ | ||
Array [ | ||
Object { | ||
"end": "now/d", | ||
"label": "Today", | ||
"start": "now/d", | ||
}, | ||
] | ||
} | ||
dateFormat="MMM D, YYYY @ HH:mm:ss.SSS" | ||
recentlyUsedRanges={ | ||
Array [ | ||
Object { | ||
"end": "now/d", | ||
"label": "Today", | ||
"start": "now/d", | ||
}, | ||
] | ||
} | ||
/> | ||
</React.Fragment> | ||
<EuiRefreshInterval | ||
applyRefreshInterval={[Function]} | ||
isPaused={true} | ||
refreshInterval={0} | ||
/> | ||
</div> | ||
</EuiPopover> | ||
`; | ||
|
||
exports[`EuiQuickSelectPopover isAutoRefreshOnly 1`] = ` | ||
<EuiPopover | ||
anchorPosition="downLeft" | ||
button={ | ||
<EuiButtonEmpty | ||
aria-label="Date quick select" | ||
className="euiFormControlLayout__prepend" | ||
color="primary" | ||
data-test-subj="superDatePickerToggleQuickMenuButton" | ||
iconSide="right" | ||
iconType="arrowDown" | ||
onClick={[Function]} | ||
size="xs" | ||
textProps={ | ||
Object { | ||
"className": "euiQuickSelectPopover__buttonText", | ||
} | ||
} | ||
type="button" | ||
> | ||
<EuiIcon | ||
size="m" | ||
type="clock" | ||
/> | ||
</EuiButtonEmpty> | ||
} | ||
closePopover={[Function]} | ||
hasArrow={true} | ||
id="QuickSelectPopover" | ||
isOpen={false} | ||
ownFocus={true} | ||
panelPaddingSize="m" | ||
> | ||
<div | ||
className="euiQuickSelectPopover__content" | ||
data-test-subj="superDatePickerQuickMenu" | ||
> | ||
<EuiRefreshInterval | ||
applyRefreshInterval={[Function]} | ||
isPaused={true} | ||
refreshInterval={0} | ||
/> | ||
</div> | ||
</EuiPopover> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.