Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NP] Get rid of usage redirectWhenMissing service #59777

Merged
merged 18 commits into from
Mar 17, 2020
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move invalid vistype check into editor.js
sulemanof committed Mar 12, 2020
commit 2f8afe6c28c0f5ff294ead3ba7af7c25cd9607e1
Original file line number Diff line number Diff line change
@@ -30,8 +30,9 @@ import { VisualizeConstants } from '../visualize_constants';
import { getEditBreadcrumbs } from '../breadcrumbs';

import { addHelpMenuToAppChrome } from '../help_menu/help_menu_util';
import { unhashUrl, redirectWhenMissing } from '../../../../../../../plugins/kibana_utils/public';
import { unhashUrl } from '../../../../../../../plugins/kibana_utils/public';
import { kbnBaseUrl } from '../../../../../../../plugins/kibana_legacy/public';
import { MarkdownSimple, toMountPoint } from '../../../../../../../plugins/kibana_react/public';
import {
SavedObjectSaveModal,
showSaveModal,
@@ -312,22 +313,29 @@ function VisualizeAppController(
}
);

const stopAllSyncing = () => {
stopStateSync();
stopSyncingQueryServiceStateWithUrl();
stopSyncingAppFilters();
};

// The savedVis is pulled from elasticsearch, but the appState is pulled from the url, with the
// defaults applied. If the url was from a previous session which included modifications to the
// appState then they won't be equal.
if (!_.isEqual(stateContainer.getState().vis, stateDefaults.vis)) {
try {
vis.setState(stateContainer.getState().vis);
} catch (error) {
const redirect = redirectWhenMissing({
history,
mapping: {
'index-pattern-field': '/visualize',
},
toastNotifications,
stopAllSyncing();
kertal marked this conversation as resolved.
Show resolved Hide resolved

toastNotifications.addWarning({
title: i18n.translate('kbn.visualize.visualizationTypeInvalidNotificationMessage', {
defaultMessage: 'Invalid visualization type',
}),
text: toMountPoint(<MarkdownSimple>{error.message}</MarkdownSimple>),
});

redirect(error);
history.replace('/notFound=visualization');
}
}

@@ -503,9 +511,8 @@ function VisualizeAppController(

unsubscribePersisted();
unsubscribeStateUpdates();
stopStateSync();
stopSyncingQueryServiceStateWithUrl();
stopSyncingAppFilters();

stopAllSyncing();
});

$timeout(() => {
Original file line number Diff line number Diff line change
@@ -63,11 +63,6 @@ export function redirectWhenMissing({
throw error;
}

const unknownVisType = error.message.indexOf('Invalid type') === 0;
if (unknownVisType) {
error.savedObjectType = 'visualization';
}

let url = localMappingObject[error.savedObjectType] || localMappingObject['*'] || '/';
url += (url.indexOf('?') >= 0 ? '&' : '?') + `notFound=${error.savedObjectType}`;