From 72aa2392cb0b0e968f6ab0e94c3813a0cda1e9f5 Mon Sep 17 00:00:00 2001 From: Oscar Kilhed Date: Mon, 10 Mar 2025 10:47:15 +0100 Subject: [PATCH] Dashboards tabs: If trying to navigate to non existing tab with url, default to the first tab (#101784) * if tab does from url does not exist default to 0 * fix lint --- .../scene/layout-tabs/TabsLayoutManager.tsx | 7 ++++++- .../scene/layout-tabs/TabsLayoutManagerRenderer.tsx | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/public/app/features/dashboard-scene/scene/layout-tabs/TabsLayoutManager.tsx b/public/app/features/dashboard-scene/scene/layout-tabs/TabsLayoutManager.tsx index 0628850ed68..319210697cd 100644 --- a/public/app/features/dashboard-scene/scene/layout-tabs/TabsLayoutManager.tsx +++ b/public/app/features/dashboard-scene/scene/layout-tabs/TabsLayoutManager.tsx @@ -56,7 +56,12 @@ export class TabsLayoutManager extends SceneObjectBase i return; } if (typeof values.tab === 'string') { - this.setState({ currentTabIndex: parseInt(values.tab, 10) }); + const tabIndex = parseInt(values.tab, 10); + if (this.state.tabs[tabIndex]) { + this.setState({ currentTabIndex: tabIndex }); + } else { + this.setState({ currentTabIndex: 0 }); + } } } diff --git a/public/app/features/dashboard-scene/scene/layout-tabs/TabsLayoutManagerRenderer.tsx b/public/app/features/dashboard-scene/scene/layout-tabs/TabsLayoutManagerRenderer.tsx index bab343f3936..375f2f779ff 100644 --- a/public/app/features/dashboard-scene/scene/layout-tabs/TabsLayoutManagerRenderer.tsx +++ b/public/app/features/dashboard-scene/scene/layout-tabs/TabsLayoutManagerRenderer.tsx @@ -12,8 +12,8 @@ import { TabsLayoutManager } from './TabsLayoutManager'; export function TabsLayoutManagerRenderer({ model }: SceneComponentProps) { const styles = useStyles2(getStyles); - const { tabs, currentTabIndex } = model.useState(); - const currentTab = tabs[currentTabIndex]; + const { tabs } = model.useState(); + const currentTab = model.getCurrentTab(); const { layout } = currentTab.useState(); const dashboard = getDashboardSceneFor(model); const { isEditing } = dashboard.useState();