You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2023/10/17 16:45:32 UTC

[superset] branch master updated: fix(header navlinks): link navlinks to path prefix (#25495)

This is an automated email from the ASF dual-hosted git repository.

elizabeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 51c56dd2a0 fix(header navlinks): link navlinks to path prefix (#25495)
51c56dd2a0 is described below

commit 51c56dd2a0f52fa092862f8bc5833749f9adc1ba
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)
---
 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 428a7366f0..bcb10dfbbe 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 = {