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
This commit is contained in:
Oscar Kilhed
2025-03-10 10:47:15 +01:00
committed by GitHub
parent 7cd7d7f608
commit 72aa2392cb
2 changed files with 8 additions and 3 deletions
@@ -56,7 +56,12 @@ export class TabsLayoutManager extends SceneObjectBase<TabsLayoutManagerState> 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 });
}
}
}
@@ -12,8 +12,8 @@ import { TabsLayoutManager } from './TabsLayoutManager';
export function TabsLayoutManagerRenderer({ model }: SceneComponentProps<TabsLayoutManager>) {
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();