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

[Canvas] Converting time filter (and children) component to typescript and adding to storybook #40443

Merged
merged 9 commits into from
Jul 12, 2019

Conversation

poffdeluxe
Copy link
Contributor

@poffdeluxe poffdeluxe commented Jul 5, 2019

Summary

Converting all the time filter components to typescript and adding them to storybook (and storyshots) to work towards #40160. This PR uses a lot of the @cqliu1's work from #31672

Also, for storyshots, mocks the dateMath.parse function so that even if the storybook story uses the date format of "now-7d" (or something similar), the snapshot generated will be consistent and won't change.

Would also love feedback on the snapshots generated for some of the bigger components (particularly the components that uses the react-datepicker under the hood. I was considering mocking out the react-datepicker component so the whole thing isn't rendered but would love feedback/guidance here.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

- [ ] This was checked for cross-browser compatibility, including a check against IE11
- [ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
- [ ] Documentation was added for features that require explanation or tutorials

For maintainers

@poffdeluxe poffdeluxe added chore impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. release_note:skip Skip the PR/issue when compiling release notes loe:medium Medium Level of Effort labels Jul 5, 2019
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@poffdeluxe poffdeluxe added the Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas label Jul 5, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-canvas

@poffdeluxe poffdeluxe marked this pull request as ready for review July 5, 2019 21:03
@poffdeluxe poffdeluxe requested a review from a team as a code owner July 5, 2019 21:03
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@poffdeluxe poffdeluxe requested a review from cqliu1 July 8, 2019 16:27
@poffdeluxe
Copy link
Contributor Author

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@poffdeluxe
Copy link
Contributor Author

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@clintandrewhall clintandrewhall left a comment

Choose a reason for hiding this comment

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

Just a few nits and considerations. I'll accept to unblock, but please address them before committing.

Nice work!!

@@ -51,5 +64,5 @@ export const DatetimeRangeAbsolute = ({ from, to, onSelect }) => (
DatetimeRangeAbsolute.propTypes = {
from: PropTypes.object, // a moment
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's consider either integrating react-moment-proptypes or PropTypes.instanceof here.

@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const timeUnits = {
export const timeUnits: { [key: string]: string } = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider:

export enum TimeUnit {
  SECONDS = 's',
  MINUTES = 'm',
  // etc
}

export const timeUnits: Record<TimeUnit, string> = {
  [TimeUnit.SECONDS]: 'second',
  [TimeUnit.MINUTE]: 'minute',
  // etc
}

* you may not use this file except in compliance with the Elastic License.
*/

export { TimePickerMini } from './time_picker_mini';
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I've been renaming mini to popover, as that seems much more descriptive of the underlying component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

taken care of. I had to do change a css file and a template as well but it should all be switched from TimePickerMini -> TimePickerPopover

@@ -36,9 +47,11 @@ export const DatetimeRangeAbsolute = ({ from, to, onSelect }) => (
minDate={from}
onValueChange={val => onSelect(from, val)}
onSelect={val => {
if (!val || !to) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be formatted with braces... curious why this wasn't done for you automatically.

children?: ReactNode;
}

const quickRanges = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding these as an export with TimeUnit below in some common file. We'll need to i18n both at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a little hesitant to making that move of the quickRanges here to a common place since there's another quickRanges specific to the PrettyDuration component as well. I can refactor them to perhaps share the same quickRanges array so that we only need to update the string for i18n in one place if you think that's worth it in this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd track a follow-up. We have a lot of instances where we have these kinds of ranges, (e.g. refresh, auto-play, etc).

Copy link
Contributor

@cqliu1 cqliu1 Jul 12, 2019

Choose a reason for hiding this comment

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

Do we want them all to share the same quick ranges? I imagine refresh/autoplay would share the same set of quick range time intervals, but I think time filter should probably have a different set of date ranges from the ones used for refresh/autoplay.

Side note: While looking through the available Kibana advanced settings, I noticed there was a timepicker:quickRanges setting which we may want to consider using instead of the static quickRanges array used in the time_filter component. I've added it to my list of Kibana advanced settings we'd want to integrate into Canvas (#37436).

I agree that this doesn't need to be addressed in this PR and that we should create an issue to track it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tracking that here: #41055

@poffdeluxe poffdeluxe requested a review from a team as a code owner July 10, 2019 22:28
);

DatetimeCalendar.propTypes = {
value: PropTypes.oneOfType([momentObj, PropTypes.object]), // Handle both valid and invalid moment objects
Copy link
Contributor Author

@poffdeluxe poffdeluxe Jul 10, 2019

Choose a reason for hiding this comment

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

@clintandrewhall for moment proptypes, I went the react-moment-proptypes approach (Mostly because with typescript, Moment is the typescript type and not the moment class so the instanceOf(Moment) approach won't work unless I'm missing something). The downside is that react-moment-proptypes checks not only if the prop is a moment but it also checks if it's a valid moment which messes with the DatetimeCalendar component since it's supposed to be able to handle invalid moments.

My compromise was to make the value proptype be either a moment or an object but I don't love it. I could make a custom validator proptype for value but it'd be only for just this single prop. Any thoughts or suggestions?

@elasticmachine
Copy link
Contributor

💔 Build Failed

@@ -4,12 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const timeUnits = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

weird diff here

…ing to storybook

Mocking the datepicker dep to avoid rendering huge snapshots

Updating moments in examples to be timezone agnostic

Updating snapshots for time picker
@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@snide snide left a comment

Choose a reason for hiding this comment

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

Sass changes in here are just namespacing. Didn't test in browser for review, just code.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@cqliu1 cqliu1 left a comment

Choose a reason for hiding this comment

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

Just a few nitpicks, but overall the code looks good!

import { TimePicker as Component } from './time_picker';

export const TimePicker = compose(
withState('range', 'setRange', ({ from, to }) => ({ from, to })),
Copy link
Contributor

Choose a reason for hiding this comment

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

++ to removing all of this recompose stuff and converting the component to a class.

setStrValue(moment.format('YYYY-MM-DD HH:mm:ss'));
setValid(true);
},
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: Any reason why you removed the recompose stuff from time_picker/index.js, but not here? Not saying you have to refactor this one, but I'd prefer converting this component to a class instead of calling lifecycle functions in the /index using recompose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kinda wanted to minimize this PRs footprint by only updating what needed to be updated. I removed recompose from time_picker/index.js since the typing in there with recompose was getting very hard to read. Def down for removing recompose in a future PR though

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@poffdeluxe poffdeluxe merged commit 8be17fe into elastic:master Jul 12, 2019
@poffdeluxe poffdeluxe deleted the timefilter-ts branch July 12, 2019 21:48
poffdeluxe added a commit to poffdeluxe/kibana that referenced this pull request Jul 12, 2019
…t and adding to storybook (elastic#40443)

* Converting time filter (and children) component to typescript and adding to storybook
poffdeluxe added a commit that referenced this pull request Jul 13, 2019
…t and adding to storybook (#40443) (#41058)

* Converting time filter (and children) component to typescript and adding to storybook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. loe:medium Medium Level of Effort release_note:skip Skip the PR/issue when compiling release notes review Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas v7.4.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants