Skip to content

Commit

Permalink
Fixed lens redirect after reload issue for 7.7 (elastic#66491)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson authored May 14, 2020
1 parent 8e3a4a5 commit 3dba1a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand All @@ -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' });

Expand Down Expand Up @@ -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 () => {
Expand Down
10 changes: 6 additions & 4 deletions x-pack/legacy/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface State {
isLoading: boolean;
isSaveModalVisible: boolean;
indexPatternsForTopNav: IndexPatternInstance[];
isAddToDashMode?: boolean;
persistedDoc?: Document;
lastKnownDoc?: Document;

Expand Down Expand Up @@ -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 =
Expand All @@ -71,6 +72,7 @@ export function App({
return {
isLoading: !!docId,
isSaveModalVisible: false,
isAddToDashMode: addToDashboardMode,
indexPatternsForTopNav: [],
query: { query: '', language },
dateRange: {
Expand Down Expand Up @@ -190,7 +192,7 @@ export function App({

const { TopNavMenu } = npStart.plugins.navigation.ui;

const confirmButton = addToDashboardMode ? (
const confirmButton = state.isAddToDashMode ? (
<FormattedMessage
id="xpack.lens.app.saveAddToDashboard"
defaultMessage="Save and add to dashboard"
Expand Down Expand Up @@ -368,7 +370,7 @@ export function App({
lastKnownDoc: newDoc,
}));
if (docId !== id) {
redirectTo(id);
redirectTo(id, state.isAddToDashMode);
}
})
.catch(e => {
Expand All @@ -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',
})}
Expand Down
13 changes: 9 additions & 4 deletions x-pack/legacy/plugins/lens/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 (
<App
core={coreStart}
Expand All @@ -186,7 +189,9 @@ export class LensPlugin {
storage={new Storage(localStorage)}
docId={routeProps.match.params.id}
docStorage={new SavedObjectIndexStore(savedObjectsClient)}
redirectTo={id => redirectTo(routeProps, addToDashboardMode, id)}
redirectTo={(id?: string, isAddToDashMode?: boolean) =>
redirectTo(routeProps, id, isAddToDashMode)
}
addToDashboardMode={addToDashboardMode}
/>
);
Expand Down

0 comments on commit 3dba1a0

Please sign in to comment.