From e3376387e9d28178f58024cfe79f4957ce4e2a07 Mon Sep 17 00:00:00 2001 From: Marco Liberati Date: Thu, 15 Dec 2022 11:30:26 +0100 Subject: [PATCH] [Lens] Extend explore data in Discover/open in Discover drilldown to visualizations with annotations and reference lines (#147541) ## Summary Fixes #147427 This PR extends the support of the *open in Discover* drilldown/explore data in Discover to visualizations that have annotation and/or reference line layers, but still a single data layer. Screenshot 2022-12-14 at 11 07 04 Screenshot 2022-12-14 at 11 07 16 Screenshot 2022-12-14 at 11 07 25 ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [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 - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### Risk Matrix Delete this section if it is not applicable to this PR. Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release. When forming the risk matrix, consider some of the following examples and how they may potentially impact the change: | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | Multiple Spaces—unexpected behavior in non-default Kibana Space. | Low | High | Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces. | | Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. | High | Low | Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure. | | Code should gracefully handle cases when feature X or plugin Y are disabled. | Medium | High | Unit tests will verify that any feature flag or plugin combination still results in our service operational. | | [See more potential risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) | ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) Co-authored-by: Stratoula Kalafateli --- .../lens/public/app_plugin/lens_top_nav.tsx | 7 + .../app_plugin/show_underlying_data.test.ts | 197 ++++++++++++------ .../public/app_plugin/show_underlying_data.ts | 35 ++-- .../lens/public/embeddable/embeddable.tsx | 26 +++ .../lens/public/mocks/datasource_mock.ts | 10 +- x-pack/plugins/lens/public/utils.ts | 7 + .../apps/lens/group2/show_underlying_data.ts | 51 +++++ .../group2/show_underlying_data_dashboard.ts | 29 +++ 8 files changed, 285 insertions(+), 77 deletions(-) diff --git a/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx b/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx index 54bae8b037847..6019389284fea 100644 --- a/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx +++ b/x-pack/plugins/lens/public/app_plugin/lens_top_nav.tsx @@ -479,9 +479,14 @@ export const LensTopNavMenu = ({ if (!activeDatasourceId || !discoverLocator) { return; } + if (visualization.activeId == null) { + return; + } return getLayerMetaInfo( datasourceMap[activeDatasourceId], datasourceStates[activeDatasourceId].state, + visualizationMap[visualization.activeId], + visualization.state, activeData, dataViews.indexPatterns, data.query.timefilter.timefilter.getTime(), @@ -490,8 +495,10 @@ export const LensTopNavMenu = ({ }, [ activeDatasourceId, discoverLocator, + visualization, datasourceMap, datasourceStates, + visualizationMap, activeData, dataViews.indexPatterns, data.query.timefilter.timefilter, diff --git a/x-pack/plugins/lens/public/app_plugin/show_underlying_data.test.ts b/x-pack/plugins/lens/public/app_plugin/show_underlying_data.test.ts index 793064bd008fd..68059b293f2f9 100644 --- a/x-pack/plugins/lens/public/app_plugin/show_underlying_data.test.ts +++ b/x-pack/plugins/lens/public/app_plugin/show_underlying_data.test.ts @@ -5,11 +5,11 @@ * 2.0. */ -import { createMockDatasource } from '../mocks'; +import { createMockDatasource, createMockVisualization } from '../mocks'; import { combineQueryAndFilters, getLayerMetaInfo } from './show_underlying_data'; import { Filter } from '@kbn/es-query'; -import { DatasourcePublicAPI } from '../types'; import { createMockedIndexPattern } from '../datasources/form_based/mocks'; +import { LayerType } from '..'; describe('getLayerMetaInfo', () => { const capabilities = { @@ -21,6 +21,8 @@ describe('getLayerMetaInfo', () => { getLayerMetaInfo( createMockDatasource('testDatasource'), {}, + createMockVisualization('testVisualization'), + {}, undefined, {}, undefined, @@ -29,14 +31,17 @@ describe('getLayerMetaInfo', () => { ).toBe('Visualization has no data available to show'); }); - it('should return error in case of multiple layers', () => { + it('should return error in case of multiple data layers', () => { + const mockDatasource = createMockDatasource('testDatasource'); + mockDatasource.getLayers.mockReturnValue(['layer1', 'layer2']); expect( getLayerMetaInfo( - createMockDatasource('testDatasource'), + mockDatasource, + {}, + createMockVisualization('testVisualization'), {}, { datatable1: { type: 'datatable', columns: [], rows: [] }, - datatable2: { type: 'datatable', columns: [], rows: [] }, }, {}, undefined, @@ -46,17 +51,43 @@ describe('getLayerMetaInfo', () => { }); it('should return error in case of missing activeDatasource', () => { - expect(getLayerMetaInfo(undefined, {}, undefined, {}, undefined, capabilities).error).toBe( - 'Visualization has no data available to show' - ); + expect( + getLayerMetaInfo( + undefined, + {}, + createMockVisualization('testVisualization'), + {}, + undefined, + {}, + undefined, + capabilities + ).error + ).toBe('Visualization has no data available to show'); + }); + + it('should return error in case of missing datasource configuration/state', () => { + expect( + getLayerMetaInfo( + createMockDatasource('testDatasource'), + undefined, + createMockVisualization('testVisualization'), + {}, + {}, + {}, + undefined, + capabilities + ).error + ).toBe('Visualization has no data available to show'); }); - it('should return error in case of missing configuration/state', () => { + it('should return error in case of missing activeVisualization', () => { expect( getLayerMetaInfo( createMockDatasource('testDatasource'), + {}, undefined, {}, + undefined, {}, undefined, capabilities @@ -64,10 +95,74 @@ describe('getLayerMetaInfo', () => { ).toBe('Visualization has no data available to show'); }); + it('should return error in case of missing visualization configuration/state', () => { + expect( + getLayerMetaInfo( + createMockDatasource('testDatasource'), + {}, + createMockVisualization('testVisualization'), + undefined, + {}, + {}, + undefined, + capabilities + ).error + ).toBe('Visualization has no data available to show'); + }); + + it('should ignore the number of datatables passed, rather check the datasource and visualization configuration', () => { + expect( + getLayerMetaInfo( + createMockDatasource('testDatasource', { + getFilters: jest.fn(() => ({ + enabled: { kuery: [], lucene: [] }, + disabled: { kuery: [], lucene: [] }, + })), + }), + {}, + createMockVisualization('testVisualization'), + {}, + { + datatable1: { type: 'datatable', columns: [], rows: [] }, + datatable2: { type: 'datatable', columns: [], rows: [] }, + }, + {}, + undefined, + capabilities + ).error + ).toBeUndefined(); + }); + + it('should return no multiple layers error when non-data layers are used together with a single data layer', () => { + const mockDatasource = createMockDatasource('testDatasource', { + getFilters: jest.fn(() => ({ + enabled: { kuery: [], lucene: [] }, + disabled: { kuery: [], lucene: [] }, + })), + }); + mockDatasource.getLayers.mockReturnValue(['layer1', 'layer2', 'layer3']); + const mockVisualization = createMockVisualization('testVisualization'); + let counter = 0; + const layerTypes: LayerType[] = ['data', 'annotations', 'referenceLine']; + mockVisualization.getLayerType.mockImplementation(() => layerTypes[counter++]); + expect( + getLayerMetaInfo( + mockDatasource, + {}, + mockVisualization, + {}, + { + datatable1: { type: 'datatable', columns: [], rows: [] }, + }, + {}, + undefined, + capabilities + ).error + ).toBeUndefined(); + }); + it('should return error in case of a timeshift declared in a column', () => { - const mockDatasource = createMockDatasource('testDatasource'); - const updatedPublicAPI: DatasourcePublicAPI = { - datasourceId: 'testDatasource', + const mockDatasource = createMockDatasource('testDatasource', { getOperationForColumnId: jest.fn(() => ({ dataType: 'number', isBucketed: false, @@ -78,39 +173,33 @@ describe('getLayerMetaInfo', () => { hasTimeShift: true, hasReducedTimeRange: true, })), - getTableSpec: jest.fn(), - getVisualDefaults: jest.fn(), - getSourceId: jest.fn(), - getMaxPossibleNumValues: jest.fn(), - getFilters: jest.fn(), - isTextBasedLanguage: jest.fn(() => false), - hasDefaultTimeField: jest.fn(() => true), - }; - mockDatasource.getPublicAPI.mockReturnValue(updatedPublicAPI); + }); expect( - getLayerMetaInfo(createMockDatasource('testDatasource'), {}, {}, {}, undefined, capabilities) - .error + getLayerMetaInfo( + mockDatasource, + {}, + createMockVisualization('testVisualization'), + {}, + {}, + {}, + undefined, + capabilities + ).error ).toBe('Visualization has no data available to show'); }); it('should return error in case of getFilters returning errors', () => { - const mockDatasource = createMockDatasource('testDatasource'); - const updatedPublicAPI: DatasourcePublicAPI = { + const mockDatasource = createMockDatasource('testDatasource', { datasourceId: 'formBased', - getOperationForColumnId: jest.fn(), getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes'] }]), - getVisualDefaults: jest.fn(), - getSourceId: jest.fn(), - getMaxPossibleNumValues: jest.fn(), getFilters: jest.fn(() => ({ error: 'filters error' })), - isTextBasedLanguage: jest.fn(() => false), - hasDefaultTimeField: jest.fn(() => true), - }; - mockDatasource.getPublicAPI.mockReturnValue(updatedPublicAPI); + }); expect( getLayerMetaInfo( mockDatasource, {}, // the publicAPI has been mocked, so no need for a state here + createMockVisualization('testVisualization'), + {}, { datatable1: { type: 'datatable', columns: [], rows: [] }, }, @@ -122,24 +211,18 @@ describe('getLayerMetaInfo', () => { }); it('should not be visible if discover is not available', () => { - const mockDatasource = createMockDatasource('testDatasource'); - const updatedPublicAPI: DatasourcePublicAPI = { + const mockDatasource = createMockDatasource('testDatasource', { datasourceId: 'indexpattern', - getOperationForColumnId: jest.fn(), getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes'] }]), - getVisualDefaults: jest.fn(), - getSourceId: jest.fn(), - getMaxPossibleNumValues: jest.fn(), getFilters: jest.fn(() => ({ error: 'filters error' })), - isTextBasedLanguage: jest.fn(() => false), - hasDefaultTimeField: jest.fn(() => true), - }; - mockDatasource.getPublicAPI.mockReturnValue(updatedPublicAPI); + }); // both capabilities should be enabled to enable discover expect( getLayerMetaInfo( mockDatasource, {}, + createMockVisualization('testVisualization'), + {}, { datatable1: { type: 'datatable', columns: [], rows: [] }, }, @@ -155,6 +238,8 @@ describe('getLayerMetaInfo', () => { getLayerMetaInfo( mockDatasource, {}, + createMockVisualization('testVisualization'), + {}, { datatable1: { type: 'datatable', columns: [], rows: [] }, }, @@ -169,15 +254,10 @@ describe('getLayerMetaInfo', () => { }); it('should basically work collecting fields and filters in the visualization', () => { - const mockDatasource = createMockDatasource('testDatasource'); - const updatedPublicAPI: DatasourcePublicAPI = { + const mockDatasource = createMockDatasource('testDatasource', { datasourceId: 'formBased', - getOperationForColumnId: jest.fn(), getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes'] }]), - getVisualDefaults: jest.fn(), getSourceId: jest.fn(() => '1'), - getMaxPossibleNumValues: jest.fn(), - isTextBasedLanguage: jest.fn(() => false), getFilters: jest.fn(() => ({ enabled: { kuery: [[{ language: 'kuery', query: 'memory > 40000' }]], @@ -185,15 +265,15 @@ describe('getLayerMetaInfo', () => { }, disabled: { kuery: [], lucene: [] }, })), - hasDefaultTimeField: jest.fn(() => true), - }; - mockDatasource.getPublicAPI.mockReturnValue(updatedPublicAPI); + }); const sampleIndexPatternsFromService = { '1': createMockedIndexPattern(), }; const { error, meta } = getLayerMetaInfo( mockDatasource, {}, // the publicAPI has been mocked, so no need for a state here + createMockVisualization('testVisualization'), + {}, { datatable1: { type: 'datatable', columns: [], rows: [] }, }, @@ -220,15 +300,10 @@ describe('getLayerMetaInfo', () => { }); it('should order date fields first', () => { - const mockDatasource = createMockDatasource('testDatasource'); - const updatedPublicAPI: DatasourcePublicAPI = { + const mockDatasource = createMockDatasource('testDatasource', { datasourceId: 'formBased', - getOperationForColumnId: jest.fn(), getTableSpec: jest.fn(() => [{ columnId: 'col1', fields: ['bytes', 'timestamp'] }]), - getVisualDefaults: jest.fn(), getSourceId: jest.fn(() => '1'), - getMaxPossibleNumValues: jest.fn(), - isTextBasedLanguage: jest.fn(() => false), getFilters: jest.fn(() => ({ enabled: { kuery: [[{ language: 'kuery', query: 'memory > 40000' }]], @@ -236,15 +311,15 @@ describe('getLayerMetaInfo', () => { }, disabled: { kuery: [], lucene: [] }, })), - hasDefaultTimeField: jest.fn(() => true), - }; - mockDatasource.getPublicAPI.mockReturnValue(updatedPublicAPI); + }); const sampleIndexPatternsFromService = { '1': createMockedIndexPattern(), }; const { meta } = getLayerMetaInfo( mockDatasource, {}, // the publicAPI has been mocked, so no need for a state here + createMockVisualization('testVisualization'), + {}, { datatable1: { type: 'datatable', columns: [], rows: [] }, }, diff --git a/x-pack/plugins/lens/public/app_plugin/show_underlying_data.ts b/x-pack/plugins/lens/public/app_plugin/show_underlying_data.ts index 9a0c4a9ed70eb..bc0e926e64589 100644 --- a/x-pack/plugins/lens/public/app_plugin/show_underlying_data.ts +++ b/x-pack/plugins/lens/public/app_plugin/show_underlying_data.ts @@ -20,9 +20,12 @@ import { i18n } from '@kbn/i18n'; import { RecursiveReadonly } from '@kbn/utility-types'; import { Capabilities } from '@kbn/core/public'; import { partition } from 'lodash'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { showMemoizedErrorNotification } from '../lens_ui_errors'; import { TableInspectorAdapter } from '../editor_frame_service/types'; import { Datasource, DatasourcePublicAPI, IndexPatternMap } from '../types'; +import { Visualization } from '..'; +import { getLayerType } from '../editor_frame_service/editor_frame/config_panel/add_layer'; /** * Joins a series of queries. @@ -83,6 +86,8 @@ const sortByDateFieldsFirst = ( export function getLayerMetaInfo( currentDatasource: Datasource | undefined, datasourceState: unknown, + activeVisualization: Visualization | undefined, + visualizationState: unknown, activeData: TableInspectorAdapter | undefined, indexPatterns: IndexPatternMap, timeRange: TimeRange | undefined, @@ -94,8 +99,8 @@ export function getLayerMetaInfo( const isVisible = Boolean(capabilities.navLinks?.discover && capabilities.discover?.show); // If Multiple tables, return // If there are time shifts, return - const [datatable, ...otherTables] = Object.values(activeData || {}); - if (!datatable || !currentDatasource || !datasourceState) { + const datatables = Object.values(activeData || {}); + if (!datatables.length || !currentDatasource || !datasourceState || !activeVisualization) { return { meta: undefined, error: i18n.translate('xpack.lens.app.showUnderlyingDataNoData', { @@ -104,21 +109,25 @@ export function getLayerMetaInfo( isVisible, }; } - if (otherTables.length) { - return { - meta: undefined, - error: i18n.translate('xpack.lens.app.showUnderlyingDataMultipleLayers', { - defaultMessage: 'Cannot show underlying data for visualizations with multiple layers', - }), - isVisible, - }; - } let datasourceAPI: DatasourcePublicAPI; try { - const [firstLayerId] = currentDatasource.getLayers(datasourceState); + const layerIds = currentDatasource.getLayers(datasourceState); + const dataLayerIds = layerIds.filter( + (layerId) => + getLayerType(activeVisualization, visualizationState, layerId) === LayerTypes.DATA + ); + if (dataLayerIds.length > 1) { + return { + meta: undefined, + error: i18n.translate('xpack.lens.app.showUnderlyingDataMultipleLayers', { + defaultMessage: 'Cannot show underlying data for visualizations with multiple layers', + }), + isVisible, + }; + } datasourceAPI = currentDatasource.getPublicAPI({ - layerId: firstLayerId, + layerId: dataLayerIds[0], state: datasourceState, indexPatterns, }); diff --git a/x-pack/plugins/lens/public/embeddable/embeddable.tsx b/x-pack/plugins/lens/public/embeddable/embeddable.tsx index aecb794efb8f2..5af66f23d1eb7 100644 --- a/x-pack/plugins/lens/public/embeddable/embeddable.tsx +++ b/x-pack/plugins/lens/public/embeddable/embeddable.tsx @@ -88,6 +88,7 @@ import { getLensInspectorService, LensInspector } from '../lens_inspector_servic import { SharingSavedObjectProps, VisualizationDisplayOptions } from '../types'; import { getActiveDatasourceIdFromDoc, + getActiveVisualizationIdFromDoc, getIndexPatternsObjects, getSearchWarningMessages, inferTimeField, @@ -183,6 +184,8 @@ const getExpressionFromDocument = async ( function getViewUnderlyingDataArgs({ activeDatasource, activeDatasourceState, + activeVisualization, + activeVisualizationState, activeData, dataViews, capabilities, @@ -194,6 +197,8 @@ function getViewUnderlyingDataArgs({ }: { activeDatasource: Datasource; activeDatasourceState: unknown; + activeVisualization: Visualization; + activeVisualizationState: unknown; activeData: TableInspectorAdapter | undefined; dataViews: DataViewBase[] | undefined; capabilities: LensEmbeddableDeps['capabilities']; @@ -206,6 +211,8 @@ function getViewUnderlyingDataArgs({ const { error, meta } = getLayerMetaInfo( activeDatasource, activeDatasourceState, + activeVisualization, + activeVisualizationState, activeData, indexPatternsCache, timeRange, @@ -289,6 +296,8 @@ export class Embeddable activeData?: TableInspectorAdapter; activeDatasource?: Datasource; activeDatasourceState?: unknown; + activeVisualization?: Visualization; + activeVisualizationState?: unknown; } = {}; private indexPatterns: DataView[] = []; @@ -903,7 +912,14 @@ export class Embeddable return false; } + const activeVisualizationId = getActiveVisualizationIdFromDoc(this.savedVis); + if (!activeVisualizationId) { + return false; + } + this.activeDataInfo.activeDatasource = this.deps.datasourceMap[activeDatasourceId]; + this.activeDataInfo.activeVisualization = this.deps.visualizationMap[activeVisualizationId]; + const docDatasourceState = this.savedVis?.state.datasourceStates[activeDatasourceId]; const adHocDataviews = await Promise.all( Object.values(this.savedVis?.state.adHocDataViews || {}) @@ -936,9 +952,19 @@ export class Embeddable ); } + if (!this.activeDataInfo.activeVisualizationState) { + this.activeDataInfo.activeVisualizationState = + this.activeDataInfo.activeVisualization.initialize( + () => '', + this.savedVis?.state.visualization + ); + } + const viewUnderlyingDataArgs = getViewUnderlyingDataArgs({ activeDatasource: this.activeDataInfo.activeDatasource, activeDatasourceState: this.activeDataInfo.activeDatasourceState, + activeVisualization: this.activeDataInfo.activeVisualization, + activeVisualizationState: this.activeDataInfo.activeVisualizationState, activeData: this.activeDataInfo.activeData, dataViews: this.indexPatterns, capabilities: this.deps.capabilities, diff --git a/x-pack/plugins/lens/public/mocks/datasource_mock.ts b/x-pack/plugins/lens/public/mocks/datasource_mock.ts index a9936a90c764f..ab4a5fb519ab5 100644 --- a/x-pack/plugins/lens/public/mocks/datasource_mock.ts +++ b/x-pack/plugins/lens/public/mocks/datasource_mock.ts @@ -11,8 +11,11 @@ export type DatasourceMock = jest.Mocked & { publicAPIMock: jest.Mocked; }; -export function createMockDatasource(id: string): DatasourceMock { - const publicAPIMock: jest.Mocked = { +export function createMockDatasource( + id: string, + customPublicApi: Partial = {} +): DatasourceMock { + const publicAPIMock = { datasourceId: id, getTableSpec: jest.fn(() => []), getOperationForColumnId: jest.fn(), @@ -22,7 +25,8 @@ export function createMockDatasource(id: string): DatasourceMock { getMaxPossibleNumValues: jest.fn(), isTextBasedLanguage: jest.fn(() => false), hasDefaultTimeField: jest.fn(() => true), - }; + ...customPublicApi, + } as jest.Mocked; return { id: 'testDatasource', diff --git a/x-pack/plugins/lens/public/utils.ts b/x-pack/plugins/lens/public/utils.ts index 01591155c9dd0..16ad6a026851d 100644 --- a/x-pack/plugins/lens/public/utils.ts +++ b/x-pack/plugins/lens/public/utils.ts @@ -69,6 +69,13 @@ export function getActiveDatasourceIdFromDoc(doc?: Document) { return firstDatasourceFromDoc || null; } +export function getActiveVisualizationIdFromDoc(doc?: Document) { + if (!doc) { + return null; + } + return doc.visualizationType || null; +} + export const getInitialDatasourceId = (datasourceMap: DatasourceMap, doc?: Document) => { return (doc && getActiveDatasourceIdFromDoc(doc)) || Object.keys(datasourceMap)[0] || null; }; diff --git a/x-pack/test/functional/apps/lens/group2/show_underlying_data.ts b/x-pack/test/functional/apps/lens/group2/show_underlying_data.ts index 41e327234009b..f1f5ffcac75cd 100644 --- a/x-pack/test/functional/apps/lens/group2/show_underlying_data.ts +++ b/x-pack/test/functional/apps/lens/group2/show_underlying_data.ts @@ -49,6 +49,57 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await browser.switchToWindow(lensWindowHandler); }); + it('should show the open button if visualization has an annotation layer', async () => { + await PageObjects.lens.createLayer('annotations'); + await testSubjects.clickWhenNotDisabledWithoutRetry(`lnsApp_openInDiscover`); + const [lensWindowHandler, discoverWindowHandle] = await browser.getAllWindowHandles(); + await browser.switchToWindow(discoverWindowHandle); + + await PageObjects.header.waitUntilLoadingHasFinished(); + await testSubjects.existOrFail('unifiedHistogramChart'); + const columns = await PageObjects.discover.getColumnHeaders(); + expect(columns).to.eql(['@timestamp', 'extension.raw', 'bytes']); + await browser.closeCurrentWindow(); + await browser.switchToWindow(lensWindowHandler); + }); + + it('should show the open button if visualization has a reference line layer', async () => { + await PageObjects.lens.createLayer('referenceLine'); + await testSubjects.clickWhenNotDisabledWithoutRetry(`lnsApp_openInDiscover`); + const [lensWindowHandler, discoverWindowHandle] = await browser.getAllWindowHandles(); + await browser.switchToWindow(discoverWindowHandle); + + await PageObjects.header.waitUntilLoadingHasFinished(); + await testSubjects.existOrFail('unifiedHistogramChart'); + const columns = await PageObjects.discover.getColumnHeaders(); + expect(columns).to.eql(['@timestamp', 'extension.raw', 'bytes']); + await browser.closeCurrentWindow(); + await browser.switchToWindow(lensWindowHandler); + }); + + it('should not show the open button if visualization has multiple data layers', async () => { + await PageObjects.lens.createLayer(); + await PageObjects.lens.configureDimension({ + dimension: 'lns-layerPanel-3 > lnsXY_xDimensionPanel > lns-empty-dimension', + operation: 'date_histogram', + field: '@timestamp', + }); + + await PageObjects.lens.configureDimension({ + dimension: 'lns-layerPanel-3 > lnsXY_yDimensionPanel > lns-empty-dimension', + operation: 'median', + field: 'bytes', + }); + + await PageObjects.lens.waitForVisualization('xyVisChart'); + + expect(await testSubjects.isEnabled(`lnsApp_openInDiscover`)).to.be(false); + + for (const index of [3, 2, 1]) { + await PageObjects.lens.removeLayer(index); + } + }); + it('should ignore the top values column if other category is enabled', async () => { // Make the breakdown dimention be ignored await PageObjects.lens.openDimensionEditor( diff --git a/x-pack/test/functional/apps/lens/group2/show_underlying_data_dashboard.ts b/x-pack/test/functional/apps/lens/group2/show_underlying_data_dashboard.ts index 46fdc94879d03..2cc447238de3b 100644 --- a/x-pack/test/functional/apps/lens/group2/show_underlying_data_dashboard.ts +++ b/x-pack/test/functional/apps/lens/group2/show_underlying_data_dashboard.ts @@ -56,6 +56,35 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await browser.switchToWindow(dashboardWindowHandle); }); + it('should show the open button for a compatible saved visualization with annotations and reference line', async () => { + await PageObjects.dashboard.switchToEditMode(); + await dashboardPanelActions.clickEdit(); + + await PageObjects.lens.createLayer('annotations'); + await PageObjects.lens.createLayer('referenceLine'); + await PageObjects.lens.save('Embedded Visualization', false); + + await PageObjects.dashboard.saveDashboard(`Open in Discover Testing ${uuid()}`, { + exitFromEditMode: true, + }); + + await dashboardPanelActions.openContextMenu(); + + await testSubjects.click('embeddablePanelAction-ACTION_OPEN_IN_DISCOVER'); + + const [dashboardWindowHandle, discoverWindowHandle] = await browser.getAllWindowHandles(); + await browser.switchToWindow(discoverWindowHandle); + + await PageObjects.header.waitUntilLoadingHasFinished(); + await testSubjects.existOrFail('unifiedHistogramChart'); + // check the table columns + const columns = await PageObjects.discover.getColumnHeaders(); + expect(columns).to.eql(['@timestamp', 'ip', 'bytes']); + + await browser.closeCurrentWindow(); + await browser.switchToWindow(dashboardWindowHandle); + }); + it('should bring both dashboard context and visualization context to discover', async () => { await PageObjects.dashboard.switchToEditMode(); await dashboardPanelActions.clickEdit();