Skip to content

Commit

Permalink
Navlink url tracker: Reset navlink on failed redirect (elastic#61460)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Mar 27, 2020
1 parent bbe940f commit b2deed4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
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,
onBeforeRedirect() {
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>, 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,
onBeforeRedirect() {
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,
onBeforeRedirect,
}: {
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 directly before a redirect is triggered
*/
onBeforeRedirect?: (error: SavedObjectNotFound) => void;
}) {
let localMappingObject: Mapping;

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

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

0 comments on commit b2deed4

Please sign in to comment.