Skip to content

Commit 574f5ca

Browse files
authored
fixing refresh and auto refresh (#12752)
* 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
1 parent ef492a7 commit 574f5ca

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/core_plugins/kibana/public/visualize/editor/editor.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie
105105
}, {
106106
key: 'refresh',
107107
description: 'Refresh',
108-
run: function () { $scope.fetch(); },
108+
run: function () {
109+
vis.forceReload();
110+
},
109111
testId: 'visualizeRefreshButton',
110112
}];
111113

@@ -202,7 +204,7 @@ function VisEditor($scope, $route, timefilter, AppState, $window, kbnUrl, courie
202204

203205
// update the searchSource when query updates
204206
$scope.fetch = function () {
205-
$state.save();
207+
$scope.vis.forceReload();
206208
};
207209

208210
$scope.$on('ready:vis', function () {

src/ui/public/vis/request_handlers/courier.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const CourierRequestHandlerProvider = function (Private, courier, timefilter) {
1010
}
1111

1212
const shouldQuery = () => {
13-
if (!searchSource.lastQuery) return true;
13+
if (!searchSource.lastQuery || vis.reload) return true;
1414
if (!_.isEqual(_.cloneDeep(searchSource.get('filter')), searchSource.lastQuery.filter)) return true;
1515
if (!_.isEqual(_.cloneDeep(searchSource.get('query')), searchSource.lastQuery.query)) return true;
1616
if (!_.isEqual(_.cloneDeep(searchSource.get('aggs')()), searchSource.lastQuery.aggs)) return true;
@@ -21,6 +21,7 @@ const CourierRequestHandlerProvider = function (Private, courier, timefilter) {
2121

2222
return new Promise((resolve, reject) => {
2323
if (shouldQuery()) {
24+
delete vis.reload;
2425
searchSource.onResults().then(resp => {
2526
searchSource.lastQuery = {
2627
filter: _.cloneDeep(searchSource.get('filter')),

src/ui/public/vis/vis.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ export function VisProvider(Private, indexPatterns, timefilter, getAppState) {
9898
this.setCurrentState(this._state);
9999
}
100100

101+
forceReload() {
102+
this.emit('reload');
103+
}
104+
101105
getCurrentState(includeDisabled) {
102106
return {
103107
title: this.title,

src/ui/public/visualize/visualize.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515

1616
uiModules
1717
.get('kibana/directive', ['ngSanitize'])
18-
.directive('visualize', function (Notifier, Private, timefilter, getAppState, $timeout) {
18+
.directive('visualize', function (Notifier, Private, timefilter, getAppState) {
1919
const notify = new Notifier({ location: 'Visualize' });
2020
const requestHandlers = Private(VisRequestHandlersRegistryProvider);
2121
const responseHandlers = Private(VisResponseHandlersRegistryProvider);
@@ -83,6 +83,15 @@ uiModules
8383
}
8484
});
8585

86+
const reload = () => {
87+
$scope.vis.reload = true;
88+
$scope.fetch();
89+
};
90+
$scope.vis.on('reload', reload);
91+
$scope.$on('courier:searchRefresh', reload);
92+
// dashboard will trigger this event when refreshing
93+
$scope.$on('fetch', reload);
94+
8695
if ($scope.appState) {
8796
let oldUiState;
8897
const stateMonitor = stateMonitorFactory.create($scope.appState);
@@ -99,12 +108,14 @@ uiModules
99108
// current visualizations uiState changed.
100109
if (!oldUiState || oldUiState !== JSON.stringify($scope.uiState.toJSON())) {
101110
oldUiState = JSON.stringify($scope.uiState.toJSON());
102-
$timeout(() => {
103-
$scope.$broadcast('render');
104-
});
111+
$scope.fetch();
105112
}
106113
}
107114
});
115+
116+
$scope.$on('$destroy', () => {
117+
stateMonitor.destroy();
118+
});
108119
}
109120

110121
let resizeInit = false;

0 commit comments

Comments
 (0)