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

Navlink url tracker: Reset navlink on failed redirect #61460

Merged
merged 5 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ export function setServices(newServices: any) {
services = newServices;
}

export const [getUrlTracker, setUrlTracker] = createGetterSetter<{
setTrackedUrl: (url: string) => void;
}>('urlTracker');

// EXPORT legacy static dependencies, should be migrated when available in a new version;
export { angular };
export { wrapInI18nContext } from 'ui/i18n';
import { search } from '../../../../../plugins/data/public';
import { createGetterSetter } from '../../../../../plugins/kibana_utils/common';
export const { getRequestInspectorStats, getResponseInspectorStats, tabifyAggResponse } = search;
export {
unhashUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
getRequestInspectorStats,
getResponseInspectorStats,
getServices,
getUrlTracker,
unhashUrl,
subscribeWithScope,
tabifyAggResponse,
Expand Down Expand Up @@ -160,6 +161,9 @@ app.config($routeProvider => {
'/management/kibana/objects/savedSearches/' + $route.current.params.id,
},
toastNotifications,
onRedirect() {
getUrlTracker().setTrackedUrl('/discover');
},
})
),
});
Expand Down
10 changes: 8 additions & 2 deletions src/legacy/core_plugins/kibana/public/discover/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { registerFeature } from './np_ready/register_feature';
import './kibana_services';
import { EmbeddableStart, EmbeddableSetup } from '../../../../../plugins/embeddable/public';
import { getInnerAngularModule, getInnerAngularModuleEmbeddable } from './get_inner_angular';
import { setAngularModule, setServices } from './kibana_services';
import { setAngularModule, setServices, setUrlTracker } from './kibana_services';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public';
import { ChartsPluginStart } from '../../../../../plugins/charts/public';
import { buildServices } from './build_services';
Expand Down Expand Up @@ -92,7 +92,12 @@ export class DiscoverPlugin implements Plugin<void, void> {
public initializeServices?: () => Promise<{ core: CoreStart; plugins: DiscoverStartPlugins }>;

setup(core: CoreSetup<DiscoverStartPlugins, void>, plugins: DiscoverSetupPlugins) {
const { appMounted, appUnMounted, stop: stopUrlTracker } = createKbnUrlTracker({
const {
appMounted,
appUnMounted,
stop: stopUrlTracker,
setActiveUrl: setTrackedUrl,
} = createKbnUrlTracker({
baseUrl: core.http.basePath.prepend('/app/kibana'),
defaultSubUrl: '#/discover',
storageKey: 'lastUrl:discover',
Expand All @@ -113,6 +118,7 @@ export class DiscoverPlugin implements Plugin<void, void> {
},
],
});
setUrlTracker({ setTrackedUrl });
this.stopUrlTracking = () => {
stopUrlTracker();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ export function initVisualizeApp(app, deps) {
'/management/kibana/objects/savedVisualizations/' + $route.current.params.id,
},
toastNotifications,
onRedirect() {
deps.setActiveUrl(VisualizeConstants.LANDING_PAGE_PATH);
},
})
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function redirectWhenMissing({
history,
mapping,
toastNotifications,
onRedirect,
}: {
history: History;
/**
Expand All @@ -48,6 +49,10 @@ export function redirectWhenMissing({
* Toast notifications service to show toasts in error cases.
*/
toastNotifications: ToastsSetup;
/**
* Optional callback invoked when a redirect occurs
*/
onRedirect?: (error: SavedObjectNotFound) => void;
Dosant marked this conversation as resolved.
Show resolved Hide resolved
}) {
let localMappingObject: Mapping;

Expand Down Expand Up @@ -75,6 +80,9 @@ export function redirectWhenMissing({
text: toMountPoint(<MarkdownSimple>{error.message}</MarkdownSimple>),
});

if (onRedirect) {
onRedirect(error);
}
history.replace(url);
};
}