From 562384f6929f8fd52bb51f5ba5436bbddd2a2383 Mon Sep 17 00:00:00 2001 From: Andrew Tate Date: Mon, 22 Nov 2021 08:06:14 -0600 Subject: [PATCH] [Vega] timelion & vega apply dataview from first filter (#119209) --- .../public/helpers/timelion_request_handler.ts | 13 +++++++++++-- .../vega/public/vega_request_handler.ts | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/plugins/vis_types/timelion/public/helpers/timelion_request_handler.ts b/src/plugins/vis_types/timelion/public/helpers/timelion_request_handler.ts index e9a076b4dc832..69a818b4ae16e 100644 --- a/src/plugins/vis_types/timelion/public/helpers/timelion_request_handler.ts +++ b/src/plugins/vis_types/timelion/public/helpers/timelion_request_handler.ts @@ -8,11 +8,12 @@ import { i18n } from '@kbn/i18n'; import type { KibanaExecutionContext } from 'kibana/public'; +import { DataView } from 'src/plugins/data/common'; import { KibanaContext, TimeRange, Filter, esQuery, Query } from '../../../../data/public'; import { TimelionVisDependencies } from '../plugin'; import { getTimezone } from './get_timezone'; import { TimelionVisParams } from '../timelion_vis_fn'; -import { getDataSearch } from '../helpers/plugin_services'; +import { getDataSearch, getIndexPatterns } from '../helpers/plugin_services'; import { VisSeries } from '../../common/vis_data'; interface Stats { @@ -81,6 +82,14 @@ export function getTimelionRequestHandler({ ); } + let dataView: DataView | undefined; + const firstFilterIndex = filters[0]?.meta.index; + if (firstFilterIndex) { + dataView = await getIndexPatterns() + .get(firstFilterIndex) + .catch(() => undefined); + } + const esQueryConfigs = esQuery.getEsQueryConfig(uiSettings); // parse the time range client side to make sure it behaves like other charts @@ -100,7 +109,7 @@ export function getTimelionRequestHandler({ sheet: [expression], extended: { es: { - filter: esQuery.buildEsQuery(undefined, query, filters, esQueryConfigs), + filter: esQuery.buildEsQuery(dataView, query, filters, esQueryConfigs), }, }, time: { diff --git a/src/plugins/vis_types/vega/public/vega_request_handler.ts b/src/plugins/vis_types/vega/public/vega_request_handler.ts index 2ae7169c2f732..78552ea2a170a 100644 --- a/src/plugins/vis_types/vega/public/vega_request_handler.ts +++ b/src/plugins/vis_types/vega/public/vega_request_handler.ts @@ -6,6 +6,7 @@ * Side Public License, v 1. */ import type { KibanaExecutionContext } from 'src/core/public'; +import { DataView } from 'src/plugins/data/common'; import { Filter, esQuery, TimeRange, Query } from '../../../data/public'; import { SearchAPI } from './data_model/search_api'; @@ -18,7 +19,7 @@ import { VegaInspectorAdapters } from './vega_inspector'; interface VegaRequestHandlerParams { query: Query; - filters: Filter; + filters: Filter[]; timeRange: TimeRange; visParams: VisParams; searchSessionId?: string; @@ -46,14 +47,14 @@ export function createVegaRequestHandler( searchSessionId, executionContext, }: VegaRequestHandlerParams) { - if (!searchAPI) { - const { search, indexPatterns } = getData(); + const { dataViews, search } = getData(); + if (!searchAPI) { searchAPI = new SearchAPI( { uiSettings, search, - indexPatterns, + indexPatterns: dataViews, injectedMetadata: getInjectedMetadata(), }, context.abortSignal, @@ -65,8 +66,14 @@ export function createVegaRequestHandler( timeCache.setTimeRange(timeRange); + let dataView: DataView; + const firstFilterIndex = filters[0]?.meta.index; + if (firstFilterIndex) { + dataView = await dataViews.get(firstFilterIndex).catch(() => undefined); + } + const esQueryConfigs = esQuery.getEsQueryConfig(uiSettings); - const filtersDsl = esQuery.buildEsQuery(undefined, query, filters, esQueryConfigs); + const filtersDsl = esQuery.buildEsQuery(dataView, query, filters, esQueryConfigs); const { VegaParser } = await import('./data_model/vega_parser'); const vp = new VegaParser(visParams.spec, searchAPI, timeCache, filtersDsl, getServiceSettings);