Skip to content

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

Migrate last direct usage of settings store url, to useStoreUrl (#63771)

Jakub Chodorowicze4d0318213f7
diff --git a/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.tsx b/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.tsx
index 7dd1a86aba2..a6697267210 100644
--- a/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.tsx
+++ b/frontend/src/metabase/admin/settings/components/CloudPanel/CloudPanel.tsx
@@ -1,11 +1,11 @@
-import { useEffect, useMemo, useState } from "react";
+import { useEffect, useState } from "react";
import {
useCreateCloudMigrationMutation,
useGetCloudMigrationQuery,
} from "metabase/api";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { useSetting } from "metabase/common/hooks";
+import { useStoreUrl } from "metabase/common/hooks";
import { useDispatch } from "metabase/lib/redux";
import { refreshSiteSettings } from "metabase/redux/settings";
import { Box } from "metabase/ui";
@@ -26,7 +26,7 @@ import {
interface CloudPanelProps {
getPollingInterval?: (migration: CloudMigration) => number | undefined;
- onMigrationStart?: (storeUrl: string, migration: CloudMigration) => void;
+ onMigrationStart?: (checkoutUrl: string, migration: CloudMigration) => void;
}
export const CloudPanel = ({
@@ -68,21 +68,15 @@ export const CloudPanel = ({
[dispatch, migrationState],
);
- const storeUrl = useSetting("store-url");
-
- const checkoutUrl = useMemo(() => {
- return migration
- ? `${storeUrl}/checkout?migration-id=${migration.external_id}`
- : `${storeUrl}/checkout`;
- }, [migration, storeUrl]);
-
const [createCloudMigration, createCloudMigrationResult] =
useCreateCloudMigrationMutation();
+ const checkoutUrl = useStoreUrl("checkout");
+
const handleCreateMigration = async () => {
const newMigration = await createCloudMigration().unwrap();
await dispatch(refreshSiteSettings());
- onMigrationStart(storeUrl, newMigration);
+ onMigrationStart(checkoutUrl, newMigration);
};
return (
diff --git a/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationInProgress.tsx b/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationInProgress.tsx
index 1a39d4009a5..f9630359639 100644
--- a/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationInProgress.tsx
+++ b/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationInProgress.tsx
@@ -21,6 +21,7 @@ import {
import { MigrationCard } from "./CloudPanel.styled";
import type { InProgressCloudMigration, InProgressStates } from "./utils";
+import { getMigrationUrl } from "./utils";
interface MigrationInProgressProps {
migration: InProgressCloudMigration;
@@ -59,6 +60,8 @@ export const MigrationInProgress = ({
);
};
+ const migrationUrl = getMigrationUrl(checkoutUrl, migration);
+
return (
<>
<MigrationCard>
@@ -103,7 +106,7 @@ export const MigrationInProgress = ({
<Button
mt="md"
component={ExternalLink}
- href={checkoutUrl}
+ href={migrationUrl}
variant="filled"
>{t`Go to Metabase Store`}</Button>
</Flex>
diff --git a/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationSuccess.tsx b/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationSuccess.tsx
index 3b49c0ad259..a55f1fd2d75 100644
--- a/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationSuccess.tsx
+++ b/frontend/src/metabase/admin/settings/components/CloudPanel/MigrationSuccess.tsx
@@ -6,7 +6,7 @@ import { Box, Button, Flex, Icon, Text } from "metabase/ui";
import type { CloudMigration } from "metabase-types/api/cloud-migration";
import { LargeIconContainer, MigrationCard } from "./CloudPanel.styled";
-import { getMigrationEventTime } from "./utils";
+import { getMigrationEventTime, getMigrationUrl } from "./utils";
interface MigrationSuccessProps {
migration: CloudMigration;
@@ -22,6 +22,7 @@ export const MigrationSuccess = ({
checkoutUrl,
}: MigrationSuccessProps) => {
const uploadedAt = getMigrationEventTime(migration.updated_at);
+ const migrationUrl = getMigrationUrl(checkoutUrl, migration);
return (
<>
@@ -41,7 +42,7 @@ export const MigrationSuccess = ({
</Text>
<Box mt="1.5rem">
- <ExternalLink href={checkoutUrl}>
+ <ExternalLink href={migrationUrl}>
<Button variant="filled">{t`Go to Metabase Store`}</Button>
</ExternalLink>
</Box>
diff --git a/frontend/src/metabase/admin/settings/components/CloudPanel/utils.ts b/frontend/src/metabase/admin/settings/components/CloudPanel/utils.ts
index 514a1fc281c..03a2dc87d34 100644
--- a/frontend/src/metabase/admin/settings/components/CloudPanel/utils.ts
+++ b/frontend/src/metabase/admin/settings/components/CloudPanel/utils.ts
@@ -70,13 +70,16 @@ export const getMigrationEventTime = (isoString: string) =>
dayjs(isoString).format("MMMM DD, YYYY, hh:mm A");
export const openCheckoutInNewTab = (
- storeUrl: string,
+ checkoutUrl: string,
migration: CloudMigration,
) => {
- window
- .open(
- `${storeUrl}/checkout?migration-id=${migration.external_id}`,
- "_blank",
- )
- ?.focus();
+ const migrationUrl = getMigrationUrl(checkoutUrl, migration);
+ window.open(migrationUrl, "_blank")?.focus();
};
+
+export function getMigrationUrl(
+ checkoutUrl: string,
+ migration: CloudMigration,
+) {
+ return `${checkoutUrl}?migration-id=${migration.external_id}`;
+}