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();