From b2d3750e90ed95a528a3316b914550341d50a48f Mon Sep 17 00:00:00 2001 From: Devon A Thomson Date: Tue, 12 May 2020 15:41:00 -0400 Subject: [PATCH 1/7] Changed the way the lens app tracks originatingApp. It is now removed from the url when the app starts and tracked as part of the state --- .../application/dashboard_app_controller.tsx | 2 +- x-pack/plugins/lens/public/app_plugin/app.tsx | 23 ++++++++++++------- .../lens/public/app_plugin/mounter.tsx | 21 +++++++++-------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx index fa2f06bfcdcdd..428cf0e5b96c5 100644 --- a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx +++ b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx @@ -341,7 +341,6 @@ export class DashboardAppController { .then((container: DashboardContainer | ErrorEmbeddable | undefined) => { if (container && !isErrorEmbeddable(container)) { dashboardContainer = container; - dashboardContainer.renderEmpty = () => { const shouldShowEditHelp = getShouldShowEditHelp(); const shouldShowViewHelp = getShouldShowViewHelp(); @@ -405,6 +404,7 @@ export class DashboardAppController { const type = $routeParams[DashboardConstants.ADD_EMBEDDABLE_TYPE]; const id = $routeParams[DashboardConstants.ADD_EMBEDDABLE_ID]; container.addNewEmbeddable(type, { savedObjectId: id }); + // debugger; removeQueryParam(history, DashboardConstants.ADD_EMBEDDABLE_TYPE); removeQueryParam(history, DashboardConstants.ADD_EMBEDDABLE_ID); } diff --git a/x-pack/plugins/lens/public/app_plugin/app.tsx b/x-pack/plugins/lens/public/app_plugin/app.tsx index 6b8248fa2030b..b0160b8509a56 100644 --- a/x-pack/plugins/lens/public/app_plugin/app.tsx +++ b/x-pack/plugins/lens/public/app_plugin/app.tsx @@ -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, @@ -225,7 +232,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 => { @@ -265,7 +272,7 @@ export function App({
{ if (isSaveable && lastKnownDoc) { setState(s => ({ ...s, isSaveModalVisible: true })); @@ -418,7 +425,7 @@ export function App({
{lastKnownDoc && state.isSaveModalVisible && ( runSave(props)} onClose={() => setState(s => ({ ...s, isSaveModalVisible: false }))} documentInfo={{ diff --git a/x-pack/plugins/lens/public/app_plugin/mounter.tsx b/x-pack/plugins/lens/public/app_plugin/mounter.tsx index 74bc5821aa713..f05a4acec3dcd 100644 --- a/x-pack/plugins/lens/public/app_plugin/mounter.tsx +++ b/x-pack/plugins/lens/public/app_plugin/mounter.tsx @@ -52,15 +52,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('/lens'); } else if (!originatingApp) { @@ -82,7 +78,7 @@ export async function mountApp( addLensId, urlVars ); - window.history.pushState({}, '', dashboardUrl); + window.location.href = dashboardUrl; } else { window.location.href = originatingAppLink.url; } @@ -92,7 +88,12 @@ export async function mountApp( const renderEditor = (routeProps: RouteComponentProps<{ id?: string }>) => { trackUiEvent('loaded'); const urlParams = parse(routeProps.location.search) as Record; - const originatingApp = urlParams.embeddableOriginatingApp; + const originatingAppFromUrl = urlParams.embeddableOriginatingApp; + if (urlParams.embeddableOriginatingApp) { + setTimeout(() => { + removeQueryParam(routeProps.history, 'embeddableOriginatingApp'); + }, 0); + } return ( - redirectTo(routeProps, originatingApp, id, returnToOrigin, newlyCreated) + redirectTo={(id, returnToOrigin, originatingApp, newlyCreated) => + redirectTo(routeProps, id, returnToOrigin, originatingApp, newlyCreated) } - originatingApp={originatingApp} + originatingAppFromUrl={originatingAppFromUrl} /> ); }; From ae4d523a7147c635831453f32cf1cb14a27576be Mon Sep 17 00:00:00 2001 From: Devon A Thomson Date: Tue, 12 May 2020 17:34:13 -0400 Subject: [PATCH 2/7] removed debugger --- .../dashboard/public/application/dashboard_app_controller.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx index 428cf0e5b96c5..8e837bffea71c 100644 --- a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx +++ b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx @@ -404,7 +404,6 @@ export class DashboardAppController { const type = $routeParams[DashboardConstants.ADD_EMBEDDABLE_TYPE]; const id = $routeParams[DashboardConstants.ADD_EMBEDDABLE_ID]; container.addNewEmbeddable(type, { savedObjectId: id }); - // debugger; removeQueryParam(history, DashboardConstants.ADD_EMBEDDABLE_TYPE); removeQueryParam(history, DashboardConstants.ADD_EMBEDDABLE_ID); } From 506209241147ac5471c0b33cb3e501c4a10284c4 Mon Sep 17 00:00:00 2001 From: Devon A Thomson Date: Tue, 12 May 2020 18:44:18 -0400 Subject: [PATCH 3/7] fixed test --- .../lens/public/app_plugin/app.test.tsx | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/lens/public/app_plugin/app.test.tsx b/x-pack/plugins/lens/public/app_plugin/app.test.tsx index 888854a4e83b8..135527b559b58 100644 --- a/x-pack/plugins/lens/public/app_plugin/app.test.tsx +++ b/x-pack/plugins/lens/public/app_plugin/app.test.tsx @@ -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; }>; @@ -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(() => { From ba5274c1f3bbd502cb00e6bd8d0ba0b6f8cebb68 Mon Sep 17 00:00:00 2001 From: Devon A Thomson Date: Wed, 13 May 2020 10:38:59 -0400 Subject: [PATCH 4/7] fixed x-pack jest test --- x-pack/plugins/lens/public/app_plugin/app.test.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/lens/public/app_plugin/app.test.tsx b/x-pack/plugins/lens/public/app_plugin/app.test.tsx index 135527b559b58..66c0a20996581 100644 --- a/x-pack/plugins/lens/public/app_plugin/app.test.tsx +++ b/x-pack/plugins/lens/public/app_plugin/app.test.tsx @@ -543,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' }); @@ -563,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' }); @@ -631,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 () => { From 960cab112763a80ec36d7fa24720516e18d9c56b Mon Sep 17 00:00:00 2001 From: Devon A Thomson Date: Wed, 13 May 2020 11:21:30 -0400 Subject: [PATCH 5/7] removed async for removeQueryParam --- x-pack/plugins/lens/public/app_plugin/mounter.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/plugins/lens/public/app_plugin/mounter.tsx b/x-pack/plugins/lens/public/app_plugin/mounter.tsx index d84da8fe53705..7c875935f6320 100644 --- a/x-pack/plugins/lens/public/app_plugin/mounter.tsx +++ b/x-pack/plugins/lens/public/app_plugin/mounter.tsx @@ -76,9 +76,7 @@ export async function mountApp( const urlParams = parse(routeProps.location.search) as Record; const originatingAppFromUrl = urlParams.embeddableOriginatingApp; if (urlParams.embeddableOriginatingApp) { - setTimeout(() => { - removeQueryParam(routeProps.history, 'embeddableOriginatingApp'); - }, 0); + removeQueryParam(routeProps.history, 'embeddableOriginatingApp'); } return ( From 8f566374689a71897485db31336f010be2db8d02 Mon Sep 17 00:00:00 2001 From: Devon Thomson Date: Wed, 13 May 2020 17:38:14 -0400 Subject: [PATCH 6/7] Cleaned dif a little --- .../dashboard/public/application/dashboard_app_controller.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx index 8e837bffea71c..0917df96f836a 100644 --- a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx +++ b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx @@ -341,6 +341,7 @@ export class DashboardAppController { .then((container: DashboardContainer | ErrorEmbeddable | undefined) => { if (container && !isErrorEmbeddable(container)) { dashboardContainer = container; + dashboardContainer.renderEmpty = () => { const shouldShowEditHelp = getShouldShowEditHelp(); const shouldShowViewHelp = getShouldShowViewHelp(); From 4132a54fb320770a28fea0499662c180362279d3 Mon Sep 17 00:00:00 2001 From: Devon Thomson Date: Wed, 13 May 2020 17:39:19 -0400 Subject: [PATCH 7/7] Cleaned dif a little --- .../dashboard/public/application/dashboard_app_controller.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx index 0917df96f836a..fa2f06bfcdcdd 100644 --- a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx +++ b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx @@ -341,7 +341,7 @@ export class DashboardAppController { .then((container: DashboardContainer | ErrorEmbeddable | undefined) => { if (container && !isErrorEmbeddable(container)) { dashboardContainer = container; - + dashboardContainer.renderEmpty = () => { const shouldShowEditHelp = getShouldShowEditHelp(); const shouldShowViewHelp = getShouldShowViewHelp();