Snapshot: Show proper breadcrumb path (#98806)

* fix snapshot breadcrumbs

* cleaner
This commit is contained in:
Ashley Harrison 2025-01-10 14:50:44 +00:00 committed by GitHub
parent 3fa0834c49
commit ee362ed978
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 6 deletions

View File

@ -411,20 +411,21 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
}
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,
}),
};

View File

@ -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<DashboardS
panelsPerRow,
isEditing,
} = model.useState();
const { type } = useParams();
const location = useLocation();
const navIndex = useSelector((state) => 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

View File

@ -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',

View File

@ -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}`;
}