diff --git a/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.js
index 6bac4e4c62efa..cae1e40cd445a 100644
--- a/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.js
+++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/listing/visualize_listing.js
@@ -32,7 +32,7 @@ export function initListingDirective(app) {
);
}
-export function VisualizeListingController($injector, createNewVis) {
+export function VisualizeListingController($injector, $scope, createNewVis) {
const {
addBasePath,
chrome,
@@ -59,7 +59,7 @@ export function VisualizeListingController($injector, createNewVis) {
this.savedObjects = savedObjects;
this.createNewVis = () => {
- visualizations.showNewVisModal();
+ this.closeNewVisModal = visualizations.showNewVisModal();
};
this.editItem = ({ editUrl }) => {
@@ -73,7 +73,7 @@ export function VisualizeListingController($injector, createNewVis) {
if (createNewVis) {
// In case the user navigated to the page via the /visualize/new URL we start the dialog immediately
- visualizations.showNewVisModal({
+ this.closeNewVisModal = visualizations.showNewVisModal({
onClose: () => {
// In case the user came via a URL to this page, change the URL to the regular landing page URL after closing the modal
kbnUrl.changePath(VisualizeConstants.LANDING_PAGE_PATH);
@@ -124,4 +124,10 @@ export function VisualizeListingController($injector, createNewVis) {
this.listingLimit = uiSettings.get('savedObjects:listingLimit');
addHelpMenuToAppChrome(chrome, docLinks);
+
+ $scope.$on('$destroy', () => {
+ if (this.closeNewVisModal) {
+ this.closeNewVisModal();
+ }
+ });
}
diff --git a/src/legacy/core_plugins/visualizations/public/np_ready/public/wizard/new_vis_modal.test.tsx b/src/legacy/core_plugins/visualizations/public/np_ready/public/wizard/new_vis_modal.test.tsx
index 0701b5042a4bd..58f7bc49d1cdb 100644
--- a/src/legacy/core_plugins/visualizations/public/np_ready/public/wizard/new_vis_modal.test.tsx
+++ b/src/legacy/core_plugins/visualizations/public/np_ready/public/wizard/new_vis_modal.test.tsx
@@ -155,6 +155,26 @@ describe('NewVisModal', () => {
expect(window.location.assign).toBeCalledWith('testbasepath/aliasUrl?addToDashboard');
expect(onClose).toHaveBeenCalled();
});
+
+ it('closes and redirects properly if visualization with aliasUrl and without addToDashboard in editorParams', () => {
+ const onClose = jest.fn();
+ window.location.assign = jest.fn();
+ const wrapper = mountWithIntl(
+
+ );
+ const visButton = wrapper.find('button[data-test-subj="visType-visWithAliasUrl"]');
+ visButton.simulate('click');
+ expect(window.location.assign).toBeCalledWith('testbasepath/aliasUrl');
+ expect(onClose).toHaveBeenCalled();
+ });
});
describe('filter for visualization types', () => {
diff --git a/src/legacy/core_plugins/visualizations/public/np_ready/public/wizard/new_vis_modal.tsx b/src/legacy/core_plugins/visualizations/public/np_ready/public/wizard/new_vis_modal.tsx
index fe66d2e56c611..b39e8e8926707 100644
--- a/src/legacy/core_plugins/visualizations/public/np_ready/public/wizard/new_vis_modal.tsx
+++ b/src/legacy/core_plugins/visualizations/public/np_ready/public/wizard/new_vis_modal.tsx
@@ -145,8 +145,8 @@ class NewVisModal extends React.Component {
+ if (isClosed) return;
ReactDOM.unmountComponentAtNode(container);
document.body.removeChild(container);
if (onClose) {
onClose();
}
+ isClosed = true;
};
document.body.appendChild(container);
@@ -55,4 +58,6 @@ export function showNewVisModal({ editorParams = [], onClose }: ShowNewVisModalP
);
ReactDOM.render(element, container);
+
+ return () => handleClose();
}