mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Snapshot: Show proper breadcrumb path (#98806)
* fix snapshot breadcrumbs * cleaner
This commit is contained in:
parent
3fa0834c49
commit
ee362ed978
@ -411,20 +411,21 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getPageNav(location: H.Location, navIndex: NavIndex) {
|
public getPageNav(location: H.Location, navIndex: NavIndex) {
|
||||||
const { meta, viewPanelScene, editPanel } = this.state;
|
const { meta, viewPanelScene, editPanel, title, uid } = this.state;
|
||||||
|
|
||||||
if (meta.dashboardNotFound) {
|
if (meta.dashboardNotFound) {
|
||||||
return { text: 'Not found' };
|
return { text: 'Not found' };
|
||||||
}
|
}
|
||||||
|
|
||||||
let pageNav: NavModelItem = {
|
let pageNav: NavModelItem = {
|
||||||
text: this.state.title,
|
text: title,
|
||||||
url: getDashboardUrl({
|
url: getDashboardUrl({
|
||||||
uid: this.state.uid,
|
uid,
|
||||||
slug: meta.slug,
|
slug: meta.slug,
|
||||||
currentQueryParams: location.search,
|
currentQueryParams: location.search,
|
||||||
updateQuery: { viewPanel: null, inspect: null, editview: null, editPanel: null, tab: null, shareView: null },
|
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,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useMemo } from 'react';
|
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 { PageLayoutType } from '@grafana/data';
|
||||||
import { SceneComponentProps } from '@grafana/scenes';
|
import { SceneComponentProps } from '@grafana/scenes';
|
||||||
@ -28,11 +28,12 @@ export function DashboardSceneRenderer({ model }: SceneComponentProps<DashboardS
|
|||||||
panelsPerRow,
|
panelsPerRow,
|
||||||
isEditing,
|
isEditing,
|
||||||
} = model.useState();
|
} = model.useState();
|
||||||
|
const { type } = useParams();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navIndex = useSelector((state) => state.navIndex);
|
const navIndex = useSelector((state) => state.navIndex);
|
||||||
const pageNav = model.getPageNav(location, navIndex);
|
const pageNav = model.getPageNav(location, navIndex);
|
||||||
const bodyToRender = model.getBodyToRender();
|
const bodyToRender = model.getBodyToRender();
|
||||||
const navModel = getNavModel(navIndex, 'dashboards/browse');
|
const navModel = getNavModel(navIndex, `dashboards/${type === 'snapshot' ? 'snapshots' : 'browse'}`);
|
||||||
const isSettingsOpen = editview !== undefined;
|
const isSettingsOpen = editview !== undefined;
|
||||||
|
|
||||||
// Remember scroll pos when going into view panel, edit panel or settings
|
// Remember scroll pos when going into view panel, edit panel or settings
|
||||||
|
@ -17,6 +17,16 @@ describe('dashboard utils', () => {
|
|||||||
expect(url).toBe('/d/dash-1/panel-edit/2?orgId=1&filter=A');
|
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', () => {
|
it('Can getUrl with slug', () => {
|
||||||
const url = getDashboardUrl({
|
const url = getDashboardUrl({
|
||||||
uid: 'dash-1',
|
uid: 'dash-1',
|
||||||
|
@ -18,6 +18,7 @@ export interface DashboardUrlOptions {
|
|||||||
timeZone?: string;
|
timeZone?: string;
|
||||||
// Check if we are on the home dashboard
|
// Check if we are on the home dashboard
|
||||||
isHomeDashboard?: boolean;
|
isHomeDashboard?: boolean;
|
||||||
|
isSnapshot?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDashboardUrl(options: DashboardUrlOptions) {
|
export function getDashboardUrl(options: DashboardUrlOptions) {
|
||||||
@ -27,6 +28,10 @@ export function getDashboardUrl(options: DashboardUrlOptions) {
|
|||||||
path = '/dashboard/new';
|
path = '/dashboard/new';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.isSnapshot) {
|
||||||
|
path = `/dashboard/snapshot/${options.uid}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.soloRoute) {
|
if (options.soloRoute) {
|
||||||
path = `/d-solo/${options.uid}`;
|
path = `/d-solo/${options.uid}`;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user