[Convert2Lens] Carry vis filters to the converted Vis (#151255)

## Summary

Closes https://github.com/elastic/kibana/issues/151234

Solves the bug described in the issue. If the visualization has
filters/query, when converted the filters are carried to the converted
viz (unreleased bug)

### 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>
This commit is contained in:
Stratoula Kalafateli 2023-02-20 13:04:31 +02:00 committed by GitHub
parent 82c0d6c234
commit cb03bb67c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View file

@ -71,9 +71,12 @@ export class EditInLensAction implements Action<EditInLensContext> {
if (isVisualizeEmbeddable(embeddable)) {
const vis = embeddable.getVis();
const navigateToLensConfig = await vis.type.navigateToLens?.(vis, this.timefilter);
// Filters and query set on the visualization level
const visFilters = vis.data.searchSource?.getField('filter');
const visQuery = vis.data.searchSource?.getField('query');
const parentSearchSource = vis.data.searchSource?.getParent();
const searchFilters = parentSearchSource?.getField('filter');
const searchQuery = parentSearchSource?.getField('query');
const searchFilters = parentSearchSource?.getField('filter') ?? visFilters;
const searchQuery = parentSearchSource?.getField('query') ?? visQuery;
const title = vis.title || embeddable.getOutput().title;
const updatedWithMeta = {
...navigateToLensConfig,

View file

@ -75,5 +75,28 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await dashboard.waitForRenderComplete();
expect(await dashboard.isNotificationExists(1)).to.be(false);
});
it('should carry the visualizations filters to Lens', async () => {
await dashboardAddPanel.clickEditorMenuButton();
await dashboardAddPanel.clickAggBasedVisualizations();
await dashboardAddPanel.clickVisType('histogram');
await testSubjects.click('savedObjectTitlelogstash-*');
await filterBar.addFilter({ field: 'geo.src', operation: 'is', value: 'CN' });
await testSubjects.exists('visualizesaveAndReturnButton');
await testSubjects.click('visualizesaveAndReturnButton');
await dashboard.waitForRenderComplete();
expect(await dashboard.isNotificationExists(2)).to.be(true);
const panel = (await dashboard.getDashboardPanels())[2];
await panelActions.convertToLens(panel);
await lens.waitForVisualization('xyVisChart');
const filterCount = await filterBar.getFilterCount();
expect(filterCount).to.equal(1);
await lens.replaceInDashboard();
await dashboard.waitForRenderComplete();
expect(await dashboard.isNotificationExists(2)).to.be(false);
});
});
}