[Lens] fix redirect after reload (#66328)
Changed the way the lens app tracks originatingApp. It is now removed from the url when the app starts and is tracked as part of the state
This commit is contained in:
parent
02a2d075af
commit
28623ad33a
|
@ -104,7 +104,12 @@ describe('Lens App', () => {
|
|||
storage: Storage;
|
||||
docId?: string;
|
||||
docStorage: SavedObjectStore;
|
||||
redirectTo: (id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => void;
|
||||
redirectTo: (
|
||||
id?: string,
|
||||
returnToOrigin?: boolean,
|
||||
originatingApp?: string | undefined,
|
||||
newlyCreated?: boolean
|
||||
) => void;
|
||||
originatingApp: string | undefined;
|
||||
}> {
|
||||
return ({
|
||||
|
@ -140,7 +145,14 @@ describe('Lens App', () => {
|
|||
load: jest.fn(),
|
||||
save: jest.fn(),
|
||||
},
|
||||
redirectTo: jest.fn((id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => {}),
|
||||
redirectTo: jest.fn(
|
||||
(
|
||||
id?: string,
|
||||
returnToOrigin?: boolean,
|
||||
originatingApp?: string | undefined,
|
||||
newlyCreated?: boolean
|
||||
) => {}
|
||||
),
|
||||
} as unknown) as jest.Mocked<{
|
||||
navigation: typeof navigationStartMock;
|
||||
editorFrame: EditorFrameInstance;
|
||||
|
@ -149,7 +161,12 @@ describe('Lens App', () => {
|
|||
storage: Storage;
|
||||
docId?: string;
|
||||
docStorage: SavedObjectStore;
|
||||
redirectTo: (id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => void;
|
||||
redirectTo: (
|
||||
id?: string,
|
||||
returnToOrigin?: boolean,
|
||||
originatingApp?: string | undefined,
|
||||
newlyCreated?: boolean
|
||||
) => void;
|
||||
originatingApp: string | undefined;
|
||||
}>;
|
||||
}
|
||||
|
@ -348,7 +365,12 @@ describe('Lens App', () => {
|
|||
storage: Storage;
|
||||
docId?: string;
|
||||
docStorage: SavedObjectStore;
|
||||
redirectTo: (id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => void;
|
||||
redirectTo: (
|
||||
id?: string,
|
||||
returnToOrigin?: boolean,
|
||||
originatingApp?: string | undefined,
|
||||
newlyCreated?: boolean
|
||||
) => void;
|
||||
originatingApp: string | undefined;
|
||||
}>;
|
||||
|
||||
|
@ -521,7 +543,7 @@ describe('Lens App', () => {
|
|||
expression: 'kibana 3',
|
||||
});
|
||||
|
||||
expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined, true);
|
||||
expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined, undefined, true);
|
||||
|
||||
inst.setProps({ docId: 'aaa' });
|
||||
|
||||
|
@ -541,7 +563,7 @@ describe('Lens App', () => {
|
|||
expression: 'kibana 3',
|
||||
});
|
||||
|
||||
expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined, true);
|
||||
expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined, undefined, true);
|
||||
|
||||
inst.setProps({ docId: 'aaa' });
|
||||
|
||||
|
@ -609,7 +631,7 @@ describe('Lens App', () => {
|
|||
title: 'hello there',
|
||||
});
|
||||
|
||||
expect(args.redirectTo).toHaveBeenCalledWith('aaa', true, true);
|
||||
expect(args.redirectTo).toHaveBeenCalledWith('aaa', true, undefined, true);
|
||||
});
|
||||
|
||||
it('saves app filters and does not save pinned filters', async () => {
|
||||
|
@ -677,7 +699,12 @@ describe('Lens App', () => {
|
|||
storage: Storage;
|
||||
docId?: string;
|
||||
docStorage: SavedObjectStore;
|
||||
redirectTo: (id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => void;
|
||||
redirectTo: (
|
||||
id?: string,
|
||||
returnToOrigin?: boolean,
|
||||
originatingApp?: string | undefined,
|
||||
newlyCreated?: boolean
|
||||
) => void;
|
||||
}>;
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -33,6 +33,7 @@ interface State {
|
|||
isLoading: boolean;
|
||||
isSaveModalVisible: boolean;
|
||||
indexPatternsForTopNav: IndexPatternInstance[];
|
||||
originatingApp: string | undefined;
|
||||
persistedDoc?: Document;
|
||||
lastKnownDoc?: Document;
|
||||
|
||||
|
@ -54,7 +55,7 @@ export function App({
|
|||
docId,
|
||||
docStorage,
|
||||
redirectTo,
|
||||
originatingApp,
|
||||
originatingAppFromUrl,
|
||||
navigation,
|
||||
}: {
|
||||
editorFrame: EditorFrameInstance;
|
||||
|
@ -64,8 +65,13 @@ export function App({
|
|||
storage: IStorageWrapper;
|
||||
docId?: string;
|
||||
docStorage: SavedObjectStore;
|
||||
redirectTo: (id?: string, returnToOrigin?: boolean, newlyCreated?: boolean) => void;
|
||||
originatingApp?: string | undefined;
|
||||
redirectTo: (
|
||||
id?: string,
|
||||
returnToOrigin?: boolean,
|
||||
originatingApp?: string | undefined,
|
||||
newlyCreated?: boolean
|
||||
) => void;
|
||||
originatingAppFromUrl?: string | undefined;
|
||||
}) {
|
||||
const language =
|
||||
storage.get('kibana.userQueryLanguage') || core.uiSettings.get('search:queryLanguage');
|
||||
|
@ -77,6 +83,7 @@ export function App({
|
|||
isSaveModalVisible: false,
|
||||
indexPatternsForTopNav: [],
|
||||
query: { query: '', language },
|
||||
originatingApp: originatingAppFromUrl,
|
||||
dateRange: {
|
||||
fromDate: currentRange.from,
|
||||
toDate: currentRange.to,
|
||||
|
@ -229,7 +236,7 @@ export function App({
|
|||
lastKnownDoc: newDoc,
|
||||
}));
|
||||
if (docId !== id || saveProps.returnToOrigin) {
|
||||
redirectTo(id, saveProps.returnToOrigin, newlyCreated);
|
||||
redirectTo(id, saveProps.returnToOrigin, state.originatingApp, newlyCreated);
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
|
@ -269,7 +276,7 @@ export function App({
|
|||
<div className="lnsApp__header">
|
||||
<TopNavMenu
|
||||
config={[
|
||||
...(!!originatingApp && lastKnownDoc?.id
|
||||
...(!!state.originatingApp && lastKnownDoc?.id
|
||||
? [
|
||||
{
|
||||
label: i18n.translate('xpack.lens.app.saveAndReturn', {
|
||||
|
@ -294,14 +301,14 @@ export function App({
|
|||
: []),
|
||||
{
|
||||
label:
|
||||
lastKnownDoc?.id && !!originatingApp
|
||||
lastKnownDoc?.id && !!state.originatingApp
|
||||
? i18n.translate('xpack.lens.app.saveAs', {
|
||||
defaultMessage: 'Save as',
|
||||
})
|
||||
: i18n.translate('xpack.lens.app.save', {
|
||||
defaultMessage: 'Save',
|
||||
}),
|
||||
emphasize: !originatingApp || !lastKnownDoc?.id,
|
||||
emphasize: !state.originatingApp || !lastKnownDoc?.id,
|
||||
run: () => {
|
||||
if (isSaveable && lastKnownDoc) {
|
||||
setState(s => ({ ...s, isSaveModalVisible: true }));
|
||||
|
@ -422,7 +429,7 @@ export function App({
|
|||
</div>
|
||||
{lastKnownDoc && state.isSaveModalVisible && (
|
||||
<SavedObjectSaveModalOrigin
|
||||
originatingApp={originatingApp}
|
||||
originatingApp={state.originatingApp}
|
||||
onSave={props => runSave(props)}
|
||||
onClose={() => setState(s => ({ ...s, isSaveModalVisible: false }))}
|
||||
documentInfo={{
|
||||
|
|
|
@ -47,15 +47,11 @@ export async function mountApp(
|
|||
);
|
||||
const redirectTo = (
|
||||
routeProps: RouteComponentProps<{ id?: string }>,
|
||||
originatingApp: string,
|
||||
id?: string,
|
||||
returnToOrigin?: boolean,
|
||||
originatingApp?: string,
|
||||
newlyCreated?: boolean
|
||||
) => {
|
||||
if (!!originatingApp && !returnToOrigin) {
|
||||
removeQueryParam(routeProps.history, 'embeddableOriginatingApp');
|
||||
}
|
||||
|
||||
if (!id) {
|
||||
routeProps.history.push('/');
|
||||
} else if (!originatingApp) {
|
||||
|
@ -78,7 +74,10 @@ export async function mountApp(
|
|||
const renderEditor = (routeProps: RouteComponentProps<{ id?: string }>) => {
|
||||
trackUiEvent('loaded');
|
||||
const urlParams = parse(routeProps.location.search) as Record<string, string>;
|
||||
const originatingApp = urlParams.embeddableOriginatingApp;
|
||||
const originatingAppFromUrl = urlParams.embeddableOriginatingApp;
|
||||
if (urlParams.embeddableOriginatingApp) {
|
||||
removeQueryParam(routeProps.history, 'embeddableOriginatingApp');
|
||||
}
|
||||
|
||||
return (
|
||||
<App
|
||||
|
@ -89,10 +88,10 @@ export async function mountApp(
|
|||
storage={new Storage(localStorage)}
|
||||
docId={routeProps.match.params.id}
|
||||
docStorage={new SavedObjectIndexStore(savedObjectsClient)}
|
||||
redirectTo={(id, returnToOrigin, newlyCreated) =>
|
||||
redirectTo(routeProps, originatingApp, id, returnToOrigin, newlyCreated)
|
||||
redirectTo={(id, returnToOrigin, originatingApp, newlyCreated) =>
|
||||
redirectTo(routeProps, id, returnToOrigin, originatingApp, newlyCreated)
|
||||
}
|
||||
originatingApp={originatingApp}
|
||||
originatingAppFromUrl={originatingAppFromUrl}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue