diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx b/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx index 6c10cb1cdd5cf..d207cbb71ac4c 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/dashboard_app_controller.tsx @@ -431,7 +431,7 @@ export class DashboardAppController { }; $scope.onSavedQueryUpdated = savedQuery => { - $scope.savedQuery = savedQuery; + $scope.savedQuery = { ...savedQuery }; }; $scope.onClearSavedQuery = () => { diff --git a/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js b/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js index 0c7d919c91d18..c3aadfd614607 100644 --- a/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js +++ b/src/legacy/core_plugins/kibana/public/discover/controllers/discover.js @@ -923,7 +923,7 @@ function discoverController( }; $scope.onSavedQueryUpdated = savedQuery => { - $scope.savedQuery = savedQuery; + $scope.savedQuery = { ...savedQuery }; }; $scope.onClearSavedQuery = () => { diff --git a/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js b/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js index 0921659d9a568..4dac5e26d3a4b 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/legacy/core_plugins/kibana/public/visualize/editor/editor.js @@ -476,7 +476,7 @@ function VisEditor( }; $scope.onSavedQueryUpdated = savedQuery => { - $scope.savedQuery = savedQuery; + $scope.savedQuery = { ...savedQuery }; }; $scope.onClearSavedQuery = () => { diff --git a/test/functional/apps/discover/_saved_queries.js b/test/functional/apps/discover/_saved_queries.js index b744f7d9e224b..68a1e999b7ba8 100644 --- a/test/functional/apps/discover/_saved_queries.js +++ b/test/functional/apps/discover/_saved_queries.js @@ -123,6 +123,13 @@ export default function ({ getService, getPageObjects }) { await savedQueryManagementComponent.clearCurrentlyLoadedQuery(); expect(await queryBar.getQueryString()).to.eql(''); }); + + it('resets any changes to a loaded query on reloading the same saved query', async () => { + await savedQueryManagementComponent.loadSavedQuery('OkResponse'); + await queryBar.setQuery('response:503'); + await savedQueryManagementComponent.loadSavedQuery('OkResponse'); + expect(await queryBar.getQueryString()).to.eql('response:404'); + }); }); }); }