-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Custom labels for ranges #79628
Conversation
Stumbled across this. I know it's still in draft mode 🙈 but just wanted to add a note that whenever we implement a proper Currently the expression function for the If you want to do that here, feel free -- but no pressure. I'm mainly noting it so that we don't forget. |
Pinging @elastic/kibana-app-arch (Team:AppArch) |
Pinging @elastic/kibana-app (Team:KibanaApp) |
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.
Great catch, @dej611 I will check it out |
@dej611 I didn't handle partial ranges correctly, it should be fixed now. |
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.
Did a code review. Will check the PR locally with the new changes
this.gte = bucket.from == null ? -Infinity : bucket.from; | ||
this.lt = bucket.to == null ? +Infinity : bucket.to; | ||
this.label = allRanges ? RangeKey.findCustomLabel(this.gte, this.lt, allRanges) : undefined; |
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.
Passing bucket.from/to
here can simplify the code in the findCustomLabel
a bit (removing non-finite check).
They effectively equivalent, but the current version is more verbose.
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.
Also the ternary operator can be dropped as the missing ranges
would be handled by findCustomLabel
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.
Good catch for the ternary operator, I'm not sure whether it makes it much easier because we still have to look for null
/undefined
.
x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/ranges/ranges.tsx
Outdated
Show resolved
Hide resolved
Thanks @dej611 , pushed some changes |
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.
LGTM 👍
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.
expect(format.convert({ gte: 1, lt: 20, label: 'custom' })).toBe('custom'); | ||
// underlying formatter is not called because custom label can be used directly | ||
expect(getFormat).toHaveBeenCalledTimes(0); | ||
}); |
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.
Could you add a test for handling multiple overlapping ranges?
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.
What kind of test are you expecting? The formatter only ever gets a single value passed in. Do you want to cover the behavior of the built-in cache?
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 think I left this in the wrong place- I was worried about the duplicate label case, but this is the wrong place to test it.
onChange={(newLabel) => { | ||
const newRange = { | ||
...tempRange, | ||
label: newLabel, |
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.
So this resets to the empty string to indicate that it's empty, is that going to cause problems with equality? Imagine the steps 1. Create custom label 2. Delete custom label 3. Formats correctly?
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.
Tested, this doesn't cause any issues
I think the missing bar is caused by the chart only working with the formatted label so there is no difference in the two data points and only one of them is shown. We can either try to mess with chart serializers and formatters or just not allow this case, show an error in the popover and never persist such a state (which would be my preferred option) |
@wylieconlon I tested and we have the same behavior for "Filters" - you are allowed to create two separate filters with the same custom label and only one bar will be shown. While it's not the best behavior, it's at least consistent, so I would like to keep it for the scope of this PR and open a separate bug issue to solve it consistently. |
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.
@flash1293 I'm fine with the decision to allow duplicate labels in this PR, but I'll create a follow-up issue to track it as a minor annoyance.
expect(format.convert({ gte: 1, lt: 20, label: 'custom' })).toBe('custom'); | ||
// underlying formatter is not called because custom label can be used directly | ||
expect(getFormat).toHaveBeenCalledTimes(0); | ||
}); |
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 think I left this in the wrong place- I was worried about the duplicate label case, but this is the wrong place to test it.
@elasticmachine merge upstream |
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.
Code LGTM - tested Chrome (macOS). Just had one question
@@ -67,11 +68,11 @@ export const getRangeBucketAgg = ({ getFieldFormatsStart }: RangeBucketAggDepend | |||
keyCaches.set(agg, keys); | |||
} | |||
|
|||
const id = RangeKey.idBucket(bucket); | |||
const id = RangeKey.idBucket(bucket, agg.params.ranges); |
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.
Forgive me if this is a naive question -- but why is it necessary to change the format of the bucket id to include the label? I assume this is solving an edge case, but it wasn't completely clear to me from reading the discussion above.
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 was under the impression it's necessary to not run into cached RangeKey
objects with outdated labels, but I realized the cache is only used for a single request, so it's not an issue. Removed it
💚 Build SucceededMetrics [docs]async chunks size
page load bundle size
History
To update your PR or re-run it, just comment with: |
@@ -159,6 +164,25 @@ export const RangePopover = ({ | |||
</EuiFlexItem> | |||
</EuiFlexGroup> | |||
</EuiFormRow> | |||
<EuiFormRow> | |||
<LabelInput |
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.
Hey @flash1293, I saw this one got merged already, but you make this input compressed
since it lives in a popover and will then match the range inputs better.
Fixes #77878
This PR adds optional custom labels for ranges and exposes them in Lens similar to custom labels for filters.
This includes some small changes in the range AggType and range field formatter as well to map the label from the agg config into the result table and to pick up the custom label if present when formatting the value. Also, the label has to be excluded when building a filter out of a range value