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
pull/101428/head
Oscar Kilhed 4 months ago committed by GitHub
parent 7cd7d7f608
commit 72aa2392cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      public/app/features/dashboard-scene/scene/layout-tabs/TabsLayoutManager.tsx
  2. 4
      public/app/features/dashboard-scene/scene/layout-tabs/TabsLayoutManagerRenderer.tsx

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

Loading…
Cancel
Save