Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion superset-frontend/src/features/home/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ test('should render the environment tag', async () => {
const {
data: { environment_tag },
} = mockedProps;
render(<Menu {...mockedProps} />, { useRedux: true, useQueryParams: true });
render(<Menu {...mockedProps} />, {
useRedux: true,
useQueryParams: true,
useRouter: true,
});
expect(await screen.findByText(environment_tag.text)).toBeInTheDocument();
});

Expand Down
30 changes: 29 additions & 1 deletion superset-frontend/src/features/home/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getUrlParam } from 'src/utils/urlUtils';
import { Row, Col, Grid } from 'src/components';
import { MainNav as DropdownMenu, MenuMode } from 'src/components/Menu';
import { Tooltip } from 'src/components/Tooltip';
import { Link } from 'react-router-dom';
import { Link, useLocation } from 'react-router-dom';
import { GenericLink } from 'src/components/GenericLink/GenericLink';
import Icons from 'src/components/Icons';
import { useUiConfig } from 'src/components/UiConfigContext';
Expand Down Expand Up @@ -186,6 +186,33 @@ export function Menu({
return () => window.removeEventListener('resize', windowResize);
}, []);

enum paths {
EXPLORE = '/explore',
DASHBOARD = '/dashboard',
CHART = '/chart',
DATASETS = '/tablemodelview',
}

const defaultTabSelection: string[] = [];
const [activeTabs, setActiveTabs] = useState(defaultTabSelection);
const location = useLocation();
useEffect(() => {
const path = location.pathname;
switch (true) {
case path.startsWith(paths.DASHBOARD):
setActiveTabs(['Dashboards']);
break;
case path.startsWith(paths.CHART) || path.startsWith(paths.EXPLORE):
setActiveTabs(['Charts']);
break;
case path.startsWith(paths.DATASETS):
setActiveTabs(['Datasets']);
break;
default:
setActiveTabs(defaultTabSelection);
}
}, [location.pathname]);

const standalone = getUrlParam(URL_PARAMS.standalone);
if (standalone || uiConfig.hideNav) return <></>;

Expand Down Expand Up @@ -268,6 +295,7 @@ export function Menu({
mode={showMenu}
data-test="navbar-top"
className="main-nav"
selectedKeys={activeTabs}
>
{menu.map((item, index) => {
const props = {
Expand Down