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

fixed super date picker crash #5263

Merged
merged 4 commits into from
Oct 13, 2021

Conversation

JordanSh
Copy link
Contributor

Summary

fixing #4777.
also mentioned in #91138, more on that later.

SuperDatePicker was crashing due to toAbsoluteString calling toISOString on an invalid date. I've used moment's validity check to prevent this from happening and return a flag of "invalid_date" instead. the consumer can then decide how to handle this situation.

I've tried to mimic another error case that was handled before (negative numbers are not allowed) in order to maintain the same UX choices. So, if the value from toAbsoluteString is "invalid_date" I have added an error message under the input field to imply to the user what is wrong with his input and added an Invalid Date label to the pretty_duration output in that case.

note: this change will prevent super_date_picker from crashing but a piece of code in Kibana repeats the same mistake by calling toISOString on an invalid date (which causes #91138). both cases must be resolved in order to completely prevent Kibana from crashing.
this PR is the first step and I can open another PR in Kibana to fix the error there.

Before:

super_date_picker_crash.mp4

After:

super_date_picker_fix.mp4

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Props have proper autodocs and playground toggles
  • Added documentation
  • Checked Code Sandbox works for any docs examples
  • Added or updated jest and cypress tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5263/

@thompsongl thompsongl self-requested a review October 13, 2021 14:42
Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to push an i18ntoken file cleanup commit, but otherwise this LGTM

Really appreciate the help, @JordanSh!

@@ -58,6 +58,10 @@ export function formatTimeString(
}

const tryParse = dateMath.parse(timeString, { roundUp: roundUp });
if (!moment(tryParse).isValid()) {
return 'Invalid Date';
Copy link
Contributor

@thompsongl thompsongl Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see this use i18n, but none of the other values from this function use it and it's unclear how we'd adjust the output.

I'll open a separate issue to explore (#5266); this doesn't need to be a blocker for this PR.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5263/

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again, @JordanSh!

@JordanSh
Copy link
Contributor Author

thanks for the quick review @thompsongl :)

@JordanSh JordanSh merged commit 274f474 into elastic:master Oct 13, 2021
@JordanSh JordanSh deleted the fix-super-date-picker-crash branch October 14, 2021 08:46
ym pushed a commit to ym/eui that referenced this pull request Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants