Skip to content

Commit 43c5f90

Browse files
authored
Tenant details navigation issues fix (#2336)
Fixes issues with Tenant details page navigation - Back issue between tenant summary & tenants list page - Not show the selected tab correctly on tenant details after clicking back on browser's back button Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 51ab9c5 commit 43c5f90

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

portal-ui/src/screens/Console/Common/VerticalTabs/VerticalTabs.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import React from "react";
1+
import React, { useState, useEffect } from "react";
22
import { Box, Tab, TabProps } from "@mui/material";
33
import { TabContext, TabList, TabPanel } from "@mui/lab";
44
import withStyles from "@mui/styles/withStyles";
55
import { Theme, useTheme } from "@mui/material/styles";
66
import createStyles from "@mui/styles/createStyles";
77
import useMediaQuery from "@mui/material/useMediaQuery";
8+
import { useLocation } from "react-router-dom";
89

910
export type TabItemProps = {
1011
tabConfig: TabProps | any;
@@ -91,25 +92,39 @@ const VerticalTabs = ({
9192
routes,
9293
isRouteTabs,
9394
}: VerticalTabsProps) => {
94-
const [value, setValue] = React.useState(selectedTab);
95-
9695
const theme = useTheme();
96+
const { pathname = "" } = useLocation();
97+
9798
const isSmallScreen = useMediaQuery(theme.breakpoints.down("md"));
9899

99-
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
100-
setValue(newValue);
101-
};
100+
const [value, setValue] = useState(selectedTab);
102101

103102
const headerList: TabProps[] = [];
104103
const contentList: React.ReactNode[] = [];
105104

105+
useEffect(() => {
106+
if (isRouteTabs) {
107+
const tabConfigElement = children.find(
108+
(item) => item.tabConfig.to === pathname
109+
);
110+
111+
if (tabConfigElement) {
112+
setValue(tabConfigElement.tabConfig.value);
113+
}
114+
}
115+
}, [isRouteTabs, children, pathname]);
116+
106117
if (!children) return null;
107118

108119
children.forEach((child) => {
109120
headerList.push(child.tabConfig);
110121
contentList.push(child.content);
111122
});
112123

124+
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
125+
setValue(newValue);
126+
};
127+
113128
return (
114129
<TabContext value={`${value}`}>
115130
<Box className={classes.tabsContainer}>

portal-ui/src/screens/Console/Tenants/ListTenants/TenantListItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ const TenantListItem = ({ tenant, classes }: ITenantListItem) => {
187187
})
188188
);
189189
dispatch(getTenantAsync());
190-
navigate(`/namespaces/${tenant.namespace}/tenants/${tenant.name}`);
190+
navigate(`/namespaces/${tenant.namespace}/tenants/${tenant.name}/summary`);
191191
};
192192

193193
return (

0 commit comments

Comments
 (0)