From 55ca88be2760b197d4422858a87071b22347c0a5 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Tue, 11 Jul 2017 10:10:32 +0200 Subject: [PATCH 1/5] fixing refresh and auto refresh --- src/core_plugins/kibana/public/visualize/editor/editor.js | 4 +++- src/ui/public/vis/request_handlers/courier.js | 3 ++- src/ui/public/visualize/visualize.js | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.js b/src/core_plugins/kibana/public/visualize/editor/editor.js index 2680916e5f911..6012686a45fec 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/core_plugins/kibana/public/visualize/editor/editor.js @@ -105,7 +105,9 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie }, { key: 'refresh', description: 'Refresh', - run: function () { $scope.fetch(); }, + run: function () { + vis.emit('reload'); + }, testId: 'visualizeRefreshButton', }]; diff --git a/src/ui/public/vis/request_handlers/courier.js b/src/ui/public/vis/request_handlers/courier.js index 17ceb6c2524d7..3b841a1e2c59a 100644 --- a/src/ui/public/vis/request_handlers/courier.js +++ b/src/ui/public/vis/request_handlers/courier.js @@ -10,7 +10,7 @@ const CourierRequestHandlerProvider = function (Private, courier, timefilter) { } const shouldQuery = () => { - if (!searchSource.lastQuery) return true; + if (!searchSource.lastQuery || vis.reload) return true; 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(searchSource.get('aggs')()), searchSource.lastQuery.aggs)) return true; @@ -21,6 +21,7 @@ const CourierRequestHandlerProvider = function (Private, courier, timefilter) { return new Promise((resolve, reject) => { if (shouldQuery()) { + delete vis.reload; searchSource.onResults().then(resp => { searchSource.lastQuery = { filter: _.cloneDeep(searchSource.get('filter')), diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index 9477d49bb268c..405065e966f78 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -83,6 +83,13 @@ uiModules } }); + const reload = () => { + $scope.vis.reload = true; + $scope.fetch(); + }; + $scope.vis.on('reload', reload); + $scope.$on('courier:searchRefresh', reload); + if ($scope.appState) { let oldUiState; const stateMonitor = stateMonitorFactory.create($scope.appState); From deaf3ed20128f9789753871a191c55dc29b77312 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 12 Jul 2017 10:45:03 +0200 Subject: [PATCH 2/5] cleaning up state monitor --- src/ui/public/visualize/visualize.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index 405065e966f78..a427369905687 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -112,6 +112,10 @@ uiModules } } }); + + $scope.$on('$destroy', () => { + stateMonitor.destroy(); + }); } let resizeInit = false; From 9a08034cca0afe5de5b3ac6e0318b28ad1ae5f01 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 12 Jul 2017 10:54:48 +0200 Subject: [PATCH 3/5] uiState should trigger normal reload path --- src/core_plugins/kibana/public/visualize/editor/editor.js | 2 +- src/ui/public/vis/vis.js | 4 ++++ src/ui/public/visualize/visualize.js | 6 ++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.js b/src/core_plugins/kibana/public/visualize/editor/editor.js index 6012686a45fec..89ebfb8197534 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/core_plugins/kibana/public/visualize/editor/editor.js @@ -106,7 +106,7 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie key: 'refresh', description: 'Refresh', run: function () { - vis.emit('reload'); + vis.forceReload(); }, testId: 'visualizeRefreshButton', }]; diff --git a/src/ui/public/vis/vis.js b/src/ui/public/vis/vis.js index f6d8da57e953a..d8b951838743a 100644 --- a/src/ui/public/vis/vis.js +++ b/src/ui/public/vis/vis.js @@ -98,6 +98,10 @@ export function VisProvider(Private, indexPatterns, timefilter, getAppState) { this.setCurrentState(this._state); } + forceReload() { + this.emit('reload'); + } + getCurrentState(includeDisabled) { return { title: this.title, diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index a427369905687..3b2ac0df9bd7d 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -15,7 +15,7 @@ import { uiModules .get('kibana/directive', ['ngSanitize']) -.directive('visualize', function (Notifier, Private, timefilter, getAppState, $timeout) { +.directive('visualize', function (Notifier, Private, timefilter, getAppState) { const notify = new Notifier({ location: 'Visualize' }); const requestHandlers = Private(VisRequestHandlersRegistryProvider); const responseHandlers = Private(VisResponseHandlersRegistryProvider); @@ -106,9 +106,7 @@ uiModules // current visualizations uiState changed. if (!oldUiState || oldUiState !== JSON.stringify($scope.uiState.toJSON())) { oldUiState = JSON.stringify($scope.uiState.toJSON()); - $timeout(() => { - $scope.$broadcast('render'); - }); + $scope.fetch(); } } }); From 76e7633dc3099f4a838bdaefc4e070cc3b9ed491 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 12 Jul 2017 16:17:56 +0200 Subject: [PATCH 4/5] query bar search should force refresh --- src/core_plugins/kibana/public/visualize/editor/editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.js b/src/core_plugins/kibana/public/visualize/editor/editor.js index 89ebfb8197534..407c4719ecaa0 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/core_plugins/kibana/public/visualize/editor/editor.js @@ -204,7 +204,7 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie // update the searchSource when query updates $scope.fetch = function () { - $state.save(); + $scope.vis.forceReload(); }; $scope.$on('ready:vis', function () { From 05e6cafd65d58b0447ecfe413c0178e1e08ad2b1 Mon Sep 17 00:00:00 2001 From: ppisljar Date: Wed, 12 Jul 2017 17:08:06 +0200 Subject: [PATCH 5/5] reload on global fetch event --- src/ui/public/visualize/visualize.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/public/visualize/visualize.js b/src/ui/public/visualize/visualize.js index 3b2ac0df9bd7d..bd8f154cc6fb4 100644 --- a/src/ui/public/visualize/visualize.js +++ b/src/ui/public/visualize/visualize.js @@ -89,6 +89,8 @@ uiModules }; $scope.vis.on('reload', reload); $scope.$on('courier:searchRefresh', reload); + // dashboard will trigger this event when refreshing + $scope.$on('fetch', reload); if ($scope.appState) { let oldUiState;