Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EuiSuperDatePicker small changes #1464

Merged
merged 9 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
- Fixed `textProps` and `contentProps` of `EuiButton` and `EuiButtonEmpty` so they don’t override classes ([#1455](https://github.com/elastic/eui/pull/1455))
- Fixed `closeButtonProps` of `EuiBadge` so it doesn't override classes ([#1455](https://github.com/elastic/eui/pull/1455))
- Fixed font weight shift of `EuiFilterButton` when notification is present ([#1455](https://github.com/elastic/eui/pull/1455))
- Fixed `EuiSuperDatePicker` not updating derived `showPrettyDuration` state on prop update ([#1464](https://github.com/elastic/eui/pull/1464))
- Fixed `EuiSuperDatePicker` not passing `refreshInterval` to callback when refresh internval start/stop toggle button clicked ([#1464](https://github.com/elastic/eui/pull/1464))
- Fixed `EuiSuperDatePicker` `refreshInterval` input not allowing decimals ([#1464](https://github.com/elastic/eui/pull/1464))

## [`6.5.1`](https://github.com/elastic/eui/tree/v6.5.1)

Expand Down
8 changes: 3 additions & 5 deletions src-docs/src/views/date_picker/super_date_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ export default class extends Component {
}

onRefreshChange = ({ isPaused, refreshInterval }) => {
this.setState((prevState) => {
return {
isPaused: isPaused == null ? prevState.isPaused : isPaused,
refreshInterval: refreshInterval == null ? prevState.refreshInterval : refreshInterval,
};
this.setState({
isPaused,
refreshInterval,
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Component, Fragment } from 'react';
import { timeUnits } from '../time_units';
Expand All @@ -19,34 +20,40 @@ const refreshUnitsOptions = Object.keys(timeUnits)
const MILLISECONDS_IN_MINUTE = 1000 * 60;
const MILLISECONDS_IN_HOUR = MILLISECONDS_IN_MINUTE * 60;

function convertMilliseconds(milliseconds) {
function fromMilliseconds(milliseconds) {
if (milliseconds > MILLISECONDS_IN_HOUR) {
return {
units: 'h',
value: milliseconds / MILLISECONDS_IN_HOUR
value: _.round(milliseconds / MILLISECONDS_IN_HOUR, 3)
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved
};
}

return {
units: 'm',
value: milliseconds / MILLISECONDS_IN_MINUTE
value: _.round(milliseconds / MILLISECONDS_IN_MINUTE, 3)
};
}

function toMilliseconds(units, value) {
return units === 'h'
? Math.round(value * MILLISECONDS_IN_HOUR)
: Math.round(value * MILLISECONDS_IN_MINUTE);
}

export class EuiRefreshInterval extends Component {

constructor(props) {
super(props);

const { value, units } = convertMilliseconds(props.refreshInterval);
const { value, units } = fromMilliseconds(props.refreshInterval);
this.state = {
value,
units,
};
}

onValueChange = (evt) => {
const sanitizedValue = parseInt(evt.target.value, 10);
const sanitizedValue = parseFloat(evt.target.value);
this.setState({
value: isNaN(sanitizedValue) ? '' : sanitizedValue,
}, this.applyRefreshInterval);
Expand All @@ -63,9 +70,7 @@ export class EuiRefreshInterval extends Component {
return;
}

const valueInMilliSeconds = this.state.units === 'h'
? this.state.value * MILLISECONDS_IN_HOUR
: this.state.value * MILLISECONDS_IN_MINUTE;
const valueInMilliSeconds = toMilliseconds(this.state.units, this.state.value);

this.props.applyRefreshInterval({
refreshInterval: valueInMilliSeconds,
Expand All @@ -75,6 +80,7 @@ export class EuiRefreshInterval extends Component {

toogleRefresh = () => {
this.props.applyRefreshInterval({
refreshInterval: toMilliseconds(this.state.units, this.state.value),
isPaused: !this.props.isPaused
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class EuiSuperDatePicker extends Component {
end: nextProps.end,
isInvalid: false,
hasChanged: false,
showPrettyDuration: showPrettyDuration(nextProps.start, nextProps.end, nextProps.commonlyUsedRanges),
};
}

Expand Down