Snapshots: Fix breadcrumb when not logged in (#110820)

This commit is contained in:
Juan Cabanas
2025-09-09 15:02:26 -03:00
committed by GitHub
parent acbc2cf01a
commit ebd1f63aab
2 changed files with 31 additions and 1 deletions
@@ -49,4 +49,26 @@ describe('getNavModel', () => {
expect(navModel.main.children![2].active).toBe(undefined);
expect(navModel.main.children![2].children![0].active).toBe(true);
});
test('returns fallback nav model when provided for non-existent node', () => {
const fallbackNavModel = {
main: { id: 'fallback-main', text: 'Fallback Main', url: '/fallback' },
node: { id: 'fallback-node', text: 'Fallback Node', url: '/fallback/node' },
};
const navModel = getNavModel(navIndex, 'non-existent-id', fallbackNavModel);
expect(navModel).toBe(fallbackNavModel);
expect(navModel.main.id).toBe('fallback-main');
expect(navModel.node.id).toBe('fallback-node');
});
test('returns not found nav model when no fallback provided for non-existent node', () => {
const navModel = getNavModel(navIndex, 'non-existent-id');
expect(navModel.main.id).toBe('not-found');
expect(navModel.node.id).toBe('not-found');
expect(navModel.main.text).toBe('Page not found');
expect(navModel.main.subTitle).toBe('404 Error');
expect(navModel.main.icon).toBe('exclamation-triangle');
expect(navModel.main.url).toBe('not-found');
});
});
@@ -32,7 +32,15 @@ export function DashboardSceneRenderer({ model }: SceneComponentProps<DashboardS
const scopesContext = useContext(ScopesContext);
const navIndex = useSelector((state) => state.navIndex);
const pageNav = model.getPageNav(location, navIndex);
const navModel = getNavModel(navIndex, `dashboards/${type === 'snapshot' ? 'snapshots' : 'browse'}`);
const navModel =
type === 'snapshot'
? getNavModel(
navIndex,
'dashboards/snapshots',
// fallback navModel to prevent showing `Page not found` in snapshots
getNavModel(navIndex, 'home')
)
: getNavModel(navIndex, 'dashboards/browse');
const isSettingsOpen = editview !== undefined;
const soloPanelContext = useDefineSoloPanelContext(viewPanel);