Skip to content

[lens] Use top nav in Lens app #46190

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

Merged
merged 21 commits into from
Oct 3, 2019
Merged

Conversation

wylieconlon
Copy link
Contributor

@wylieconlon wylieconlon commented Sep 19, 2019

Integrates the Top Nav component and saved queries into Lens. Also implements basic "read-only" permissioning using feature-level security.

With all permissions, the user can save the query and the entire visualization:

Screenshot 2019-10-01 13 49 48

With read-only permissions the user can use saved queries, and can run visualizations, but cannot save them:

Screenshot 2019-10-01 13 49 40

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

Made comments where the saved query addition assumptions are incorrect.

onSavedQueryUpdated?: (savedQuery: SavedQuery) => void;
// User has cleared the active query, which should not clear filters
Copy link
Contributor

Choose a reason for hiding this comment

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

All the filters are removed when an active saved query is loaded. This includes those that one might have added in addition to the filters that come from the active saved query.

...state,
savedQuery,
filters: savedQuery.attributes.filters || state.filters,
query: savedQuery.attributes.query || state.query,
Copy link
Contributor

Choose a reason for hiding this comment

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

A saved query will always have a query, regardless of if one was added or not. If a saved query only has contents for filters and/or a time filter and no query was added in the query bar, then the saved query will have an empty string as the query bar input. This means that savedQuery.attributes.query || state.query will always be truthy because savedQuery.attributes.query will be true.

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

Some assumptions about saved queries are incorrect:

  1. When an active saved query is cleared, all the filters are removed, regardless of whether they come from the saved query or not. On clearing a saved query, the filters are replaced with an empty array.
  2. A saved query will always contain a query, even if it is an empty one.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@wylieconlon wylieconlon added release_note:skip Skip the PR/issue when compiling release notes v7.5.0 v8.0.0 labels Sep 24, 2019
@wylieconlon wylieconlon marked this pull request as ready for review September 24, 2019 20:21
@wylieconlon wylieconlon requested review from a team and TinaHeiligers September 24, 2019 20:21
@wylieconlon wylieconlon added the Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) label Sep 24, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

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

Added a few comments on data plugin usage

}}
query={state.query}
dateRangeFrom={state.dateRange.fromDate}
dateRangeTo={state.dateRange.toDate}
toasts={core.notifications.toasts}
uiSettings={core.uiSettings}
savedObjectsClient={savedObjectsClient}
Copy link
Contributor

Choose a reason for hiding this comment

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

You should pass core.savedObjects.client in here.

SavedQuery,
} from 'src/legacy/core_plugins/data/public';
import { Filter } from '@kbn/es-query';
import { TopNavMenu } from '../../../../../../src/legacy/core_plugins/kibana_react/public';
import { Query } from '../../../../../../src/legacy/core_plugins/data/public/query';
Copy link
Contributor

Choose a reason for hiding this comment

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

You can do this import from data/public (without query in the end, which won't work in NP)

@@ -60,6 +65,7 @@ export class AppPlugin {
return (
<App
core={core}
data={plugins.data}
editorFrame={this.instance!}
store={new Storage(localStorage)}
savedObjectsClient={chrome.getSavedObjectsClient()}
Copy link
Contributor

Choose a reason for hiding this comment

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

Core.savedObjects.client

toasts={core.notifications.toasts}
uiSettings={core.uiSettings}
savedObjectsClient={savedObjectsClient}
http={core.http}
timeHistory={data.timefilter.history}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lizozom We're using the time history here,

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

The top nav works as expected when using saved queries, the normal query bar and the date picker. Good job there!
Unfortunately, the top nav filters are not updating the data source as one would expect. There's also no indication in the search bar that the data source has not changed if a filter is added/edited or otherwise changed:
filter_changes_not_taking_effect
I went digging into the code and tried to work out which effect wasn't triggering when the data source should be changing but couldn't track down where the issue is.
Maybe we can somehow let users know that filter changes don't effect the data source automatically?

@@ -111,7 +112,7 @@ export function FieldItem(props: FieldItemProps) {
core.http
.post(`/api/lens/index_stats/${indexPattern.title}/field`, {
body: JSON.stringify({
query: toElasticsearchQuery(query, indexPattern),
dslQuery: buildEsQuery(indexPattern, query, filters),
Copy link
Contributor

Choose a reason for hiding this comment

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

buildEsQuery also takes in an optional config that allows us to use the global Kibana query language (either KQL or lucene) and the timezone users choose to set in their Kibana advanced settings. We have access to those from KibanaContextProvider services. There are defaults though, so it's optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the buildEsQuery call here.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

Filters are almost working now, I can add a filter and the update button shows. Removing a filter triggers an update automatically and some of the filter editor methods also trigger an automatic update.
However, adding a new filter only fetches fields from my default index pattern and not the one selected for the vis. There's no way of changing the index pattern from which to select a new filters' fields.
In the screen shot below, the index pattern for the vis is kibana_sample_data_ecommerce but the fields for the new filter are only from kibana_sample_data_logs.

Screen Shot 2019-10-02 at 7 28 46 AM

@wylieconlon
Copy link
Contributor Author

@TinaHeiligers That's not what I'm seeing when I have two layers: Screenshot 2019-10-02 13 02 10

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@wylieconlon wylieconlon added release_note:skip Skip the PR/issue when compiling release notes and removed release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. labels Oct 2, 2019
Copy link
Contributor

@chrisdavies chrisdavies left a comment

Choose a reason for hiding this comment

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

LGTM w/ possible tweaks. The tweaks aren't necessary.

}
})
.catch(reason => {
core.notifications.toasts.addDanger(
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use addError instead, which takes the error object directly. I think that would probably be preferable here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I think you found a potential issue- I don't think these are human-readable error messages, so showing "Error saving document" was my attempt to humanize it. There's a test that verifies that if there's a save error it lets you retry.

}
export class AppPlugin {
private instance: EditorFrameInstance | null = null;
private store: SavedObjectIndexStore | null = null;

constructor() {}

setup(core: CoreSetup) {
setup(core: CoreSetup, plugins: {}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the point of this second argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit closer to what the new platform will do. @lizozom has been moving code out of the legacy data plugin, and into a new platform data plugin, and we will soon need to pass both in.

@TinaHeiligers
Copy link
Contributor

@TinaHeiligers That's not what I'm seeing when I have two layers: Screenshot 2019-10-02 13 02 10

Yes, with two layers, we get to choose the index pattern for the filter fields.
The problem is when we only have one layer. In this case, regardless of if we have more than one index pattern loaded, there isn't an option to choose the index pattern from which to select filter fields.
To reproduce:

  1. Load kibana_sample_data_logs, kibana_sample_data_ecommerce and kibana_sample_data_flights
  2. create a new Lens visualization
  3. Add data to the vis in a single layer. Do not add a second layer
  4. add a new filter from the search bar. Observe that one does not get the option to select an index pattern and that the fields available to create a filter from are from the default index pattern.
    Screen Shot 2019-10-02 at 12 02 40 PM

@wylieconlon
Copy link
Contributor Author

@TinaHeiligers I still can't reproduce the behavior you're describing with a non-default index pattern.

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

Adding a new filter with only one layer in the vis built from data that's not the default index pattern now works perfectly.
LGTM after adding the test for the change that fixed the problem.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@wylieconlon
Copy link
Contributor Author

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@wylieconlon
Copy link
Contributor Author

There was a flaky ML test failure, it's unrelated to my changes

}}
isDirty={isLocalStateDirty(state.localQueryBarState, state.query, state.dateRange)}
indexPatterns={state.indexPatternTitles}
appName={'lens'}
Copy link
Contributor

Choose a reason for hiding this comment

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

//nit
showQueryBar, showFilterBar and showDatePicker are true by default

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

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

LGTM in terms of TopNavMenu integration

@wylieconlon wylieconlon merged commit ab05bbd into elastic:master Oct 3, 2019
@wylieconlon wylieconlon deleted the lens/use-top-nav branch October 3, 2019 15:24
wylieconlon pushed a commit to wylieconlon/kibana that referenced this pull request Oct 3, 2019
* [lens] Use top nav in Lens app

* Add tests for saved query, pass filters around more places

* Fix filter passing

* Add unit test for field popover making correct queries

* Respond to review feedback

* Fix type errors

* Respond to all review comments

* Remove commented code

* Top nav should be compatible as angular directive

* Fix rendering issue with filter updates

* Respond to review comments and add onChange test

* Add specific test for the index pattern bug from Tina
wylieconlon pushed a commit that referenced this pull request Oct 4, 2019
* [lens] Use top nav in Lens app

* Add tests for saved query, pass filters around more places

* Fix filter passing

* Add unit test for field popover making correct queries

* Respond to review feedback

* Fix type errors

* Respond to all review comments

* Remove commented code

* Top nav should be compatible as angular directive

* Fix rendering issue with filter updates

* Respond to review comments and add onChange test

* Add specific test for the index pattern bug from Tina
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 Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) v7.5.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants