Skip to content

Commit

Permalink
fixing refresh and auto refresh (elastic#12752)
Browse files Browse the repository at this point in the history
* fixing refresh and auto refresh

* cleaning up state monitor

* uiState should trigger normal reload path

* query bar search should force refresh

* reload on global fetch event
  • Loading branch information
ppisljar authored Jul 12, 2017
1 parent ef492a7 commit 574f5ca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/core_plugins/kibana/public/visualize/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie
}, {
key: 'refresh',
description: 'Refresh',
run: function () { $scope.fetch(); },
run: function () {
vis.forceReload();
},
testId: 'visualizeRefreshButton',
}];

Expand Down Expand Up @@ -202,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 () {
Expand Down
3 changes: 2 additions & 1 deletion src/ui/public/vis/request_handlers/courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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')),
Expand Down
4 changes: 4 additions & 0 deletions src/ui/public/vis/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 15 additions & 4 deletions src/ui/public/visualize/visualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -83,6 +83,15 @@ uiModules
}
});

const reload = () => {
$scope.vis.reload = true;
$scope.fetch();
};
$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;
const stateMonitor = stateMonitorFactory.create($scope.appState);
Expand All @@ -99,12 +108,14 @@ 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();
}
}
});

$scope.$on('$destroy', () => {
stateMonitor.destroy();
});
}

let resizeInit = false;
Expand Down

0 comments on commit 574f5ca

Please sign in to comment.