Skip to content

Commit 51c56dd

Browse files
authored
fix(header navlinks): link navlinks to path prefix (#25495)
1 parent e58a3ab commit 51c56dd

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

superset-frontend/src/features/home/Menu.test.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,11 @@ test('should render the environment tag', async () => {
295295
const {
296296
data: { environment_tag },
297297
} = mockedProps;
298-
render(<Menu {...mockedProps} />, { useRedux: true, useQueryParams: true });
298+
render(<Menu {...mockedProps} />, {
299+
useRedux: true,
300+
useQueryParams: true,
301+
useRouter: true,
302+
});
299303
expect(await screen.findByText(environment_tag.text)).toBeInTheDocument();
300304
});
301305

superset-frontend/src/features/home/Menu.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { getUrlParam } from 'src/utils/urlUtils';
2424
import { Row, Col, Grid } from 'src/components';
2525
import { MainNav as DropdownMenu, MenuMode } from 'src/components/Menu';
2626
import { Tooltip } from 'src/components/Tooltip';
27-
import { Link } from 'react-router-dom';
27+
import { Link, useLocation } from 'react-router-dom';
2828
import { GenericLink } from 'src/components/GenericLink/GenericLink';
2929
import Icons from 'src/components/Icons';
3030
import { useUiConfig } from 'src/components/UiConfigContext';
@@ -186,6 +186,33 @@ export function Menu({
186186
return () => window.removeEventListener('resize', windowResize);
187187
}, []);
188188

189+
enum paths {
190+
EXPLORE = '/explore',
191+
DASHBOARD = '/dashboard',
192+
CHART = '/chart',
193+
DATASETS = '/tablemodelview',
194+
}
195+
196+
const defaultTabSelection: string[] = [];
197+
const [activeTabs, setActiveTabs] = useState(defaultTabSelection);
198+
const location = useLocation();
199+
useEffect(() => {
200+
const path = location.pathname;
201+
switch (true) {
202+
case path.startsWith(paths.DASHBOARD):
203+
setActiveTabs(['Dashboards']);
204+
break;
205+
case path.startsWith(paths.CHART) || path.startsWith(paths.EXPLORE):
206+
setActiveTabs(['Charts']);
207+
break;
208+
case path.startsWith(paths.DATASETS):
209+
setActiveTabs(['Datasets']);
210+
break;
211+
default:
212+
setActiveTabs(defaultTabSelection);
213+
}
214+
}, [location.pathname]);
215+
189216
const standalone = getUrlParam(URL_PARAMS.standalone);
190217
if (standalone || uiConfig.hideNav) return <></>;
191218

@@ -268,6 +295,7 @@ export function Menu({
268295
mode={showMenu}
269296
data-test="navbar-top"
270297
className="main-nav"
298+
selectedKeys={activeTabs}
271299
>
272300
{menu.map((item, index) => {
273301
const props = {

0 commit comments

Comments
 (0)