Skip to content

Commit

Permalink
added redirect to dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Jun 10, 2021
1 parent 761e896 commit c8c07ce
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
3 changes: 0 additions & 3 deletions x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export function App({
initialInput,
incomingState,
redirectToOrigin,
redirectToDashboard,
setHeaderActionMenu,
initialContext,
}: LensAppProps) {
Expand Down Expand Up @@ -219,7 +218,6 @@ export function App({
getIsByValueMode,
savedObjectsTagging,
initialInput,
redirectToDashboard,
redirectToOrigin,
persistedDoc: appState.persistedDoc,
onAppLeave,
Expand Down Expand Up @@ -281,7 +279,6 @@ export function App({
persistedDoc={appState.persistedDoc}
initialInput={initialInput}
redirectTo={redirectTo}
redirectToDashboard={redirectToDashboard}
redirectToOrigin={redirectToOrigin}
returnToOriginSwitchLabel={
getIsByValueMode() && initialInput
Expand Down
18 changes: 0 additions & 18 deletions x-pack/plugins/lens/public/app_plugin/mounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,6 @@ export async function mountApp(
}
};

const redirectToDashboard = (embeddableInput: LensEmbeddableInput, dashboardId: string) => {
if (!lensServices.dashboardFeatureFlag.allowByValueEmbeddables) {
throw new Error('redirectToDashboard called with by-value embeddables disabled');
}

const state = {
input: embeddableInput,
type: LENS_EMBEDDABLE_TYPE,
};

const path = dashboardId === 'new' ? '#/create' : `#/view/${dashboardId}`;
stateTransfer.navigateToWithEmbeddablePackage('dashboards', {
state,
path,
});
};

const redirectToOrigin = (props?: RedirectToOriginProps) => {
if (!embeddableEditorIncomingState?.originatingApp) {
throw new Error('redirectToOrigin called without an originating app');
Expand Down Expand Up @@ -222,7 +205,6 @@ export async function mountApp(
initialInput={initialInput}
redirectTo={redirectCallback}
redirectToOrigin={redirectToOrigin}
redirectToDashboard={redirectToDashboard}
onAppLeave={params.onAppLeave}
setHeaderActionMenu={params.setHeaderActionMenu}
history={props.history}
Expand Down
44 changes: 36 additions & 8 deletions x-pack/plugins/lens/public/app_plugin/save_modal_container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import { checkForDuplicateTitle } from '../../../../../src/plugins/saved_objects
import { LensAppState } from '../state_management';

type ExtraProps = Pick<LensAppProps, 'initialInput'> &
Partial<
Pick<LensAppProps, 'redirectToOrigin' | 'redirectTo' | 'redirectToDashboard' | 'onAppLeave'>
>;
Partial<Pick<LensAppProps, 'redirectToOrigin' | 'redirectTo' | 'onAppLeave'>>;

export type SaveModalContainerProps = {
isVisible: boolean;
Expand All @@ -55,7 +53,6 @@ export function SaveModalContainer({
originatingApp,
initialInput,
redirectTo,
redirectToDashboard,
redirectToOrigin,
getAppNameFromId = () => undefined,
isSaveable = true,
Expand Down Expand Up @@ -114,7 +111,6 @@ export function SaveModalContainer({
initialInput,
attributeService,
redirectTo,
redirectToDashboard,
redirectToOrigin,
getIsByValueMode: () => false,
onAppLeave: () => {},
Expand Down Expand Up @@ -150,6 +146,33 @@ export function SaveModalContainer({
);
}

const redirectToDashboard = ({
embeddableInput,
dashboardFeatureFlag,
dashboardId,
stateTransfer,
}: {
embeddableInput: LensEmbeddableInput;
dashboardId: string;
dashboardFeatureFlag: LensAppServices['dashboardFeatureFlag'];
stateTransfer: LensAppServices['stateTransfer'];
}) => {
if (!dashboardFeatureFlag.allowByValueEmbeddables) {
throw new Error('redirectToDashboard called with by-value embeddables disabled');
}

const state = {
input: embeddableInput,
type: LENS_EMBEDDABLE_TYPE,
};

const path = dashboardId === 'new' ? '#/create' : `#/view/${dashboardId}`;
stateTransfer.navigateToWithEmbeddablePackage('dashboards', {
state,
path,
});
};

export const runSaveLensVisualization = async (
props: {
lastKnownDoc?: Document;
Expand All @@ -175,11 +198,11 @@ export const runSaveLensVisualization = async (
stateTransfer,
attributeService,
savedObjectsTagging,
redirectToDashboard,
getIsByValueMode,
redirectToOrigin,
onAppLeave,
redirectTo,
dashboardFeatureFlag,
} = props;

const tagsIds =
Expand Down Expand Up @@ -254,12 +277,17 @@ export const runSaveLensVisualization = async (
});
redirectToOrigin({ input: newInput, isCopied: saveProps.newCopyOnSave });
return;
} else if (saveProps.dashboardId && redirectToDashboard) {
} else if (saveProps.dashboardId) {
// disabling the validation on app leave because the document has been saved.
onAppLeave?.((actions) => {
return actions.default();
});
redirectToDashboard(newInput, saveProps.dashboardId);
redirectToDashboard({
embeddableInput: newInput,
dashboardId: saveProps.dashboardId,
stateTransfer,
dashboardFeatureFlag,
});
return;
}

Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/lens/public/app_plugin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export interface LensAppProps {
setHeaderActionMenu: AppMountParameters['setHeaderActionMenu'];
redirectTo: (savedObjectId?: string) => void;
redirectToOrigin?: (props?: RedirectToOriginProps) => void;
redirectToDashboard?: (input: LensEmbeddableInput, dashboardId: string) => void;

// The initial input passed in by the container when editing. Can be either by reference or by value.
initialInput?: LensEmbeddableInput;
Expand Down

0 comments on commit c8c07ce

Please sign in to comment.