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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user