Skip to content

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

feat: transform setting into collection list (#68758)

Edward Pagetad8af02598fe
diff --git a/enterprise/frontend/src/metabase-enterprise/collections/utils.ts b/enterprise/frontend/src/metabase-enterprise/collections/utils.ts
index 26ede9a6a72..298cbe12380 100644
--- a/enterprise/frontend/src/metabase-enterprise/collections/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/collections/utils.ts
@@ -1,6 +1,7 @@
import type { IconData, ObjectWithModel } from "metabase/lib/icon";
import { getIconBase } from "metabase/lib/icon";
import type { ItemWithCollection } from "metabase/plugins";
+import { PLUGIN_DATA_STUDIO } from "metabase/plugins";
import type {
Bookmark,
Collection,
@@ -68,6 +69,14 @@ export const getIcon = (
}
if (item.model === "collection") {
+ // Library collections keep their special icon regardless of sync status
+ const libraryCollectionType = PLUGIN_DATA_STUDIO.getLibraryCollectionType(
+ item.type as CollectionType,
+ );
+ if (libraryCollectionType != null) {
+ return getIconBase(item);
+ }
+
// tenant users see the normal icon, they don't know what a synced collection is
if (item.is_remote_synced && !isTenantUser) {
return {
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncList/CollectionSyncList.module.css b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncList/CollectionSyncList.module.css
new file mode 100644
index 00000000000..d76ca6eb53a
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncList/CollectionSyncList.module.css
@@ -0,0 +1,6 @@
+.collectionSyncList {
+ background-color: var(--mb-color-background-primary);
+ border-radius: var(--mantine-radius-md);
+ border: 1px solid var(--mb-color-border);
+ overflow: hidden;
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncList/CollectionSyncList.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncList/CollectionSyncList.tsx
index 17d1ad36e59..916403b23f8 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncList/CollectionSyncList.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncList/CollectionSyncList.tsx
@@ -1,5 +1,5 @@
import { useFormikContext } from "formik";
-import { useCallback, useEffect } from "react";
+import { useCallback, useEffect, useMemo } from "react";
import { usePrevious } from "react-use";
import { Box, Flex, Loader, Text } from "metabase/ui";
@@ -11,24 +11,28 @@ import type {
import { COLLECTIONS_KEY, TYPE_KEY } from "../../constants";
import { CollectionSyncRow } from "../CollectionSyncRow";
+import { TransformsSyncRow } from "../TransformsSyncRow";
+
+import S from "./CollectionSyncList.module.css";
interface CollectionSyncListProps {
collections: CollectionItem[];
- isLoading: boolean;
- error: string | null;
emptyMessage: string;
+ error: string | null;
+ isLoading: boolean;
+ showTransformsRow?: boolean;
}
export const CollectionSyncList = ({
collections,
- isLoading,
- error,
emptyMessage,
+ error,
+ isLoading,
+ showTransformsRow,
}: CollectionSyncListProps) => {
const { values, setFieldValue, initialValues } =
useFormikContext<RemoteSyncConfigurationSettings>();
- const syncMap: CollectionSyncPreferences = values[COLLECTIONS_KEY] ?? {};
const currentType = values[TYPE_KEY];
const isReadOnly = currentType === "read-only";
const previousType = usePrevious(currentType);
@@ -48,6 +52,37 @@ export const CollectionSyncList = ({
[setFieldValue],
);
+ const syncRows = useMemo(() => {
+ const syncMap: CollectionSyncPreferences = values[COLLECTIONS_KEY] ?? {};
+ const rowsItems = collections.map((collection) => (
+ <CollectionSyncRow
+ key={collection.id}
+ collection={collection}
+ isChecked={syncMap[collection.id] ?? false}
+ onToggle={handleToggle}
+ isReadOnly={isReadOnly}
+ />
+ ));
+
+ if (showTransformsRow) {
+ const transformsRow = (
+ <TransformsSyncRow key="transforms" isReadOnly={isReadOnly} />
+ );
+ const libraryIndex = collections.findIndex(
+ (collection) => collection.type === "library",
+ );
+
+ // Insert transforms row before library collection or as last item
+ if (libraryIndex !== -1) {
+ rowsItems.splice(libraryIndex + 1, 0, transformsRow);
+ } else {
+ rowsItems.push(transformsRow);
+ }
+ }
+
+ return rowsItems;
+ }, [collections, handleToggle, isReadOnly, showTransformsRow, values]);
+
if (isLoading) {
return (
<Flex justify="center" py="lg">
@@ -60,29 +95,9 @@ export const CollectionSyncList = ({
return <Text c="error">{error}</Text>;
}
- if (collections.length === 0) {
+ if (!syncRows.length) {
return <Text c="text-secondary">{emptyMessage}</Text>;
}
- return (
- <Box
- bg="background-primary"
- style={{
- borderRadius: "var(--mantine-radius-md)",
- border: "1px solid var(--mb-color-border)",
- overflow: "hidden",
- }}
- >
- {collections.map((collection, index) => (
- <CollectionSyncRow
- key={collection.id}
- collection={collection}
- isChecked={syncMap[collection.id] ?? false}
- onToggle={handleToggle}
- isLast={index === collections.length - 1}
- isReadOnly={isReadOnly}
- />
- ))}
- </Box>
- );
+ return <Box className={S.collectionSyncList}>{syncRows}</Box>;
};
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.tsx
index 55898b13be2..7f4fde0c8a8 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.tsx
@@ -1,5 +1,6 @@
import { c, t } from "ttag";
+import CS from "metabase/css/core/bordered.module.css";
import { PLUGIN_COLLECTIONS } from "metabase/plugins";
import { Box, Flex, Icon, Switch, Text } from "metabase/ui";
import type { CollectionItem } from "metabase-types/api";
@@ -8,7 +9,6 @@ interface CollectionSyncRowProps {
collection: CollectionItem;
isChecked: boolean;
onToggle: (collection: CollectionItem, checked: boolean) => void;
- isLast: boolean;
isReadOnly: boolean;
}
@@ -16,22 +16,17 @@ export const CollectionSyncRow = ({
collection,
isChecked,
onToggle,
- isLast,
isReadOnly,
}: CollectionSyncRowProps) => {
const canWrite = collection.can_write ?? false;
const icon = PLUGIN_COLLECTIONS.getIcon({
model: "collection",
+ type: collection.type,
is_remote_synced: isChecked,
});
return (
- <Box
- p="md"
- style={{
- borderBottom: isLast ? undefined : "1px solid var(--mb-color-border)",
- }}
- >
+ <Box p="md" className={CS.borderRowDivider}>
<Flex justify="space-between" align="center">
<Flex align="center" gap="sm">
<Icon name={icon.name} c={icon.color ?? "text-secondary"} />
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.unit.spec.tsx
index 17eced59532..bc5d65946a2 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/CollectionSyncRow/CollectionSyncRow.unit.spec.tsx
@@ -20,14 +20,12 @@ const createMockCollection = (
interface SetupOpts {
collection?: CollectionItem;
isChecked?: boolean;
- isLast?: boolean;
isReadOnly?: boolean;
}
const setup = ({
collection = createMockCollection(),
isChecked = false,
- isLast = true,
isReadOnly = false,
}: SetupOpts = {}) => {
const onToggle = jest.fn();
@@ -37,7 +35,6 @@ const setup = ({
collection={collection}
isChecked={isChecked}
onToggle={onToggle}
- isLast={isLast}
isReadOnly={isReadOnly}
/>,
);
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx
index ca297fb48cb..6c8e9b960f0 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.tsx
@@ -53,7 +53,6 @@ import {
REMOTE_SYNC_KEY,
REMOTE_SYNC_SCHEMA,
TOKEN_KEY,
- TRANSFORMS_KEY,
TYPE_KEY,
URL_KEY,
} from "../../constants";
@@ -433,21 +432,6 @@ export const RemoteSyncSettingsForm = (props: RemoteSyncSettingsFormProps) => {
</RemoteSyncSettingsSection>
)}
- {/* Section 5: Transforms sync */}
- {(isRemoteSyncEnabled || values?.[TYPE_KEY] === "read-write") && (
- <RemoteSyncSettingsSection
- title={t`Transforms`}
- variant={variant}
- >
- <FormSwitch
- label={t`Sync transforms with git`}
- description={t`When enabled, all transforms and transform tags will be synced.`}
- name={TRANSFORMS_KEY}
- size="sm"
- />
- </RemoteSyncSettingsSection>
- )}
-
{/* Read-write mode info */}
{isModalVariant && values?.[TYPE_KEY] === "read-write" && (
<Text c="text-secondary" size="sm">
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx
index 483396edf11..2d8b5b7caaa 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncSettingsForm.unit.spec.tsx
@@ -1,6 +1,7 @@
import userEvent from "@testing-library/user-event";
import { screen, waitFor } from "__support__/ui";
+import { PLUGIN_TRANSFORMS } from "metabase/plugins";
import {
createMockLibraryCollection,
@@ -161,22 +162,29 @@ describe("RemoteSyncSettingsForm", () => {
});
describe("transforms sync toggle", () => {
- it("should not display transforms toggle when remote sync is disabled and read-only mode", () => {
+ afterEach(() => {
+ PLUGIN_TRANSFORMS.isEnabled = false;
+ });
+
+ it("should not display transforms toggle when transforms feature is disabled", () => {
setup({
- remoteSyncEnabled: false,
- remoteSyncType: "read-only",
+ remoteSyncEnabled: true,
+ remoteSyncType: "read-write",
+ remoteSyncUrl: "https://github.com/test/repo.git",
});
- expect(screen.queryByText("Transforms")).not.toBeInTheDocument();
expect(
- screen.queryByLabelText("Sync transforms with git"),
+ screen.queryByLabelText("Sync Transforms"),
).not.toBeInTheDocument();
});
- it("should display transforms section in admin variant when read-write mode is selected during initial setup", async () => {
+ it("should display transforms row in collections list when transforms feature is enabled", async () => {
+ PLUGIN_TRANSFORMS.isEnabled = true;
+
setup({
- remoteSyncEnabled: false,
+ remoteSyncEnabled: true,
remoteSyncType: "read-write",
+ remoteSyncUrl: "https://github.com/test/repo.git",
});
// Wait for the form to be fully rendered with read-write mode
@@ -184,13 +192,16 @@ describe("RemoteSyncSettingsForm", () => {
expect(screen.getByLabelText("Read-write")).toBeChecked();
});
- expect(screen.getByText("Transforms")).toBeInTheDocument();
+ expect(screen.getByLabelText("Sync Transforms")).toBeInTheDocument();
});
- it("should display transforms section in modal variant when read-write mode is selected during initial setup", async () => {
+ it("should not display transforms row in modal variant (collections section is hidden)", async () => {
+ PLUGIN_TRANSFORMS.isEnabled = true;
+
setup({
- remoteSyncEnabled: false,
+ remoteSyncEnabled: true,
remoteSyncType: "read-write",
+ remoteSyncUrl: "https://github.com/test/repo.git",
variant: "settings-modal",
});
@@ -199,7 +210,10 @@ describe("RemoteSyncSettingsForm", () => {
expect(screen.getByLabelText("Read-write")).toBeChecked();
});
- expect(screen.getByText("Transforms")).toBeInTheDocument();
+ // In modal variant, collections section is hidden, so transforms row is also hidden
+ expect(
+ screen.queryByLabelText("Sync Transforms"),
+ ).not.toBeInTheDocument();
});
});
@@ -230,8 +244,7 @@ describe("RemoteSyncSettingsForm", () => {
expect(screen.getByLabelText("Read-write")).toBeChecked();
});
- // Transforms should be visible but collections should not
- expect(screen.getByText("Transforms")).toBeInTheDocument();
+ // Collections section (which includes transforms row) should not appear in modal variant
expect(screen.queryByText("Collections to sync")).not.toBeInTheDocument();
});
@@ -248,8 +261,7 @@ describe("RemoteSyncSettingsForm", () => {
expect(screen.getByLabelText("Read-write")).toBeChecked();
});
- // Transforms should be visible but collections should not
- expect(screen.getByText("Transforms")).toBeInTheDocument();
+ // Collections section (which includes transforms row) should not appear in modal variant
expect(screen.queryByText("Collections to sync")).not.toBeInTheDocument();
});
});
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/TopLevelCollectionsList/TopLevelCollectionsList.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/TopLevelCollectionsList/TopLevelCollectionsList.tsx
index ca7281b8d31..11c41907e29 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/TopLevelCollectionsList/TopLevelCollectionsList.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/TopLevelCollectionsList/TopLevelCollectionsList.tsx
@@ -2,6 +2,7 @@ import { useMemo } from "react";
import { t } from "ttag";
import { useListCollectionItemsQuery } from "metabase/api";
+import { PLUGIN_TRANSFORMS } from "metabase/plugins";
import { useGetLibraryCollectionQuery } from "metabase-enterprise/api";
import type { CollectionItem } from "metabase-types/api";
@@ -39,9 +40,10 @@ export const TopLevelCollectionsList = () => {
return (
<CollectionSyncList
collections={collections}
- isLoading={isLoading || isLoadingLibrary}
- error={error ? t`Failed to load collections` : null}
emptyMessage={t`No collections found`}
+ error={error ? t`Failed to load collections` : null}
+ isLoading={isLoading || isLoadingLibrary}
+ showTransformsRow={PLUGIN_TRANSFORMS.isEnabled}
/>
);
};
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/TransformsSyncRow/TransformsSyncRow.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/TransformsSyncRow/TransformsSyncRow.tsx
new file mode 100644
index 00000000000..1e458b63b19
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/TransformsSyncRow/TransformsSyncRow.tsx
@@ -0,0 +1,43 @@
+import { useFormikContext } from "formik";
+import { t } from "ttag";
+
+import CS from "metabase/css/core/bordered.module.css";
+import { Box, Flex, Icon, Switch, Text } from "metabase/ui";
+import type { RemoteSyncConfigurationSettings } from "metabase-types/api";
+
+import { TRANSFORMS_KEY } from "../../constants";
+
+interface TransformsSyncRowProps {
+ isReadOnly: boolean;
+}
+
+export const TransformsSyncRow = ({ isReadOnly }: TransformsSyncRowProps) => {
+ const { values, setFieldValue } =
+ useFormikContext<RemoteSyncConfigurationSettings>();
+ const isChecked = values[TRANSFORMS_KEY] ?? false;
+
+ const handleToggle = (checked: boolean) => {
+ setFieldValue(TRANSFORMS_KEY, checked);
+ };
+
+ return (
+ <Box p="md" className={CS.borderRowDivider}>
+ <Flex justify="space-between" align="center">
+ <Flex align="center" gap="sm">
+ <Icon name="transform" c="text-secondary" />
+ <Text fw="medium">{t`Transforms`}</Text>
+ </Flex>
+ <Flex align="center" gap="sm">
+ <Switch
+ size="sm"
+ checked={isChecked}
+ onChange={(e) => handleToggle(e.currentTarget.checked)}
+ disabled={isReadOnly}
+ aria-label={t`Sync Transforms`}
+ />
+ <Text>{t`Sync`}</Text>
+ </Flex>
+ </Flex>
+ </Box>
+ );
+};
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/TransformsSyncRow/index.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/TransformsSyncRow/index.ts
new file mode 100644
index 00000000000..8780f4998dd
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/TransformsSyncRow/index.ts
@@ -0,0 +1 @@
+export { TransformsSyncRow } from "./TransformsSyncRow";