Skip to content

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

Show confirmation popup when overwriting data during remote sync setup (#68525)

Anderson1d0eaf9ca8c0
diff --git a/e2e/support/assets/example_synced_transforms_collection/transforms/BssO7GsawP2WszjcnIjMw_simple_sql_transform.yaml b/e2e/support/assets/example_synced_transforms_collection/transforms/BssO7GsawP2WszjcnIjMw_simple_sql_transform.yaml
new file mode 100644
index 00000000000..105f9d5a598
--- /dev/null
+++ b/e2e/support/assets/example_synced_transforms_collection/transforms/BssO7GsawP2WszjcnIjMw_simple_sql_transform.yaml
@@ -0,0 +1,23 @@
+collection_id: null
+created_at: '2026-01-30T15:33:24.179945Z'
+description: null
+entity_id: BssO7GsawP2WszjcnIjMw
+name: Imported Simple SQL transform
+source:
+ query:
+ database: Writable Postgres12
+ native:
+ query: select 1;
+ type: native
+ type: query
+source_database_id: Writable Postgres12
+tags: []
+target:
+ database: Writable Postgres12
+ name: imported_transform
+ schema: public
+ type: table
+serdes/meta:
+ - id: BssO7GsawP2WszjcnIjMw
+ label: imported_transform
+ model: Transform
diff --git a/e2e/support/helpers/e2e-remote-sync-helpers.ts b/e2e/support/helpers/e2e-remote-sync-helpers.ts
index 056588f380e..8413eb3156a 100644
--- a/e2e/support/helpers/e2e-remote-sync-helpers.ts
+++ b/e2e/support/helpers/e2e-remote-sync-helpers.ts
@@ -16,6 +16,9 @@ export const LOCAL_GIT_PATH =
export const SYNCED_COLLECTION_FIXTURE_PATH =
Cypress.config("projectRoot") +
"/e2e/support/assets/example_synced_collection";
+export const SYNCED_TRANSFORMS_COLLECTION_FIXTURE_PATH =
+ Cypress.config("projectRoot") +
+ "/e2e/support/assets/example_synced_transforms_collection";
// Copy the sample synced collection from the fixture folder to the working directory
export const copySyncedCollectionFixture = () => {
@@ -24,6 +27,13 @@ export const copySyncedCollectionFixture = () => {
destination: LOCAL_GIT_PATH,
});
};
+// Copy the sample synced transforms collection from the fixture folder to the working directory
+export const copySyncedTransformsCollectionFixture = () => {
+ cy.task("copyDirectory", {
+ source: SYNCED_TRANSFORMS_COLLECTION_FIXTURE_PATH,
+ destination: LOCAL_GIT_PATH,
+ });
+};
export const checkoutSyncedCollectionBranch = (branch: string) => {
cy.exec("git -C " + LOCAL_GIT_PATH + ` checkout -b '${branch}'`);
@@ -248,7 +258,7 @@ export const interceptTask = () =>
export const waitForTask = (
{ taskName }: { taskName: "import" | "export" },
retries = 0,
-) => {
+): Cypress.Chainable => {
if (retries > 3) {
throw Error(`Too many retries waiting for ${taskName}`);
}
@@ -267,7 +277,7 @@ export const waitForTask = (
export const pollForTask = (
{ taskName }: { taskName: "import" | "export" },
retries = 0,
-) => {
+): Cypress.Chainable => {
if (retries > 30) {
throw Error(`Too many retries waiting for ${taskName}`);
}
@@ -297,6 +307,13 @@ export const pollForTask = (
`Task ${taskName} failed: ${body.error_message || "Unknown error"}`,
);
}
+
+ if (body.status === "conflict") {
+ throw Error(
+ `Task ${taskName} returned conflict: ${body.error_message || "Unknown error"}`,
+ );
+ }
+
cy.wait(500);
return pollForTask({ taskName }, retries + 1);
}
diff --git a/e2e/support/helpers/e2e-transform-helpers.ts b/e2e/support/helpers/e2e-transform-helpers.ts
index d78dc4d0230..f6ba93fcec7 100644
--- a/e2e/support/helpers/e2e-transform-helpers.ts
+++ b/e2e/support/helpers/e2e-transform-helpers.ts
@@ -119,7 +119,9 @@ export function createSqlTransform({
tagIds,
visitTransform,
sourceCheckpointStrategy,
+ name = "SQL transform",
}: {
+ name?: string;
sourceQuery: string;
targetTable: string;
targetSchema: string;
@@ -129,7 +131,7 @@ export function createSqlTransform({
}) {
return createTransform(
{
- name: "SQL transform",
+ name,
source: {
type: "query",
query: {
diff --git a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
index d2717eb65dc..a24c78f959d 100644
--- a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
+++ b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
@@ -1,3 +1,4 @@
+import { WRITABLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { ORDERS_DASHBOARD_ID } from "e2e/support/cypress_sample_instance_data";
import type { Collection } from "metabase-types/api";
@@ -12,7 +13,7 @@ const REMOTE_QUESTION_NAME = "Remote Sync Test Question";
describe("Remote Sync", () => {
beforeEach(() => {
- H.restore();
+ H.restore("postgres-writable");
H.resetSnowplow();
cy.signInAsAdmin();
H.activateToken("bleeding-edge");
@@ -871,6 +872,99 @@ describe("Remote Sync", () => {
});
});
});
+
+ describe("initial pull conflict handling", () => {
+ beforeEach(() => {
+ // Create a local transform that could be overwritten by the remote
+ H.createSqlTransform({
+ sourceQuery: "SELECT 1",
+ targetTable: "existing_transform",
+ targetSchema: "public",
+ name: "Batman's Existing Transform",
+ });
+
+ // Create the target table for the imported transform
+ H.queryWritableDB(
+ "CREATE TABLE IF NOT EXISTS imported_transform (column1 INT);",
+ );
+
+ // Resync the database so Metabase knows about the new table
+ H.resyncDatabase({
+ dbId: WRITABLE_DB_ID,
+ tableName: "imported_transform",
+ });
+
+ // Add collection to remote repository
+ H.copySyncedTransformsCollectionFixture();
+ H.commitToRepo();
+
+ // Set up in read-write mode without marking anything as synced and pull changes
+ H.configureGit("read-write");
+ });
+
+ it("shows conflict modal with available options when remote would override local", () => {
+ H.DataStudio.Transforms.visit();
+
+ cy.findByRole("treegrid").within(() => {
+ cy.findByText("Batman's Existing Transform").should("be.visible");
+ });
+
+ H.getPullOption().click();
+
+ cy.log("make sure conflict modal is displayed");
+ H.modal().within(() => {
+ cy.findByRole("heading", {
+ name: /Your local data will be overwritten by the remote branch/,
+ }).should("be.visible");
+ });
+ cy.findAllByRole("radio").should("have.length", 2);
+ cy.findByLabelText(/Create a new branch and push changes there/).should(
+ "be.visible",
+ );
+
+ cy.log("choose the delete option and pull");
+ cy.findByLabelText(/Delete unsynced changes/)
+ .should("be.visible")
+ .click();
+
+ cy.findByRole("button", { name: "Delete unsynced changes" }).click();
+
+ cy.findByRole("treegrid").within(() => {
+ cy.log(
+ "check existing transform was removed after pulling from remote",
+ );
+ cy.findByText("Batman's Existing Transform").should("not.exist");
+ cy.log("check remote transform was pulled in");
+ cy.findByText("Imported Simple SQL transform").should("be.visible");
+ });
+ });
+
+ it("can push to a new branch", () => {
+ cy.intercept("POST", "/api/ee/remote-sync/export").as("exportChanges");
+ H.DataStudio.Transforms.visit();
+ H.getPullOption().click();
+
+ cy.log("choose the new branch option and push");
+ cy.findByLabelText(/Create a new branch and push changes there/)
+ .should("be.visible")
+ .click();
+
+ cy.findByLabelText("Name for your new branch")
+ .should("be.visible")
+ .type("new-branch");
+
+ cy.findByRole("button", { name: "Push changes" }).click();
+
+ cy.wait("@exportChanges");
+ H.waitForTask({ taskName: "export" });
+
+ H.getGitSyncControls().should("have.text", "new-branch");
+
+ cy.findByRole("treegrid").within(() => {
+ cy.findByText("Batman's Existing Transform").should("be.visible");
+ });
+ });
+ });
});
const ensureSyncedCollectionIsVisible = () => {
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsx
index ad49ab9de56..d6f04e73d80 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsx
@@ -4,11 +4,14 @@ import { useCallback, useState } from "react";
import { t } from "ttag";
import { useToast } from "metabase/common/hooks";
+import { useDispatch, useSelector } from "metabase/lib/redux";
import { Button, Combobox, Icon, Loader, Text, useCombobox } from "metabase/ui";
import {
useGetHasRemoteChangesQuery,
useImportChangesMutation,
} from "metabase-enterprise/api";
+import { getSyncConflictVariant } from "metabase-enterprise/remote_sync/selectors";
+import { syncConflictVariantUpdated } from "metabase-enterprise/remote_sync/sync-task-slice";
import { trackBranchSwitched, trackPullChanges } from "../../analytics";
import { useGitSyncVisible } from "../../hooks/use-git-sync-visible";
@@ -16,10 +19,7 @@ import { useRemoteSyncDirtyState } from "../../hooks/use-remote-sync-dirty-state
import { useSyncStatus } from "../../hooks/use-sync-status";
import { type SyncError, parseSyncError } from "../../utils";
import { PushChangesModal } from "../PushChangesModal";
-import {
- SyncConflictModal,
- type SyncConflictVariant,
-} from "../SyncConflictModal";
+import { SyncConflictModal } from "../SyncConflictModal";
import { BranchDropdown } from "./BranchDropdown";
import S from "./GitSyncControls.module.css";
@@ -28,12 +28,12 @@ import { GitSyncOptionsDropdown } from "./GitSyncOptionsDropdown";
type DropdownView = "options" | "branch";
export const GitSyncControls = () => {
+ const dispatch = useDispatch();
+ const conflictVariant = useSelector(getSyncConflictVariant);
const { isVisible, currentBranch } = useGitSyncVisible();
const [importChanges, { isLoading: isImporting }] =
useImportChangesMutation();
- const [syncConflictVariant, setSyncConflictVariant] =
- useState<SyncConflictVariant>();
const { isRunning: isSyncTaskRunning } = useSyncStatus();
const [nextBranch, setNextBranch] = useState<string | null>(null);
@@ -91,7 +91,7 @@ export const GitSyncControls = () => {
const hasDirtyChanges = freshDirtyData.dirty.length > 0;
if (hasDirtyChanges && !isNewBranch) {
- setSyncConflictVariant("switch-branch");
+ dispatch(syncConflictVariantUpdated("switch-branch"));
} else {
await changeBranch(branch, isNewBranch);
setNextBranch(null);
@@ -105,7 +105,7 @@ export const GitSyncControls = () => {
setNextBranch(null);
}
},
- [currentBranch, changeBranch, refetchDirty, sendToast],
+ [currentBranch, refetchDirty, dispatch, changeBranch, sendToast],
);
const handlePushClick = useCallback(() => {
@@ -129,7 +129,7 @@ export const GitSyncControls = () => {
const { hasConflict, errorMessage } = parseSyncError(error as SyncError);
if (hasConflict) {
- setSyncConflictVariant("pull");
+ dispatch(syncConflictVariantUpdated("pull"));
return;
}
@@ -140,12 +140,12 @@ export const GitSyncControls = () => {
}
combobox.closeDropdown();
- }, [combobox, currentBranch, importChanges, sendToast]);
+ }, [combobox, currentBranch, dispatch, importChanges, sendToast]);
const handleCloseSyncConflictModal = useCallback(() => {
- setSyncConflictVariant(undefined);
+ dispatch(syncConflictVariantUpdated(null));
setNextBranch(null);
- }, []);
+ }, [dispatch]);
const handleSwitchBranchClick = useCallback(() => {
setDropdownView("branch");
@@ -225,12 +225,12 @@ export const GitSyncControls = () => {
/>
)}
- {syncConflictVariant && (
+ {conflictVariant && (
<SyncConflictModal
currentBranch={currentBranch}
nextBranch={nextBranch}
onClose={handleCloseSyncConflictModal}
- variant={syncConflictVariant}
+ variant={conflictVariant}
/>
)}
</>
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 9bea0af75fb..52d2cceb7cb 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
@@ -19,7 +19,7 @@ import {
FormSwitch,
FormTextInput,
} from "metabase/forms";
-import { useSelector } from "metabase/lib/redux";
+import { useDispatch, useSelector } from "metabase/lib/redux";
import { PLUGIN_TRANSFORMS } from "metabase/plugins";
import { getApplicationName } from "metabase/selectors/whitelabel";
import {
@@ -40,6 +40,9 @@ import {
useGetRemoteSyncChangesQuery,
useUpdateRemoteSyncSettingsMutation,
} from "metabase-enterprise/api/remote-sync";
+import { useGitSyncVisible } from "metabase-enterprise/remote_sync/hooks/use-git-sync-visible";
+import { getSyncConflictVariant } from "metabase-enterprise/remote_sync/selectors";
+import { syncConflictVariantUpdated } from "metabase-enterprise/remote_sync/sync-task-slice";
import type {
RemoteSyncConfigurationSettings,
SettingDefinition,
@@ -63,6 +66,7 @@ import {
URL_KEY,
} from "../../constants";
import { SharedTenantCollectionsList } from "../SharedTenantCollectionsList";
+import { SyncConflictModal } from "../SyncConflictModal";
import { TopLevelCollectionsList } from "../TopLevelCollectionsList";
import { PullChangesButton } from "./PullChangesButton";
@@ -94,7 +98,7 @@ export const RemoteSyncSettingsForm = (props: RemoteSyncSettingsFormProps) => {
const pendingConfirmationSettingsRef =
useRef<RemoteSyncConfigurationSettings | null>(null);
- const isRemoteSyncEnabled = useSetting(REMOTE_SYNC_KEY);
+ const isRemoteSyncEnabled = !!useSetting(REMOTE_SYNC_KEY);
const useTenants = useSetting("use-tenants");
const applicationName = useSelector(getApplicationName);
@@ -117,6 +121,9 @@ export const RemoteSyncSettingsForm = (props: RemoteSyncSettingsFormProps) => {
libraryCollectionData && "name" in libraryCollectionData
? libraryCollectionData
: undefined;
+ const dispatch = useDispatch();
+ const conflictVariant = useSelector(getSyncConflictVariant);
+ const { currentBranch } = useGitSyncVisible();
// Fetch tenant collections to build initial sync state
const { data: tenantCollectionsData } = useListCollectionItemsQuery(
@@ -335,7 +342,7 @@ export const RemoteSyncSettingsForm = (props: RemoteSyncSettingsFormProps) => {
},
);
- const hasUnsyncedChanges = !!dirtyData?.dirty?.length;
+ const hasUnsyncedChanges = !!dirtyData?.dirty?.length && isRemoteSyncEnabled;
return (
<>
@@ -550,6 +557,16 @@ export const RemoteSyncSettingsForm = (props: RemoteSyncSettingsFormProps) => {
{changeBranchConfirmationModal}
{disableConfirmationModal}
+
+ {!!conflictVariant && !!currentBranch && (
+ <SyncConflictModal
+ currentBranch={currentBranch}
+ onClose={() => {
+ dispatch(syncConflictVariantUpdated(null));
+ }}
+ variant={conflictVariant}
+ />
+ )}
</>
);
};
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/OutOfSyncOptions.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/OutOfSyncOptions.tsx
index fe75f11a2c2..1aea37b9bbb 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/OutOfSyncOptions.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/OutOfSyncOptions.tsx
@@ -2,14 +2,16 @@ import { useMemo } from "react";
import { c, t } from "ttag";
import { Box, Radio, Stack, Text } from "metabase/ui";
+import type { RemoteSyncConflictVariant } from "metabase-types/api";
-import type { OptionValue, SyncConflictVariant } from "./utils";
+import type { OptionValue } from "./utils";
interface BranchSwitchOptionsProps {
currentBranch: string;
handleOptionChange: (value: OptionValue) => void;
+ isRemoteSyncReadOnly: boolean;
optionValue?: OptionValue;
- variant: SyncConflictVariant;
+ variant: RemoteSyncConflictVariant;
}
interface OutOfSyncOption {
@@ -18,7 +20,14 @@ interface OutOfSyncOption {
}
export const OutOfSyncOptions = (props: BranchSwitchOptionsProps) => {
- const { currentBranch, handleOptionChange, optionValue, variant } = props;
+ const {
+ currentBranch,
+ handleOptionChange,
+ isRemoteSyncReadOnly,
+ optionValue,
+ variant,
+ } = props;
+
const options = useMemo<OutOfSyncOption[]>(() => {
const newBranchOption: OutOfSyncOption = {
value: "new-branch",
@@ -44,10 +53,16 @@ export const OutOfSyncOptions = (props: BranchSwitchOptionsProps) => {
return [newBranchOption, forcePushOption];
case "switch-branch":
return [pushOption, newBranchOption, discardOption];
+ case "setup":
+ return isRemoteSyncReadOnly
+ ? [discardOption]
+ : [newBranchOption, discardOption];
default: // pull
- return [forcePushOption, newBranchOption, discardOption];
+ return isRemoteSyncReadOnly
+ ? [discardOption]
+ : [forcePushOption, newBranchOption, discardOption];
}
- }, [currentBranch, variant]);
+ }, [currentBranch, isRemoteSyncReadOnly, variant]);
return (
<Box mt="xl">
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/OutOfSyncOptions.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/OutOfSyncOptions.unit.spec.tsx
new file mode 100644
index 00000000000..f795b91c573
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/OutOfSyncOptions.unit.spec.tsx
@@ -0,0 +1,100 @@
+import { render, screen } from "__support__/ui";
+import type { RemoteSyncConflictVariant } from "metabase-types/api";
+
+import { OutOfSyncOptions } from "./OutOfSyncOptions";
+
+type SetupOpts = {
+ isRemoteSyncReadOnly?: boolean;
+ variant: RemoteSyncConflictVariant;
+};
+
+const setup = ({ variant, isRemoteSyncReadOnly = false }: SetupOpts) => {
+ render(
+ <OutOfSyncOptions
+ currentBranch="main"
+ handleOptionChange={jest.fn}
+ isRemoteSyncReadOnly={isRemoteSyncReadOnly}
+ variant={variant}
+ />,
+ );
+};
+
+describe("OutOfSyncOptions", () => {
+ describe("push variant", () => {
+ it("shows correct options", () => {
+ setup({ variant: "push" });
+ expect(screen.getAllByRole("radio")).toHaveLength(2);
+ expect(
+ screen.getByLabelText(/Create a new branch and push changes there/),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByLabelText(
+ /Force push to main \(this will overwrite the remote branch\)/,
+ ),
+ ).toBeInTheDocument();
+ });
+ });
+
+ describe("switch-branch variant", () => {
+ it("shows correct options", () => {
+ setup({ variant: "switch-branch" });
+ expect(screen.getAllByRole("radio")).toHaveLength(3);
+ expect(
+ screen.getByLabelText(/Push changes to the current branch, main/),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByLabelText(/Create a new branch and push changes there/),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByLabelText(/Delete unsynced changes/),
+ ).toBeInTheDocument();
+ });
+ });
+
+ describe("pull variant (default)", () => {
+ it("shows correct options when remote sync is read-write", () => {
+ setup({ variant: "pull", isRemoteSyncReadOnly: false });
+ expect(screen.getAllByRole("radio")).toHaveLength(3);
+ expect(
+ screen.getByLabelText(
+ /Force push to main \(this will overwrite the remote branch\)/,
+ ),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByLabelText(/Create a new branch and push changes there/),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByLabelText(/Delete unsynced changes/),
+ ).toBeInTheDocument();
+ });
+
+ it("shows correct options when remote sync is read-only", () => {
+ setup({ variant: "pull", isRemoteSyncReadOnly: true });
+ expect(screen.getAllByRole("radio")).toHaveLength(1);
+ expect(
+ screen.getByLabelText(/Delete unsynced changes/),
+ ).toBeInTheDocument();
+ });
+ });
+
+ describe("setup variant", () => {
+ it("shows correct options when remote sync is read-write", () => {
+ setup({ variant: "setup", isRemoteSyncReadOnly: false });
+ expect(screen.getAllByRole("radio")).toHaveLength(2);
+ expect(
+ screen.getByLabelText(/Create a new branch and push changes there/),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByLabelText(/Delete unsynced changes/),
+ ).toBeInTheDocument();
+ });
+
+ it("shows correct options when remote sync is read-only", () => {
+ setup({ variant: "setup", isRemoteSyncReadOnly: true });
+ expect(screen.getAllByRole("radio")).toHaveLength(1);
+ expect(
+ screen.getByLabelText(/Delete unsynced changes/),
+ ).toBeInTheDocument();
+ });
+ });
+});
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/SetupConflictInfo.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/SetupConflictInfo.tsx
new file mode 100644
index 00000000000..8ef2d4ebc63
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/SetupConflictInfo.tsx
@@ -0,0 +1,52 @@
+import { useMemo } from "react";
+import { t } from "ttag";
+
+import { useSelector } from "metabase/lib/redux";
+import { Text } from "metabase/ui";
+import { getCurrentTask } from "metabase-enterprise/remote_sync/selectors";
+
+export const SetupConflictInfo = () => {
+ const conflictedEntityNames = useConflictedEntityNames();
+
+ return (
+ <>
+ <Text component="p">
+ {t`We detected your instance has unsynced items that will be overwritten by setting up Remote Sync.`}
+ </Text>
+ <Text component="p">
+ {t`What will be overwritten: `}
+ <Text component="em" display="inline" fw="bold" fs="normal">
+ {conflictedEntityNames}
+ </Text>
+ </Text>
+ </>
+ );
+};
+
+const useConflictedEntityNames = () => {
+ const currentTask = useSelector(getCurrentTask);
+
+ return useMemo(() => {
+ const conflictKeys = (currentTask?.conflicts || []).map((key) =>
+ key.toLowerCase(),
+ );
+ const names = [];
+ const conflictNameMap: Record<string, string> = {
+ transforms: t`Transforms`,
+ snippets: t`Snippets`,
+ library: t`Library`,
+ };
+
+ for (const conflictKey of conflictKeys) {
+ if (conflictNameMap[conflictKey]) {
+ names.push(conflictNameMap[conflictKey]);
+ }
+ }
+
+ if (!names?.length) {
+ return t`Library, Transforms and Snippets.`;
+ }
+
+ return names.join(", ");
+ }, [currentTask]);
+};
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/SyncConflictModal.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/SyncConflictModal.tsx
index bb86cae712d..0dce9e69082 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/SyncConflictModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/SyncConflictModal.tsx
@@ -1,13 +1,39 @@
-import { useMemo, useState } from "react";
+import { useCallback, useMemo, useState } from "react";
import { t } from "ttag";
+import {
+ useGetAdminSettingsDetailsQuery,
+ useGetSettingsQuery,
+} from "metabase/api";
+import { useSetting } from "metabase/common/hooks";
+import { useSelector } from "metabase/lib/redux";
+import { useMetadataToasts } from "metabase/metadata/hooks";
import { Box, Button, Group, Icon, Modal } from "metabase/ui";
-import { useGetBranchesQuery } from "metabase-enterprise/api";
+import {
+ useGetBranchesQuery,
+ useUpdateRemoteSyncSettingsMutation,
+} from "metabase-enterprise/api";
+import { useGetLibraryCollection } from "metabase-enterprise/data-studio/library/utils";
+import {
+ BRANCH_KEY,
+ COLLECTIONS_KEY,
+ REMOTE_SYNC_KEY,
+ TOKEN_KEY,
+ TRANSFORMS_KEY,
+ TYPE_KEY,
+ URL_KEY,
+} from "metabase-enterprise/remote_sync/constants";
+import { getIsRemoteSyncReadOnly } from "metabase-enterprise/remote_sync/selectors";
+import type {
+ RemoteSyncConfigurationSettings,
+ RemoteSyncConflictVariant,
+} from "metabase-types/api";
import { ChangesLists } from "../ChangesLists";
import { BranchNameInput } from "./BranchNameInput";
import { OutOfSyncOptions } from "./OutOfSyncOptions";
+import { SetupConflictInfo } from "./SetupConflictInfo";
import {
useDiscardChangesAndImportAction,
usePushChangesAction,
@@ -15,32 +41,76 @@ import {
} from "./mutation-wrappers";
import {
type OptionValue,
- type SyncConflictVariant,
getContinueButtonText,
+ getModalTitle,
} from "./utils";
interface UnsyncedWarningModalProps {
currentBranch: string;
nextBranch?: string | null;
onClose: VoidFunction;
- variant: SyncConflictVariant;
+ variant: RemoteSyncConflictVariant;
}
export const SyncConflictModal = (props: UnsyncedWarningModalProps) => {
const { onClose, currentBranch, nextBranch, variant } = props;
const [optionValue, setOptionValue] = useState<OptionValue>();
const [newBranchName, setNewBranchName] = useState<string>("");
+ const { sendErrorToast } = useMetadataToasts();
+ const isRemoteSyncEnabled = !!useSetting(REMOTE_SYNC_KEY);
+ const isRemoteSyncReadOnly = useSelector(getIsRemoteSyncReadOnly);
+ const { data: settingValues } = useGetSettingsQuery();
+ const { data: settingDetails } = useGetAdminSettingsDetailsQuery();
+ const { data: libraryCollection } = useGetLibraryCollection({
+ skip: !isRemoteSyncEnabled,
+ });
const { data: branchesData } = useGetBranchesQuery();
const existingBranches = useMemo(
() => branchesData?.items || [],
[branchesData],
);
+ const [updateRemoteSyncSettings, { isLoading: isUpdatingSettings }] =
+ useUpdateRemoteSyncSettingsMutation();
const { pushChanges, isPushingChanges } = usePushChangesAction();
const { stashToNewBranch, isStashing } =
useStashToNewBranchAction(existingBranches);
const { discardChangesAndImport, isImporting } =
useDiscardChangesAndImportAction();
+ const markLibraryAndTransformsAsSynced = useCallback(async () => {
+ try {
+ const remoteSyncSettings: RemoteSyncConfigurationSettings = {
+ [URL_KEY]: settingDetails?.[URL_KEY]?.value || null,
+ [TOKEN_KEY]: settingDetails?.[TOKEN_KEY]?.value || null,
+ [BRANCH_KEY]: settingValues?.[BRANCH_KEY] || null,
+ [TYPE_KEY]: settingValues?.[TYPE_KEY] || null,
+ [COLLECTIONS_KEY]: (settingValues as RemoteSyncConfigurationSettings)[
+ COLLECTIONS_KEY
+ ],
+ [REMOTE_SYNC_KEY]: true,
+ [TRANSFORMS_KEY]: true,
+ };
+
+ if (libraryCollection?.id) {
+ remoteSyncSettings[COLLECTIONS_KEY] = {
+ ...remoteSyncSettings[COLLECTIONS_KEY],
+ [libraryCollection.id]: !!libraryCollection?.id,
+ };
+ }
+
+ await updateRemoteSyncSettings(remoteSyncSettings).unwrap();
+ } catch (error) {
+ sendErrorToast(t`Failed to mark library and transforms as synced`);
+ throw error;
+ }
+ }, [
+ libraryCollection?.id,
+ sendErrorToast,
+ settingDetails,
+ settingValues,
+ updateRemoteSyncSettings,
+ ]);
+
const handleContinueButtonClick = async () => {
if (!optionValue) {
return;
@@ -51,6 +121,10 @@ export const SyncConflictModal = (props: UnsyncedWarningModalProps) => {
}
if (optionValue === "new-branch") {
+ if (variant === "setup") {
+ await markLibraryAndTransformsAsSynced();
+ }
+
await stashToNewBranch(newBranchName, onClose);
}
@@ -59,7 +133,8 @@ export const SyncConflictModal = (props: UnsyncedWarningModalProps) => {
}
};
- const isProcessing = isImporting || isPushingChanges || isStashing;
+ const isProcessing =
+ isImporting || isPushingChanges || isStashing || isUpdatingSettings;
const isButtonDisabled = useMemo(() => {
let disabled = !optionValue || isProcessing;
@@ -74,26 +149,18 @@ export const SyncConflictModal = (props: UnsyncedWarningModalProps) => {
<Modal
onClose={onClose}
opened
- title={
- variant === "push" ? (
- <>
- {t`Your branch is behind the remote branch.`}{" "}
- {t`What do you want to do?`}
- </>
- ) : (
- t`You have unsynced changes. What do you want to do?`
- )
- }
padding="xl"
styles={{ title: { lineHeight: "2rem" } }}
+ title={getModalTitle(variant)}
withCloseButton={false}
>
<Box pt="md">
- <ChangesLists />
+ {variant === "setup" ? <SetupConflictInfo /> : <ChangesLists />}
<OutOfSyncOptions
currentBranch={currentBranch}
handleOptionChange={setOptionValue}
+ isRemoteSyncReadOnly={isRemoteSyncReadOnly}
optionValue={optionValue}
variant={variant}
/>
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/index.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/index.ts
index 330811e7a81..83a10c33a56 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/index.ts
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/index.ts
@@ -1,2 +1 @@
export { SyncConflictModal } from "./SyncConflictModal";
-export type { SyncConflictVariant } from "./utils";
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/mutation-wrappers.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/mutation-wrappers.ts
index e3ab6d60d8c..e91405cbd06 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/mutation-wrappers.ts
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/mutation-wrappers.ts
@@ -35,8 +35,7 @@ export const usePushChangesAction = () => {
sendToast({
message: c("{0} is the GitHub branch name")
- .t`Changes pushed to branch ${branch} successfully.`,
- timeout: 8000,
+ .t`Pushing changes to branch ${branch}...`,
});
closeModal();
} catch (error) {
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/utils.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/utils.ts
deleted file mode 100644
index a11e839884f..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/utils.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import { t } from "ttag";
-
-export type OptionValue = "push" | "force-push" | "new-branch" | "discard";
-export type SyncConflictVariant = "push" | "pull" | "switch-branch";
-
-export const getContinueButtonText = (optionValue?: OptionValue) => {
- switch (optionValue) {
- case "push":
- case "force-push":
- case "new-branch":
- return t`Push changes`;
- case "discard":
- return t`Delete unsynced changes`;
- default:
- return t`Continue`;
- }
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/utils.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/utils.tsx
new file mode 100644
index 00000000000..36f80be4f6f
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/utils.tsx
@@ -0,0 +1,42 @@
+import type { ReactNode } from "react";
+import { t } from "ttag";
+
+import type { RemoteSyncConflictVariant } from "metabase-types/api";
+
+export type OptionValue = "push" | "force-push" | "new-branch" | "discard";
+
+export const getContinueButtonText = (optionValue?: OptionValue) => {
+ switch (optionValue) {
+ case "push":
+ case "force-push":
+ case "new-branch":
+ return t`Push changes`;
+ case "discard":
+ return t`Delete unsynced changes`;
+ default:
+ return t`Continue`;
+ }
+};
+
+export const getModalTitle = (
+ variant: RemoteSyncConflictVariant,
+): ReactNode => {
+ switch (variant) {
+ case "push":
+ return (
+ <>
+ {t`Your branch is behind the remote branch.`}{" "}
+ {t`What do you want to do?`}
+ </>
+ );
+ case "setup":
+ return (
+ <>
+ {t`Your local data will be overwritten by the remote branch.`}{" "}
+ {t`What do you want to do?`}
+ </>
+ );
+ default:
+ return t`You have unsynced changes. What do you want to do?`;
+ }
+};
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts
index d062ba0d56b..f8309adc63c 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.ts
@@ -11,6 +11,7 @@ import type { State } from "metabase-types/store";
import { REMOTE_SYNC_INVALIDATION_TAGS } from "../constants";
import {
modalDismissed,
+ syncConflictVariantUpdated,
taskCleared,
taskStarted,
taskUpdated,
@@ -117,6 +118,12 @@ remoteSyncListenerMiddleware.startListening({
if (task) {
dispatch(taskUpdated(task));
+ if (task.status === "conflict") {
+ dispatch(modalDismissed());
+ dispatch(syncConflictVariantUpdated("setup"));
+ return;
+ }
+
const isTerminalState = terminalTaskStates.includes(task.status);
if (isTerminalState && task.ended_at) {
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.unit.spec.ts
index 2c56c158cd2..c1b0efc1898 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.unit.spec.ts
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/middleware/remote-sync-listener-middleware.unit.spec.ts
@@ -1,4 +1,5 @@
import { combineReducers, configureStore } from "@reduxjs/toolkit";
+import { waitFor } from "@testing-library/react";
import fetchMock from "fetch-mock";
import {
@@ -246,6 +247,35 @@ describe("remote-sync-listener-middleware", () => {
expect(state.remoteSyncPlugin?.showModal).toBe(false);
expect(state.remoteSyncPlugin?.currentTask).toBeNull();
});
+
+ it("should set conflict variant to 'setup' when import fails with conflict", async () => {
+ fetchMock.get("path:/api/ee/remote-sync/current-task", {
+ status: 200,
+ body: {
+ status: "conflict",
+ },
+ });
+
+ const store = createTestStore();
+
+ // Dispatch the mutation
+ store.dispatch(
+ remoteSyncApi.endpoints.getRemoteSyncCurrentTask.initiate(),
+ );
+
+ // Wait for the request to fail
+ await waitForCondition(() =>
+ fetchMock.callHistory.done("path:/api/ee/remote-sync/current-task"),
+ );
+
+ expect(store.getState().remoteSyncPlugin?.showModal).toBe(false);
+
+ await waitFor(() => {
+ expect(store.getState().remoteSyncPlugin?.syncConflictVariant).toBe(
+ "setup",
+ );
+ });
+ });
});
describe("collection listeners for transforms namespace", () => {
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/selectors.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/selectors.ts
index 5b63f6e32c7..2d30139aad4 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/selectors.ts
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/selectors.ts
@@ -67,3 +67,8 @@ export const getIsRemoteSyncReadOnly = (state: State): boolean => {
getSetting(state, "remote-sync-type") === "read-only"
);
};
+
+export const getSyncConflictVariant = createSelector(
+ getRemoteSyncState,
+ (state) => state.syncConflictVariant,
+);
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/sync-task-slice.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/sync-task-slice.ts
index f1b81bc2fde..cf83e8d374c 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/sync-task-slice.ts
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/sync-task-slice.ts
@@ -1,15 +1,21 @@
import { createSlice } from "@reduxjs/toolkit";
-import type { RemoteSyncTask, RemoteSyncTaskType } from "metabase-types/api";
+import type {
+ RemoteSyncConflictVariant,
+ RemoteSyncTask,
+ RemoteSyncTaskType,
+} from "metabase-types/api";
export interface SyncTaskState {
currentTask: RemoteSyncTask | null;
showModal: boolean;
+ syncConflictVariant: RemoteSyncConflictVariant | null;
}
export const initialState: SyncTaskState = {
currentTask: null,
showModal: false,
+ syncConflictVariant: null,
};
export const remoteSyncSlice = createSlice({
@@ -52,10 +58,21 @@ export const remoteSyncSlice = createSlice({
state.currentTask = null;
state.showModal = false;
},
+ syncConflictVariantUpdated: (
+ state,
+ action: { payload: RemoteSyncConflictVariant | null },
+ ) => {
+ state.syncConflictVariant = action.payload;
+ },
},
});
-export const { taskStarted, taskUpdated, modalDismissed, taskCleared } =
- remoteSyncSlice.actions;
+export const {
+ taskStarted,
+ taskUpdated,
+ modalDismissed,
+ taskCleared,
+ syncConflictVariantUpdated,
+} = remoteSyncSlice.actions;
export const remoteSyncReducer = remoteSyncSlice.reducer;
diff --git a/frontend/src/metabase-types/api/remote-sync.ts b/frontend/src/metabase-types/api/remote-sync.ts
index c9cf93d8006..aa3d1979966 100644
--- a/frontend/src/metabase-types/api/remote-sync.ts
+++ b/frontend/src/metabase-types/api/remote-sync.ts
@@ -100,6 +100,7 @@ export type RemoteSyncTaskStatus =
| "successful"
| "timed-out"
| "cancelled"
+ | "conflict"
| "errored";
export type RemoteSyncTaskType = "import" | "export" | null;
@@ -114,8 +115,15 @@ export type RemoteSyncTask = {
last_progress_report_at: string | null;
error_message: string | null;
initiated_by: UserId;
+ conflicts?: string[];
};
+export type RemoteSyncConflictVariant =
+ | "push" // Conflict when pushing (need to pull from remote first)
+ | "pull" // Conflict when pulling (need to sync local changes)
+ | "switch-branch" // Conflict when switching branches
+ | "setup"; // Conflict when setting up or pulling for the first time
+
export type GetBranchesResponse = {
items: string[];
};