-
Notifications
You must be signed in to change notification settings - Fork 8.3k
[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
Conversation
💔 Build Failed |
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.
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 |
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.
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, |
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.
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.
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.
Some assumptions about saved queries are incorrect:
- 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.
- A saved query will always contain a query, even if it is an empty one.
💔 Build Failed |
Pinging @elastic/kibana-app |
💔 Build Failed |
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.
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} |
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.
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'; |
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.
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()} |
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.
Core.savedObjects.client
toasts={core.notifications.toasts} | ||
uiSettings={core.uiSettings} | ||
savedObjectsClient={savedObjectsClient} | ||
http={core.http} | ||
timeHistory={data.timefilter.history} |
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.
@lizozom We're using the time history here,
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.
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:
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), |
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.
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.
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.
Adding the buildEsQuery
call here.
💚 Build Succeeded |
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.
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.
@TinaHeiligers That's not what I'm seeing when I have two layers: |
💚 Build Succeeded |
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 w/ possible tweaks. The tweaks aren't necessary.
} | ||
}) | ||
.catch(reason => { | ||
core.notifications.toasts.addDanger( |
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.
You can use addError
instead, which takes the error object directly. I think that would probably be preferable here.
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.
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: {}) { |
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 is the point of this second argument?
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.
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.
Yes, with two layers, we get to choose the index pattern for the filter fields.
|
@TinaHeiligers I still can't reproduce the behavior you're describing with a non-default index pattern. |
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.
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.
💚 Build Succeeded |
💔 Build Failed |
retest |
💚 Build Succeeded |
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'} |
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.
//nit
showQueryBar, showFilterBar and showDatePicker are true by default
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 in terms of TopNavMenu integration
* [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
* [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
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:
With read-only permissions the user can use saved queries, and can run visualizations, but cannot save them: