Skip to content

Commit

Permalink
EuiSuperDatePicker handle invalid start and end property values (elas…
Browse files Browse the repository at this point in the history
…tic#1544)

* EuiSuperDatePicker handle invalid start and end property values

* change log
  • Loading branch information
nreese authored and chandlerprall committed Feb 7, 2019
1 parent bee175d commit e462454
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `6.10.1`.

## [`6.10.11`](https://github.com/elastic/eui/tree/6.10.11)

**Note: this release is a backport containing changes originally made in `6.11.0`**

**Bug fixes**

- Fixed `EuiSuperDatePicker` crashing with negative relative value ([#1537](https://github.com/elastic/eui/pull/1537))
- Fixed `EuiSuperDatePicker` crashing with invalid start and end prop values ([#1544](https://github.com/elastic/eui/pull/1544))

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

Expand Down
18 changes: 16 additions & 2 deletions src-docs/src/views/date_picker/super_date_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ export default class extends Component {
}, this.startLoading);
}

onStartInputChange = e => {
this.setState({
start: e.target.value,
});
};

onEndInputChange = e => {
this.setState({
end: e.target.value,
});
};

startLoading = () => {
setTimeout(
this.stopLoading,
Expand Down Expand Up @@ -74,17 +86,19 @@ export default class extends Component {
<Fragment>
<EuiFormRow
label="start"
helpText="EuiSuperDatePicker should be resilient to invalid start values. Try to break it with unexpected values"
>
<EuiFieldText
readOnly
onChange={this.onStartInputChange}
value={this.state.start}
/>
</EuiFormRow>
<EuiFormRow
label="end"
helpText="EuiSuperDatePicker should be resilient to invalid end values. Try to break it with unexpected values"
>
<EuiFieldText
readOnly
onChange={this.onEndInputChange}
value={this.state.end}
/>
</EuiFormRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class EuiAbsoluteTab extends Component {
super(props);

const parsedValue = dateMath.parse(props.value, { roundUp: props.roundUp });
const valueAsMoment = parsedValue ? parsedValue : moment();
const valueAsMoment = parsedValue && parsedValue.isValid() ? parsedValue : moment();
this.state = {
valueAsMoment,
textInputValue: valueAsMoment.format(INPUT_DATE_FORMAT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export class EuiRelativeTab extends Component {

render() {
const isInvalid = this.state.count < 0;
const formatedValue = isInvalid ? '' : dateMath.parse(this.props.value).format(this.props.dateFormat);
const parsedValue = dateMath.parse(this.props.value);
const formatedValue = isInvalid || !parsedValue || !parsedValue.isValid()
? ''
: parsedValue.format(this.props.dateFormat);
return (
<EuiForm className="euiDatePopoverContent__padded">
<EuiFlexGroup gutterSize="s" responsive={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export class EuiQuickSelect extends Component {
const startMoment = dateMath.parse(this.props.start);
const endMoment = dateMath.parse(this.props.end, { roundUp: true });
return {
min: startMoment ? startMoment : moment().subtract(15, 'minute'),
max: endMoment ? endMoment : moment(),
min: startMoment && startMoment.isValid() ? startMoment : moment().subtract(15, 'minute'),
max: endMoment && endMoment.isValid() ? endMoment : moment(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function isRangeInvalid(start, end) {

const startMoment = dateMath.parse(start);
const endMoment = dateMath.parse(end, { roundUp: true });
if (!startMoment || !endMoment) {
if (!startMoment || !endMoment || !startMoment.isValid() || !endMoment.isValid()) {
return true;
}
if (startMoment.isAfter(endMoment)) {
Expand Down

0 comments on commit e462454

Please sign in to comment.