-
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
[Lens] Make date histogram interval more customizable #49217
[Lens] Make date histogram interval more customizable #49217
Conversation
💔 Build Failed |
💔 Build Failed |
retest |
💔 Build Failed |
💚 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.
I haven't tested this locally, but the pieces here make sense to me. I think there's a conflict with master because I changed the text in one place you did too.
@@ -7,31 +7,26 @@ | |||
import React from 'react'; | |||
import { i18n } from '@kbn/i18n'; | |||
import { FormattedMessage } from '@kbn/i18n/react'; | |||
import { EuiForm, EuiFormRow, EuiRange, EuiSwitch } from '@elastic/eui'; | |||
import { isValidInterval } from 'ui/agg_types/utils'; |
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.
Imports from ui/<something>
won't be possible in the new platform, maybe this needs to be passed in from the plugin?
}, | ||
}, | ||
}, | ||
} as unknown) as IndexPatternPrivateState; |
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.
...wow
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.
lol. I'm open to alternatives. This is an example of where TypeScript isn't super helpful.
@@ -217,7 +252,7 @@ describe('date_histogram', () => { | |||
expect(column.label).toContain('start_date'); | |||
}); | |||
|
|||
it('should change interval from auto when switching to a non primary time field', () => { | |||
it('should not change interval from auto when switching to a non primary time field', () => { |
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.
👍
uiSettings={{} as UiSettingsClientContract} | ||
savedObjectsClient={{} as SavedObjectsClientContract} | ||
dateRange={dateRange} | ||
http={{} as HttpServiceBase} |
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.
Might be good to do the same {...defaultOptions}
as below
💔 Build Failed |
retest |
💚 Build Succeeded |
@elasticmachine merge upstream |
💚 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.
Still haven't tested locally but LGTM
mockDatasource.initialize.mockResolvedValue(datasourceState); | ||
mockDatasource.getLayers.mockReturnValue(['first']); | ||
|
||
mount( | ||
<EditorFrame | ||
{...getDefaultProps()} | ||
{...{ ...getDefaultProps(), dateRange }} |
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.
Isn't this the same as {...getDefaultProps()} dateRange={dateRange}
?
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.
Yup. I'll change 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.
Overall looks good to me. Have one concern regarding typing and one regarding wordings.
// isValidInterval involves breaking changes in other areas. | ||
const isValid = isValidInterval( | ||
`${interval.value === '' ? '1' : interval.value}${interval.unit}`, | ||
restrictedInterval(field!.aggregationRestrictions) as 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.
We always cast the actual return type string | undefined
here to a string
when we use this. As someone not that familiar with the code, it's not clear to me why we could do that? Why do we know that that method will always return a string, even though it could also return undefined
? Is there potentially a better way to type that? If not, can we at least leave a comment, why we know this can never return undefined
, or build an assert into that restrictedInterval
function that will throw if it ever would be (and TS would then properly detect that it's only a 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.
It's because the type signature for isValidInterval is wrong. It requires a string, but handles undefined explicitly and properly. I just didn't want to have a post-feature-freeze PR affect code outside of Lens, if possible, so I didn't fix the type signature.
[Edit: I'll fix the type signature!]
@@ -197,7 +190,7 @@ export const dateHistogramOperation: OperationDefinition<DateHistogramIndexPatte | |||
{currentColumn.params.interval !== autoInterval && ( | |||
<EuiFormRow | |||
label={i18n.translate('xpack.lens.indexPattern.dateHistogram.interval', { | |||
defaultMessage: 'Time intervals', | |||
defaultMessage: 'Time interval', |
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.
We should use the same wording here as in the old editor here, since we don't actually guarantee that we will use that exact interval, but this interval or an interval larger than that (in case we would generate too many buckets otherwise). We've seen in the old editor that users were often confused before the wording change, why they configure a time interval and we use a different one nevertheless.
…ibana into lens/custom-time-intervals
💚 Build Succeeded |
Fixes #48445
The date histogram no longer uses a slider for customizing the interval. It's a combination of a numeric input plus a unit dropdown:
When switching from auto, the initial value is automatically determined using the same interval as the auto generation.
The error state is similar to visualize's, which is pretty generic. Eventually, it'd be nice to provide the user with more helpful information:
[Note: the example screenshot should not be an error state... fixing that in a subsequent commit.]