From bae4f14bc1c90102b7d4fae60a0227e22a87c9e3 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Tue, 13 Mar 2018 15:44:12 +0100 Subject: [PATCH 01/12] Fix visualization individual timeranges --- .../public/visualize/editor/editor.html | 1 + .../kibana/public/visualize/editor/editor.js | 1 + .../visualize_embeddable_factory.js | 1 + .../public/kbn_vis_types/request_handler.js | 8 ++-- .../public/vis/timelion_request_handler.js | 14 ++---- .../agg_types/buckets/date_histogram.js | 1 + src/ui/public/vis/request_handlers/courier.js | 31 ++++++++++++- src/ui/public/visualize/visualize.js | 43 +++++++------------ 8 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.html b/src/core_plugins/kibana/public/visualize/editor/editor.html index 5506dc1afc4b56..a9615e90ff19a5 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.html +++ b/src/core_plugins/kibana/public/visualize/editor/editor.html @@ -71,6 +71,7 @@ app-state="state" editor-mode="chrome.getVisible()" show-spy-panel="chrome.getVisible()" + time-range="timeRange" > diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.js b/src/core_plugins/kibana/public/visualize/editor/editor.js index 2e528a5b4a36d2..950e6e4245d504 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/core_plugins/kibana/public/visualize/editor/editor.js @@ -186,6 +186,7 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie $scope.isAddToDashMode = () => addToDashMode; $scope.timefilter = timefilter; + $scope.timeRange = timefilter.time; $scope.opts = _.pick($scope, 'doSave', 'savedVis', 'shareData', 'timefilter', 'isAddToDashMode'); stateMonitor = stateMonitorFactory.create($state, stateDefaults); diff --git a/src/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.js b/src/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.js index 003092fb21d11c..3c7901675a7f2f 100644 --- a/src/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.js +++ b/src/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.js @@ -17,6 +17,7 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory { this.savedVisualizations = savedVisualizations; this.name = 'visualization'; this.Promise = Promise; + this.timefilter = timefilter; this.brushEvent = utilsBrushEventProvider(timefilter); this.filterBarClickHandler = filterBarClickHandlerProvider(Private); } 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 73d2a2052ca596..edfc0ff662cc4d 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 @@ -8,17 +8,17 @@ const MetricsRequestHandlerProvider = function (Private, Notifier, config, timef return { name: 'metrics', - handler: function (vis, appState, uiState) { + handler: function (vis, { uiState, timeRange }) { const timezone = Private(timezoneProvider)(); return new Promise((resolve) => { const panel = vis.params; const uiStateObj = uiState.get(panel.type, {}); - const timeRange = vis.params.timeRange || timefilter.getBounds(); + const parsedTimeRange = timefilter.calculateBounds(timeRange); const scaledDataFormat = config.get('dateFormat:scaled'); const dateFormat = config.get('dateFormat'); if (panel && panel.id) { const params = { - timerange: { timezone, ...timeRange }, + timerange: { timezone, ...parsedTimeRange }, filters: [dashboardContext()], panels: [panel], state: uiStateObj @@ -26,7 +26,7 @@ const MetricsRequestHandlerProvider = function (Private, Notifier, config, timef try { const maxBuckets = config.get('metrics:max_buckets'); - validateInterval(timeRange, panel, maxBuckets); + validateInterval(parsedTimeRange, panel, maxBuckets); const httpResult = $http.post('../api/metrics/vis/data', params) .then(resp => ({ dateFormat, scaledDataFormat, timezone, ...resp.data })) .catch(resp => { throw resp.data; }); 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 30ba451ccc3eac..f435fb34be5bf6 100644 --- a/src/core_plugins/timelion/public/vis/timelion_request_handler.js +++ b/src/core_plugins/timelion/public/vis/timelion_request_handler.js @@ -2,7 +2,7 @@ import _ from 'lodash'; import { dashboardContextProvider } from 'plugins/kibana/dashboard/dashboard_context'; import { timezoneProvider } from 'ui/vis/lib/timezone'; -const TimelionRequestHandlerProvider = function (Private, Notifier, $http, $rootScope, timefilter) { +const TimelionRequestHandlerProvider = function (Private, Notifier, $http) { const timezone = Private(timezoneProvider)(); const dashboardContext = Private(dashboardContextProvider); @@ -12,20 +12,12 @@ const TimelionRequestHandlerProvider = function (Private, Notifier, $http, $root return { name: 'timelion', - handler: function (vis /*, appState, uiState, queryFilter*/) { + handler: function (vis, { timeRange }) { return new Promise((resolve, reject) => { const expression = vis.params.expression; if (!expression) return; - let timeFilter = timefilter.time; - if (vis.params.timeRange) { - timeFilter = { - mode: 'absolute', - from: vis.params.timeRange.min.toJSON(), - to: vis.params.timeRange.max.toJSON() - }; - } const httpResult = $http.post('../api/timelion/run', { sheet: [expression], extended: { @@ -33,7 +25,7 @@ const TimelionRequestHandlerProvider = function (Private, Notifier, $http, $root filter: dashboardContext() } }, - time: _.extend(timeFilter, { + time: _.extend(timeRange, { interval: vis.params.interval, timezone: timezone }), diff --git a/src/ui/public/agg_types/buckets/date_histogram.js b/src/ui/public/agg_types/buckets/date_histogram.js index f7b76e8ce50331..ae06c522ff0031 100644 --- a/src/ui/public/agg_types/buckets/date_histogram.js +++ b/src/ui/public/agg_types/buckets/date_histogram.js @@ -27,6 +27,7 @@ export function AggTypesBucketsDateHistogramProvider(timefilter, config, Private } function getBounds(vis) { + // TODO: How do we get access to the request handlers timeRange here? if (!vis.getTimeRange) { return timefilter.getActiveBounds(); } diff --git a/src/ui/public/vis/request_handlers/courier.js b/src/ui/public/vis/request_handlers/courier.js index 159a53c8f87736..a0e619e195a5c2 100644 --- a/src/ui/public/vis/request_handlers/courier.js +++ b/src/ui/public/vis/request_handlers/courier.js @@ -5,10 +5,39 @@ import { VisRequestHandlersRegistryProvider } from 'ui/registry/vis_request_hand const CourierRequestHandlerProvider = function (Private, courier, timefilter) { const SearchSource = Private(SearchSourceProvider); + /** + * TODO: This code can be removed as soon as we got rid of inheritance in the + * searchsource and pass down every filter explicitly. + * we're only adding one range filter against the timeFieldName to ensure + * that our filter is the only one applied and override the global filters. + * this does rely on the "implementation detail" that filters are added first + * on the leaf SearchSource and subsequently on the parents. + */ + function removeSearchSourceParentTimefilter(searchSource) { + searchSource.addFilterPredicate((filter, state) => { + if (!filter.range) { + return true; + } + + const timeFieldName = searchSource.index().timeFieldName; + if (!timeFieldName) { + return true; + } + + return !(state.filters || []).find(f => f.range && f.range[timeFieldName]); + }); + + } + return { name: 'courier', - handler: function (vis, appState, uiState, queryFilter, searchSource) { + handler: function (vis, { appState, queryFilter, searchSource, timeRange }) { + + searchSource.filter(() => { + return timefilter.get(searchSource.index(), timeRange); + }); + removeSearchSourceParentTimefilter(searchSource, timeRange); if (queryFilter && vis.editorMode) { searchSource.set('filter', queryFilter.getFilters()); diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index c10e3dd924661d..feac62cb56538b 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -59,32 +59,6 @@ uiModules $scope.vis.description = $scope.savedObj.description; - if ($scope.timeRange) { - $scope.vis.getTimeRange = () => $scope.timeRange; - - const searchSource = $scope.savedObj.searchSource; - searchSource.filter(() => { - return timefilter.get(searchSource.index(), $scope.timeRange); - }); - - // we're only adding one range filter against the timeFieldName to ensure - // that our filter is the only one applied and override the global filters. - // this does rely on the "implementation detail" that filters are added first - // on the leaf SearchSource and subsequently on the parents - searchSource.addFilterPredicate((filter, state) => { - if (!filter.range) { - return true; - } - - const timeFieldName = searchSource.index().timeFieldName; - if (!timeFieldName) { - return true; - } - - return !(state.filters || []).find(f => f.range && f.range[timeFieldName]); - }); - } - $scope.editorMode = $scope.editorMode || false; $scope.vis.editorMode = $scope.editorMode; @@ -96,8 +70,23 @@ uiModules // was still waiting for its debounce, in this case we don't want to start // fetching new data and rendering. if (!$scope.vis.initialized || !$scope.savedObj || destroyed) return; + + // TODO: This should ALWAYS be passed into this component via the loader + // in the future. Unfortunately we need some refactoring in dashboard + // to make this working and correctly rerender, so for now we will either + // use the one passed in to us or look into the timefilter ourselfs (which + // will be removed in the future). + const timeRange = $scope.timeRange || timefilter.time; + + const handlerParams = { + appState: $scope.appState, + uiState: $scope.uiState, + queryFilter: queryFilter, + searchSource: $scope.savedObj.searchSource, + timeRange: timeRange, + }; // searchSource is only there for courier request handler - requestHandler($scope.vis, $scope.appState, $scope.uiState, queryFilter, $scope.savedObj.searchSource) + requestHandler($scope.vis, handlerParams) .then(requestHandlerResponse => { //No need to call the response handler when there have been no data nor has been there changes From 266148266771d1de3d18ec8d9f4ea5fdb977cea5 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Tue, 13 Mar 2018 15:58:43 +0100 Subject: [PATCH 02/12] Make Vega request handler use passed in timeRange --- src/core_plugins/vega/public/data_model/time_cache.js | 6 +++++- src/core_plugins/vega/public/vega_request_handler.js | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core_plugins/vega/public/data_model/time_cache.js b/src/core_plugins/vega/public/data_model/time_cache.js index df82b90a4bfdae..26a591cc92424d 100644 --- a/src/core_plugins/vega/public/data_model/time_cache.js +++ b/src/core_plugins/vega/public/data_model/time_cache.js @@ -58,13 +58,17 @@ export class TimeCache { return this._cachedBounds; } + setTimeRange(timeRange) { + this._timeRange = timeRange; + } + /** * Get parsed min/max values * @returns {{min: number, max: number}} * @private */ _getBounds() { - const bounds = this._timefilter.getBounds(); + const bounds = this._timefilter.calculateBounds(this._timeRange); return { min: bounds.min.valueOf(), max: bounds.max.valueOf() diff --git a/src/core_plugins/vega/public/vega_request_handler.js b/src/core_plugins/vega/public/vega_request_handler.js index 20108de5cebcd4..8c917ebf6305b0 100644 --- a/src/core_plugins/vega/public/vega_request_handler.js +++ b/src/core_plugins/vega/public/vega_request_handler.js @@ -13,7 +13,8 @@ export function VegaRequestHandlerProvider(Private, es, timefilter, serviceSetti name: 'vega', - handler(vis) { + handler(vis, { timeRange }) { + timeCache.setTimeRange(timeRange); const vp = new VegaParser(vis.params.spec, searchCache, timeCache, dashboardContext, serviceSettings); return vp.parseAsync(); } From e59c43e6aaf88da9d7e83518a19e438570852d83 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Tue, 13 Mar 2018 16:32:42 +0100 Subject: [PATCH 03/12] Remove unneeded private variable --- .../public/visualize/embeddable/visualize_embeddable_factory.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.js b/src/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.js index 3c7901675a7f2f..003092fb21d11c 100644 --- a/src/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.js +++ b/src/core_plugins/kibana/public/visualize/embeddable/visualize_embeddable_factory.js @@ -17,7 +17,6 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory { this.savedVisualizations = savedVisualizations; this.name = 'visualization'; this.Promise = Promise; - this.timefilter = timefilter; this.brushEvent = utilsBrushEventProvider(timefilter); this.filterBarClickHandler = filterBarClickHandlerProvider(Private); } From 105c1cd9051775c4e554c9b9716b8368a07aa04d Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Tue, 13 Mar 2018 16:44:16 +0100 Subject: [PATCH 04/12] Use timeRange for courier caching check --- src/ui/public/vis/request_handlers/courier.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui/public/vis/request_handlers/courier.js b/src/ui/public/vis/request_handlers/courier.js index a0e619e195a5c2..b9f07698e13eec 100644 --- a/src/ui/public/vis/request_handlers/courier.js +++ b/src/ui/public/vis/request_handlers/courier.js @@ -60,7 +60,7 @@ const CourierRequestHandlerProvider = function (Private, courier, timefilter) { if (!_.isEqual(_.cloneDeep(searchSource.get('filter')), searchSource.lastQuery.filter)) return true; if (!_.isEqual(_.cloneDeep(searchSource.get('query')), searchSource.lastQuery.query)) return true; if (!_.isEqual(_.cloneDeep(copyAggs(vis.aggs)), searchSource.lastQuery.aggs)) return true; - if (!_.isEqual(_.cloneDeep(timefilter.time), searchSource.lastQuery.time)) return true; + if (!_.isEqual(_.cloneDeep(timeRange), searchSource.lastQuery.timeRange)) return true; return false; }; @@ -73,7 +73,7 @@ const CourierRequestHandlerProvider = function (Private, courier, timefilter) { filter: _.cloneDeep(searchSource.get('filter')), query: _.cloneDeep(searchSource.get('query')), aggs: _.cloneDeep(copyAggs(vis.aggs)), - time: _.cloneDeep(timefilter.time) + timeRange: _.cloneDeep(timeRange) }; searchSource.rawResponse = resp; From 877a7e3a038060303342a4b15860439fdd000e3a Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Tue, 13 Mar 2018 21:12:19 +0100 Subject: [PATCH 05/12] Fix developer documentation --- .../development-create-visualization.asciidoc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/development/visualize/development-create-visualization.asciidoc b/docs/development/visualize/development-create-visualization.asciidoc index f607262baf32aa..923d004d68ffb8 100644 --- a/docs/development/visualize/development-create-visualization.asciidoc +++ b/docs/development/visualize/development-create-visualization.asciidoc @@ -294,8 +294,12 @@ Using 'none' as your request handles means your visualization does not require a [[development-custom-request-handler]] ==== custom request handler -You can define your custom request handler by providing a function with the following definition: -`function (vis, appState, uiState, searchSource) { ... }` +You can define your custom request handler by providing a function with the following signature: +`function (vis, { uiState, appState, timeRange }) { ... }` + +The `timeRange` will be an object with a `from` and `to` key, that can contain +datemath expressions, like `now-7d`. You can use the `datemath` library to parse +them. This function must return a promise, which should get resolved with new data that will be passed to responseHandler. @@ -306,7 +310,7 @@ It's up to function to decide when it wants to issue a new request or return pre ----------- import { VisFactoryProvider } from 'ui/vis/vis_factory'; -const myRequestHandler = async (vis, appState, uiState, searchSource) => { +const myRequestHandler = async (vis, { appState, uiState, timeRange }) => { const data = ... parse ... return data; }; From 78289cd26a049542f6d86979f3207eef3b5c4c1d Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Wed, 14 Mar 2018 10:16:27 +0100 Subject: [PATCH 06/12] Fix date_histogram --- src/ui/public/agg_types/buckets/date_histogram.js | 8 ++------ src/ui/public/visualize/visualize.js | 2 ++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ui/public/agg_types/buckets/date_histogram.js b/src/ui/public/agg_types/buckets/date_histogram.js index ae06c522ff0031..5c8e16905ff482 100644 --- a/src/ui/public/agg_types/buckets/date_histogram.js +++ b/src/ui/public/agg_types/buckets/date_histogram.js @@ -27,13 +27,9 @@ export function AggTypesBucketsDateHistogramProvider(timefilter, config, Private } function getBounds(vis) { - // TODO: How do we get access to the request handlers timeRange here? - if (!vis.getTimeRange) { - return timefilter.getActiveBounds(); + if (timefilter.isTimeRangeSelectorEnabled) { + return timefilter.calculateBounds(vis.filters.timeRange); } - - const timeRange = vis.getTimeRange(); - return timefilter.calculateBounds(timeRange); } function setBounds(agg, force) { diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index feac62cb56538b..bfe5b87aec45a6 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -78,6 +78,8 @@ uiModules // will be removed in the future). const timeRange = $scope.timeRange || timefilter.time; + $scope.vis.filters.timeRange = timeRange; + const handlerParams = { appState: $scope.appState, uiState: $scope.uiState, From 7a579b9ff84c21f6c6caa1005c0036e4c3cc137f Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Thu, 15 Mar 2018 22:43:03 +0100 Subject: [PATCH 07/12] Fix issue --- src/ui/public/visualize/visualize.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index bfe5b87aec45a6..c12a55b4ba7ccd 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -78,7 +78,7 @@ uiModules // will be removed in the future). const timeRange = $scope.timeRange || timefilter.time; - $scope.vis.filters.timeRange = timeRange; + $scope.vis.filters = { timeRange }; const handlerParams = { appState: $scope.appState, From edd54820ab191e12c982f4de11d26e0bfd9b3a26 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Fri, 16 Mar 2018 12:49:30 +0100 Subject: [PATCH 08/12] Fix broken tests --- .../__tests__/buckets/date_histogram/_params.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ui/public/agg_types/__tests__/buckets/date_histogram/_params.js b/src/ui/public/agg_types/__tests__/buckets/date_histogram/_params.js index 59500dec171666..189bda8591f0f8 100644 --- a/src/ui/public/agg_types/__tests__/buckets/date_histogram/_params.js +++ b/src/ui/public/agg_types/__tests__/buckets/date_histogram/_params.js @@ -36,10 +36,12 @@ describe('params', function () { setTimeBounds = function (n, units) { timefilter.enableAutoRefreshSelector(); timefilter.enableTimeRangeSelector(); - timefilter.getBounds = _.constant({ - min: now.clone().subtract(n, units), - max: now.clone() - }); + paramWriter.vis.filters = { + timeRange: { + from: now.clone().subtract(n, units), + to: now.clone() + } + }; }; })); From 28291a054055cdea48018fd7ebbdc2ec9b568f50 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Mon, 19 Mar 2018 14:58:58 +0100 Subject: [PATCH 09/12] Fix issue in discover visualization --- .../kibana/public/discover/controllers/discover.js | 4 ++++ src/ui/public/agg_types/buckets/date_histogram.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core_plugins/kibana/public/discover/controllers/discover.js b/src/core_plugins/kibana/public/discover/controllers/discover.js index 54788bf7b9053e..7b308d6ddfab5b 100644 --- a/src/core_plugins/kibana/public/discover/controllers/discover.js +++ b/src/core_plugins/kibana/public/discover/controllers/discover.js @@ -699,6 +699,10 @@ function discoverController( return $scope.vis.getAggConfig().toDsl(); }); } + + $scope.vis.filters = { + timeRange: timefilter.time + }; } function resolveIndexPatternLoading() { diff --git a/src/ui/public/agg_types/buckets/date_histogram.js b/src/ui/public/agg_types/buckets/date_histogram.js index 5c8e16905ff482..b27a6ac3df98d1 100644 --- a/src/ui/public/agg_types/buckets/date_histogram.js +++ b/src/ui/public/agg_types/buckets/date_histogram.js @@ -27,7 +27,7 @@ export function AggTypesBucketsDateHistogramProvider(timefilter, config, Private } function getBounds(vis) { - if (timefilter.isTimeRangeSelectorEnabled) { + if (timefilter.isTimeRangeSelectorEnabled && vis.filters) { return timefilter.calculateBounds(vis.filters.timeRange); } } From ba9a882d7e81ccd35bace8a4fa4977e13c0266ef Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Mon, 19 Mar 2018 15:04:07 +0100 Subject: [PATCH 10/12] Fix vega tests --- src/core_plugins/vega/public/data_model/__tests__/time_cache.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core_plugins/vega/public/data_model/__tests__/time_cache.js b/src/core_plugins/vega/public/data_model/__tests__/time_cache.js index 6684a12c075cd1..475251a09f82a2 100644 --- a/src/core_plugins/vega/public/data_model/__tests__/time_cache.js +++ b/src/core_plugins/vega/public/data_model/__tests__/time_cache.js @@ -17,7 +17,7 @@ describe(`TimeCache`, () => { this._max = max; } - getBounds() { + calculateBounds() { this._accessCount++; return { min: { valueOf: () => this._min }, From 0e3b5f197a0ea421f5c6fbaa51b996591ff90ec0 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Tue, 20 Mar 2018 11:21:28 +0100 Subject: [PATCH 11/12] Fix issue with saved search visualizations --- src/ui/public/vis/request_handlers/courier.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ui/public/vis/request_handlers/courier.js b/src/ui/public/vis/request_handlers/courier.js index b9f07698e13eec..c4868a58d9232f 100644 --- a/src/ui/public/vis/request_handlers/courier.js +++ b/src/ui/public/vis/request_handlers/courier.js @@ -19,11 +19,18 @@ const CourierRequestHandlerProvider = function (Private, courier, timefilter) { return true; } - const timeFieldName = searchSource.index().timeFieldName; + const index = searchSource.index() || searchSource.getParent().index(); + const timeFieldName = index.timeFieldName; if (!timeFieldName) { return true; } + // Only check if we need to filter out this filter if it's actual a range filter + // on our time field and not any other field. + if (!filter.range[timeFieldName]) { + return true; + } + return !(state.filters || []).find(f => f.range && f.range[timeFieldName]); }); From 5b65c91d65da132e366ee1176e47cc1b157d0363 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Wed, 21 Mar 2018 11:27:06 +0100 Subject: [PATCH 12/12] Update timeRange correctly in editor --- src/core_plugins/kibana/public/visualize/editor/editor.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.js b/src/core_plugins/kibana/public/visualize/editor/editor.js index 950e6e4245d504..d313be348fc49e 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/core_plugins/kibana/public/visualize/editor/editor.js @@ -217,6 +217,12 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie } }); + const updateTimeRange = () => { + $scope.timeRange = timefilter.time; + }; + + timefilter.on('update', updateTimeRange); + // update the searchSource when filters update $scope.$listen(queryFilter, 'update', function () { $state.save(); @@ -231,6 +237,7 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie $scope.$on('$destroy', function () { savedVis.destroy(); stateMonitor.destroy(); + timefilter.off('update', updateTimeRange); }); }