Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

do not show toggles on library collections in main app (#74027)

Nick Fitzpatrick7fc65ddb6c1e
diff --git a/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.tsx b/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.tsx
index 16b8ac32f92..b6aa7c7155f 100644
--- a/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.tsx
+++ b/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.tsx
@@ -9,13 +9,11 @@ import type {
OnMove,
OnToggleSelectedWithItem,
} from "metabase/collections/types";
-import {
- isRootTrashCollection,
- isTrashedCollection,
-} from "metabase/collections/utils";
+import { isTrashedCollection } from "metabase/collections/utils";
import { BaseItemsTableBody } from "metabase/common/components/ItemsTable/BaseItemsTableBody/BaseItemsTableBody";
import type { ItemRendererProps } from "metabase/common/components/ItemsTable/DefaultItemRenderer";
import { DefaultItemRenderer } from "metabase/common/components/ItemsTable/DefaultItemRenderer";
+import { canSelectItems } from "metabase/common/components/ItemsTable/utils";
import type Database from "metabase-lib/v1/metadata/Database";
import type {
Bookmark,
@@ -156,9 +154,7 @@ export const BaseItemsTable = ({
onClick,
...props
}: BaseItemsTableProps) => {
- const canSelect =
- (collection?.can_write || isRootTrashCollection(collection)) &&
- typeof onToggleSelected === "function";
+ const canSelect = canSelectItems(collection, onToggleSelected);
const isTrashed = !!collection && isTrashedCollection(collection);
return (
diff --git a/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.unit.spec.tsx b/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.unit.spec.tsx
index 4329ad2ea05..8097e2f0581 100644
--- a/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.unit.spec.tsx
+++ b/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.unit.spec.tsx
@@ -2,6 +2,8 @@ import userEvent from "@testing-library/user-event";
import dayjs from "dayjs";
import { Route } from "react-router";
+import { setupEnterpriseOnlyPlugin } from "__support__/enterprise";
+import { mockSettings } from "__support__/settings";
import { getIcon, renderWithProviders, screen } from "__support__/ui";
import { DEFAULT_VISIBLE_COLUMNS_LIST } from "metabase/collections/components/CollectionContent";
import { getVisibleColumnsMap } from "metabase/common/components/ItemsTable/utils";
@@ -12,7 +14,10 @@ import {
DEFAULT_TIME_STYLE,
} from "metabase/utils/formatting/datetime-utils";
import type { CollectionItem } from "metabase-types/api";
-import { createMockCollection } from "metabase-types/api/mocks";
+import {
+ createMockCollection,
+ createMockTokenFeatures,
+} from "metabase-types/api/mocks";
import type { BaseItemsTableProps } from "./BaseItemsTable";
import { BaseItemsTable } from "./BaseItemsTable";
@@ -134,6 +139,31 @@ describe("BaseItemsTable", () => {
expect(screen.queryByLabelText("Select all items")).not.toBeInTheDocument();
});
+ describe("library collections", () => {
+ beforeEach(() => {
+ mockSettings({
+ "token-features": createMockTokenFeatures({ library: true }),
+ });
+ setupEnterpriseOnlyPlugin("library");
+ });
+
+ it("does not display select all checkbox for library collections", () => {
+ setup({
+ hasUnselected: true,
+ onSelectAll: jest.fn(),
+ onToggleSelected: jest.fn(),
+ collection: createMockCollection({
+ can_write: true,
+ type: "library",
+ }),
+ });
+
+ expect(
+ screen.queryByLabelText("Select all items"),
+ ).not.toBeInTheDocument();
+ });
+ });
+
describe("description", () => {
it("shows description on hover", async () => {
const DESCRIPTION = "My collection";
diff --git a/frontend/src/metabase/common/components/ItemsTable/DefaultItemRenderer.tsx b/frontend/src/metabase/common/components/ItemsTable/DefaultItemRenderer.tsx
index 3e010bfe156..b32f1847f6c 100644
--- a/frontend/src/metabase/common/components/ItemsTable/DefaultItemRenderer.tsx
+++ b/frontend/src/metabase/common/components/ItemsTable/DefaultItemRenderer.tsx
@@ -2,9 +2,9 @@ import { useCallback } from "react";
import type { ActionMenuProps } from "metabase/collections/components/ActionMenu";
import type { OnToggleSelectedWithItem } from "metabase/collections/types";
-import { isRootTrashCollection } from "metabase/collections/utils";
import type { BaseItemsTableProps } from "metabase/common/components/ItemsTable/BaseItemsTable";
import { Columns } from "metabase/common/components/ItemsTable/Columns";
+import { canSelectItems } from "metabase/common/components/ItemsTable/utils";
import { useGetIcon } from "metabase/hooks/use-icon";
import type Database from "metabase-lib/v1/metadata/Database";
import type { Bookmark, Collection, CollectionItem } from "metabase-types/api";
@@ -39,9 +39,7 @@ export const DefaultItemRenderer = ({
visibleColumnsMap,
}: ItemRendererProps) => {
const getIcon = useGetIcon();
- const canSelect =
- (collection?.can_write || isRootTrashCollection(collection)) &&
- typeof onToggleSelected === "function";
+ const canSelect = canSelectItems(collection, onToggleSelected);
const icon = getIcon(item);
if (item.model === "card" || item.archived) {
diff --git a/frontend/src/metabase/common/components/ItemsTable/utils.ts b/frontend/src/metabase/common/components/ItemsTable/utils.ts
index 275facc7ad4..27311632c35 100644
--- a/frontend/src/metabase/common/components/ItemsTable/utils.ts
+++ b/frontend/src/metabase/common/components/ItemsTable/utils.ts
@@ -2,7 +2,11 @@ import type {
CollectionContentTableColumn,
CollectionContentTableColumnsMap,
} from "metabase/collections/components/CollectionContent";
+import type { OnToggleSelectedWithItem } from "metabase/collections/types";
+import { isRootTrashCollection } from "metabase/collections/utils";
+import { PLUGIN_LIBRARY } from "metabase/plugins";
import { type BreakpointName, breakpoints } from "metabase/ui/theme";
+import type { Collection } from "metabase-types/api";
export interface ResponsiveProps {
/** The element will be hidden when the container's width is below this breakpoint */
@@ -24,3 +28,16 @@ export const getVisibleColumnsMap = (
result[item] = true;
return result;
}, {} as CollectionContentTableColumnsMap);
+
+export const canSelectItems = (
+ collection: Collection | undefined,
+ onToggleSelected: OnToggleSelectedWithItem | undefined,
+): boolean => {
+ if (typeof onToggleSelected !== "function") {
+ return false;
+ }
+ if (PLUGIN_LIBRARY.isLibraryCollectionType(collection?.type)) {
+ return false;
+ }
+ return Boolean(collection?.can_write) || isRootTrashCollection(collection);
+};