diff --git a/src/plugins/unified_histogram/public/chart/histogram.tsx b/src/plugins/unified_histogram/public/chart/histogram.tsx index e63cf775158aa..7e8c6ea382bd4 100644 --- a/src/plugins/unified_histogram/public/chart/histogram.tsx +++ b/src/plugins/unified_histogram/public/chart/histogram.tsx @@ -10,12 +10,12 @@ import { useEuiTheme } from '@elastic/eui'; import { css } from '@emotion/react'; import React, { useState } from 'react'; -import type { DataView } from '@kbn/data-views-plugin/public'; +import type { DataView, DataViewSpec } from '@kbn/data-views-plugin/public'; import type { DefaultInspectorAdapters, Datatable } from '@kbn/expressions-plugin/common'; import type { IKibanaSearchResponse } from '@kbn/search-types'; import type { estypes } from '@elastic/elasticsearch'; import type { TimeRange } from '@kbn/es-query'; -import type { +import { EmbeddableComponentProps, LensEmbeddableInput, LensEmbeddableOutput, @@ -59,6 +59,32 @@ export interface HistogramProps { withDefaultActions: EmbeddableComponentProps['withDefaultActions']; } +/** + * To prevent flakiness in the chart, we need to ensure that the data view config is valid. + * This requires that there are not multiple different data view ids in the given configuration. + * @param dataView + * @param visContext + * @param adHocDataViews + */ +const checkValidDataViewConfig = ( + dataView: DataView, + visContext: UnifiedHistogramVisContext, + adHocDataViews: { [key: string]: DataViewSpec } | undefined +) => { + if (!dataView.id) { + return false; + } + + if (!dataView.isPersisted() && !adHocDataViews?.[dataView.id]) { + return false; + } + + if (dataView.id !== visContext.requestData.dataViewId) { + return false; + } + return true; +}; + const computeTotalHits = ( hasLensSuggestions: boolean, adapterTables: @@ -204,6 +230,10 @@ export function Histogram({ } `; + if (!checkValidDataViewConfig(dataView, visContext, lensProps.attributes.state.adHocDataViews)) { + return <>; + } + return ( <>
{ await security.testUser.setRoles(['kibana_admin', 'test_logstash_reader']); await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional'); @@ -655,8 +654,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await discover.waitUntilSearchingHasFinished(); await testSubjects.missingOrFail('unsavedChangesBadge'); - await discover.chooseLensSuggestion('pie'); - expect(await getCurrentVisTitle()).to.be('Pie'); + await discover.chooseLensSuggestion('waffle'); + expect(await getCurrentVisTitle()).to.be('Waffle'); await testSubjects.existOrFail('partitionVisChart'); expect(await discover.getVisContextSuggestionType()).to.be('lensSuggestion');