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
Fix 'Upgrade to Pro' button to open upgrade modal / Show two transforms tier options when on trial (#69387)
Anderson52c4ff856d19
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.setup.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.setup.spec.tsxindex 97b2cba34e5..c95725124e7 100644--- a/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.setup.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.setup.spec.tsx@@ -21,6 +21,7 @@ type SetupOpts = {hasBasicTransforms?: boolean;isHosted: boolean;isStoreUser: boolean;+ isOnTrial?: boolean;};export const transformsBasicPrice = 100;@@ -30,6 +31,7 @@ export const setup = ({isHosted,isStoreUser,hasBasicTransforms,+ isOnTrial = false,}: SetupOpts) => {const user = createMockUser();const settings = createMockSettings({@@ -38,6 +40,7 @@ export const setup = ({status: "valid",valid: true,"store-users": isStoreUser ? [{ email: user.email }] : [],+ trial: isOnTrial,},"token-features": createMockTokenFeatures({transforms: !!hasBasicTransforms,diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.tsxindex 983feafbac3..a8a91d28392 100644--- a/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.tsx+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.tsx@@ -27,6 +27,22 @@ import S from "./TransformsUpsellPage.module.css";import { PricingSummary } from "./components/PricingSummary";import { TierSelection, type TransformTier } from "./components/TierSelection";+/**+ * Expected scenarios:+ * - User with basic transforms: show advanced only, upgrade flow+ * - Trial user: show both tiers with radio selection, $0 due today, "Add to trial"+ * - Regular user (no transforms, no trial): show both tiers with radio selection, $X due today, "Add to plan"+ *+ * TODO: There is the case where the user is on a starter plan, no trial, and+ * hasn't trialed or purchased any transforms add-on in the past.+ * The way HM works is that, if an add-on hasn't been purchased in the past,+ * the first activation will be a 14-day trial, but we currently don't have any+ * way to ask HM if the add-on is eligible for a trial in order to show a "Try for free"+ * CTA rather than the "Purchase" CTA.+ * Without this, the worst case scenario is that the user thinks they purchased the+ * add-on, but they actually got a 14-day trial, and they end up paying for the add-on+ * after the trial ends, which is still a miscommunication.+ */export function TransformsUpsellPage() {const bulletPoints = [t`Schedule and run transforms as groups with jobs`,@@ -54,21 +70,6 @@ export function TransformsUpsellPage() {billingPeriodMonths !== undefined && (transformsProduct || pythonProduct);const billingPeriod: BillingPeriod =billingPeriodMonths === 1 ? "monthly" : "yearly";- // Determine which scenario we're in:- // - Trial user: show advanced only, $0 due today, "Add to trial"- // - User with basic transforms: show advanced only, upgrade flow- // - Regular user: show both tiers with radio selection- //- // TODO: There is also the case where the user is on a starter plan (no trial),- // but hasn't purchased any transforms add-on yet - the way HM works is that, if- // an add-on hasn't been purchased in the past, the first activation will be a 14- // day trial, but we currently don't have any way to ask HM if the add-on is eligible- // for a trial in order to show a "Try for free" CTA rather than the "Purchase" CTA.- //- // Without this, the worst case scenario is that the user thinks they purchased the- // add-on, but they actually got a 14 day trial, and they end up paying for the add-on- // after the trial ends, which is still a miscommunication.- const showAdvancedOnly = isOnTrial || hasBasicTransforms;const isTrialFlow = isOnTrial && !hasBasicTransforms;const transformsPrice = transformsProduct?.default_base_fee ?? 0;@@ -91,9 +92,14 @@ export function TransformsUpsellPage() {return t`Add transforms to your plan`;};- // Determine if we should show the single-column layout:- // - Non-store user on hosted- // - No billing data available (can't show pricing)+ /**+ * Single-column layout is used when the user doesn't have authority to+ * purchase the add-on - we just show the information about the feature+ * and a note to ask a store admin to enable it for them.+ * Single-column layout will be displayed when:+ * - Current user is not a store user; or+ * - No billing data available (can't show pricing)+ */const showSingleColumn = (isHosted && !isStoreUser) || !hasData;if (error || isLoading) {@@ -182,7 +188,7 @@ export function TransformsUpsellPage() {pythonPrice={pythonPrice}selectedTier={selectedTier}setSelectedTier={setSelectedTier}- showAdvancedOnly={showAdvancedOnly}+ showAdvancedOnly={hasBasicTransforms}transformsPrice={transformsPrice}/><PricingSummary@@ -190,7 +196,7 @@ export function TransformsUpsellPage() {pythonPrice={pythonPrice}selectedTier={selectedTier}setSelectedTier={setSelectedTier}- showAdvancedOnly={showAdvancedOnly}+ showAdvancedOnly={hasBasicTransforms}transformsPrice={transformsPrice}/></Stack>diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.unit.spec.tsxindex f41772fd372..4b503338eef 100644--- a/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/upsells/pages/TransformsUpsellPage/TransformsUpsellPage.unit.spec.tsx@@ -83,4 +83,13 @@ describe("TransformsUpsellPage", () => {`$${transformsAdvancedPrice}`,);});++ it("shows both transforms tiers when cloud user is on trial", async () => {+ setup({ isHosted: true, isStoreUser: true, isOnTrial: true });++ await waitForLoadingToFinish();++ expect(screen.getByText(/SQL only/)).toBeInTheDocument();+ expect(screen.getByText(/SQL \+ Python/)).toBeInTheDocument();+ });});diff --git a/frontend/src/metabase/admin/upsells/components/UpgradeModal/use-upgrade-action.tsx b/frontend/src/metabase/admin/upsells/components/UpgradeModal/use-upgrade-action.tsxindex 2cdbd75a08c..778a6260679 100644--- a/frontend/src/metabase/admin/upsells/components/UpgradeModal/use-upgrade-action.tsx+++ b/frontend/src/metabase/admin/upsells/components/UpgradeModal/use-upgrade-action.tsx@@ -4,7 +4,7 @@ import { useSetting } from "metabase/common/hooks";import { useDispatch } from "metabase/lib/redux";import { setOpenModal } from "metabase/redux/ui";-import { UPGRADE_URL } from "../../constants";+import { DATA_STUDIO_UPGRADE_URL, UPGRADE_URL } from "../../constants";import { useUpsellLink } from "../use-upsell-link";interface UseUpgradeActionProps {@@ -31,7 +31,8 @@ export function useUpgradeAction({dispatch(setOpenModal("upgrade"));}, [dispatch]);- const shouldUseModal = isHosted && url === UPGRADE_URL;+ const shouldUseModal =+ isHosted && (url === UPGRADE_URL || url === DATA_STUDIO_UPGRADE_URL);if (shouldUseModal) {return {diff --git a/frontend/src/metabase/admin/upsells/components/UpgradeModal/use-upgrade-action.unit.spec.tsx b/frontend/src/metabase/admin/upsells/components/UpgradeModal/use-upgrade-action.unit.spec.tsxnew file mode 100644index 00000000000..369b07d4c59--- /dev/null+++ b/frontend/src/metabase/admin/upsells/components/UpgradeModal/use-upgrade-action.unit.spec.tsx@@ -0,0 +1,85 @@+import { renderHookWithProviders } from "__support__/ui";+import {+ DATA_STUDIO_UPGRADE_URL,+ UPGRADE_URL,+} from "metabase/admin/upsells/constants";+import {+ createMockSettingsState,+ createMockState,+} from "metabase-types/store/mocks";++import { useUpgradeAction } from "./use-upgrade-action";++type SetupOpts = {+ isHosted: boolean;+ url: string;+ campaign?: string;+ location?: string;+};++const setup = ({+ isHosted,+ url,+ campaign = "test",+ location = "test",+}: SetupOpts) => {+ return renderHookWithProviders(+ () =>+ useUpgradeAction({+ url,+ campaign,+ location,+ }),+ {+ storeInitialState: createMockState({+ settings: createMockSettingsState({+ "is-hosted?": isHosted,+ }),+ }),+ },+ );+};++describe("useUpgradeAction", () => {+ it("should set onClick to open modal when hosted and url is UPGRADE_URL", () => {+ const { result, store } = setup({ isHosted: true, url: UPGRADE_URL });++ expect(store.getState().modal.id).toBeNull();++ expect(result.current.url).toBe(undefined);+ result.current.onClick?.();++ expect(store.getState().modal.id).toBe("upgrade");+ });++ it("should set onClick to open modal when hosted and url is DATA_STUDIO_UPGRADE_URL", () => {+ const { result, store } = setup({+ isHosted: true,+ url: DATA_STUDIO_UPGRADE_URL,+ });++ expect(store.getState().modal.id).toBeNull();++ expect(result.current.url).toBe(undefined);+ result.current.onClick?.();++ expect(store.getState().modal.id).toBe("upgrade");+ });++ it("should set url with params and onClick undefined when is-hosted is false", () => {+ const { result, store } = setup({+ isHosted: false,+ url: UPGRADE_URL,+ campaign: "test-campaign",+ location: "test-location",+ });++ expect(result.current.url).toBe(+ UPGRADE_URL ++ "?utm_source=product&utm_medium=upsell&utm_campaign=test-campaign&utm_content=test-location&source_plan=oss",+ );+ expect(result.current.onClick).toBe(undefined);++ expect(store.getState().modal.id).toBeNull();+ });+});