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: UXW-606 Bookmark drag and drop handle shown when there's nothing to rearrange (#63358)
Brad Anderson2fcecd5de8ac
diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsxindex 655660aa484..a0a6ec61518 100644--- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsx+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.tsx@@ -51,6 +51,7 @@ interface CollectionSidebarBookmarksProps {interface BookmarkItemProps {bookmark: Bookmark;index: number;+ isDraggable?: boolean;isSorting: boolean;selectedItem?: SelectedItem;onSelect: () => void;@@ -68,6 +69,7 @@ function isBookmarkSelected(bookmark: Bookmark, selectedItem?: SelectedItem) {const BookmarkItem = ({bookmark,+ isDraggable,isSorting,selectedItem,onSelect,@@ -92,6 +94,7 @@ const BookmarkItem = ({icon={icon}isSelected={isSelected}isDragging={isSorting}+ isDraggable={isDraggable}hasDefaultIconStyle={!isIrregularCollection}onClick={onSelect}right={@@ -172,6 +175,7 @@ const BookmarkList = ({{orderedBookmarks.map((bookmark, index) => (<BookmarkItembookmark={bookmark}+ isDraggable={orderedBookmarks.length > 1}isSorting={isSorting}key={index}index={index}diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.unit.spec.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.unit.spec.tsxnew file mode 100644index 00000000000..c501073e056--- /dev/null+++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbarContainer/BookmarkList/BookmarkList.unit.spec.tsx@@ -0,0 +1,53 @@+import type { ComponentProps } from "react";+import { times } from "underscore";++import { renderWithProviders, screen } from "__support__/ui";+import { createMockBookmark } from "metabase-types/api/mocks";++import BookmarkList from "./BookmarkList";++const mockProps: ComponentProps<typeof BookmarkList> = {+ bookmarks: [],+ onSelect: jest.fn(),+ reorderBookmarks: jest.fn(),+ onToggle: jest.fn(),+ initialState: "expanded",+};++const createBookmarks = (howMany: number) => {+ return times(howMany, (i) => {+ const n = i + 1;+ return createMockBookmark({+ id: `bookmark-${n}`,+ name: `Bookmark ${n}`,+ item_id: n,+ });+ });+};++describe("BookmarkList", () => {+ it("shows drag handles when there are multiple bookmarks", () => {+ const bookmarks = createBookmarks(3);++ renderWithProviders(<BookmarkList {...mockProps} bookmarks={bookmarks} />);++ bookmarks.forEach((bookmark) => {+ expect(screen.getByText(bookmark.name)).toBeInTheDocument();+ });++ const grabberIcons = screen.getAllByLabelText("grabber icon");+ expect(grabberIcons).toHaveLength(bookmarks.length);+ });++ it("hides drag handles when there is only one bookmark", () => {+ const bookmarks = createBookmarks(1);++ renderWithProviders(<BookmarkList {...mockProps} bookmarks={bookmarks} />);++ bookmarks.forEach((bookmark) => {+ expect(screen.getByText(bookmark.name)).toBeInTheDocument();+ });++ expect(screen.queryByLabelText("grabber icon")).not.toBeInTheDocument();+ });+});diff --git a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/DraggableSidebarLink.tsx b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/DraggableSidebarLink.tsxindex 165114d1de9..f9e1110afdd 100644--- a/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/DraggableSidebarLink.tsx+++ b/frontend/src/metabase/nav/containers/MainNavbar/SidebarItems/DraggableSidebarLink.tsx@@ -2,9 +2,15 @@ import { DragIcon, StyledSidebarLink } from "./DraggableSidebarLink.styled";import type { SidebarLinkProps } from "./SidebarLink";interface Props extends Omit<SidebarLinkProps, "left"> {+ isDraggable?: boolean;isDragging: boolean;}-export function DraggableSidebarLink(props: Props) {- return <StyledSidebarLink {...props} left={<DragIcon name="grabber" />} />;+export function DraggableSidebarLink({ isDraggable, ...props }: Props) {+ return (+ <StyledSidebarLink+ {...props}+ left={isDraggable && <DragIcon name="grabber" />}+ />+ );}