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
Do not fold SidebarCollectionLink on click if item is not active (#73320)
Oleh Kc948c17ea389
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsxindex b78530cd618..bbd6035fc1d 100644--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsx+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/SidebarCollectionLink.tsx@@ -103,11 +103,11 @@ const SidebarCollectionLink = forwardRef<HTMLLIElement, Props>(aria-selected={isSelected}isSelected={isSelected}hovered={isHovered}- onClick={onToggleExpand}+ onClick={isSelected ? onToggleExpand : undefined}hasDefaultIconStyle={isRegularCollection}ref={ref}>- <ExpandToggleButton hidden={!hasChildren}>+ <ExpandToggleButton hidden={!hasChildren} onClick={onToggleExpand}><TreeNode.ExpandToggleIconisExpanded={isExpanded}name="chevronright"diff --git a/frontend/src/metabase/nav/containers/MainNavbar/tests/common.unit.spec.tsx b/frontend/src/metabase/nav/containers/MainNavbar/tests/common.unit.spec.tsxindex d800a00a478..6220e44f1da 100644--- a/frontend/src/metabase/nav/containers/MainNavbar/tests/common.unit.spec.tsx+++ b/frontend/src/metabase/nav/containers/MainNavbar/tests/common.unit.spec.tsx@@ -12,6 +12,7 @@ import {} from "metabase-types/api/mocks";import {+ NESTED_COLLECTION,PERSONAL_COLLECTION_BASE,TEST_COLLECTION,setup,@@ -376,6 +377,74 @@ describe("nav > containers > MainNavbar", () => {screen.queryByRole("button", { name: "Create a new collection" }),).not.toBeInTheDocument();});++ it("should toggle active collection on click", async () => {+ const { regularCollectionElements } = await setupCollectionPage({+ pathname: Urls.collection(TEST_COLLECTION),+ route: "/collection/:slug",+ });++ expect(regularCollectionElements.listItem).toHaveAttribute(+ "aria-selected",+ "true",+ );+ expect(+ screen.getByRole("treeitem", { name: /Nested collection/i }),+ ).toBeInTheDocument();++ await userEvent.click(regularCollectionElements.listItem);+ expect(+ screen.queryByRole("treeitem", { name: /Nested collection/i }),+ ).not.toBeInTheDocument();++ await userEvent.click(regularCollectionElements.listItem);+ expect(+ screen.getByRole("treeitem", { name: /Nested collection/i }),+ ).toBeInTheDocument();+ });++ it("should not toggle inactive collection on click", async () => {+ const { regularCollectionElements } = await setupCollectionPage({+ pathname: Urls.collection(NESTED_COLLECTION),+ route: "/collection/:slug",+ });++ expect(regularCollectionElements.listItem).toHaveAttribute(+ "aria-selected",+ "false",+ );+ expect(+ screen.getByRole("treeitem", { name: /Nested collection/i }),+ ).toBeInTheDocument();++ await userEvent.click(regularCollectionElements.listItem);+ expect(+ screen.getByRole("treeitem", { name: /Nested collection/i }),+ ).toBeInTheDocument();+ });++ it("should toggle inactive collection via the chevron button", async () => {+ const { regularCollectionElements } = await setupCollectionPage({+ pathname: Urls.collection(PERSONAL_COLLECTION_BASE),+ route: "/collection/:slug",+ });++ expect(regularCollectionElements.listItem).toHaveAttribute(+ "aria-selected",+ "false",+ );+ expect(+ screen.queryByRole("treeitem", { name: /Nested collection/i }),+ ).not.toBeInTheDocument();++ const chevron = within(regularCollectionElements.listItem).getByRole(+ "button",+ );+ await userEvent.click(chevron);+ expect(+ screen.getByRole("treeitem", { name: /Nested collection/i }),+ ).toBeInTheDocument();+ });});describe("Personal Collections", () => {diff --git a/frontend/src/metabase/nav/containers/MainNavbar/tests/setup.tsx b/frontend/src/metabase/nav/containers/MainNavbar/tests/setup.tsxindex 3e28ba423f1..be20705326f 100644--- a/frontend/src/metabase/nav/containers/MainNavbar/tests/setup.tsx+++ b/frontend/src/metabase/nav/containers/MainNavbar/tests/setup.tsx@@ -65,9 +65,17 @@ export const PERSONAL_COLLECTION_BASE = createMockCollection({originalName: "John's Personal Collection",});+export const NESTED_COLLECTION = createMockCollection({+ id: 3,+ name: "Nested collection",+ location: "/2/",+ parent_id: 2,+});+export const TEST_COLLECTION = createMockCollection({id: 2,name: "Test collection",+ children: [NESTED_COLLECTION],});export async function setup({@@ -141,7 +149,7 @@ export async function setup({currentUserId: user?.id,});setupCollectionByIdEndpoint({- collections: [PERSONAL_COLLECTION_BASE, TEST_COLLECTION],+ collections: [PERSONAL_COLLECTION_BASE, TEST_COLLECTION, NESTED_COLLECTION],});setupDatabasesEndpoints(databases);setupSearchEndpoints(models);