From 3dba1a0896b73f334834f7614188e6b768850093 Mon Sep 17 00:00:00 2001 From: Devon Thomson Date: Thu, 14 May 2020 12:28:41 -0400 Subject: [PATCH] Fixed lens redirect after reload issue for 7.7 (#66491) --- .../plugins/lens/public/app_plugin/app.test.tsx | 6 +++--- .../legacy/plugins/lens/public/app_plugin/app.tsx | 10 ++++++---- x-pack/legacy/plugins/lens/public/plugin.tsx | 13 +++++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx b/x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx index be72dd4b4edef..4c9efca6e509b 100644 --- a/x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx +++ b/x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx @@ -523,7 +523,7 @@ describe('Lens App', () => { expression: 'kibana 3', }); - expect(args.redirectTo).toHaveBeenCalledWith('aaa'); + expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined); inst.setProps({ docId: 'aaa' }); @@ -543,7 +543,7 @@ describe('Lens App', () => { expression: 'kibana 3', }); - expect(args.redirectTo).toHaveBeenCalledWith('aaa'); + expect(args.redirectTo).toHaveBeenCalledWith('aaa', undefined); inst.setProps({ docId: 'aaa' }); @@ -611,7 +611,7 @@ describe('Lens App', () => { title: 'hello there', }); - expect(args.redirectTo).toHaveBeenCalledWith('aaa'); + expect(args.redirectTo).toHaveBeenCalledWith('aaa', true); }); it('saves app filters and does not save pinned filters', async () => { diff --git a/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx b/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx index dfea2e39fcbc5..d30e808d2e71e 100644 --- a/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx +++ b/x-pack/legacy/plugins/lens/public/app_plugin/app.tsx @@ -31,6 +31,7 @@ interface State { isLoading: boolean; isSaveModalVisible: boolean; indexPatternsForTopNav: IndexPatternInstance[]; + isAddToDashMode?: boolean; persistedDoc?: Document; lastKnownDoc?: Document; @@ -60,7 +61,7 @@ export function App({ storage: IStorageWrapper; docId?: string; docStorage: SavedObjectStore; - redirectTo: (id?: string) => void; + redirectTo: (id?: string, isAddToDashMode?: boolean) => void; addToDashboardMode?: boolean; }) { const language = @@ -71,6 +72,7 @@ export function App({ return { isLoading: !!docId, isSaveModalVisible: false, + isAddToDashMode: addToDashboardMode, indexPatternsForTopNav: [], query: { query: '', language }, dateRange: { @@ -190,7 +192,7 @@ export function App({ const { TopNavMenu } = npStart.plugins.navigation.ui; - const confirmButton = addToDashboardMode ? ( + const confirmButton = state.isAddToDashMode ? ( { @@ -385,7 +387,7 @@ export function App({ }} onClose={() => setState(s => ({ ...s, isSaveModalVisible: false }))} title={lastKnownDoc.title || ''} - showCopyOnSave={!addToDashboardMode} + showCopyOnSave={!state.isAddToDashMode} objectType={i18n.translate('xpack.lens.app.saveModalType', { defaultMessage: 'Lens visualization', })} diff --git a/x-pack/legacy/plugins/lens/public/plugin.tsx b/x-pack/legacy/plugins/lens/public/plugin.tsx index 16f1d194b240a..f00e056763331 100644 --- a/x-pack/legacy/plugins/lens/public/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/plugin.tsx @@ -12,7 +12,7 @@ import { AppMountParameters, CoreSetup, CoreStart } from 'src/core/public'; import { DataPublicPluginSetup, DataPublicPluginStart } from 'src/plugins/data/public'; import rison, { RisonObject, RisonValue } from 'rison-node'; import { isObject } from 'lodash'; -import { Storage } from '../../../../../src/plugins/kibana_utils/public'; +import { Storage, removeQueryParam } from '../../../../../src/plugins/kibana_utils/public'; import { EditorFrameService } from './editor_frame_service'; import { IndexPatternDatasource } from './indexpattern_datasource'; import { addHelpMenuToAppChrome } from './help_menu_util'; @@ -135,8 +135,8 @@ export class LensPlugin { }; const redirectTo = ( routeProps: RouteComponentProps<{ id?: string }>, - addToDashboardMode: boolean, - id?: string + id?: string, + addToDashboardMode?: boolean ) => { if (!id) { routeProps.history.push('/lens'); @@ -178,6 +178,9 @@ export class LensPlugin { trackUiEvent('loaded'); const addToDashboardMode = !!routeProps.location.search && routeProps.location.search.includes('addToDashboard'); + if (addToDashboardMode) { + removeQueryParam(routeProps.history, 'addToDashboard'); + } return ( redirectTo(routeProps, addToDashboardMode, id)} + redirectTo={(id?: string, isAddToDashMode?: boolean) => + redirectTo(routeProps, id, isAddToDashMode) + } addToDashboardMode={addToDashboardMode} /> );