From cb1aeaf3e6f494e16b1d5b79f66bae14c16178b4 Mon Sep 17 00:00:00 2001 From: Brandon Kobel Date: Fri, 14 Apr 2017 12:40:02 -0400 Subject: [PATCH] Discover and visualization set appStatus.dirty before saving new (#11156) Sharing relies upon appStatus.dirty to determine whether changes have been made that must be saved. This wasn't being set correctly in Discover and Visualize when the user first creates a new object and hasn't saved it yet. --- .../kibana/public/discover/controllers/discover.js | 6 ++++-- src/core_plugins/kibana/public/visualize/editor/editor.js | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core_plugins/kibana/public/discover/controllers/discover.js b/src/core_plugins/kibana/public/discover/controllers/discover.js index 9405b3fe32f78..3ff8eb12630da 100644 --- a/src/core_plugins/kibana/public/discover/controllers/discover.js +++ b/src/core_plugins/kibana/public/discover/controllers/discover.js @@ -150,7 +150,9 @@ function discoverController($scope, config, courier, $route, $window, Notifier, } let stateMonitor; - const $appStatus = $scope.appStatus = this.appStatus = {}; + const $appStatus = $scope.appStatus = this.appStatus = { + dirty: !savedSearch.id + }; const $state = $scope.state = new AppState(getStateDefaults()); $scope.uiState = $state.makeStateful('uiState'); @@ -195,7 +197,7 @@ function discoverController($scope, config, courier, $route, $window, Notifier, stateMonitor = stateMonitorFactory.create($state, getStateDefaults()); stateMonitor.onChange((status) => { - $appStatus.dirty = status.dirty; + $appStatus.dirty = status.dirty || !savedSearch.id; }); $scope.$on('$destroy', () => stateMonitor.destroy()); diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.js b/src/core_plugins/kibana/public/visualize/editor/editor.js index 8a5d762dd4b98..8f4771b559b4d 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/core_plugins/kibana/public/visualize/editor/editor.js @@ -77,11 +77,14 @@ function VisEditor($rootScope, $scope, $route, timefilter, AppState, $window, kb }); let stateMonitor; - const $appStatus = this.appStatus = {}; // Retrieve the resolved SavedVis instance. const savedVis = $route.current.locals.savedVis; + const $appStatus = this.appStatus = { + dirty: !savedVis.id + }; + // Instance of src/ui/public/vis/vis.js. const vis = savedVis.vis; @@ -186,7 +189,7 @@ function VisEditor($rootScope, $scope, $route, timefilter, AppState, $window, kb stateMonitor = stateMonitorFactory.create($state, stateDefaults); stateMonitor.ignoreProps([ 'vis.listeners' ]).onChange((status) => { - $appStatus.dirty = status.dirty; + $appStatus.dirty = status.dirty || !savedVis.id; }); $scope.$on('$destroy', () => stateMonitor.destroy());