You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2023/10/19 13:06:14 UTC
[superset] 06/09: fix(header navlinks): link navlinks to path prefix (#25495)
This is an automated email from the ASF dual-hosted git repository.
michaelsmolina pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/superset.git
commit b95ff2da23a87b84b9a62af6433f53c98ccb49b8
Author: Jack <41...@users.noreply.github.com>
AuthorDate: Tue Oct 17 11:45:25 2023 -0500
fix(header navlinks): link navlinks to path prefix (#25495)
(cherry picked from commit 51c56dd2a0f52fa092862f8bc5833749f9adc1ba)
---
superset-frontend/src/features/home/Menu.test.tsx | 6 ++++-
superset-frontend/src/features/home/Menu.tsx | 30 ++++++++++++++++++++++-
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/superset-frontend/src/features/home/Menu.test.tsx b/superset-frontend/src/features/home/Menu.test.tsx
index b40a5ab075..04a0a9876f 100644
--- a/superset-frontend/src/features/home/Menu.test.tsx
+++ b/superset-frontend/src/features/home/Menu.test.tsx
@@ -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();
});
diff --git a/superset-frontend/src/features/home/Menu.tsx b/superset-frontend/src/features/home/Menu.tsx
index 92766cfdda..56a2fd611e 100644
--- a/superset-frontend/src/features/home/Menu.tsx
+++ b/superset-frontend/src/features/home/Menu.tsx
@@ -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';
@@ -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 <></>;
@@ -268,6 +295,7 @@ export function Menu({
mode={showMenu}
data-test="navbar-top"
className="main-nav"
+ selectedKeys={activeTabs}
>
{menu.map((item, index) => {
const props = {