diff --git a/src/core_plugins/metrics/public/kbn_vis_types/request_handler.js b/src/core_plugins/metrics/public/kbn_vis_types/request_handler.js index f20c998b845b..51bce4c094fb 100644 --- a/src/core_plugins/metrics/public/kbn_vis_types/request_handler.js +++ b/src/core_plugins/metrics/public/kbn_vis_types/request_handler.js @@ -28,10 +28,10 @@ const MetricsRequestHandlerProvider = function (Private, Notifier, config, $http return { name: 'metrics', - handler: function (vis, { uiState, timeRange, filters, query }) { + handler: function ({ aggs, uiState, timeRange, filters, query, visParams }) { const timezone = Private(timezoneProvider)(); return new Promise((resolve) => { - const panel = vis.params; + const panel = visParams; const uiStateObj = uiState.get(panel.type, {}); const parsedTimeRange = timefilter.calculateBounds(timeRange); const scaledDataFormat = config.get('dateFormat:scaled'); @@ -39,7 +39,7 @@ const MetricsRequestHandlerProvider = function (Private, Notifier, config, $http if (panel && panel.id) { const params = { timerange: { timezone, ...parsedTimeRange }, - filters: [buildEsQuery(vis.indexPattern, [query], filters)], + filters: [buildEsQuery(aggs.indexPattern, [query], filters)], panels: [panel], state: uiStateObj }; diff --git a/src/core_plugins/timelion/public/vis/timelion_request_handler.js b/src/core_plugins/timelion/public/vis/timelion_request_handler.js index f79332c56144..a2aa4b8f5582 100644 --- a/src/core_plugins/timelion/public/vis/timelion_request_handler.js +++ b/src/core_plugins/timelion/public/vis/timelion_request_handler.js @@ -31,21 +31,21 @@ const TimelionRequestHandlerProvider = function (Private, Notifier, $http) { return { name: 'timelion', - handler: function (vis, { timeRange, filters, query }) { + handler: function ({ aggs, timeRange, filters, query, visParams }) { return new Promise((resolve, reject) => { - const expression = vis.params.expression; + const expression = visParams.expression; if (!expression) return; const httpResult = $http.post('../api/timelion/run', { sheet: [expression], extended: { es: { - filter: buildEsQuery(vis.indexPattern, [query], filters) + filter: buildEsQuery(aggs.indexPattern, [query], filters) } }, time: _.extend(timeRange, { - interval: vis.params.interval, + interval: visParams.interval, timezone: timezone }), }) diff --git a/src/core_plugins/vega/public/vega_request_handler.js b/src/core_plugins/vega/public/vega_request_handler.js index f65c5b95f4c5..3fba8216c723 100644 --- a/src/core_plugins/vega/public/vega_request_handler.js +++ b/src/core_plugins/vega/public/vega_request_handler.js @@ -33,10 +33,10 @@ export function VegaRequestHandlerProvider(Private, es, serviceSettings) { name: 'vega', - handler(vis, { timeRange, filters, query }) { + handler({ aggs, timeRange, filters, query, visParams }) { timeCache.setTimeRange(timeRange); - const filtersDsl = buildEsQuery(vis.indexPattern, [query], filters); - const vp = new VegaParser(vis.params.spec, searchCache, timeCache, filtersDsl, serviceSettings); + const filtersDsl = buildEsQuery(aggs.indexPattern, [query], filters); + const vp = new VegaParser(visParams.spec, searchCache, timeCache, filtersDsl, serviceSettings); return vp.parseAsync(); } diff --git a/src/ui/public/vis/request_handlers/courier.js b/src/ui/public/vis/request_handlers/courier.js index fba0c221f018..844a472bb668 100644 --- a/src/ui/public/vis/request_handlers/courier.js +++ b/src/ui/public/vis/request_handlers/courier.js @@ -30,7 +30,7 @@ const CourierRequestHandlerProvider = function () { return { name: 'courier', - handler: async function (vis, { + handler: async function ({ searchSource, aggs, timeRange, @@ -38,7 +38,9 @@ const CourierRequestHandlerProvider = function () { filters, forceFetch, partialRows, + isHierarchical, inspectorAdapters, + queryFilter }) { // Create a new search source that inherits the original search source @@ -65,7 +67,7 @@ const CourierRequestHandlerProvider = function () { }); requestSearchSource.setField('aggs', function () { - return aggs.toDsl(vis.isHierarchical()); + return aggs.toDsl(isHierarchical); }); requestSearchSource.onRequestStart((searchSource, searchRequest) => { @@ -130,24 +132,23 @@ const CourierRequestHandlerProvider = function () { } const parsedTimeRange = timeRange ? getTime(aggs.indexPattern, timeRange) : null; - const tabifyAggs = vis.getAggConfig(); const tabifyParams = { - metricsAtAllLevels: vis.isHierarchical(), + metricsAtAllLevels: isHierarchical, partialRows, timeRange: parsedTimeRange ? parsedTimeRange.range : undefined, }; - const tabifyCacheHash = calculateObjectHash({ tabifyAggs, ...tabifyParams }); + const tabifyCacheHash = calculateObjectHash({ tabifyAggs: aggs, ...tabifyParams }); // We only need to reexecute tabify, if either we did a new request or some input params to tabify changed const shouldCalculateNewTabify = shouldQuery || (searchSource.lastTabifyHash !== tabifyCacheHash); if (shouldCalculateNewTabify) { searchSource.lastTabifyHash = tabifyCacheHash; - searchSource.tabifiedResponse = tabifyAggResponse(tabifyAggs, searchSource.finalResponse, tabifyParams); + searchSource.tabifiedResponse = tabifyAggResponse(aggs, searchSource.finalResponse, tabifyParams); } inspectorAdapters.data.setTabularLoader( - () => buildTabularInspectorData(searchSource.tabifiedResponse, vis.API.queryFilter), + () => buildTabularInspectorData(searchSource.tabifiedResponse, queryFilter), { returnsFormattedValues: true } ); diff --git a/src/ui/public/vis/request_handlers/request_handlers.d.ts b/src/ui/public/vis/request_handlers/request_handlers.d.ts index e8261dd9b34f..357cced0e1fb 100644 --- a/src/ui/public/vis/request_handlers/request_handlers.d.ts +++ b/src/ui/public/vis/request_handlers/request_handlers.d.ts @@ -36,9 +36,11 @@ export interface RequestHandlerParams { uiState: PersistedState; partialRows?: boolean; inspectorAdapters?: Adapters; + isHierarchical?: boolean; + visParams?: any; } -export type RequestHandler = (vis: Vis, params: RequestHandlerParams) => T; +export type RequestHandler = (params: RequestHandlerParams) => T; export interface RequestHandlerDescription { name: string; diff --git a/src/ui/public/visualize/loader/visualize_data_loader.ts b/src/ui/public/visualize/loader/visualize_data_loader.ts index 0488ab680830..52f78e83d39d 100644 --- a/src/ui/public/visualize/loader/visualize_data_loader.ts +++ b/src/ui/public/visualize/loader/visualize_data_loader.ts @@ -74,8 +74,10 @@ export class VisualizeDataLoader { try { // searchSource is only there for courier request handler - const requestHandlerResponse = await this.requestHandler(this.vis, { + const requestHandlerResponse = await this.requestHandler({ partialRows: this.vis.params.partialRows || this.vis.type.requiresPartialRows, + isHierarchical: this.vis.isHierarchical(), + visParams: this.vis.params, ...params, filters: params.filters ? params.filters.filter(filter => !filter.meta.disabled)