: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
feat(web-analytics): review drafts with checks, brief and sources (#109629)
Jordan Mryyan3e2568980417
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex adbf30cffa01..16c08f03147c 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -7286,6 +7286,14 @@ snapshots:hash: v1.k794b7964.e25d2ce438dde5ff089d92d1504c6fa7b4bef2753263469896a025c9a12ca8ef.Y5pJiZoVIFxN2U2W1U-Jhl_k6BiEer-NAFSZHG2nzNsproducts-web-analytics-content-autopilot-workspace--onboarding--light:hash: v1.k794b7964.3260bba8be9bb83600881de8669062332538e93deb3db5293d9a66b9aa761126.2LtqyaPy7LCKst40HPfbLagOFtLgCG5jLWxI9rD_ubM+ products-web-analytics-content-autopilot-workspace--proposal-preview--dark:+ hash: v1.k794b7964.2603b94d96ac1d8977930ba236120a36a6a42bc6f13d754fe27399dbd367df2d.nQScRCjEByxzq0m7TyFMOVNZN-_gXtFu2ORBwbsOK_8+ products-web-analytics-content-autopilot-workspace--proposal-preview--light:+ hash: v1.k794b7964.918dc05271cb6a516a4ddac349229f8153d5422d38bb09be8870fe6427fb7d66.468dJUMixIUncJ2NydVmzcONY_cAFjHBWtLBO4xHu00+ products-web-analytics-content-autopilot-workspace--proposal-review--dark:+ hash: v1.k794b7964.3dd695acd0f14fe26be179c56f03a3634928432881b5b55d593d111e3b464bab.ypcWxacARNVYXNxZK7XHLh7W72bJKyYiTVnptevisXg+ products-web-analytics-content-autopilot-workspace--proposal-review--light:+ hash: v1.k794b7964.60e92f685328afbda918ce8a1d46a9b8f40509d3cba15a9b0d7eb31dfdf1253a.qdJZahp8Yox9x8AB-DJ22blfoEDsoHiyjCBBjgkh6L4products-web-analytics-content-autopilot-workspace--ready-for-review--dark:hash: v1.k794b7964.e2a8bdaa2bb31d1d592af3e025420d607798e51389e2f09e947fdbc475f9416c.fB2i7pY1QaxzzAuxe8CmRPAK0rEFqg3Ybdrn3vPT5Awproducts-web-analytics-content-autopilot-workspace--ready-for-review--light:diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsxindex 2d2605950c9b..b5920ed3f750 100644--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsx+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsx@@ -1,4 +1,6 @@import type { Meta, StoryFn } from '@storybook/react'+import { useActions, useValues } from 'kea'+import { useEffect } from 'react'import { FEATURE_FLAGS } from 'lib/constants'@@ -11,6 +13,7 @@ import type {ContentAutopilotSiteProfileApi,} from '../generated/api.schemas'import { ContentAutopilot } from './ContentAutopilot'+import { type ContentAutopilotProposalTab, contentAutopilotLogic } from './contentAutopilotLogic'import { ContentAutopilotSetup } from './ContentAutopilotSetup'import {EXAMPLE_OPPORTUNITIES,@@ -129,3 +132,34 @@ ActiveRun.decorators = [runs: [{ ...EXAMPLE_RUN, run_status: 'generating', completed_at: null }],}),]++const ProposalStory = ({ tab }: { tab?: ContentAutopilotProposalTab }): JSX.Element => {+ const { profileDataLoaded } = useValues(contentAutopilotLogic)+ const { selectProposal, setProposalTab } = useActions(contentAutopilotLogic)+ useEffect(() => {+ if (profileDataLoaded) {+ selectProposal(EXAMPLE_PROPOSAL.id)+ if (tab) {+ setProposalTab(tab)+ }+ }+ }, [profileDataLoaded, selectProposal, setProposalTab, tab])+ return (+ <div className="p-6">+ <ContentAutopilot />+ </div>+ )+}++export const ProposalReview: StoryFn<typeof ContentAutopilot> = () => <ProposalStory tab="changes" />+ProposalReview.decorators = [+ workspaceHandlers({+ profiles: [EXAMPLE_PROFILE],+ runs: [EXAMPLE_RUN],+ proposals: [EXAMPLE_PROPOSAL_LIST],+ opportunities: EXAMPLE_OPPORTUNITIES,+ }),+]++export const ProposalPreview: StoryFn<typeof ContentAutopilot> = () => <ProposalStory />+ProposalPreview.decorators = ProposalReview.decoratorsdiff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotProposalDetail.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotProposalDetail.tsxindex 3098afc35775..42eb3454f116 100644--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotProposalDetail.tsx+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotProposalDetail.tsx@@ -1,17 +1,14 @@import { useActions, useValues } from 'kea'-import {- LemonBanner,- LemonButton,- LemonCollapse,- LemonDialog,- LemonModal,- LemonSkeleton,- LemonTag,- LemonTextArea,-} from '@posthog/lemon-ui'+import { LemonButton, LemonDialog, LemonModal, LemonSkeleton, LemonTabs, LemonTextArea } from '@posthog/lemon-ui'+import { MarkdownTextDiff } from 'lib/components/MarkdownNotebook/MarkdownTextDiff'+import { LemonMarkdown } from 'lib/lemon-ui/LemonMarkdown'++import { ContentAutopilotBriefPanel } from './ContentAutopilotBriefPanel'import { contentAutopilotLogic } from './contentAutopilotLogic'+import { ContentAutopilotSourceLedger } from './ContentAutopilotSourceLedger'+import { ContentAutopilotValidationSummary } from './ContentAutopilotValidationSummary'export const ContentAutopilotProposalDetail = (): JSX.Element | null => {const {@@ -22,9 +19,17 @@ export const ContentAutopilotProposalDetail = (): JSX.Element | null => {proposalMutationLoading,exportedProposalLoading,proposalActionReasons,+ proposalTab,} = useValues(contentAutopilotLogic)- const { selectProposal, setProposedMarkdown, saveProposal, rejectProposal, regenerateProposal, exportProposal } =- useActions(contentAutopilotLogic)+ const {+ selectProposal,+ setProposedMarkdown,+ saveProposal,+ rejectProposal,+ regenerateProposal,+ exportProposal,+ setProposalTab,+ } = useActions(contentAutopilotLogic)if (!selectedProposalId) {return null@@ -49,7 +54,7 @@ export const ContentAutopilotProposalDetail = (): JSX.Element | null => {if (!selectedProposal) {return (- <LemonModal isOpen onClose={closeProposal} title="Loading proposal" width={960}>+ <LemonModal isOpen onClose={closeProposal} title="Loading draft" width={960}><LemonSkeleton className="h-72 w-full" /></LemonModal>)@@ -57,14 +62,14 @@ export const ContentAutopilotProposalDetail = (): JSX.Element | null => {const confirmReject = (): void => {LemonDialog.open({- title: 'Reject this proposal?',- description: 'The proposal will leave the review queue. This does not change your site.',+ title: 'Reject this draft?',+ description: 'The draft leaves the review queue. This does not change your site.',primaryButton: {- children: 'Reject proposal',+ children: 'Reject draft',status: 'danger',onClick: () => rejectProposal(selectedProposal.id),},- secondaryButton: { children: 'Keep proposal' },+ secondaryButton: { children: 'Keep draft' },})}@@ -98,98 +103,101 @@ export const ContentAutopilotProposalDetail = (): JSX.Element | null => {</div><div className="flex gap-2"><LemonButton- type="secondary"+ type="primary"onClick={() => exportProposal(selectedProposal.id)}loading={exportedProposalLoading}disabledReason={proposalActionReasons.exportMarkdown}+ data-attr="content-autopilot-download-draft">- Export Markdown+ Download Markdown</LemonButton></div></div>}>- <div className="flex flex-col gap-5">- {selectedProposal.evidence.length > 0 ? (- <section>- <h3>Why PostHog selected this</h3>- <div className="flex flex-col gap-2">- {selectedProposal.evidence.map((evidence) => (- <div- key={`${evidence.opportunity_kind}-${evidence.page_url}-${evidence.query}-${evidence.explanation}`}- className="rounded border p-3"- >- <LemonTag>{evidence.opportunity_kind.replaceAll('_', ' ')}</LemonTag>- <p className="mb-0 mt-2">{evidence.explanation}</p>- {evidence.query ? (- <div className="text-sm mt-2">Query: {evidence.query}</div>- ) : null}- </div>- ))}- </div>- </section>- ) : null}+ <div className="flex flex-col gap-4">+ <ContentAutopilotValidationSummary report={selectedProposal.validation_report} />- <section>- <h3>Validation</h3>- {!selectedProposal.validation_report.passed ? (- <LemonBanner type="error" className="mb-3">- You cannot export this proposal until its blocked checks pass. Edit the draft or regenerate- it.- </LemonBanner>- ) : null}- <div className="grid grid-cols-1 md:grid-cols-2 gap-2">- {selectedProposal.validation_report.checks.map((check) => (- <div key={check.check_key} className="rounded border p-3">- <div className="flex items-center justify-between gap-2">- <span className="font-semibold">{check.label}</span>- <LemonTag type={check.passed ? 'success' : check.blocking ? 'danger' : 'warning'}>- {check.passed ? 'Passed' : check.blocking ? 'Blocked' : 'Review'}- </LemonTag>+ <LemonTabs+ activeKey={proposalTab}+ onChange={setProposalTab}+ data-attr="content-autopilot-proposal-tabs"+ rightSlot={+ proposalTab === 'draft' ? (+ <LemonButton+ type="secondary"+ size="small"+ onClick={() => saveProposal(selectedProposal.id)}+ loading={proposalMutationLoading}+ disabledReason={proposalActionReasons.save}+ >+ Save changes+ </LemonButton>+ ) : null+ }+ tabs={[+ {+ key: 'preview',+ label: 'Preview',+ content: proposedMarkdown ? (+ <div className="max-h-160 overflow-auto rounded border p-4">+ <LemonMarkdown disableImages="all" disableLinks disableMentions>+ {proposedMarkdown}+ </LemonMarkdown></div>- <div className="text-sm mt-1 text-muted">{check.message}</div>- </div>- ))}- </div>- </section>-- <section>- <div className="flex items-center justify-between gap-2 mb-2">- <h3 className="m-0">Draft</h3>- <LemonButton- type="secondary"- size="small"- onClick={() => saveProposal(selectedProposal.id)}- loading={proposalMutationLoading}- disabledReason={proposalActionReasons.save}- >- Save changes- </LemonButton>- </div>- {selectedProposal.proposal_type === 'page_improvement' && selectedProposal.original_markdown ? (- <LemonCollapse- className="mb-3"- panels={[- {- key: 'original',- header: 'View original content',- content: (- <pre className="max-h-72 overflow-auto rounded border p-3 whitespace-pre-wrap">- {selectedProposal.original_markdown}- </pre>- ),- },- ]}- />- ) : null}- <LemonTextArea- aria-label="Proposal Markdown"- value={proposedMarkdown}- onChange={setProposedMarkdown}- minRows={18}- className="font-mono"- />- </section>+ ) : (+ <p className="text-muted m-0">Nothing to preview yet. Regenerate to write the draft.</p>+ ),+ },+ {+ key: 'draft',+ label: 'Edit',+ content: (+ <LemonTextArea+ aria-label="Draft Markdown"+ value={proposedMarkdown}+ onChange={setProposedMarkdown}+ minRows={18}+ className="font-mono"+ />+ ),+ },+ selectedProposal.proposal_type === 'page_improvement' && selectedProposal.original_markdown+ ? {+ key: 'changes',+ label: 'Changes',+ content: (+ <div className="max-h-160 overflow-auto rounded border p-3 whitespace-pre-wrap font-mono text-sm">+ <MarkdownTextDiff+ before={selectedProposal.original_markdown}+ after={proposedMarkdown}+ />+ </div>+ ),+ }+ : null,+ {+ key: 'brief',+ label: 'Brief',+ content: (+ <ContentAutopilotBriefPanel+ brief={selectedProposal.brief}+ evidence={selectedProposal.evidence}+ />+ ),+ },+ {+ key: 'sources',+ label: 'Sources',+ content: (+ <ContentAutopilotSourceLedger+ entries={selectedProposal.source_ledger}+ notes={selectedProposal.content_package.source_notes}+ />+ ),+ },+ ]}+ /></div></LemonModal>)diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.tsindex af6e1ddccacc..83c496cbe98d 100644--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.ts+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.ts@@ -445,31 +445,31 @@ describe('contentAutopilotLogic', () => {['ready_for_review' as const, undefined, undefined, 'No unsaved changes', undefined],['failed' as const,- 'Only a proposal ready for review can be rejected',+ 'Only a draft ready for review can be rejected',undefined,- 'Only a proposal ready for review can be edited',- 'Only a proposal ready for review can be exported',+ 'Only a draft ready for review can be edited',+ 'Only a draft ready for review can be downloaded',],['rejected' as const,- 'Only a proposal ready for review can be rejected',- 'Only proposals ready for review or failed can be regenerated',- 'Only a proposal ready for review can be edited',- 'Only a proposal ready for review can be exported',+ 'Only a draft ready for review can be rejected',+ 'Only drafts ready for review or failed can be regenerated',+ 'Only a draft ready for review can be edited',+ 'Only a draft ready for review can be downloaded',],['generating' as const,- 'Only a proposal ready for review can be rejected',- 'Only proposals ready for review or failed can be regenerated',- 'Only a proposal ready for review can be edited',- 'Only a proposal ready for review can be exported',+ 'Only a draft ready for review can be rejected',+ 'Only drafts ready for review or failed can be regenerated',+ 'Only a draft ready for review can be edited',+ 'Only a draft ready for review can be downloaded',],['exported' as const,- 'Only a proposal ready for review can be rejected',- 'Only proposals ready for review or failed can be regenerated',- 'Only a proposal ready for review can be edited',- 'Only a proposal ready for review can be exported',+ 'Only a draft ready for review can be rejected',+ 'Only drafts ready for review or failed can be regenerated',+ 'Only a draft ready for review can be edited',+ 'Only a draft ready for review can be downloaded',],])('only offers the proposal actions a %s proposal accepts',diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.tsindex 09dc5846fcbe..424f58f4fa41 100644--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.ts+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.ts@@ -18,6 +18,7 @@ import type {import { webAnalyticsContentAutopilotOpportunitiesDraftBodyOpportunityIdsMax } from 'products/web_analytics/frontend/generated/api.zod'export type ContentAutopilotOnboardingStep = 'site' | 'sources'+export type ContentAutopilotProposalTab = 'preview' | 'draft' | 'changes' | 'brief' | 'sources'export type ContentAutopilotWorkspaceTab = 'opportunities' | 'drafts'export type ContentAutopilotWorkspaceResource = 'profiles' | 'runs' | 'proposals'export type ContentAutopilotProfileResource = 'runs' | 'proposals'@@ -160,6 +161,7 @@ export interface contentAutopilotLogicValues {proposalHasUnsavedChanges: booleanproposalMutation: ContentAutopilotProposalApi | nullproposalMutationLoading: boolean+ proposalTab: ContentAutopilotProposalTabproposals: ContentAutopilotProposalListApi[]proposalsLoading: booleanproposedMarkdown: string@@ -488,6 +490,9 @@ export interface contentAutopilotLogicActions {setProfileDraft: (profileDraft: Partial<ContentAutopilotProfileDraft>) => {profileDraft: Partial<ContentAutopilotProfileDraft>}+ setProposalTab: (proposalTab: ContentAutopilotProposalTab) => {+ proposalTab: ContentAutopilotProposalTab+ }setProposedMarkdown: (proposedMarkdown: string) => {proposedMarkdown: string}@@ -586,6 +591,7 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([setProfileDraft: (profileDraft: Partial<ContentAutopilotProfileDraft>) => ({ profileDraft }),selectProposal: (proposalId: string | null) => ({ proposalId }),setProposedMarkdown: (proposedMarkdown: string) => ({ proposedMarkdown }),+ setProposalTab: (proposalTab: ContentAutopilotProposalTab) => ({ proposalTab }),loadOpportunities: true,refreshOpportunities: true,toggleOpportunitySelection: (opportunityId: string) => ({ opportunityId }),@@ -638,6 +644,13 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([setProposedMarkdown: (_, { proposedMarkdown }) => proposedMarkdown,},],+ proposalTab: [+ 'preview' as ContentAutopilotProposalTab,+ {+ selectProposal: () => 'preview',+ setProposalTab: (_, { proposalTab }) => proposalTab,+ },+ ],workspaceTab: ['opportunities' as ContentAutopilotWorkspaceTab,{@@ -960,7 +973,7 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([{exportProposal: async (proposalId: string) => {if (values.selectedProposalId === proposalId && values.proposalHasUnsavedChanges) {- throw new Error('Save or discard your changes before exporting this proposal')+ throw new Error('Save or discard your changes before downloading this draft')}const exported = await webAnalyticsApi.webAnalyticsContentAutopilotProposalsExport(String(values.currentTeamIdStrict),@@ -1057,31 +1070,31 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([return {}}const readyForReview = selectedProposal.lifecycle_status === 'ready_for_review'- const exportInFlight = exportedProposalLoading ? 'Wait for the export to finish' : undefined+ const exportInFlight = exportedProposalLoading ? 'Wait for the download to finish' : undefinedconst unsavedChanges = proposalHasUnsavedChanges ? 'Save or discard your changes first' : undefinedreturn {reject:- (!readyForReview ? 'Only a proposal ready for review can be rejected' : undefined) ??+ (!readyForReview ? 'Only a draft ready for review can be rejected' : undefined) ??exportInFlight ??unsavedChanges,regenerate:(!readyForReview && selectedProposal.lifecycle_status !== 'failed'- ? 'Only proposals ready for review or failed can be regenerated'+ ? 'Only drafts ready for review or failed can be regenerated': undefined) ??exportInFlight ??unsavedChanges,save:- (!readyForReview ? 'Only a proposal ready for review can be edited' : undefined) ??+ (!readyForReview ? 'Only a draft ready for review can be edited' : undefined) ??(proposalDetailLoading ? 'Wait for the proposal to load' : undefined) ??exportInFlight ??(!proposalHasUnsavedChanges ? 'No unsaved changes' : undefined),exportMarkdown:(!selectedProposal.validation_report.passed- ? 'Fix the blocked checks before exporting'+ ? 'Fix the checks marked Must fix first': undefined) ??- (!readyForReview ? 'Only a proposal ready for review can be exported' : undefined) ??- (proposalHasUnsavedChanges ? 'Save or discard your changes before exporting' : undefined) ??- (proposalMutationLoading ? 'Wait for proposal changes to finish' : undefined),+ (!readyForReview ? 'Only a draft ready for review can be downloaded' : undefined) ??+ (proposalHasUnsavedChanges ? 'Save or discard your changes before downloading' : undefined) ??+ (proposalMutationLoading ? 'Wait for your changes to save' : undefined),}},],@@ -1272,7 +1285,7 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([lemonToast.error(getErrorMessage(errorObject))},exportProposalSuccess: () => {- lemonToast.success('Markdown exported')+ lemonToast.success('Draft downloaded')actions.loadProposals()},exportProposalFailure: ({ errorObject }) => {diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.tsindex 879823b6213e..8f55790d3f91 100644--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.ts+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.ts@@ -79,8 +79,9 @@ export const EXAMPLE_PROPOSAL: ContentAutopilotProposalApi = {internal_links: [],source_notes: [],},- original_markdown: '# Web analytics',- proposed_markdown: '# Web analytics',+ original_markdown: '# Web analytics\n\nWeb analytics shows traffic.',+ proposed_markdown:+ '# Web analytics\n\nWeb analytics shows traffic, sources, and conversions without cookies.\n\n## Frequently asked questions',brief: {intent: 'Decide whether a privacy-friendly web analytics tool covers their needs.',audience: 'Marketers and founders comparing analytics tools',