Skip to content

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

Improvements to pro-self-hosted to cloud migration flow (#66806)

Benoit Vinay4adf66e56cd5
diff --git a/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.tsx b/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.tsx
index a6697267210..d4136550c1f 100644
--- a/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.tsx
+++ b/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.tsx
@@ -6,8 +6,10 @@ import {
} from "metabase/api";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import { useStoreUrl } from "metabase/common/hooks";
-import { useDispatch } from "metabase/lib/redux";
+import { type Plan, getPlan } from "metabase/common/utils/plan";
+import { useDispatch, useSelector } from "metabase/lib/redux";
import { refreshSiteSettings } from "metabase/redux/settings";
+import { getSetting } from "metabase/selectors/settings";
import { Box } from "metabase/ui";
import type { CloudMigration } from "metabase-types/api/cloud-migration";
@@ -26,7 +28,11 @@ import {
interface CloudPanelProps {
getPollingInterval?: (migration: CloudMigration) => number | undefined;
- onMigrationStart?: (checkoutUrl: string, migration: CloudMigration) => void;
+ onMigrationStart?: (
+ storeUrl: string,
+ plan: Plan,
+ migration: CloudMigration,
+ ) => void;
}
export const CloudPanel = ({
@@ -71,12 +77,15 @@ export const CloudPanel = ({
const [createCloudMigration, createCloudMigrationResult] =
useCreateCloudMigrationMutation();
- const checkoutUrl = useStoreUrl("checkout");
+ const storeUrl = useStoreUrl("checkout");
+ const plan = useSelector((state) =>
+ getPlan(getSetting(state, "token-features")),
+ );
const handleCreateMigration = async () => {
const newMigration = await createCloudMigration().unwrap();
await dispatch(refreshSiteSettings());
- onMigrationStart(checkoutUrl, newMigration);
+ onMigrationStart(storeUrl, plan, newMigration);
};
return (
@@ -90,17 +99,19 @@ export const CloudPanel = ({
<Box>
{migration && isInProgressMigration(migration) && (
<MigrationInProgress
+ storeUrl={storeUrl}
+ plan={plan}
migration={migration}
- checkoutUrl={checkoutUrl}
/>
)}
{migration && migrationState === "done" && (
<MigrationSuccess
+ storeUrl={storeUrl}
+ plan={plan}
migration={migration}
restartMigration={handleCreateMigration}
isRestarting={createCloudMigrationResult.isLoading}
- checkoutUrl={checkoutUrl}
/>
)}
diff --git a/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.unit.spec.tsx
index 1a4d387866d..87f251c9f0b 100644
--- a/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.unit.spec.tsx
+++ b/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.unit.spec.tsx
@@ -6,6 +6,7 @@ import {
setupPropertiesEndpoints,
} from "__support__/server-mocks";
import { renderWithProviders, screen, waitFor, within } from "__support__/ui";
+import { getPlan } from "metabase/common/utils/plan";
import type { CloudMigration } from "metabase-types/api/cloud-migration";
import { createMockSettings, createMockUser } from "metabase-types/api/mocks";
import { createMockState } from "metabase-types/store/mocks";
@@ -29,8 +30,9 @@ const setup = () => {
},
);
- const STORE_URL = store.getState().settings.values["store-url"];
- const metabaseStoreLink = `${STORE_URL}/checkout?migration-id=${BASE_RESPONSE.external_id}`;
+ const storeUrl = store.getState().settings.values["store-url"];
+ const plan = getPlan(store.getState().settings.values["token-features"]);
+ const metabaseStoreLink = `${storeUrl}/checkout?migration-source-plan=${plan}&migration-id=${BASE_RESPONSE.external_id}`;
return { mockMigrationStart, store, metabaseStoreLink };
};
@@ -242,7 +244,7 @@ const expectStartConfirmationModal = async () => {
).toBeInTheDocument();
};
-const expectProgressState = async (STORE_LINK: string) => {
+const expectProgressState = async (storeUrl: string) => {
expect(
await screen.findByText("Migrating to Metabase Cloud…"),
).toBeInTheDocument();
@@ -250,16 +252,16 @@ const expectProgressState = async (STORE_LINK: string) => {
// expect to have correct store link for this exact migration
const storeLink = screen.getByRole("link", { name: /Metabase Store/ });
expect(storeLink).toBeInTheDocument();
- expect(storeLink).toHaveAttribute("href", STORE_LINK);
+ expect(storeLink).toHaveAttribute("href", storeUrl);
};
-const expectSuccessState = async (STORE_LINK: string) => {
+const expectSuccessState = async (storeUrl: string) => {
expect(
await screen.findByText("The snapshot has been uploaded to the Cloud"),
).toBeInTheDocument();
expect(
screen.getByRole("link", { name: /Go to Metabase Store/ }),
- ).toHaveAttribute("href", STORE_LINK);
+ ).toHaveAttribute("href", storeUrl);
};
const expectCancelConfirmationModal = async () => {
diff --git a/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationInProgress.tsx b/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationInProgress.tsx
index c1f774b55a6..9e5423c7379 100644
--- a/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationInProgress.tsx
+++ b/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationInProgress.tsx
@@ -5,6 +5,7 @@ import { useCancelCloudMigrationMutation } from "metabase/api";
import ExternalLink from "metabase/common/components/ExternalLink";
import { useSetting } from "metabase/common/hooks";
import { useToggle } from "metabase/common/hooks/use-toggle";
+import type { Plan } from "metabase/common/utils/plan";
import { useDispatch } from "metabase/lib/redux";
import { addUndo } from "metabase/redux/undo";
import {
@@ -23,8 +24,9 @@ import type { InProgressCloudMigration, InProgressStates } from "./utils";
import { getMigrationUrl } from "./utils";
interface MigrationInProgressProps {
+ storeUrl: string;
+ plan: Plan;
migration: InProgressCloudMigration;
- checkoutUrl: string;
}
const progressMessage: Record<InProgressStates, string> = {
@@ -35,8 +37,9 @@ const progressMessage: Record<InProgressStates, string> = {
};
export const MigrationInProgress = ({
+ storeUrl,
+ plan,
migration,
- checkoutUrl,
}: MigrationInProgressProps) => {
const dispatch = useDispatch();
@@ -59,7 +62,7 @@ export const MigrationInProgress = ({
);
};
- const migrationUrl = getMigrationUrl(checkoutUrl, migration);
+ const migrationUrl = getMigrationUrl(storeUrl, plan, migration);
return (
<>
diff --git a/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationSuccess.tsx b/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationSuccess.tsx
index a55f1fd2d75..fca389236ae 100644
--- a/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationSuccess.tsx
+++ b/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationSuccess.tsx
@@ -1,6 +1,7 @@
import { t } from "ttag";
import ExternalLink from "metabase/common/components/ExternalLink";
+import type { Plan } from "metabase/common/utils/plan";
import { color } from "metabase/lib/colors";
import { Box, Button, Flex, Icon, Text } from "metabase/ui";
import type { CloudMigration } from "metabase-types/api/cloud-migration";
@@ -9,20 +10,22 @@ import { LargeIconContainer, MigrationCard } from "./CloudPanel.styled";
import { getMigrationEventTime, getMigrationUrl } from "./utils";
interface MigrationSuccessProps {
+ storeUrl: string;
+ plan: Plan;
migration: CloudMigration;
restartMigration: () => void;
isRestarting: boolean;
- checkoutUrl: string;
}
export const MigrationSuccess = ({
+ storeUrl,
+ plan,
migration,
restartMigration,
isRestarting,
- checkoutUrl,
}: MigrationSuccessProps) => {
const uploadedAt = getMigrationEventTime(migration.updated_at);
- const migrationUrl = getMigrationUrl(checkoutUrl, migration);
+ const migrationUrl = getMigrationUrl(storeUrl, plan, migration);
return (
<>
diff --git a/frontend/src/metabase/admin/settings/components/CloudPanel/utils.ts b/frontend/src/metabase/admin/settings/components/CloudPanel/utils.ts
index 03a2dc87d34..ee16d09500e 100644
--- a/frontend/src/metabase/admin/settings/components/CloudPanel/utils.ts
+++ b/frontend/src/metabase/admin/settings/components/CloudPanel/utils.ts
@@ -1,5 +1,6 @@
import dayjs from "dayjs";
+import type { Plan } from "metabase/common/utils/plan";
import type {
CloudMigration,
CloudMigrationState,
@@ -70,16 +71,18 @@ export const getMigrationEventTime = (isoString: string) =>
dayjs(isoString).format("MMMM DD, YYYY, hh:mm A");
export const openCheckoutInNewTab = (
- checkoutUrl: string,
+ storeUrl: string,
+ plan: Plan,
migration: CloudMigration,
) => {
- const migrationUrl = getMigrationUrl(checkoutUrl, migration);
+ const migrationUrl = getMigrationUrl(storeUrl, plan, migration);
window.open(migrationUrl, "_blank")?.focus();
};
export function getMigrationUrl(
- checkoutUrl: string,
+ storeUrl: string,
+ plan: Plan,
migration: CloudMigration,
) {
- return `${checkoutUrl}?migration-id=${migration.external_id}`;
+ return `${storeUrl}?migration-source-plan=${plan}&migration-id=${migration.external_id}`;
}