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
allow disabling remote sync (#65175)
Aleksandr Lesnenko785c4185786e
diff --git a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts b/e2e/test/scenarios/admin/remote-sync.cy.spec.tsindex 75932c0c2c1..589db9179b8 100644--- a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts+++ b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts@@ -489,6 +489,35 @@ describe("Remote Sync", () => {).should("exist");});++ it("can deactivate remote sync", () => {+ H.copyLibraryFixture();+ H.commitToLibrary();+ H.configureGit("development");++ cy.visit("/admin/settings/remote-sync");++ cy.findByTestId("admin-layout-content")+ .findByText("Enabled")+ .should("exist");++ cy.button("Disable Remote Sync").click();++ H.modal().within(() => {+ cy.findByRole("heading", { name: "Disable Remote Sync?" }).should(+ "exist",+ );+ cy.button("Disable").click();+ });++ cy.findByTestId("admin-layout-content")+ .findByText("Enabled")+ .should("not.exist");++ cy.findByTestId("exit-admin").click();++ ensureLibraryCollectionIsVisible();+ });});describe("production mode", () => {@@ -545,3 +574,9 @@ describe("Remote Sync", () => {});});});++const ensureLibraryCollectionIsVisible = () => {+ H.navigationSidebar().within(() => {+ cy.findByRole("treeitem", { name: /Library/ }).should("exist");+ });+};diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncAdminSettings.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncAdminSettings.tsxindex 644588fb828..22e7bea45c2 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncAdminSettings.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncAdminSettings.tsx@@ -24,6 +24,7 @@ import {import {Badge,Box,+ Button,Flex,Radio,Stack,@@ -69,6 +70,11 @@ export const RemoteSyncAdminSettings = () => {} = useConfirmation();const [sendToast] = useToast();+ const {+ show: showDisableConfirmation,+ modalContent: disableConfirmationModal,+ } = useConfirmation();+const handleSubmit = useCallback(async (values: RemoteSyncConfigurationSettings) => {const didBranchChange =@@ -118,6 +124,30 @@ export const RemoteSyncAdminSettings = () => {],);+ const handleDisable = useCallback(async () => {+ showDisableConfirmation({+ title: t`Disable Remote Sync?`,+ message: t`This will clear all remote sync settings. Any changes made to the Library collection after disabling can be overwritten if you enable sync again.`,+ confirmButtonText: t`Disable`,+ confirmButtonProps: {+ variant: "filled",+ color: "danger",+ },+ onConfirm: async () => {+ try {+ await updateRemoteSyncSettings({ [URL_KEY]: "" }).unwrap();+ sendToast({ message: t`Remote Sync disabled`, icon: "check" });+ } catch (error) {+ console.error(error);+ sendToast({+ message: t`Failed to disable Remote Sync`,+ icon: "warning",+ });+ }+ },+ });+ }, [updateRemoteSyncSettings, sendToast, showDisableConfirmation]);+const initialValues = useMemo(() => {const values = REMOTE_SYNC_SCHEMA.cast(settingValues, {stripUnknown: true,@@ -249,6 +279,11 @@ export const RemoteSyncAdminSettings = () => {<Flex justify="end" align="center" gap="md"><FormErrorMessage />+ {isRemoteSyncEnabled && (+ <Button onClick={handleDisable}>+ {t`Disable Remote Sync`}+ </Button>+ )}<FormSubmitButtonlabel={isRemoteSyncEnabled@@ -268,6 +303,7 @@ export const RemoteSyncAdminSettings = () => {</SettingsSection>{changeBranchConfirmationModal}+ {disableConfirmationModal}</SettingsPageWrapper>);};diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsxindex 58ffc5a49cd..598a42a72f4 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsx@@ -19,7 +19,7 @@ import {useImportChangesMutation,} from "metabase-enterprise/api";-import { BRANCH_KEY } from "../../constants";+import { BRANCH_KEY, REMOTE_SYNC_KEY } from "../../constants";import { useSyncStatus } from "../../hooks/use-sync-status";import {SyncConflictModal,@@ -45,6 +45,7 @@ export const SyncedCollectionsSidebarSection = ({const hasSyncedCollections = syncedCollections.length > 0;const isAdmin = useSelector(getUserIsAdmin);+ const { value: isRemoteSyncEnabled } = useAdminSetting(REMOTE_SYNC_KEY);const { value: currentBranch } = useAdminSetting(BRANCH_KEY);const [importChanges] = useImportChangesMutation();const [syncConflictVariant, setSyncConflictVariant] =@@ -108,6 +109,10 @@ export const SyncedCollectionsSidebarSection = ({const isSwitchingBranch = !!nextBranch;+ if (!isRemoteSyncEnabled) {+ return null;+ }+return (<><SidebarSection>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.tsindex 03df3296fa1..8d9c6e9def1 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@@ -5,6 +5,7 @@ import { Api } from "metabase/api";import { cardApi } from "metabase/api/card";import { collectionApi } from "metabase/api/collection";import { dashboardApi } from "metabase/api/dashboard";+import { tag } from "metabase/api/tags";import { timelineApi } from "metabase/api/timeline";import { timelineEventApi } from "metabase/api/timeline-event";import type {@@ -32,6 +33,41 @@ function invalidateRemoteSyncTags(dispatch: any) {dispatch(Api.util.invalidateTags(REMOTE_SYNC_INVALIDATION_TAGS as any));}+function isDeactivatingRemoteSync(action: any): boolean {+ const settings = action.meta?.arg?.originalArgs;+ return settings?.["remote-sync-url"] === "";+}++const ALL_INVALIDATION_TAGS = [+ tag("action"),+ tag("alert"),+ tag("bookmark"),+ tag("card"),+ tag("channel"),+ tag("collection"),+ tag("collection-tree"),+ tag("content-translation"),+ tag("dashboard"),+ tag("dashboard-question-candidates"),+ tag("document"),+ tag("embed-card"),+ tag("embed-dashboard"),+ tag("indexed-entity"),+ tag("notification"),+ tag("parameter-values"),+ tag("public-action"),+ tag("public-card"),+ tag("public-dashboard"),+ tag("revision"),+ tag("segment"),+ tag("session-properties"),+ tag("snippet"),+ tag("subscription"),+ tag("subscription-channel"),+ tag("timeline"),+ tag("timeline-event"),+];+function shouldInvalidateForEntity(oldEntity: Card | Dashboard | Document | undefined,newEntity: Card | Dashboard | Document,@@ -272,15 +308,21 @@ remoteSyncListenerMiddleware.startListening({});remoteSyncListenerMiddleware.startListening({- matcher: isAnyOf(- remoteSyncApi.endpoints.importChanges.matchPending,- remoteSyncApi.endpoints.updateRemoteSyncSettings.matchPending,- ),+ matcher: remoteSyncApi.endpoints.importChanges.matchPending,effect: async (_action, { dispatch }) => {dispatch(taskStarted({ taskType: "import" }));},});+remoteSyncListenerMiddleware.startListening({+ matcher: remoteSyncApi.endpoints.updateRemoteSyncSettings.matchPending,+ effect: async (action, { dispatch }) => {+ if (!isDeactivatingRemoteSync(action)) {+ dispatch(taskStarted({ taskType: "import" }));+ }+ },+});+remoteSyncListenerMiddleware.startListening({matcher: isAnyOf(remoteSyncApi.endpoints.importChanges.matchRejected,@@ -318,37 +360,7 @@ remoteSyncListenerMiddleware.startListening({}, 500);if (isImportTask) {- dispatch(- Api.util.invalidateTags([- "action",- "alert",- "bookmark",- "card",- "channel",- "collection",- "collection-tree",- "content-translation",- "dashboard",- "dashboard-question-candidates",- "document",- "embed-card",- "embed-dashboard",- "indexed-entity",- "notification",- "parameter-values",- "public-action",- "public-card",- "public-dashboard",- "revision",- "segment",- "session-properties",- "snippet",- "subscription",- "subscription-channel",- "timeline",- "timeline-event",- ]),- );+ dispatch(Api.util.invalidateTags(ALL_INVALIDATION_TAGS));}}diff --git a/frontend/src/metabase-types/api/settings.ts b/frontend/src/metabase-types/api/settings.tsindex bf76c27f867..66b0545820e 100644--- a/frontend/src/metabase-types/api/settings.ts+++ b/frontend/src/metabase-types/api/settings.ts@@ -648,6 +648,7 @@ export interface EnterpriseSettings extends Settings {"remote-sync-url"?: string | null;"remote-sync-branch"?: string | null;"remote-sync-type"?: "production" | "development" | null;+ "remote-sync-auto-import"?: boolean | null;"login-page-illustration"?: IllustrationSettingValue;"login-page-illustration-custom"?: string;"landing-page-illustration"?: IllustrationSettingValue;