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

[FilterEditor] Load DataView in case it's not provided by the consuming plugin #173017

Merged
merged 26 commits into from
Jan 10, 2024

Conversation

kertal
Copy link
Member

@kertal kertal commented Dec 11, 2023

Summary

Resolves #154785

In Discover you can create filters for the current selected data view, switch data view, create another filter.
When you try to edit the first filter being created with the previous data view, it can no longer be edited, since the data view is no longer available in this context. Here is a screen cap by @drewdaemon showing this situation:

Screen.Recording.2023-04-11.at.4.38.34.PM.mov

With this PR this is resolved by actually loading the missing data view, so users can edit this Filter. Note that it doesn't resolve this issue when the filter was created by an ad-hoc data view, and it was not persisted, and the browser window was refreshed. This case we can't fix, unless we start to add e.g. the index pattern to the created filter. But this is out of scope of this PR

Checklist

@kertal
Copy link
Member Author

kertal commented Dec 11, 2023

/ci

@kertal
Copy link
Member Author

kertal commented Dec 12, 2023

/ci

@kertal kertal changed the title [FilterEditor] Load DataView if missing [FilterEditor] Load DataView if its missing in the list of available DataViews Dec 12, 2023
@kertal
Copy link
Member Author

kertal commented Dec 12, 2023

@elasticmachine merge upstream

@kertal
Copy link
Member Author

kertal commented Dec 12, 2023

/ci

…er-editor-changes

# Conflicts:
#	src/plugins/unified_search/tsconfig.json
@kertal
Copy link
Member Author

kertal commented Dec 12, 2023

/ci

@kertal kertal added Feature:Filters Feature:Discover Discover Application Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. release_note:fix labels Dec 12, 2023
@kertal
Copy link
Member Author

kertal commented Dec 13, 2023

/ci

@kertal kertal changed the title [FilterEditor] Load DataView if its missing in the list of available DataViews [FilterEditor] Load DataView in case it's not provided by the consuming plugin Dec 13, 2023
@kertal kertal marked this pull request as ready for review December 13, 2023 15:26
@kertal kertal requested review from a team as code owners December 13, 2023 15:26
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@kertal
Copy link
Member Author

kertal commented Dec 13, 2023

@elasticmachine merge upstream

@kertal kertal self-assigned this Dec 14, 2023
@kertal
Copy link
Member Author

kertal commented Jan 8, 2024

@elasticmachine merge upstream

@@ -84,6 +84,7 @@ const FilterItemsUI = React.memo(function FilterItemsUI(props: FilterItemsProps)
readOnly={readOnly}
suggestionsAbstraction={props.suggestionsAbstraction}
filtersCount={props.filters.length}
dataViews={data?.dataViews}
Copy link
Member Author

Choose a reason for hiding this comment

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

depending on the context relying on the data service cause functional test errors, same issue I encountered using the dataViews service directly.

@kertal
Copy link
Member Author

kertal commented Jan 9, 2024

@elasticmachine merge upstream

@kertal
Copy link
Member Author

kertal commented Jan 9, 2024

@elasticmachine merge upstream

Copy link
Contributor

@smith smith left a comment

Choose a reason for hiding this comment

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

Exploratory view changes look good. 👍🏻

Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

This definitely resolves this issue. I initially expected you to load all the data views and pass them to the component as is done in Lens.

However, I read your comment and I see where you're coming from.

I'm wondering if giving these mostly-presentational components a reference to the entire data views service is overkill. Have you considered passing a simple callback instead (e.g. getDataViewById), or at least constraining the call signature to just the get method using Pick?

Another thought—have we considered making the interface either/or?

Right now it looks like the components will accept both an array of already-loaded data views and a way to load new ones on-demand. Will consumers of these components understand what the function of the two are? Does it make sense to choose one or the other to support?

cc @stratoula

@stratoula
Copy link
Contributor

stratoula commented Jan 10, 2024

I am so sorry for coming late in the party. I am trying to understand why this behavior has impact high 🤔 The solution is nice but is any customer unhappy with how it worked? @kertal @drewdaemon

@drewdaemon

Right now it looks like the components will accept both an array of already-loaded data views and a way to load new ones on-demand. Will consumers of these components understand what the function of the two are? Does it make sense to choose one or the other to support?

I see your point but is it possible? The consumer (Discover, Lens ...) has knowledge of the current dataview, doesnt have knowledge of the filters dataview. So this would add a lot of complexity in the consumers' code. Only on-demand on the other hand I cant think of how it would work. A dashboard can have many charts with different indices but no filters. The consumers communicate their indices to the dashboard and the dashboard to the unified search. I am not sure how else the component can know the dataviews of these charts 🤔 But maybe you have something else in mind. Can you elaborate more?

Last but not least, I think this behavior happens only for the applications which have enabled the dataview picker (a unified search component, so it makes sense to solve this inside the unified search component)

@kertal
Copy link
Member Author

kertal commented Jan 10, 2024

This definitely resolves this issue. I initially expected you to load all the data views and pass them to the component as is done in Lens.

However, I read your comment and I see where you're coming from.

I originally thought it's an easy fix, we need to load and provide more data views in Discover. But it turned out, we would need to load all data views, which we shouldn't do, and on top of that, we would just fix the problem in Discover, not in Lens & Dashboards. That's why I closed this approach, but then I had another idea ...

I'm wondering if giving these mostly-presentational components a reference to the entire data views service is overkill. Have you considered passing a simple callback instead (e.g. getDataViewById), or at least constraining the call signature to just the get method using Pick?

This would be doable, however, I think we could need more of the data view service in this area, and maybe it's time to refactor this component, to have a better split between presentation and business logic. Why I think the whole service could be useful in the future? Mainly because of this discussion, #168131. If we e.g. would support DataViews and deduplicated Indexpatterns provided by ES|QL in an advanced filter editor, we would need to DataView service to create Ad-Hoc data views to provide the field list. Maybe it's not the time to think so far ahead, and to optimize for the given problem. I'd be fine with moving the a simple callback solution.

Another thought—have we considered making the interface either/or?

Right now it looks like the components will accept both an array of already-loaded data views and a way to load new ones on-demand. Will consumers of these components understand what the function of the two are? Does it make sense to choose one or the other to support?

The current solution is providing a fallback in case the given filter id is not part of the provided data views list. It's additional functionality, making sure it works. Just so support this fallback functionality, would mean, this list of selectable data views would no be provided, so it's complementary functionality. We could add this context in Component type description. If the data views service is not provided, this fallback doesn't work. There's some usage of this UnifiedSearch component, where the data service is not provided, although using just the dataView service of useKibana, caused other functionals to fail.

@kertal
Copy link
Member Author

kertal commented Jan 10, 2024

I am so sorry for coming late in the party.

Late party guest shouldn't be sorry, they are always welcome, and the buffet + fridge still has plenty of opportunies!

I am trying to understand why this behavior has impact high 🤔 The solution is nice but is any customer unhappy with how it worked? @kertal @drewdaemon

Maybe medium would be more accurate. This issue landed on the @elastic/kibana-data-discovery table, we thought it's very simple to run into it, it leads to bad UX when running into it and high likely simple to fix (change our consumption of the component), but that wasn't the case.

@drewdaemon

Right now it looks like the components will accept both an array of already-loaded data views and a way to load new ones on-demand. Will consumers of these components understand what the function of the two are? Does it make sense to choose one or the other to support?

I see your point but is it possible? The consumer (Discover, Lens ...) has knowledge of the current dataview, doesnt have knowledge of the filters dataview. So this would add a lot of complexity in the consumers' code. Only on-demand on the other hand I cant think of how it would work. A dashboard can have many charts with different indices but no filters. The consumers communicate their indices to the dashboard and the dashboard to the unified search. I am not sure how else the component can know the dataviews of these charts 🤔 But maybe you have something else in mind. Can you elaborate more?

As I mentioned, it's a fallback solution for these cases, it mainly fixes UX in Discover, where it's pretty easy to run into that. But opposed to my first attempt focusing on Discover, it's now fixed for all consumers (given they provide the data service)

Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

I'm not as familiar with the unified search components as I should be. I now understand that the filter_editor_wrapper is not used on its own, but only as part of unified search. This makes my architecture suggestions mostly irrelevant.

This PR fixes the issue, so no problem from my end.

@drewdaemon
Copy link
Contributor

we would need to load all data views, which we shouldn't do

FWIW, I believe this is exactly what we do in Lens

@kertal
Copy link
Member Author

kertal commented Jan 10, 2024

@elasticmachine merge upstream

@kertal kertal enabled auto-merge (squash) January 10, 2024 18:09
@kertal
Copy link
Member Author

kertal commented Jan 10, 2024

we would need to load all data views, which we shouldn't do

FWIW, I believe this is exactly what we do in Lens

Thx for the review @drewdaemon! I don't think you're loading really all data views, but missing ones, which I assume is a subset

const allIndexPatterns = await Promise.allSettled(missingIds.map((id) => dataViews.get(id)));

if you would load all, the given issue wouldn't surface in Lens, but it does/did. However, it might be the case, that you won't need to load the missingIds, if they are just being used in the FilterEditor. Then this PR takes care of loading them on demand.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
exploratoryView 203.3KB 203.3KB +48.0B
unifiedSearch 213.7KB 214.6KB +892.0B
total +940.0B

History

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

cc @kertal

@kertal kertal merged commit 797b29a into elastic:main Jan 10, 2024
24 checks passed
@kibanamachine kibanamachine added v8.13.0 backport:skip This commit does not require backporting labels Jan 10, 2024
@drewdaemon
Copy link
Contributor

@kertal that method is called with an empty cache so missingIds will be all the data views. But, when I say all the data views, I mean all the data views belonging to the current vis so I think we're okay after all :)

I can see why this approach would be untenable for Discover, where you are displaying a comprehensive list.

delanni pushed a commit to delanni/kibana that referenced this pull request Jan 11, 2024
…ng plugin (elastic#173017)

Fix issue with missing data view by loading it, allowing users to edit the filter in the FilterEditor.
@MakoWish
Copy link

This is unfortunately still not fixed in 8.14.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Discover Discover Application Feature:Filters Feature:Unified search Unified search related tasks release_note:fix Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Discover] filter data gets cleared when filter doesn't match active data view