-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
💚 Build Succeeded |
Pinging @elastic/kibana-canvas |
💚 Build Succeeded |
💔 Build Failed |
💔 Build Failed |
retest |
💔 Build Failed |
retest |
💚 Build Succeeded |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 } = { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 = [ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking that here: #41055
a087844
to
2179058
Compare
); | ||
|
||
DatetimeCalendar.propTypes = { | ||
value: PropTypes.oneOfType([momentObj, PropTypes.object]), // Handle both valid and invalid moment objects |
There was a problem hiding this comment.
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?
💔 Build Failed |
@@ -4,12 +4,4 @@ | |||
* you may not use this file except in compliance with the Elastic License. | |||
*/ | |||
|
|||
export const timeUnits = { |
There was a problem hiding this comment.
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
2179058
to
e4f5a0c
Compare
💔 Build Failed |
There was a problem hiding this 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.
💔 Build Failed |
💚 Build Succeeded |
...gin_src/renderers/time_filter/components/datetime_range_absolute/datetime_range_absolute.tsx
Outdated
Show resolved
Hide resolved
💚 Build Succeeded |
...lugins/canvas/canvas_plugin_src/renderers/time_filter/components/time_picker/time_picker.tsx
Outdated
Show resolved
Hide resolved
...lugins/canvas/canvas_plugin_src/renderers/time_filter/components/time_picker/time_picker.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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!
.../canvas/canvas_plugin_src/renderers/time_filter/components/datetime_input/datetime_input.tsx
Show resolved
Hide resolved
...gin_src/renderers/time_filter/components/datetime_range_absolute/datetime_range_absolute.tsx
Show resolved
Hide resolved
...anvas/canvas_plugin_src/renderers/time_filter/components/pretty_duration/lib/quick_ranges.ts
Show resolved
Hide resolved
...lugins/canvas/canvas_plugin_src/renderers/time_filter/components/time_filter/time_filter.tsx
Show resolved
Hide resolved
import { TimePicker as Component } from './time_picker'; | ||
|
||
export const TimePicker = compose( | ||
withState('range', 'setRange', ({ from, to }) => ({ from, to })), |
There was a problem hiding this comment.
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.
...lugins/canvas/canvas_plugin_src/renderers/time_filter/components/time_picker/time_picker.tsx
Show resolved
Hide resolved
setStrValue(moment.format('YYYY-MM-DD HH:mm:ss')); | ||
setValid(true); | ||
}, | ||
}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
...lugins/canvas/canvas_plugin_src/renderers/time_filter/components/time_picker/time_picker.tsx
Show resolved
Hide resolved
💚 Build Succeeded |
…t and adding to storybook (elastic#40443) * Converting time filter (and children) component to typescript and adding to storybook
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
strikethroughsto 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- [ ] This was checked for keyboard-only and screenreader accessibilityFor maintainers