π OpenHands: AI-Driven Development
fix: remove first-run analytics consent popup from onboarding (#1545)
Hiep Lec7c4166a2b4b
diff --git a/__tests__/components/features/analytics/analytics-consent-form-modal.test.tsx b/__tests__/components/features/analytics/analytics-consent-form-modal.test.tsxdeleted file mode 100644index c42b167edb..0000000000--- a/__tests__/components/features/analytics/analytics-consent-form-modal.test.tsx+++ /dev/null@@ -1,94 +0,0 @@-import { fireEvent, render, screen } from "@testing-library/react";-import { beforeEach, describe, expect, it, vi } from "vitest";--vi.mock("react-i18next", () => ({- useTranslation: () => ({ t: (key: string) => key }),-}));--vi.mock("posthog-js/react", () => ({- usePostHog: () => ({ capture: vi.fn() }),-}));--const { saveUserSettingsMock } = vi.hoisted(() => ({- saveUserSettingsMock: vi.fn(),-}));--vi.mock("#/hooks/mutation/use-save-settings", () => ({- useSaveSettings: () => ({ mutate: saveUserSettingsMock }),-}));--const setTelemetryConsentMock = vi.fn((_consent: string) => Promise.resolve());-vi.mock("#/services/telemetry", () => ({- setTelemetryConsent: (consent: string) => setTelemetryConsentMock(consent),-}));--vi.mock("#/utils/handle-capture-consent", () => ({- handleCaptureConsent: vi.fn(),-}));--// Import after mocks.-import { AnalyticsConsentFormModal } from "#/components/features/analytics/analytics-consent-form-modal";--const onCloseMock = vi.fn();--describe("AnalyticsConsentFormModal", () => {- beforeEach(() => {- vi.clearAllMocks();- // Make saveUserSettings call onSuccess immediately.- saveUserSettingsMock.mockImplementation(- (_data: unknown, callbacks?: { onSuccess?: () => void }) => {- callbacks?.onSuccess?.();- },- );- });-- it("calls setTelemetryConsent('granted') when user submits with analytics checked", () => {- render(<AnalyticsConsentFormModal onClose={onCloseMock} />);-- // Checkbox is checked by default (defaultChecked).- fireEvent.submit(screen.getByTestId("user-capture-consent-form"));-- expect(setTelemetryConsentMock).toHaveBeenCalledWith("granted");- });-- it("calls setTelemetryConsent('denied') when user unchecks and submits", () => {- render(<AnalyticsConsentFormModal onClose={onCloseMock} />);-- const checkbox = screen.getByRole("checkbox");- fireEvent.click(checkbox); // uncheck- fireEvent.submit(screen.getByTestId("user-capture-consent-form"));-- expect(setTelemetryConsentMock).toHaveBeenCalledWith("denied");- });-- it("calls onClose after successful submission", () => {- render(<AnalyticsConsentFormModal onClose={onCloseMock} />);-- fireEvent.submit(screen.getByTestId("user-capture-consent-form"));-- expect(onCloseMock).toHaveBeenCalled();- });-- it("saves user_consents_to_analytics: true when checkbox is checked", () => {- render(<AnalyticsConsentFormModal onClose={onCloseMock} />);-- fireEvent.submit(screen.getByTestId("user-capture-consent-form"));-- expect(saveUserSettingsMock).toHaveBeenCalledWith(- { user_consents_to_analytics: true },- expect.any(Object),- );- });-- it("saves user_consents_to_analytics: false when checkbox is unchecked", () => {- render(<AnalyticsConsentFormModal onClose={onCloseMock} />);-- fireEvent.click(screen.getByRole("checkbox"));- fireEvent.submit(screen.getByTestId("user-capture-consent-form"));-- expect(saveUserSettingsMock).toHaveBeenCalledWith(- { user_consents_to_analytics: false },- expect.any(Object),- );- });-});diff --git a/__tests__/routes/root-layout.test.tsx b/__tests__/routes/root-layout.test.tsxindex 1602405aa8..0ca4cd4233 100644--- a/__tests__/routes/root-layout.test.tsx+++ b/__tests__/routes/root-layout.test.tsx@@ -38,12 +38,6 @@ vi.mock("#/components/features/sidebar/sidebar", () => ({Sidebar: () => <div data-testid="sidebar" />,}));-vi.mock("#/components/features/analytics/analytics-consent-form-modal", () => ({- AnalyticsConsentFormModal: () => (- <div data-testid="analytics-consent-modal" />- ),-}));-vi.mock("#/components/features/alerts/alert-banner", () => ({AlertBanner: () => <div data-testid="alert-banner" />,}));@@ -119,7 +113,7 @@ describe("root layout", () => {expect(screen.getByTestId("loading-spinner")).toBeInTheDocument();});- it("renders the OSS layout and analytics modal when consent is missing", async () => {+ it("does not render the analytics consent modal when analytics consent is missing", () => {useSettingsMock.mockReturnValue({data: {language: "en",@@ -135,11 +129,11 @@ describe("root layout", () => {expect(screen.getByTestId("sidebar")).toBeInTheDocument();expect(screen.getByTestId("outlet-content")).toBeInTheDocument();- // The consent modal is loaded via React.lazy() to keep it out of the root- // layout's eager graph, so it resolves on the next microtask.+ // The analytics consent popup was removed from onboarding: a missing+ // (null) consent value must no longer surface the consent form.expect(- await screen.findByTestId("analytics-consent-modal"),- ).toBeInTheDocument();+ screen.queryByTestId("user-capture-consent-form"),+ ).not.toBeInTheDocument();expect(migrateUserConsentMock).toHaveBeenCalled();});diff --git a/src/components/features/analytics/analytics-consent-form-modal.tsx b/src/components/features/analytics/analytics-consent-form-modal.tsxdeleted file mode 100644index 1384658abc..0000000000--- a/src/components/features/analytics/analytics-consent-form-modal.tsx+++ /dev/null@@ -1,75 +0,0 @@-import { useTranslation } from "react-i18next";-import { usePostHog } from "posthog-js/react";-import {- BaseModalTitle,- BaseModalDescription,-} from "#/components/shared/modals/confirmation-modals/base-modal";-import { ModalBackdrop } from "#/components/shared/modals/modal-backdrop";-import { ModalBody } from "#/components/shared/modals/modal-body";-import { useSaveSettings } from "#/hooks/mutation/use-save-settings";-import { handleCaptureConsent } from "#/utils/handle-capture-consent";-import { setTelemetryConsent } from "#/services/telemetry";-import { BrandButton } from "../settings/brand-button";-import { I18nKey } from "#/i18n/declaration";--interface AnalyticsConsentFormModalProps {- onClose: () => void;-}--export function AnalyticsConsentFormModal({- onClose,-}: AnalyticsConsentFormModalProps) {- const posthog = usePostHog();- const { t } = useTranslation("openhands");- const { mutate: saveUserSettings } = useSaveSettings();-- const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {- e.preventDefault();- const formData = new FormData(e.currentTarget);- const analytics = formData.get("analytics") === "on";-- saveUserSettings(- { user_consents_to_analytics: analytics },- {- onSuccess: () => {- handleCaptureConsent(posthog, analytics);- // Sync telemetry.ts consent so canvas_new_session and any- // trackEvent() calls respect the same user decision.- void setTelemetryConsent(analytics ? "granted" : "denied");- onClose();- },- },- );- };-- return (- <ModalBackdrop>- <form- data-testid="user-capture-consent-form"- onSubmit={handleSubmit}- className="flex flex-col gap-2"- >- <ModalBody className="border border-[var(--oh-border)]">- <BaseModalTitle title={t(I18nKey.ANALYTICS$TITLE)} />- <BaseModalDescription>- {t(I18nKey.ANALYTICS$DESCRIPTION)}- </BaseModalDescription>-- <label className="flex gap-2 items-center self-start text-sm">- <input name="analytics" type="checkbox" defaultChecked />- {t(I18nKey.ANALYTICS$SEND_ANONYMOUS_DATA)}- </label>-- <BrandButton- testId="confirm-preferences"- type="submit"- variant="primary"- className="w-full"- >- {t(I18nKey.ANALYTICS$CONFIRM_PREFERENCES)}- </BrandButton>- </ModalBody>- </form>- </ModalBackdrop>- );-}diff --git a/src/routes/root-layout.tsx b/src/routes/root-layout.tsxindex f8d4418662..86003e2df3 100644--- a/src/routes/root-layout.tsx+++ b/src/routes/root-layout.tsx@@ -26,11 +26,6 @@ import { isOnboardingPreviewActive } from "#/components/features/onboarding/onboconst EnvironmentSwitchOverlay = React.lazy(() => import("#/components/features/backends/environment-switch-overlay"),);-const AnalyticsConsentFormModal = React.lazy(() =>- import("#/components/features/analytics/analytics-consent-form-modal").then(- (m) => ({ default: m.AnalyticsConsentFormModal }),- ),-);const AlertBanner = React.lazy(() =>import("#/components/features/alerts/alert-banner").then((m) => ({default: m.AlertBanner,@@ -82,8 +77,6 @@ export default function MainApp() {const { migrateUserConsent } = useMigrateUserConsent();const config = useConfig();- const [consentFormIsOpen, setConsentFormIsOpen] = React.useState(false);-useSyncPostHogConsent();usePostHogIdentify();// Local-mode policy: keep a profile active so a usable LLM is always selected.@@ -96,15 +89,7 @@ export default function MainApp() {}, [settings?.language]);React.useEffect(() => {- setConsentFormIsOpen(settings?.user_consents_to_analytics === null);- }, [settings?.user_consents_to_analytics]);-- React.useEffect(() => {- migrateUserConsent({- handleAnalyticsWasPresentInLocalStorage: () => {- setConsentFormIsOpen(false);- },- });+ migrateUserConsent();}, [migrateUserConsent]);if (config.isLoading) {@@ -155,16 +140,6 @@ export default function MainApp() {<Outlet /></div></div>-- {consentFormIsOpen && (- <React.Suspense fallback={null}>- <AnalyticsConsentFormModal- onClose={() => {- setConsentFormIsOpen(false);- }}- />- </React.Suspense>- )}</div><React.Suspense fallback={null}><EnvironmentSwitchOverlay />