From d331a7ef81b03cd5f76d958eaba7a6c0bc540fdc Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Thu, 7 Sep 2017 08:52:59 -0700 Subject: [PATCH] Refetch even when the query has not changed (#13759) * Refetch even when the query has not changed * Change function name to better represent what it does * Rename all occurrences --- .../kibana/public/dashboard/dashboard.html | 2 +- .../kibana/public/dashboard/dashboard.js | 13 +++++-------- .../kibana/public/discover/controllers/discover.js | 12 ++++-------- src/core_plugins/kibana/public/discover/index.html | 2 +- .../kibana/public/visualize/editor/editor.html | 2 +- .../kibana/public/visualize/editor/editor.js | 12 ++++-------- 6 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/core_plugins/kibana/public/dashboard/dashboard.html b/src/core_plugins/kibana/public/dashboard/dashboard.html index 87d4eca2c074f..4586d851d2c33 100644 --- a/src/core_plugins/kibana/public/dashboard/dashboard.html +++ b/src/core_plugins/kibana/public/dashboard/dashboard.html @@ -39,7 +39,7 @@ diff --git a/src/core_plugins/kibana/public/dashboard/dashboard.js b/src/core_plugins/kibana/public/dashboard/dashboard.js index 8dd49bfeada97..c51c9b542623b 100644 --- a/src/core_plugins/kibana/public/dashboard/dashboard.js +++ b/src/core_plugins/kibana/public/dashboard/dashboard.js @@ -183,14 +183,15 @@ app.directive('dashboardApp', function ($injector) { } }; - $scope.updateQuery = function (query) { + $scope.updateQueryAndFetch = function (query) { // reset state if language changes if ($scope.model.query.language && $scope.model.query.language !== query.language) { filterBar.removeAll(); dashboardState.getAppState().$newFilters = []; } - - $scope.model.query = query; + $scope.model.query = migrateLegacyQuery(query); + dashboardState.applyFilters($scope.model.query, filterBar.getFilters()); + $scope.refresh(); }; // called by the saved-object-finder when a user clicks a vis @@ -227,11 +228,7 @@ app.directive('dashboardApp', function ($injector) { $scope.indexPatterns = dashboardState.getPanelIndexPatterns(); }; - $scope.$watch('model.query', (newQuery) => { - $scope.model.query = migrateLegacyQuery(newQuery); - dashboardState.applyFilters($scope.model.query, filterBar.getFilters()); - $scope.refresh(); - }); + $scope.$watch('model.query', $scope.updateQueryAndFetch); $scope.$watchCollection(() => dashboardState.getAppState().$newFilters, function (filters = []) { // need to convert filters generated from user interaction with viz into kuery AST diff --git a/src/core_plugins/kibana/public/discover/controllers/discover.js b/src/core_plugins/kibana/public/discover/controllers/discover.js index 5d6a3237e8fc0..3e72eb916c323 100644 --- a/src/core_plugins/kibana/public/discover/controllers/discover.js +++ b/src/core_plugins/kibana/public/discover/controllers/discover.js @@ -352,11 +352,7 @@ function discoverController( } }); - $scope.$watch('state.query', (newQuery) => { - $state.query = migrateLegacyQuery(newQuery); - - $scope.fetch(); - }); + $scope.$watch('state.query', $scope.updateQueryAndFetch); $scope.$watchMulti([ 'rows', @@ -460,13 +456,13 @@ function discoverController( .catch(notify.error); }; - $scope.updateQuery = function (query) { + $scope.updateQueryAndFetch = function (query) { // reset state if language changes if ($state.query.language && $state.query.language !== query.language) { $state.filters = []; } - - $state.query = query; + $state.query = migrateLegacyQuery(query); + $scope.fetch(); }; $scope.searchSource.onBeginSegmentedFetch(function (segmented) { diff --git a/src/core_plugins/kibana/public/discover/index.html b/src/core_plugins/kibana/public/discover/index.html index 01c00e9a41bcc..6594cf575e4f6 100644 --- a/src/core_plugins/kibana/public/discover/index.html +++ b/src/core_plugins/kibana/public/discover/index.html @@ -20,7 +20,7 @@

diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.html b/src/core_plugins/kibana/public/visualize/editor/editor.html index 66334f7b1a53a..3193ea41387d3 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.html +++ b/src/core_plugins/kibana/public/visualize/editor/editor.html @@ -36,7 +36,7 @@ diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.js b/src/core_plugins/kibana/public/visualize/editor/editor.js index a2aa2c64a8171..9436924445a62 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/core_plugins/kibana/public/visualize/editor/editor.js @@ -196,11 +196,7 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie .then($scope.fetch); }); - $scope.$watch('state.query', (newQuery) => { - $state.query = migrateLegacyQuery(newQuery); - - $scope.fetch(); - }); + $scope.$watch('state.query', $scope.updateQueryAndFetch); $state.replace(); @@ -236,14 +232,14 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie }); } - $scope.updateQuery = function (query) { + $scope.updateQueryAndFetch = function (query) { // reset state if language changes if ($state.query.language && $state.query.language !== query.language) { $state.filters = []; $state.$newFilters = []; } - - $state.query = query; + $state.query = migrateLegacyQuery(query); + $scope.fetch(); }; /**