Skip to content

Commit

Permalink
Fix Visualize Link Redirecting to Dashboard Linked Visualization (#90243
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ThomThomson committed Feb 5, 2021
1 parent 29f8403 commit c444a4a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export const APP_NAME = 'visualize';

export const VisualizeConstants = {
VISUALIZE_BASE_PATH: '/app/visualize',
LANDING_PAGE_PATH: '/',
WIZARD_STEP_1_PAGE_PATH: '/new',
WIZARD_STEP_2_PAGE_PATH: '/new/configure',
Expand Down
19 changes: 18 additions & 1 deletion src/plugins/visualize/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class VisualizePlugin
private appStateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private stopUrlTracking: (() => void) | undefined = undefined;
private currentHistory: ScopedHistory | undefined = undefined;
private isLinkedToOriginatingApp: (() => boolean) | undefined = undefined;

private readonly visEditorsRegistry = createVisEditorsRegistry();

Expand All @@ -94,7 +95,7 @@ export class VisualizePlugin
setActiveUrl,
restorePreviousUrl,
} = createKbnUrlTracker({
baseUrl: core.http.basePath.prepend('/app/visualize'),
baseUrl: core.http.basePath.prepend(VisualizeConstants.VISUALIZE_BASE_PATH),
defaultSubUrl: '#/',
storageKey: `lastUrl:${core.http.basePath.get()}:visualize`,
navLinkUpdater$: this.appStateUpdater,
Expand All @@ -114,6 +115,15 @@ export class VisualizePlugin
},
],
getHistory: () => this.currentHistory!,
onBeforeNavLinkSaved: (urlToSave: string) => {
if (
!urlToSave.includes(`${VisualizeConstants.EDIT_PATH}/`) &&
this.isLinkedToOriginatingApp?.()
) {
return core.http.basePath.prepend(VisualizeConstants.VISUALIZE_BASE_PATH);
}
return urlToSave;
},
});
this.stopUrlTracking = () => {
stopUrlTracker();
Expand All @@ -134,6 +144,13 @@ export class VisualizePlugin
const [coreStart, pluginsStart] = await core.getStartServices();
this.currentHistory = params.history;

// allows the urlTracker to only save URLs that are not linked to an originatingApp
this.isLinkedToOriginatingApp = () => {
return Boolean(
pluginsStart.embeddable.getStateTransfer().getIncomingEditorState()?.originatingApp
);
};

// make sure the index pattern list is up to date
pluginsStart.data.indexPatterns.clearCache();
// make sure a default index pattern exists
Expand Down
30 changes: 26 additions & 4 deletions test/functional/apps/dashboard/edit_visualizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function ({ getService, getPageObjects }) {
const PageObjects = getPageObjects(['dashboard', 'header', 'visualize', 'common', 'visEditor']);
const esArchiver = getService('esArchiver');
const testSubjects = getService('testSubjects');
const appsMenu = getService('appsMenu');
const kibanaServer = getService('kibanaServer');
const dashboardPanelActions = getService('dashboardPanelActions');
const dashboardVisualizations = getService('dashboardVisualizations');
Expand All @@ -25,10 +26,14 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.visualize.clickMarkdownWidget();
await PageObjects.visEditor.setMarkdownTxt(originalMarkdownText);
await PageObjects.visEditor.clickGo();
await PageObjects.visualize.saveVisualizationExpectSuccess(title, {
saveAsNew: true,
redirectToOrigin: true,
});
if (title) {
await PageObjects.visualize.saveVisualizationExpectSuccess(title, {
saveAsNew: true,
redirectToOrigin: true,
});
} else {
await PageObjects.visualize.saveVisualizationAndReturn();
}
};

const editMarkdownVis = async () => {
Expand Down Expand Up @@ -86,5 +91,22 @@ export default function ({ getService, getPageObjects }) {
const markdownText = await testSubjects.find('markdownBody');
expect(await markdownText.getVisibleText()).to.eql(originalMarkdownText);
});

it('visualize app menu navigates to the visualize listing page if the last opened visualization was by value', async () => {
await PageObjects.dashboard.gotoDashboardLandingPage();
await PageObjects.dashboard.clickNewDashboard();

// Create markdown by value.
await createMarkdownVis();

// Edit then save and return
await editMarkdownVis();
await PageObjects.visualize.saveVisualizationAndReturn();

await PageObjects.header.waitUntilLoadingHasFinished();
await appsMenu.clickLink('Visualize');
await PageObjects.common.clickConfirmOnModal();
expect(await testSubjects.exists('visualizationLandingPage')).to.be(true);
});
});
}

0 comments on commit c444a4a

Please sign in to comment.