[ES|QL][Lens] Improves the ES|QL suggestions logic when a query changes#231767
[ES|QL][Lens] Improves the ES|QL suggestions logic when a query changes#231767stratoula merged 32 commits intoelastic:mainfrom
Conversation
| let queryColumns = results.response.columns; | ||
| // if the query columns are empty, we need to use the all_columns property | ||
| // which has all columns regardless if they have data or not | ||
| if (queryColumns.length === 0 && results.response.all_columns) { |
There was a problem hiding this comment.
Make sure that all columns are returned if they exist in the payload. This ensures that the textBasedColumns that are passed in the api has all columns with or without data.
| layer.columns?.some( | ||
| (c: { fieldName: string }) => | ||
| !context?.textBasedColumns?.find((col) => col.id === c.fieldName) | ||
| ) || layer.columns?.length !== context?.textBasedColumns?.length |
There was a problem hiding this comment.
I removed the columns length check, we dont want to revert if the user selected different columns as long as they exist in the response
| }); | ||
| }); | ||
|
|
||
| describe('injectESQLQueryIntoLensLayers', () => { |
There was a problem hiding this comment.
Move this to suggestions api tests
| } | ||
| return undefined; | ||
| }; | ||
|
|
There was a problem hiding this comment.
Moves this into suggestions api logic
| !context?.textBasedColumns?.find((col) => col.id === c.fieldName) | ||
| ) || layer.columns?.length !== context?.textBasedColumns?.length | ||
| // Check if index patterns match when context has a query | ||
| if (context && 'query' in context && context.query && 'esql' in context.query) { |
There was a problem hiding this comment.
Here we will return the suggestion if the user changed datasource
Flaky Test Runner Stats🎉 All tests passed! - kibana-flaky-test-suite-runner#9164[✅] x-pack/platform/test/functional/apps/lens/group7/config.ts: 50/50 tests passed. |
|
Pinging @elastic/kibana-visualizations (Team:Visualizations) |
| * Get the user's preferred chart type from localStorage | ||
| */ | ||
| export const getUserChartTypeFromLocalStorage = (): string | null => { | ||
| const storage = new Storage(localStorage); |
There was a problem hiding this comment.
I think it is better to use the sessionStorage instead of the localStorage to avoid conflicts and changes of the same variable across different tabs.
I tested and clicking Close on a tab besically removes the currently set viz type from the other tab and viceversa.
There was a problem hiding this comment.
Good point, I will address tomorrow
There was a problem hiding this comment.
Marco changed it to use session storage instead 211cf65
x-pack/platform/plugins/shared/lens/public/app_plugin/shared/edit_on_the_fly/helpers.ts
Outdated
Show resolved
Hide resolved
...platform/plugins/shared/lens/public/react_embeddable/inline_editing/setup_inline_editing.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Tested few cases here, but the totality of the bugs I've found are tied to the lack of handling of the ESC key down event on the new logic.
Typical bug scenario:
- create a ES|QL chart on a dashboard
- close the inline initial editing
- reopen the inline editor
- tweak the query or change the chart type
- now press ESC
- the chart is saved in the current state
A a user the ESC button is a tricky point: it "sounds" something similar to a Cancel than a Save logically, but I can see how much of a slippery slope that can be.
Maybe pressing ESC should have a confirmation modal before cancelling? cc @gvnmagni
There was a problem hiding this comment.
The ESC works the same in the main (I mean it applies the changes). You mean that it doesnt reset the session? I don't think it will be a problem mostly because when you edit another panel it will add to the session storage the new chart type.
Which bug have you found that is related with the ESC button functionality and the changes this PR is introducing?
There was a problem hiding this comment.
Synced with Marco offline, I can reset on ESC, there is a keydown handler already
There was a problem hiding this comment.
Done here ac2e092
I didn't know we had added this handler, thanx for pointing out Marco!
…dit_on_the_fly/helpers.ts Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
…line_editing/setup_inline_editing.tsx Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
History
|
…es (elastic#231767) ## Summary Improves this elastic#220939  How it improves it: 1. When the user edits an existing chart, we try to keep the chart type the viz has as long as the query returns compatible columns. If the user changes the chart type from the dropdown then this means he deliberately wants to change it and we try to respect the new choice. 2. When the user creates a new chart we are following the suggestions until the user starts changing something in the visualization parameters panel. Then we are assuming that the user wants this chart type and we try to respect it (according to this [comment](elastic#220939 (comment))). If the user changes the chart type from the dropdown then we try to respect this choice. 4. There is a special treatment for tables as they are not suggested from the suggestions api (they are always hidden) 5. **The above work as long as the query doesnt change significantly**. When the query changes significantly there is the possibility that the columns used in the chart are not being returned from the _query api. For example if I have a stats by date_histogram and I change to `from index` you have now all index columns but not the histogram buckets, this will reset. In the future we should inform the user that this change will reset the visualization. TL;DR - If the user edits an existing chart then we try to respect the chart type defined there - If the user creates a new one we follow the suggestions as long as the user hasn't changed something in the visualization settings panel - If the user changes the query and the returned columns don't contain the visualization columns we reset. Here we should inform the users in the future ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
…es (elastic#231767) ## Summary Improves this elastic#220939  How it improves it: 1. When the user edits an existing chart, we try to keep the chart type the viz has as long as the query returns compatible columns. If the user changes the chart type from the dropdown then this means he deliberately wants to change it and we try to respect the new choice. 2. When the user creates a new chart we are following the suggestions until the user starts changing something in the visualization parameters panel. Then we are assuming that the user wants this chart type and we try to respect it (according to this [comment](elastic#220939 (comment))). If the user changes the chart type from the dropdown then we try to respect this choice. 4. There is a special treatment for tables as they are not suggested from the suggestions api (they are always hidden) 5. **The above work as long as the query doesnt change significantly**. When the query changes significantly there is the possibility that the columns used in the chart are not being returned from the _query api. For example if I have a stats by date_histogram and I change to `from index` you have now all index columns but not the histogram buckets, this will reset. In the future we should inform the user that this change will reset the visualization. TL;DR - If the user edits an existing chart then we try to respect the chart type defined there - If the user creates a new one we follow the suggestions as long as the user hasn't changed something in the visualization settings panel - If the user changes the query and the returned columns don't contain the visualization columns we reset. Here we should inform the users in the future ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
…es (elastic#231767) ## Summary Improves this elastic#220939  How it improves it: 1. When the user edits an existing chart, we try to keep the chart type the viz has as long as the query returns compatible columns. If the user changes the chart type from the dropdown then this means he deliberately wants to change it and we try to respect the new choice. 2. When the user creates a new chart we are following the suggestions until the user starts changing something in the visualization parameters panel. Then we are assuming that the user wants this chart type and we try to respect it (according to this [comment](elastic#220939 (comment))). If the user changes the chart type from the dropdown then we try to respect this choice. 4. There is a special treatment for tables as they are not suggested from the suggestions api (they are always hidden) 5. **The above work as long as the query doesnt change significantly**. When the query changes significantly there is the possibility that the columns used in the chart are not being returned from the _query api. For example if I have a stats by date_histogram and I change to `from index` you have now all index columns but not the histogram buckets, this will reset. In the future we should inform the user that this change will reset the visualization. TL;DR - If the user edits an existing chart then we try to respect the chart type defined there - If the user creates a new one we follow the suggestions as long as the user hasn't changed something in the visualization settings panel - If the user changes the query and the returned columns don't contain the visualization columns we reset. Here we should inform the users in the future ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
…es (#231767) ## Summary Improves this #220939  How it improves it: 1. When the user edits an existing chart, we try to keep the chart type the viz has as long as the query returns compatible columns. If the user changes the chart type from the dropdown then this means he deliberately wants to change it and we try to respect the new choice. 2. When the user creates a new chart we are following the suggestions until the user starts changing something in the visualization parameters panel. Then we are assuming that the user wants this chart type and we try to respect it (according to this [comment](#220939 (comment))). If the user changes the chart type from the dropdown then we try to respect this choice. 4. There is a special treatment for tables as they are not suggested from the suggestions api (they are always hidden) 5. **The above work as long as the query doesnt change significantly**. When the query changes significantly there is the possibility that the columns used in the chart are not being returned from the _query api. For example if I have a stats by date_histogram and I change to `from index` you have now all index columns but not the histogram buckets, this will reset. In the future we should inform the user that this change will reset the visualization. TL;DR - If the user edits an existing chart then we try to respect the chart type defined there - If the user creates a new one we follow the suggestions as long as the user hasn't changed something in the visualization settings panel - If the user changes the query and the returned columns don't contain the visualization columns we reset. Here we should inform the users in the future ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
Summary
Improves this #220939
How it improves it:
from indexyou have now all index columns but not the histogram buckets, this will reset. In the future we should inform the user that this change will reset the visualization.TL;DR
Checklist