diff --git a/public/app/features/dashboard-scene/scene/DashboardScene.tsx b/public/app/features/dashboard-scene/scene/DashboardScene.tsx index 893b31321a8..fcecf9e15b7 100644 --- a/public/app/features/dashboard-scene/scene/DashboardScene.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardScene.tsx @@ -411,20 +411,21 @@ export class DashboardScene extends SceneObjectBase { } public getPageNav(location: H.Location, navIndex: NavIndex) { - const { meta, viewPanelScene, editPanel } = this.state; + const { meta, viewPanelScene, editPanel, title, uid } = this.state; if (meta.dashboardNotFound) { return { text: 'Not found' }; } let pageNav: NavModelItem = { - text: this.state.title, + text: title, url: getDashboardUrl({ - uid: this.state.uid, + uid, slug: meta.slug, currentQueryParams: location.search, updateQuery: { viewPanel: null, inspect: null, editview: null, editPanel: null, tab: null, shareView: null }, - isHomeDashboard: !meta.url && !meta.slug && !meta.isNew, + isHomeDashboard: !meta.url && !meta.slug && !meta.isNew && !meta.isSnapshot, + isSnapshot: meta.isSnapshot, }), }; diff --git a/public/app/features/dashboard-scene/scene/DashboardSceneRenderer.tsx b/public/app/features/dashboard-scene/scene/DashboardSceneRenderer.tsx index b0ac56b90cf..c108170eae9 100644 --- a/public/app/features/dashboard-scene/scene/DashboardSceneRenderer.tsx +++ b/public/app/features/dashboard-scene/scene/DashboardSceneRenderer.tsx @@ -1,5 +1,5 @@ import { useEffect, useMemo } from 'react'; -import { useLocation } from 'react-router-dom-v5-compat'; +import { useLocation, useParams } from 'react-router-dom-v5-compat'; import { PageLayoutType } from '@grafana/data'; import { SceneComponentProps } from '@grafana/scenes'; @@ -28,11 +28,12 @@ export function DashboardSceneRenderer({ model }: SceneComponentProps state.navIndex); const pageNav = model.getPageNav(location, navIndex); const bodyToRender = model.getBodyToRender(); - const navModel = getNavModel(navIndex, 'dashboards/browse'); + const navModel = getNavModel(navIndex, `dashboards/${type === 'snapshot' ? 'snapshots' : 'browse'}`); const isSettingsOpen = editview !== undefined; // Remember scroll pos when going into view panel, edit panel or settings diff --git a/public/app/features/dashboard-scene/utils/getDashboardUrl.test.ts b/public/app/features/dashboard-scene/utils/getDashboardUrl.test.ts index f6c1456d282..9e69c10bdaa 100644 --- a/public/app/features/dashboard-scene/utils/getDashboardUrl.test.ts +++ b/public/app/features/dashboard-scene/utils/getDashboardUrl.test.ts @@ -17,6 +17,16 @@ describe('dashboard utils', () => { expect(url).toBe('/d/dash-1/panel-edit/2?orgId=1&filter=A'); }); + it('Can getUrl for a snapshot', () => { + const url = getDashboardUrl({ + uid: 'dash-1', + isSnapshot: true, + currentQueryParams: '?orgId=1&filter=A', + }); + + expect(url).toBe('/dashboard/snapshot/dash-1?orgId=1&filter=A'); + }); + it('Can getUrl with slug', () => { const url = getDashboardUrl({ uid: 'dash-1', diff --git a/public/app/features/dashboard-scene/utils/getDashboardUrl.ts b/public/app/features/dashboard-scene/utils/getDashboardUrl.ts index 71900e57115..15f6f4ed46d 100644 --- a/public/app/features/dashboard-scene/utils/getDashboardUrl.ts +++ b/public/app/features/dashboard-scene/utils/getDashboardUrl.ts @@ -18,6 +18,7 @@ export interface DashboardUrlOptions { timeZone?: string; // Check if we are on the home dashboard isHomeDashboard?: boolean; + isSnapshot?: boolean; } export function getDashboardUrl(options: DashboardUrlOptions) { @@ -27,6 +28,10 @@ export function getDashboardUrl(options: DashboardUrlOptions) { path = '/dashboard/new'; } + if (options.isSnapshot) { + path = `/dashboard/snapshot/${options.uid}`; + } + if (options.soloRoute) { path = `/d-solo/${options.uid}`; }