:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(posthog-ai): read the homepage AI consent action from its owning logic (#83646)
Christiaan Hendriksenaeac8f3cd293
diff --git a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsxnew file mode 100644index 000000000000..a42c0936b0fc--- /dev/null+++ b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.test.tsx@@ -0,0 +1,59 @@+import { MOCK_DEFAULT_ORGANIZATION } from 'lib/api.mock'++import { fireEvent, render, screen, waitFor } from '@testing-library/react'+import { BindLogic } from 'kea'++import { maxLogic } from 'scenes/max/maxLogic'+import { organizationLogic } from 'scenes/organizationLogic'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { HOMEPAGE_TAB_ID } from './constants'+import { HomepageAiInput } from './HomepageInput'++jest.mock('scenes/max/components/SidebarQuestionInput', () => ({+ SidebarQuestionInput: () => <div data-attr="mock-question-input" />,+}))++describe('HomepageAiInput', () => {+ const APPROVE_LABEL = 'I allow AI analysis in this organization'++ function renderInput(): HTMLElement {+ const { container } = render(+ <BindLogic logic={maxLogic} props={{ panelId: HOMEPAGE_TAB_ID }}>+ <HomepageAiInput />+ </BindLogic>+ )+ return container+ }++ beforeEach(() => {+ useMocks({+ patch: {+ '/api/organizations/:id': async ({ request }) => [+ 200,+ {+ ...MOCK_DEFAULT_ORGANIZATION,+ ...((await request.json()) as Partial<typeof MOCK_DEFAULT_ORGANIZATION>),+ },+ ],+ },+ })+ initKeaTests(true, undefined, undefined, {+ ...MOCK_DEFAULT_ORGANIZATION,+ is_ai_data_processing_approved: false,+ })+ })++ it('approves AI data processing and swaps in the composer when the button is clicked', async () => {+ const container = renderInput()++ fireEvent.click(screen.getByText(APPROVE_LABEL))++ await waitFor(() =>+ expect(organizationLogic.values.currentOrganization?.is_ai_data_processing_approved).toBe(true)+ )+ expect(container.querySelector('[data-attr="mock-question-input"]')).toBeTruthy()+ })+})diff --git a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsxindex 0b6e8e9c15fb..5ada26a78754 100644--- a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx+++ b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx@@ -28,6 +28,7 @@ import { Intro } from 'scenes/max/Intro'import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'import { maxLogic } from 'scenes/max/maxLogic'import { MaxThreadLogicProps, maxThreadLogic } from 'scenes/max/maxThreadLogic'+import { aiConsentLogic } from 'scenes/settings/organization/aiConsentLogic'import { userLogic } from 'scenes/userLogic'import { ProductIconWrapper, iconForType } from '~/layout/panel-layout/ProjectTree/defaultTree'@@ -190,10 +191,11 @@ function IdleInput(): JSX.Element {)}-function HomepageAiInput(): JSX.Element {+export function HomepageAiInput(): JSX.Element {const { threadLogicKey, conversation } = useValues(maxLogic)const { dataProcessingAccepted, dataProcessingApprovalDisabledReason } = useValues(maxGlobalLogic)- const { acceptDataProcessing } = useAsyncActions(maxGlobalLogic)+ const { acceptDataProcessing } = useAsyncActions(aiConsentLogic)+ const [approving, setApproving] = useState(false)const fallbackConversationId = useMemo(() => uuid(), [])const threadProps: MaxThreadLogicProps = {@@ -215,7 +217,13 @@ function HomepageAiInput(): JSX.Element {<LemonButtontype="primary"size="small"- onClick={() => void acceptDataProcessing().catch(console.error)}+ loading={approving}+ onClick={() => {+ setApproving(true)+ void acceptDataProcessing()+ .catch(console.error)+ .finally(() => setApproving(false))+ }}sideIcon={<IconArrowRight />}>I allow AI analysis in this organization