Skip to content

Commit

Permalink
fix(header navlinks): link navlinks to path prefix (apache#25495)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisjac committed Oct 17, 2023
1 parent e58a3ab commit 51c56dd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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

0 comments on commit 51c56dd

Please sign in to comment.