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

filtering (making it work with expressions) #55351

Merged
merged 20 commits into from
Feb 3, 2020

Conversation

ppisljar
Copy link
Member

@ppisljar ppisljar commented Jan 20, 2020

Summary

Changes a bit how filtering works so it can work correctly with expressions
partly resolves #46904

  • esaggs adds meta information about the agg and field to the KibanaDatatable
  • use that meta information in createFilterFromEvent function to correctly build click filter
  • use that meta information in onBrush function to correctly build brush(range) filter
  • move filter creation inside the apply_filter_action this means that visualization doesn't emit a filter on click, but just information of what was clicked. We use this information in default apply_filter_action to correctly create the filter and apply it. This now makes it way easier to apply other actions, as its easy to extract information like cell value clicked etc.
  • added a new action called select_range_action which applies a range filter

FOLLOWUP:

  • this still doesn't solve the problem with filtering on expressions that manipulate the datatable provided by esaggs function. for example you could sum two columns into a new column and visualize it. filtering on that column will not work as meta information required is not provided.

in the future we can allow to customize default filter action for this scenarios. user could provide custom expression to build the filter which would be used when meta information provided by esaggs is not available.

Checklist

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

For maintainers

@ppisljar ppisljar added v8.0.0 Team:AppArch release_note:skip Skip the PR/issue when compiling release notes v7.7.0 labels Jan 20, 2020
@ppisljar ppisljar requested a review from a team as a code owner January 20, 2020 19:40
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@@ -292,6 +292,11 @@ export const esaggs = (): ExpressionFunction<typeof name, Context, Arguments, Re
const cleanedColumn: KibanaDatatableColumn = {
id: column.id,
name: column.name,
_meta: {
Copy link
Member Author

Choose a reason for hiding this comment

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

any ideas for naming this ?

Copy link
Contributor

Choose a reason for hiding this comment

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

meta sgtm, but I think I would remove the _

@ppisljar ppisljar requested a review from a team January 22, 2020 19:00
@ppisljar ppisljar changed the title [PoC] filtering (making it work with expressions) filtering (making it work with expressions) Jan 22, 2020
@@ -292,6 +292,11 @@ export const esaggs = (): ExpressionFunction<typeof name, Context, Arguments, Re
const cleanedColumn: KibanaDatatableColumn = {
id: column.id,
name: column.name,
_meta: {
Copy link
Contributor

Choose a reason for hiding this comment

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

meta sgtm, but I think I would remove the _

timeFieldName,
});
}
const eventName = event.name === 'brush' ? SELECT_RANGE_TRIGGER : APPLY_FILTER_TRIGGER;
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure we should separate these out instead of having a single one.

If we think the user will want something different to happen based on which one is emitted, we should separate them, but if in the users head, the same thing should happen, we should leave them together.

Right now, the user see's the same exact thing happen, the only difference here is in the code, to construct a different filter object, but in either case, a filter gets added to the view. But now, if the user wants to add a drilldown, we have two triggers, and we don't really know which one will be emitted from any given visualization. We could try to expose it but that will be difficult with lens when you don't really have the information from the renderer.

One other option is to leave these triggers separately, name them something like you suggested, SELECT_RANGE and CLICKED_DATA_POINT, and actually have each of those actions emit another trigger, maybe named ES_FILTER_SELECTED_TRIGGER. Then drilldowns actions can attach to that trigger name, and it won't matter whether it was a brush or a click, it only matters that the end result was that the user selected some filters, and any relevant drilldowns will apply.

if we wanted to do that, and eventually allow users to attach the raw URL builder drilldown where we will expose the raw data, not the es filter data, we'd need to figure out a way to batch or collect all triggers being emitted in a single event cycle. Otherwise, the user could attach an action on both CLICKED_DATA_POINT, and FILTER_SELECTED, and since they were separately emitted as part of the same event cycle, you'd see two context menu's pop up and we don't want that.

I think probably to avoid complicating drilldown feature, for phase 1, we should have at least one common trigger we can attach the drilldowns to, and not worry about having to figure out whether to attach the drilldown to the select range or data clicked trigger. Then once we expose the ability to attach actions to the triggers that have the raw data, figure out the batching then.

Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

i really like your idea about this actions emitting yet another trigger ES_FILTER_SELECTED_TRIGGER

Copy link
Member Author

@ppisljar ppisljar Jan 28, 2020

Choose a reason for hiding this comment

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

i will leave creating another trigger ES_FILTER_SELECTED_TRIGGER out of this PR, but i agree that could be a possible solution to simplify the drilldown (or any user defined action) configuration.

@@ -288,6 +288,11 @@ export const esaggs = (): ExpressionFunction<typeof name, Context, Arguments, Re
const cleanedColumn: KibanaDatatableColumn = {
id: column.id,
name: column.name,
_meta: {
type: column.aggConfig.type,
indexPattern: column.aggConfig.getIndexPattern(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure whether that's out of scope for this PR, but the index pattern object is not serializable, right? It's also pretty big: https://github.com/elastic/kibana/pull/55351/files#diff-c85d790e1f9fa1b5d3c3ca92ea62bd60R1

Should this be just the id of the pattern?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was almost going to add a comment suggesting you name this indexPatternId to avoid confusion (I thought it was the id).

export interface KibanaDatatableColumnMeta {
type: string;
indexPatternId: string;
params: Record<string, any>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
params: Record<string, any>;
aggConfig: Record<string, unknown>;

Having a generic object called params is not helpful for our use in client apps- will we need to assume that params is always the same data?

I suggest renaming to aggConfigs because that's what it appears to be in this change.

Copy link
Member Author

Choose a reason for hiding this comment

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

its aggConfigParams

export interface KibanaDatatableColumn {
id: string;
name: string;
meta?: KibanaDatatableColumnMeta;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not generic metadata about the table column any more- if it were, it would just include type. The addition of indexPattern and aggConfigs into the table is not what I would expect for all tables.

Suggestion:

  • Move the type parameter to the table column
  • Create a new table type for KibanaAggregatedTable

Copy link
Member

Choose a reason for hiding this comment

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

I agree that if we are adding a field for truly generic metadata, it should probably make the agg-specific values in KibanaDatatableColumnMeta optional, instead of assuming the only use of meta is ever going to be for aggs. KibanaAggregatedTable is an interesting idea too.

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

I don't know a ton about the vislib legend portion and I'm only somewhat familiar with the syntax for registering custom actions, so can't really comment much on those, but I think the rest makes sense to me in general. Added a few notes.

export interface KibanaDatatableColumn {
id: string;
name: string;
meta?: KibanaDatatableColumnMeta;
Copy link
Member

Choose a reason for hiding this comment

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

I agree that if we are adding a field for truly generic metadata, it should probably make the agg-specific values in KibanaDatatableColumnMeta optional, instead of assuming the only use of meta is ever going to be for aggs. KibanaAggregatedTable is an interesting idea too.

# Conflicts:
#	src/legacy/core_plugins/visualizations/public/embeddable/visualize_embeddable.ts
#	src/legacy/core_plugins/visualizations/public/np_ready/public/types/base_vis_type.js
#	src/legacy/ui/public/agg_types/index.ts
Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

Just to reiterate my disclaimer above:

I don't know a ton about the vislib legend portion and I'm only somewhat familiar with the syntax for registering custom actions, so can't really comment much on those

Other than that, code changes here LGTM, pending a green build from CI!

@ppisljar
Copy link
Member Author

ppisljar commented Feb 1, 2020

@elasticmachine merge upstream

@ppisljar
Copy link
Member Author

ppisljar commented Feb 3, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@ppisljar ppisljar merged commit f271365 into elastic:master Feb 3, 2020
ppisljar added a commit to ppisljar/kibana that referenced this pull request Feb 3, 2020
* adding meta information to KibanaDatatable

* updating filtering functions to use new information

* moving filter creation to APPLY_FILTER_ACTION

* adding SELECT_RANGE_ACTION and TRIGGER

* making _meta optional

* inlining legacy code for inspector

* fixing jest tests

* keeping apply_filter_action and adding value_click_action and trigger

* utilities for serializing/unserializing aggConfigs

* renaming prop to indexPatternId

* cleanup

* updating interpreter functional baselines

* trying to fix tests

* Fix legend tests

* reverting update to multi metric screenshot

* updating based on review

* updating tests

Co-authored-by: Nick Partridge <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
jfsiii pushed a commit to jfsiii/kibana that referenced this pull request Feb 4, 2020
* adding meta information to KibanaDatatable

* updating filtering functions to use new information

* moving filter creation to APPLY_FILTER_ACTION

* adding SELECT_RANGE_ACTION and TRIGGER

* making _meta optional

* inlining legacy code for inspector

* fixing jest tests

* keeping apply_filter_action and adding value_click_action and trigger

* utilities for serializing/unserializing aggConfigs

* renaming prop to indexPatternId

* cleanup

* updating interpreter functional baselines

* trying to fix tests

* Fix legend tests

* reverting update to multi metric screenshot

* updating based on review

* updating tests

Co-authored-by: Nick Partridge <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
export const SELECT_RANGE_ACTION = 'SELECT_RANGE_ACTION';

interface ActionContext {
data: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be further typed out? The types are so critical to the trigger and what actions can be attached to it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm going to create an issue to track this

@ppisljar ppisljar mentioned this pull request Apr 6, 2020
1 task
let filter = [];
const value = rowIndex > -1 ? table.rows[rowIndex][column.id] : cellValue;
const value = rowIndex > -1 ? table.rows[rowIndex][column.id] : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

@ppisljar This is the line you are referring to in #61949, right?

Copy link
Member Author

@ppisljar ppisljar Apr 7, 2020

Choose a reason for hiding this comment

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

yes, passing valid rowId is cruical now and regionmap was passing wrong info for a very long time.

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

Successfully merging this pull request may close these issues.

Expressions executor filtering
8 participants