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

[Lens] Make date histogram interval more customizable #49217

Merged
merged 13 commits into from
Oct 29, 2019

Conversation

chrisdavies
Copy link
Contributor

@chrisdavies chrisdavies commented Oct 24, 2019

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:

image

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:

image

[Note: the example screenshot should not be an error state... fixing that in a subsequent commit.]

@chrisdavies chrisdavies added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Feature:Lens v7.5.0 labels Oct 24, 2019
@chrisdavies chrisdavies requested review from wylieconlon and a team October 24, 2019 16:37
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@brianseeders
Copy link
Contributor

retest

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@wylieconlon wylieconlon left a 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';
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

...wow

Copy link
Contributor Author

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', () => {
Copy link
Contributor

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}
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

💔 Build Failed

@chrisdavies
Copy link
Contributor Author

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@chrisdavies
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@wylieconlon wylieconlon left a 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 }}
Copy link
Contributor

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}?

Copy link
Contributor Author

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.

Copy link
Contributor

@timroes timroes left a 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
Copy link
Contributor

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)?

Copy link
Contributor Author

@chrisdavies chrisdavies Oct 29, 2019

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',
Copy link
Contributor

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.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:skip Skip the PR/issue when compiling release notes v7.5.0 v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lens Date Histogram Customize time intervals don't go small enough
5 participants