The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Fix Admin Nested Navlink Behavior (#62771)
Ryan Lauriea40beb072a51
diff --git a/e2e/test/scenarios/admin-2/settings.cy.spec.js b/e2e/test/scenarios/admin-2/settings.cy.spec.jsindex 69270102c7f..b0270b744ed 100644--- a/e2e/test/scenarios/admin-2/settings.cy.spec.js+++ b/e2e/test/scenarios/admin-2/settings.cy.spec.js@@ -1459,3 +1459,44 @@ describe("admin > settings > updates", () => {});});});++describe("admin > settings > nav", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.visit("/admin/settings");+ });++ it("should navigate properly", () => {+ // sadly we can't test this in unit tests with the current state of react-router and redux 😭+ cy.log("clicking sidebar nav links should navigate there");++ cy.url().should("include", "/admin/settings/general");+ cy.findByTestId("admin-layout-sidebar").findByText(/email/i).click();+ cy.findByTestId("admin-layout-content").findByText(/email/i);+ cy.url().should("include", "/admin/settings/email");++ cy.log(+ "clicking folders should expand and collapse them, but not navigate",+ );++ cy.findByTestId("admin-layout-sidebar")+ .findByText(/api keys/i)+ .should("not.be.visible");+ cy.findByTestId("admin-layout-sidebar")+ .findByText(/authentication/i)+ .click();+ cy.findByTestId("admin-layout-sidebar")+ .findByText(/api keys/i)+ .should("be.visible");+ // still on email page+ cy.findByTestId("admin-layout-content").findByText(/email/i);+ cy.url().should("include", "/admin/settings/email");+ // navigate to sub-item+ cy.findByTestId("admin-layout-sidebar")+ .findByText(/api keys/i)+ .click();+ cy.findByTestId("admin-layout-content").findByText(/No API keys here yet/i);+ cy.url().should("include", "/admin/settings/authentication/api-keys");+ });+});diff --git a/frontend/src/metabase/admin/components/AdminNav/AdminNav.tsx b/frontend/src/metabase/admin/components/AdminNav/AdminNav.tsxindex 4b4af4433d5..17893be85d2 100644--- a/frontend/src/metabase/admin/components/AdminNav/AdminNav.tsx+++ b/frontend/src/metabase/admin/components/AdminNav/AdminNav.tsx@@ -34,13 +34,16 @@ export const AdminNavWrapper = ({};export type AdminNavItemProps = {- path: string;+ path?: string;+ /* folderPath is used to highlight the folder when one of its children is active, but doesn't navigate */+ folderPattern?: string;icon?: IconName;onClick?: () => void;} & Omit<NavLinkProps, "href">;export function AdminNavItem({path,+ folderPattern,label,icon,...navLinkProps@@ -50,9 +53,9 @@ export function AdminNavItem({return (<NavLink- component={Link}- to={path}- defaultOpened={subpath.includes(path)}+ component={path ? Link : undefined}+ to={path ?? ""}+ defaultOpened={folderPattern ? subpath.includes(folderPattern) : false}active={path === subpath}variant="admin-nav"label={label}diff --git a/frontend/src/metabase/admin/people/components/PeopleNav.tsx b/frontend/src/metabase/admin/people/components/PeopleNav.tsxindex 79fdcca74a6..12a0b32a18c 100644--- a/frontend/src/metabase/admin/people/components/PeopleNav.tsx+++ b/frontend/src/metabase/admin/people/components/PeopleNav.tsx@@ -41,7 +41,7 @@ const PeopleNavItem = (props: AdminNavItemProps) => {// we want to highlight the groups nav item if it's showing a details subpageconst isActive =- (props.path.includes("groups") && subpath.includes(props.path)) ||+ (props.path?.includes("groups") && subpath.includes(props.path)) ||props.path === subpath;return <AdminNavItem {...props} active={isActive} />;diff --git a/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.tsx b/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.tsxindex 37c02419b50..adf562d4892 100644--- a/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.tsx+++ b/frontend/src/metabase/admin/settings/components/SettingsNav/SettingsNav.tsx@@ -28,7 +28,11 @@ export function SettingsNav() {return (<AdminNavWrapper><SettingsNavItem path="general" label={t`General`} icon="gear" />- <SettingsNavItem label={t`Authentication`} path="auth" icon="lock">+ <SettingsNavItem+ label={t`Authentication`}+ icon="lock"+ folderPattern="auth"+ ><SettingsNavItem path="authentication" label={t`Overview`} />{hasScim && (<SettingsNavItem@@ -58,7 +62,8 @@ export function SettingsNav() {/><SettingsNavItem path="maps" label={t`Maps`} icon="pinmap" /><SettingsNavItem- path="whitelabel"+ path={!hasWhitelabel ? "whitelabel" : undefined}+ folderPattern="whitelabel"label={<Flex gap="sm" align="center"><span>{t`Appearance`}</span>@@ -88,7 +93,11 @@ export function SettingsNav() {label={t`Public sharing`}icon="share"/>- <SettingsNavItem path="embedding" label={t`Embedding`} icon="embed">+ <SettingsNavItem+ label={t`Embedding`}+ icon="embed"+ folderPattern="embedding"+ ><SettingsNavItempath="embedding-in-other-applications"label={t`Overview`}@@ -130,13 +139,17 @@ const hasActiveChild = (children: ReactElement[], pathname: string) =>(child) => child?.props?.path && pathname.includes(child.props.path),);-export function SettingsNavItem({ path, ...navItemProps }: AdminNavItemProps) {+export function SettingsNavItem({+ path,+ folderPattern,+ ...navItemProps+}: AdminNavItemProps) {const children = React.Children.toArray(navItemProps.children,) as ReactElement[];const currentPath: string = useSelector(getLocation)?.pathname ?? "";const [isOpen, { toggle: toggleOpen }] = useDisclosure(- currentPath.includes(path),+ folderPattern ? currentPath.includes(folderPattern) : false,);const showActive =@@ -146,7 +159,8 @@ export function SettingsNavItem({ path, ...navItemProps }: AdminNavItemProps) {return (<AdminNavItemdata-testid={`settings-sidebar-link`}- path={`/admin/settings/${path}`}+ path={path ? `/admin/settings/${path}` : ""}+ folderPattern={folderPattern}opened={isOpen}active={showActive}onClick={toggleOpen}diff --git a/frontend/src/metabase/admin/tools/components/ToolsApp.tsx b/frontend/src/metabase/admin/tools/components/ToolsApp.tsxindex 0632639fa1e..3f2b0e30a5b 100644--- a/frontend/src/metabase/admin/tools/components/ToolsApp.tsx+++ b/frontend/src/metabase/admin/tools/components/ToolsApp.tsx@@ -60,7 +60,7 @@ const ToolsNavItem = (props: AdminNavItemProps) => {const subpath = location?.pathname;// we want to highlight the nav item even if a subpath is active- const isActive = subpath.includes(props.path);+ const isActive = !!props.path && subpath.includes(props.path);return <AdminNavItem {...props} active={isActive} />;};