Skip to content

: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.

feat(inbox): party hog on report thumbs-up (#114417)

Dylan Martin588de869d498
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 35b9216ae276..9807b39ef7a7 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -11250,6 +11250,14 @@ snapshots:
hash: v1.k794b7964.4a72fd69c80a076b8f6040c0473d1a42aa0e574e51cd9ac16c16ce74f5434d4b.UJFgWCDdVPiMssuUXnf6Px4wj9tZljS4fKvI_6WmIqI
scenes-app-inbox-report-metrics--wide--light:
hash: v1.k794b7964.3465b8cd1a9bf286b7ae698d78dba847138201548b8a3c56978fae74b431da53.2bz4A6FW49b2OIDhumSwnnmW8eVEaLSHMmBLZx_eFOg
+ scenes-app-inbox-reportfeedbackcelebration--in-footer--dark:
+ hash: v1.k794b7964.8c093b90ac7410e55c7b3827842eb0942adee6a57b0e818870012b04c56edd86.7qvPamSn8HsMppKivui1JK1Y24EQOXmKD7_1MT6mCS4
+ scenes-app-inbox-reportfeedbackcelebration--in-footer--light:
+ hash: v1.k794b7964.026f5bceab731a89e93d16c8c0f1f0a0cc1458c38ba49db0b8323957cc444c12.1kSI4gLHiMUQssvNeHlzuT8T4GLiv4Z4TyWZoCcaw_Q
+ scenes-app-inbox-reportfeedbackcelebration--resting--dark:
+ hash: v1.k794b7964.da6e44315482e5fcd37f5460bb605d5f333d71cb52ddb46e67bb7edd49d19d4f.1SJyHVjoGXLaaS3scPoyN2NKNYINtNg_MCRvjFtZazg
+ scenes-app-inbox-reportfeedbackcelebration--resting--light:
+ hash: v1.k794b7964.dc3652045565b403ed1b757c127ada48bac2bd5554b261ee77b1fdb85d975f7f.L-a62toGSVL2GsogslMTrCuQXGcBBA_u4z62ysa1Lt0
scenes-app-inbox-reportsourcesuggestion--logs--dark:
hash: v1.k794b7964.7a1690934454b93121e9bf56db6e5b731bae66bb941e705ef3d27855458e01d9.p0wpMpu1OEWo_e2f7WnYoNgV9Pmy9PFaXsx8wFZg-aA
scenes-app-inbox-reportsourcesuggestion--logs--light:
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 8af4a76d1a33..30e6ce9c66d9 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -372,6 +372,7 @@ export const FEATURE_FLAGS = {
HOGQL_WAREHOUSE_ACCESS_CONTROL: 'hogql-warehouse-access-control', // owner: @a-lider #team-platform-features, gates per-object access control for warehouse tables and views
IDENTITY_MATCHING: 'identity-matching', // owner: @fercgomes #team-growth, gates new identity matching scene on marketing analytics
INBOX_GET_IT_MERGED: 'inbox-get-it-merged', // owner: #team-self-driving, gates the Get it merged action in the report Ask AI menu
+ INBOX_REPORT_FEEDBACK_BANG: 'inbox-report-feedback-bang', // owner: #team-self-driving, gates the party hog that pops on a report thumbs-up in the inbox and on the Today home page
INBOX_MODEL_SORT: 'inbox-model-sort', // owner: #team-self-driving, gates the staff-only ranking model sort options and the probability tag on inbox cards
INBOX_REDESIGN: 'inbox-redesign', // owner: #team-self-driving, gates the inbox redesign: report sections, triage mode, the Settings tab, and scout cards
INBOX_SELF_DRIVING_EMPTY_STATE: 'inbox-self-driving-empty-state',
diff --git a/frontend/src/scenes/project-homepage/today/TodayReportFeedback.test.tsx b/frontend/src/scenes/project-homepage/today/TodayReportFeedback.test.tsx
new file mode 100644
index 000000000000..c930ab364907
--- /dev/null
+++ b/frontend/src/scenes/project-homepage/today/TodayReportFeedback.test.tsx
@@ -0,0 +1,60 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { makeReport } from 'products/signals/frontend/inbox/__mocks__/inboxMocks'
+import { captureInboxReportFeedback } from 'products/signals/frontend/inbox/inboxAnalytics'
+
+import { TodayReportFeedback } from './TodayReportFeedback'
+
+jest.mock('products/signals/frontend/inbox/inboxAnalytics', () => ({
+ ...jest.requireActual('products/signals/frontend/inbox/inboxAnalytics'),
+ captureInboxReportFeedback: jest.fn(),
+}))
+
+describe('TodayReportFeedback', () => {
+ beforeEach(() => {
+ useMocks({
+ get: {
+ '/api/projects/:team_id/signals/reports/:id/': makeReport({ id: 'report-today' }),
+ '/api/projects/:team_id/signals/reports/:id/artefacts/': { results: [] },
+ '/api/projects/:team_id/signals/reports/:id/signals/': { signals: [] },
+ '/api/projects/:team_id/signals/reports/available_reviewers/': [],
+ '/api/projects/:team_id/signals/reports/for_you/': { results: [], count: 0 },
+ '/api/projects/:team_id/today/briefing/': [404, {}],
+ '/api/projects/:team_id/today/reports/:id/page/': [404, {}],
+ },
+ post: {
+ '/api/projects/:team_id/signals/reports/:id/feedback/': [200, { forwarded: false }],
+ },
+ })
+ initKeaTests()
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.INBOX_REPORT_FEEDBACK_BANG], {
+ [FEATURE_FLAGS.INBOX_REPORT_FEEDBACK_BANG]: true,
+ })
+ jest.mocked(captureInboxReportFeedback).mockClear()
+ render(<TodayReportFeedback report={makeReport({ id: 'report-today' })} />)
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ it('pops the hog and records the rating from the Today surface on thumbs-up', async () => {
+ await userEvent.click(screen.getByLabelText('This report was useful'))
+
+ expect(document.querySelector('[data-attr="inbox-report-feedback-celebration"]')).toBeInTheDocument()
+ expect(captureInboxReportFeedback).toHaveBeenCalledTimes(1)
+ expect(captureInboxReportFeedback).toHaveBeenCalledWith(
+ expect.objectContaining({ sentiment: 'positive', surface: 'today' })
+ )
+ })
+})
diff --git a/frontend/src/scenes/project-homepage/today/TodayReportFeedback.tsx b/frontend/src/scenes/project-homepage/today/TodayReportFeedback.tsx
index df570dfae143..9806fc2b7712 100644
--- a/frontend/src/scenes/project-homepage/today/TodayReportFeedback.tsx
+++ b/frontend/src/scenes/project-homepage/today/TodayReportFeedback.tsx
@@ -1,98 +1,146 @@
+import clsx from 'clsx'
import { useActions, useValues } from 'kea'
-import { type ChangeEvent } from 'react'
+import { type ChangeEvent, type KeyboardEvent, useState } from 'react'
-import { IconThumbsDown, IconThumbsDownFilled, IconThumbsUp, IconThumbsUpFilled } from '@posthog/icons'
-import { Button, Text, Textarea } from '@posthog/quill'
+import { IconThumbsDown, IconThumbsDownFilled, IconThumbsUp, IconThumbsUpFilled, IconX } from '@posthog/icons'
+import { Text, Textarea } from '@posthog/quill'
+import { useReportFeedbackCelebration } from 'products/signals/frontend/inbox/components/detail/ReportFeedbackCelebration'
import { inboxReportDetailLogic } from 'products/signals/frontend/inbox/logics/inboxReportDetailLogic'
import { SignalReport } from 'products/signals/frontend/inbox/types'
import { TodayActionButton } from './TodayActionButton'
-import { todayReportLogic } from './todayReportLogic'
const NOTE_MAX_LENGTH = 4000
export function TodayReportFeedback({ report }: { report: SignalReport }): JSX.Element {
const logic = inboxReportDetailLogic({ reportId: report.id, report })
- const { feedbackSentiment, feedbackNoteOpen, feedbackNoteDraft, feedbackNoteSent, feedbackNoteSubmitting } =
+ const { feedbackSentiment, feedbackNoteDraft, feedbackNoteSent, feedbackSentNote, feedbackNoteSubmitting } =
useValues(logic)
- const { rateReport, openFeedbackNote, setFeedbackNoteDraft, submitFeedbackNote } = useActions(logic)
- const { feedbackNoteFocused } = useValues(todayReportLogic({ reportId: report.id }))
- const { focusFeedbackNote } = useActions(todayReportLogic({ reportId: report.id }))
+ const { rateReport, setFeedbackNoteDraft, submitFeedbackNote } = useActions(logic)
+ const { celebrate, celebration } = useReportFeedbackCelebration()
const isPositive = feedbackSentiment === 'positive'
const isNegative = feedbackSentiment === 'negative'
- const canAddNote = !!feedbackSentiment && !feedbackNoteOpen && !feedbackNoteSent
+ const [questionDismissed, setQuestionDismissed] = useState(false)
+ const sendNote = (): void => {
+ if (feedbackNoteDraft.trim()) {
+ submitFeedbackNote(feedbackNoteDraft, 'today')
+ }
+ }
+ const askingWhy = !!feedbackSentiment && !feedbackNoteSent && !questionDismissed
return (
<div className="flex flex-col gap-2" data-attr="today-report-feedback">
<div className="flex flex-wrap items-center gap-1">
- <Text size="xs" variant="muted" render={<span />} className="me-1">
- {feedbackSentiment ? 'Thanks for the feedback' : 'Was this report useful?'}
+ {/* Both labels share one grid cell so the thumbs sit still when the text swaps. */}
+ <Text size="xs" variant="muted" render={<span />} className="me-1 grid">
+ <span
+ className={clsx('col-start-1 row-start-1', feedbackSentiment && 'invisible')}
+ aria-hidden={!!feedbackSentiment}
+ >
+ Was this report useful?
+ </span>
+ <span
+ className={clsx('col-start-1 row-start-1', !feedbackSentiment && 'invisible')}
+ aria-hidden={!feedbackSentiment}
+ >
+ Thanks for the feedback!
+ </span>
</Text>
- <TodayActionButton
- size="icon-sm"
- aria-label="This report was useful"
- aria-pressed={isPositive}
- tooltip="Yes, this was useful"
- onClick={() => !isPositive && rateReport('positive', 'today')}
- data-attr="today-report-feedback-up"
- >
- {isPositive ? <IconThumbsUpFilled /> : <IconThumbsUp />}
- </TodayActionButton>
+ <span className="relative inline-flex">
+ <TodayActionButton
+ size="icon-sm"
+ aria-label="This report was useful"
+ aria-pressed={isPositive}
+ tooltip="Yes, this was useful"
+ onClick={() => {
+ if (!isPositive) {
+ rateReport('positive', 'today')
+ setQuestionDismissed(false)
+ celebrate()
+ }
+ }}
+ data-attr="today-report-feedback-up"
+ >
+ {isPositive ? <IconThumbsUpFilled /> : <IconThumbsUp />}
+ </TodayActionButton>
+ {celebration}
+ </span>
<TodayActionButton
size="icon-sm"
aria-label="This report was not useful"
aria-pressed={isNegative}
tooltip="No, this wasn't useful"
- onClick={() => !isNegative && rateReport('negative', 'today')}
+ onClick={() => {
+ if (!isNegative) {
+ rateReport('negative', 'today')
+ setQuestionDismissed(false)
+ }
+ }}
data-attr="today-report-feedback-down"
>
{isNegative ? <IconThumbsDownFilled /> : <IconThumbsDown />}
</TodayActionButton>
- {canAddNote && (
- <Button
- variant="link-muted"
- size="sm"
- onClick={() => {
- focusFeedbackNote()
- openFeedbackNote()
- }}
- data-attr="today-report-feedback-note-open"
- >
- Add a note
- </Button>
- )}
- {feedbackNoteSent && (
- <Text size="xs" variant="muted" render={<span />}>
- Note added
- </Text>
- )}
</div>
- {feedbackNoteOpen && (
- <div className="flex flex-col items-start gap-2">
- <Textarea
- value={feedbackNoteDraft}
- onChange={(event: ChangeEvent<HTMLTextAreaElement>) => setFeedbackNoteDraft(event.target.value)}
- placeholder="What was useful or off?"
- aria-label="Add a note about this report"
- maxLength={NOTE_MAX_LENGTH}
- rows={4}
- autoFocus={feedbackNoteFocused}
- className="w-full"
- data-attr="today-report-feedback-note"
- />
- <TodayActionButton
- variant="primary"
- size="sm"
- loading={feedbackNoteSubmitting}
- disabledReason={feedbackNoteDraft.trim() ? null : 'Write a note first'}
- onClick={() => submitFeedbackNote(feedbackNoteDraft, 'today')}
- data-attr="today-report-feedback-note-send"
- >
- Send
- </TodayActionButton>
+ {/* The question lives under the row so it never pushes the thumbs sideways. */}
+ {askingWhy && (
+ <div
+ className="flex w-full max-w-96 flex-col gap-1.5 rounded-md border border-primary p-2"
+ data-attr="today-report-feedback-question"
+ >
+ <div className="flex items-center gap-1">
+ <Text size="xs" weight="medium" render={<span />} className="grow">
+ {isPositive ? 'What made it useful?' : 'What was off?'}
+ </Text>
+ <TodayActionButton
+ size="icon-sm"
+ aria-label="Dismiss"
+ onClick={() => setQuestionDismissed(true)}
+ data-attr="today-report-feedback-question-dismiss"
+ >
+ <IconX />
+ </TodayActionButton>
+ </div>
+ <div className="flex items-end gap-1.5">
+ <Textarea
+ value={feedbackNoteDraft}
+ onChange={(event: ChangeEvent<HTMLTextAreaElement>) =>
+ setFeedbackNoteDraft(event.target.value)
+ }
+ onKeyDown={(event: KeyboardEvent<HTMLTextAreaElement>) => {
+ if (event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing) {
+ event.preventDefault()
+ sendNote()
+ }
+ }}
+ placeholder="Your note improves future reports"
+ aria-label="Add a note about this report"
+ maxLength={NOTE_MAX_LENGTH}
+ rows={2}
+ autoFocus
+ className="max-h-48 min-h-14! min-w-0 flex-1 resize-none"
+ data-attr="today-report-feedback-note"
+ />
+ {/* Shown only once there is text, so there is never a disabled button to look at. */}
+ {feedbackNoteDraft.trim() && (
+ <TodayActionButton
+ variant="primary"
+ size="sm"
+ loading={feedbackNoteSubmitting}
+ onClick={sendNote}
+ data-attr="today-report-feedback-note-send"
+ >
+ Send
+ </TodayActionButton>
+ )}
+ </div>
</div>
)}
+ {feedbackNoteSent && (
+ <Text size="xs" variant="muted" render={<p className="m-0 max-w-96" />}>
+ Note added: {feedbackSentNote}
+ </Text>
+ )}
</div>
)
}
diff --git a/frontend/src/scenes/project-homepage/today/todayReportLogic.ts b/frontend/src/scenes/project-homepage/today/todayReportLogic.ts
index 9ee0f733ada2..4b82d01dfdcf 100644
--- a/frontend/src/scenes/project-homepage/today/todayReportLogic.ts
+++ b/frontend/src/scenes/project-homepage/today/todayReportLogic.ts
@@ -73,7 +73,6 @@ export interface todayReportLogicValues {
draft: string
evidenceCount: number
expandedEvidence: Record<string, boolean>
- feedbackNoteFocused: boolean
figureMarks: FigureMarkApi[] | null
figureMarksLoading: boolean
fullReport: SignalReport | null
@@ -167,9 +166,6 @@ export interface todayReportLogicActions {
expandEvidence: (signalId: string) => {
signalId: string
}
- focusFeedbackNote: () => {
- value: true
- }
loadFigureMarks: () => any
loadFigureMarksFailure: (
error: string,
@@ -324,7 +320,6 @@ export const todayReportLogic = kea<todayReportLogicType>([
collapseEvidence: (signalId: string) => ({ signalId }),
openComposer: true,
setDraft: (draft: string) => ({ draft }),
- focusFeedbackNote: true,
startWithPostHog: true,
markOpened: (kind: TodayMarkKind) => ({ kind }),
}),
@@ -428,7 +423,6 @@ export const todayReportLogic = kea<todayReportLogicType>([
},
],
composerOpen: [false, { openComposer: () => true }],
- feedbackNoteFocused: [false, { focusFeedbackNote: () => true }],
draft: [
'',
{
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index be4bf8c3ea60..92c8513d3931 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -4775,6 +4775,9 @@ importers:
'@pierre/diffs':
specifier: 1.2.11
+ '@posthog/brand':
+ specifier: 'catalog:'
+ version: 0.12.3([email protected])
'@posthog/icons':
specifier: 'catalog:'
diff --git a/products/signals/frontend/inbox/components/detail/ReportFeedbackCelebration.scss b/products/signals/frontend/inbox/components/detail/ReportFeedbackCelebration.scss
new file mode 100644
index 000000000000..d48df31def42
--- /dev/null
+++ b/products/signals/frontend/inbox/components/detail/ReportFeedbackCelebration.scss
@@ -0,0 +1,77 @@
+// The resting pose (no animation running) is the fully visible hog, so the Storybook test
+// runner, which disables animations, still captures the artwork.
+.ReportFeedbackCelebration {
+ // A zero-size point at the top centre of the wrapped button; the hog and confetti hang off it.
+ position: absolute;
+ bottom: 100%;
+ left: 50%;
+ z-index: 10;
+ width: 0;
+ height: 0;
+ pointer-events: none;
+
+ &__hog {
+ position: absolute;
+ bottom: 4px;
+ left: 0;
+
+ // The root is zero-width, so the global `img { max-width: 100% }` reset would collapse the hog.
+ max-width: none;
+ filter: drop-shadow(0 3px 4px rgb(0 0 0 / 25%));
+ transform: translateX(-50%);
+ transform-origin: 50% 100%;
+ animation: ReportFeedbackCelebration__pop 1s cubic-bezier(0.2, 1.4, 0.4, 1) both;
+ }
+
+ &__confetti {
+ position: absolute;
+ top: -4px;
+ left: -2px;
+ width: 5px;
+ height: 8px;
+ border-radius: 1px;
+ transform: translate(var(--dx), var(--dy)) rotate(var(--rot));
+ animation: ReportFeedbackCelebration__confetti 0.9s cubic-bezier(0.15, 0.85, 0.3, 1) var(--delay) both;
+ }
+}
+
+@keyframes ReportFeedbackCelebration__pop {
+ 0% {
+ opacity: 0;
+ transform: translate(-50%, 16px) scale(0.3);
+ }
+
+ 30% {
+ opacity: 1;
+ transform: translate(-50%, -6px) scale(1.08);
+ }
+
+ 45%,
+ 75% {
+ opacity: 1;
+ transform: translate(-50%, 0) scale(1);
+ }
+
+ 100% {
+ opacity: 0;
+ transform: translate(-50%, -10px) scale(0.9);
+ }
+}
+
+@keyframes ReportFeedbackCelebration__confetti {
+ 0% {
+ opacity: 1;
+ transform: translate(0, 0) rotate(0deg);
+ }
+
+ 70% {
+ opacity: 1;
+ }
+
+ 100% {
+ opacity: 0;
+
+ // Fall back a little at the end so the scatter reads as paper, not sparks.
+ transform: translate(var(--dx), calc(var(--dy) + 24px)) rotate(var(--rot));
+ }
+}
diff --git a/products/signals/frontend/inbox/components/detail/ReportFeedbackCelebration.stories.tsx b/products/signals/frontend/inbox/components/detail/ReportFeedbackCelebration.stories.tsx
new file mode 100644
index 000000000000..00ecd1b0ed4e
--- /dev/null
+++ b/products/signals/frontend/inbox/components/detail/ReportFeedbackCelebration.stories.tsx
@@ -0,0 +1,61 @@
+import type { Meta, StoryObj } from '@storybook/react'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+
+import { mswDecorator } from '~/mocks/browser'
+
+import { makeReport } from '../../__mocks__/inboxMocks'
+import { ReportFeedbackCelebration } from './ReportFeedbackCelebration'
+import { ReportFeedbackFooter } from './ReportFeedbackFooter'
+
+const meta: Meta<typeof ReportFeedbackCelebration> = {
+ title: 'Scenes-App/Inbox/ReportFeedbackCelebration',
+ component: ReportFeedbackCelebration,
+ parameters: { layout: 'fullscreen' },
+}
+export default meta
+
+type Story = StoryObj<typeof ReportFeedbackCelebration>
+
+/** The hog in its resting pose, anchored to a stand-in for the thumbs-up button. */
+export const Resting: Story = {
+ args: { onDone: () => {} },
+ render: (args) => (
+ <div className="flex h-[240px] w-[400px] items-end justify-center p-8">
+ <span className="relative inline-flex">
+ <span className="h-6 w-6 rounded border border-primary bg-surface-primary" />
+ <ReportFeedbackCelebration {...args} />
+ </span>
+ </div>
+ ),
+}
+
+/** The real footer, right-aligned as in the summary column, with the flag on: click the thumbs-up to see the hog pop. */
+export const InFooter: Story = {
+ parameters: {
+ featureFlags: { [FEATURE_FLAGS.INBOX_REPORT_FEEDBACK_BANG]: true },
+ },
+ decorators: [
+ mswDecorator({
+ get: {
+ '/api/projects/:id/signals/reports/:reportId/artefacts': { results: [] },
+ '/api/projects/:id/signals/reports/:reportId/signals': { signals: [] },
+ '/api/projects/:id/signals/reports/available_reviewers': [],
+ '/api/projects/:id/signals/reports/:reportId/checks/': { results: [] },
+ },
+ post: {
+ '/api/projects/:id/signals/reports/:reportId/feedback': { forwarded: false },
+ },
+ }),
+ ],
+ render: () => (
+ <div className="bg-primary flex min-h-[400px] items-start justify-center px-8 pt-40 pb-8">
+ <div className="w-[32rem] border border-primary bg-surface-primary p-5">
+ <ReportFeedbackFooter
+ report={makeReport({ title: 'Checkout errors spiked after the release' })}
+ align="end"
+ />
+ </div>
+ </div>
+ ),
+}
diff --git a/products/signals/frontend/inbox/components/detail/ReportFeedbackCelebration.tsx b/products/signals/frontend/inbox/components/detail/ReportFeedbackCelebration.tsx
new file mode 100644
index 000000000000..eef6190a3a09
--- /dev/null
+++ b/products/signals/frontend/inbox/components/detail/ReportFeedbackCelebration.tsx
@@ -0,0 +1,92 @@
+import './ReportFeedbackCelebration.scss'
+
+import { useEffect, useState } from 'react'
+
+import * as partyPng from '@posthog/brand/hoggies/png/party'
+
+import { pngHoggie } from 'lib/brand/hoggies'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'
+
+const HedgehogParty = pngHoggie(partyPng)
+
+/** Covers the pop, the hold, and the fade in the scss keyframes, plus a short tail. */
+export const CELEBRATION_DURATION_MS = 1100
+
+// Fixed scatter so Storybook and tests render the same picture every time.
+const CONFETTI = [
+ { dx: -54, dy: -48, rot: 300, delay: 0, color: '#f54e00' },
+ { dx: -34, dy: -74, rot: 180, delay: 30, color: '#f9bd2b' },
+ { dx: -10, dy: -88, rot: 110, delay: 10, color: '#1d4aff' },
+ { dx: 14, dy: -84, rot: 250, delay: 50, color: '#000000' },
+ { dx: 38, dy: -70, rot: 150, delay: 20, color: '#f54e00' },
+ { dx: 58, dy: -44, rot: 320, delay: 60, color: '#f9bd2b' },
+ { dx: -46, dy: -20, rot: 80, delay: 80, color: '#1d4aff' },
+ { dx: 50, dy: -16, rot: 210, delay: 70, color: '#f9bd2b' },
+]
+
+function prefersReducedMotion(): boolean {
+ return !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches
+}
+
+/**
+ * A party hog that pops up above the thumbs-up button, with a small confetti scatter, then
+ * removes itself. Render it inside a `relative` wrapper around the button: the row reflows when
+ * "Add a note" appears after the click, and the hog has to move with the thumb.
+ */
+export function ReportFeedbackCelebration({ onDone }: { onDone: () => void }): JSX.Element {
+ useOnMountEffect(() => {
+ const timer = window.setTimeout(onDone, CELEBRATION_DURATION_MS)
+ return () => window.clearTimeout(timer)
+ })
+
+ return (
+ <span className="ReportFeedbackCelebration" aria-hidden="true" data-attr="inbox-report-feedback-celebration">
+ {CONFETTI.map((piece, index) => (
+ <span
+ key={index}
+ className="ReportFeedbackCelebration__confetti"
+ // eslint-disable-next-line react/forbid-dom-props
+ style={
+ {
+ '--dx': `${piece.dx}px`,
+ '--dy': `${piece.dy}px`,
+ '--rot': `${piece.rot}deg`,
+ '--delay': `${piece.delay}ms`,
+ backgroundColor: piece.color,
+ } as React.CSSProperties
+ }
+ />
+ ))}
+ <HedgehogParty className="ReportFeedbackCelebration__hog" size={72} loading="eager" />
+ </span>
+ )
+}
+
+/**
+ * Shared by every feedback footer, so the flag, the reduced-motion check, and the once-per-rating
+ * rule hold on each surface. The celebration is view-only, so it stays in local state and only
+ * the instance that was clicked pops.
+ */
+export function useReportFeedbackCelebration(): { celebrate: () => void; celebration: JSX.Element | null } {
+ const enabled = useFeatureFlag('INBOX_REPORT_FEEDBACK_BANG')
+ const [activeId, setActiveId] = useState<number | null>(null)
+
+ useEffect(() => {
+ // The pop lasts about a second, so a first-time fetch of the hog image would miss it.
+ if (enabled) {
+ new Image().src = partyPng.src
+ }
+ }, [enabled])
+
+ const celebrate = (): void => {
+ if (enabled && !prefersReducedMotion()) {
+ setActiveId(Date.now())
+ }
+ }
+
+ const celebration =
+ activeId !== null ? <ReportFeedbackCelebration key={activeId} onDone={() => setActiveId(null)} /> : null
+
+ return { celebrate, celebration }
+}
diff --git a/products/signals/frontend/inbox/components/detail/ReportFeedbackFooter.test.tsx b/products/signals/frontend/inbox/components/detail/ReportFeedbackFooter.test.tsx
new file mode 100644
index 000000000000..6507358511e4
--- /dev/null
+++ b/products/signals/frontend/inbox/components/detail/ReportFeedbackFooter.test.tsx
@@ -0,0 +1,136 @@
+import '@testing-library/jest-dom'
+
+import { act, cleanup, render, screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import { makeReport } from '../../__mocks__/inboxMocks'
+import { captureInboxReportFeedback, captureInboxReportFeedbackNote } from '../../inboxAnalytics'
+import { CELEBRATION_DURATION_MS } from './ReportFeedbackCelebration'
+import { ReportFeedbackFooter } from './ReportFeedbackFooter'
+
+jest.mock('../../inboxAnalytics', () => ({
+ ...jest.requireActual('../../inboxAnalytics'),
+ captureInboxReportFeedback: jest.fn(),
+ captureInboxReportFeedbackNote: jest.fn(),
+}))
+
+const CELEBRATION_SELECTOR = '[data-attr="inbox-report-feedback-celebration"]'
+
+function setCelebrationFlag(enabled: boolean): void {
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.INBOX_REPORT_FEEDBACK_BANG], {
+ [FEATURE_FLAGS.INBOX_REPORT_FEEDBACK_BANG]: enabled,
+ })
+}
+
+function setReducedMotion(matches: boolean): void {
+ jest.mocked(window.matchMedia).mockImplementation(
+ (query: string) =>
+ ({
+ matches: query.includes('prefers-reduced-motion') && matches,
+ media: query,
+ onchange: null,
+ addListener: jest.fn(),
+ removeListener: jest.fn(),
+ addEventListener: jest.fn(),
+ removeEventListener: jest.fn(),
+ dispatchEvent: jest.fn(),
+ }) as MediaQueryList
+ )
+}
+
+describe('ReportFeedbackFooter', () => {
+ const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime })
+
+ beforeEach(() => {
+ jest.useFakeTimers()
+ useMocks({
+ get: {
+ '/api/projects/:team_id/signals/reports/:id/artefacts/': { results: [] },
+ '/api/projects/:team_id/signals/reports/:id/signals/': { signals: [] },
+ '/api/projects/:team_id/signals/reports/available_reviewers/': [],
+ },
+ post: {
+ '/api/projects/:team_id/signals/reports/:id/feedback/': [200, { forwarded: false }],
+ },
+ })
+ initKeaTests()
+ featureFlagLogic.mount()
+ setReducedMotion(false)
+ jest.mocked(captureInboxReportFeedback).mockClear()
+ jest.mocked(captureInboxReportFeedbackNote).mockClear()
+ render(<ReportFeedbackFooter report={makeReport({ id: 'report-celebration' })} />)
+ })
+
+ afterEach(() => {
+ cleanup()
+ jest.useRealTimers()
+ })
+
+ it('pops the hog once on thumbs-up and removes it when the animation ends', async () => {
+ setCelebrationFlag(true)
+ const thumbsUp = screen.getByLabelText('This report was useful')
+
+ await user.click(thumbsUp)
+
+ expect(document.querySelector(CELEBRATION_SELECTOR)).toBeInTheDocument()
+ expect(captureInboxReportFeedback).toHaveBeenCalledTimes(1)
+ expect(captureInboxReportFeedback).toHaveBeenCalledWith(expect.objectContaining({ sentiment: 'positive' }))
+
+ act(() => {
+ jest.advanceTimersByTime(CELEBRATION_DURATION_MS)
+ })
+ expect(document.querySelector(CELEBRATION_SELECTOR)).not.toBeInTheDocument()
+
+ // A re-click is a no-op for feedback, so it earns no second pop either.
+ await user.click(thumbsUp)
+ expect(document.querySelector(CELEBRATION_SELECTOR)).not.toBeInTheDocument()
+ expect(captureInboxReportFeedback).toHaveBeenCalledTimes(1)
+ })
+
+ it('asks a question matched to the rating, sends the note with Enter, and shows what went through', async () => {
+ setCelebrationFlag(false)
+ expect(screen.queryByLabelText('Add a note about this report')).not.toBeInTheDocument()
+
+ await user.click(screen.getByLabelText('This report was useful'))
+ expect(screen.getByText('What made it useful?')).toBeVisible()
+
+ await user.click(screen.getByLabelText('This report was not useful'))
+ expect(screen.getByText('What was off?')).toBeVisible()
+ await user.type(screen.getByLabelText('Add a note about this report'), 'The repro steps were wrong{Enter}')
+
+ expect(captureInboxReportFeedbackNote).toHaveBeenCalledWith(
+ expect.objectContaining({ sentiment: 'negative', note: 'The repro steps were wrong' })
+ )
+ expect(screen.getByText('Note added: The repro steps were wrong')).toBeVisible()
+ expect(screen.queryByLabelText('Add a note about this report')).not.toBeInTheDocument()
+ })
+
+ it('does not pop on thumbs-down', async () => {
+ setCelebrationFlag(true)
+
+ await user.click(screen.getByLabelText('This report was not useful'))
+
+ expect(document.querySelector(CELEBRATION_SELECTOR)).not.toBeInTheDocument()
+ expect(captureInboxReportFeedback).toHaveBeenCalledWith(expect.objectContaining({ sentiment: 'negative' }))
+ })
+
+ it.each([
+ ['the flag is off', false, false],
+ ['the reader prefers reduced motion', true, true],
+ ])('records the rating without a pop when %s', async (_, flagEnabled, reducedMotion) => {
+ setCelebrationFlag(flagEnabled)
+ setReducedMotion(reducedMotion)
+
+ await user.click(screen.getByLabelText('This report was useful'))
+
+ expect(document.querySelector(CELEBRATION_SELECTOR)).not.toBeInTheDocument()
+ expect(screen.getByText('Thanks for the feedback!')).toBeVisible()
+ expect(captureInboxReportFeedback).toHaveBeenCalledTimes(1)
+ })
+})
diff --git a/products/signals/frontend/inbox/components/detail/ReportFeedbackFooter.tsx b/products/signals/frontend/inbox/components/detail/ReportFeedbackFooter.tsx
index 94bdfc356542..26dfdd343cfd 100644
--- a/products/signals/frontend/inbox/components/detail/ReportFeedbackFooter.tsx
+++ b/products/signals/frontend/inbox/components/detail/ReportFeedbackFooter.tsx
@@ -1,7 +1,8 @@
+import clsx from 'clsx'
import { useActions, useValues } from 'kea'
import { useState } from 'react'
-import { IconThumbsDown, IconThumbsDownFilled, IconThumbsUp, IconThumbsUpFilled } from '@posthog/icons'
+import { IconThumbsDown, IconThumbsDownFilled, IconThumbsUp, IconThumbsUpFilled, IconX } from '@posthog/icons'
import { LemonButton } from '@posthog/lemon-ui'
import { LemonTextArea } from 'lib/lemon-ui/LemonTextArea'
@@ -9,6 +10,7 @@ import { LemonTextArea } from 'lib/lemon-ui/LemonTextArea'
import { InboxReportFeedbackSentiment } from '../../inboxAnalytics'
import { inboxReportDetailLogic } from '../../logics/inboxReportDetailLogic'
import { SignalReport } from '../../types'
+import { useReportFeedbackCelebration } from './ReportFeedbackCelebration'
// Matches the cap on the sibling inbox dialogs (Dismiss, Refund, agent question); the note rides along as
// an analytics property, so keep it under the client's per-property limit.
@@ -17,8 +19,8 @@ const FEEDBACK_NOTE_MAX_LENGTH = 4000
/**
* Thumbs rating at the end of the report body, where someone has just finished reading. The rating
* submits on the first click, so there's no text field to mistake for the dismissal reason. Only
- * once it's recorded does an optional note appear, so the note can never gate the rating, and
- * ignoring it leaves the flow exactly as it was.
+ * once it's recorded does a follow-up question appear, matched to the rating, so the note can
+ * never gate the rating and ignoring it leaves the flow exactly as it was.
*/
export function ReportFeedbackFooter({
report,
@@ -29,41 +31,72 @@ export function ReportFeedbackFooter({
align?: 'start' | 'end'
}): JSX.Element {
const logic = inboxReportDetailLogic({ reportId: report.id, report })
- const { feedbackSentiment, feedbackNoteOpen, feedbackNoteDraft, feedbackNoteSent, feedbackNoteSubmitting } =
+ const { feedbackSentiment, feedbackNoteDraft, feedbackNoteSent, feedbackSentNote, feedbackNoteSubmitting } =
useValues(logic)
- const { rateReport, openFeedbackNote, setFeedbackNoteDraft, submitFeedbackNote } = useActions(logic)
+ const { rateReport, setFeedbackNoteDraft, submitFeedbackNote } = useActions(logic)
- // Focus the note only when *this* instance opened it. `feedbackNoteOpen` is report-keyed state
- // shared with the copy of this row on the other tab, and `LemonTabs` remounts tab content, so
- // an unconditional `autoFocus` would grab focus and scroll on every tab switch with a draft open.
- const [openedHere, setOpenedHere] = useState(false)
+ const { celebrate, celebration } = useReportFeedbackCelebration()
+ // Focus the question only in the instance that was clicked: the row is rendered on more than one
+ // tab, and `LemonTabs` remounts tab content, so an unconditional `autoFocus` would grab focus on
+ // every tab switch.
+ const [askedHere, setAskedHere] = useState(false)
+ const [questionDismissed, setQuestionDismissed] = useState(false)
+ const sendNote = (): void => {
+ if (feedbackNoteDraft.trim()) {
+ submitFeedbackNote(feedbackNoteDraft)
+ }
+ }
const isPositive = feedbackSentiment === 'positive'
const isNegative = feedbackSentiment === 'negative'
// Re-clicking the chosen thumb is a no-op rather than a second identical feedback event.
const rate = (sentiment: InboxReportFeedbackSentiment): void => {
- if (feedbackSentiment !== sentiment) {
- rateReport(sentiment)
+ if (feedbackSentiment === sentiment) {
+ return
+ }
+ rateReport(sentiment)
+ setQuestionDismissed(false)
+ setAskedHere(true)
+ if (sentiment === 'positive') {
+ celebrate()
}
}
+ const askingWhy = !!feedbackSentiment && !feedbackNoteSent && !questionDismissed
return (
<div className={align === 'end' ? 'flex flex-col items-end gap-2 pt-1' : 'flex flex-col gap-2 pt-1'}>
{/* `select-none` stays on the rating row: on the wrapper it would also cover the note
textarea, where it blocks selecting text to edit or copy a draft. */}
<div className="flex items-center gap-2 flex-wrap text-xs text-tertiary select-none">
- <span>{feedbackSentiment ? 'Thanks for the feedback' : 'Was this report useful?'}</span>
+ {/* Both labels share one grid cell so the thumbs sit still when the text swaps. */}
+ <span className={clsx('grid', align === 'end' && 'text-end')}>
+ <span
+ className={clsx('col-start-1 row-start-1', feedbackSentiment && 'invisible')}
+ aria-hidden={!!feedbackSentiment}
+ >
+ Was this report useful?
+ </span>
+ <span
+ className={clsx('col-start-1 row-start-1', !feedbackSentiment && 'invisible')}
+ aria-hidden={!feedbackSentiment}
+ >
+ Thanks for the feedback!
+ </span>
+ </span>
<div className="flex items-center gap-1">
- <LemonButton
- size="xsmall"
- type={isPositive ? 'primary' : 'secondary'}
- icon={isPositive ? <IconThumbsUpFilled /> : <IconThumbsUp />}
- tooltip="Yes, this was useful"
- aria-label="This report was useful"
- aria-pressed={isPositive}
- onClick={() => rate('positive')}
- data-attr="inbox-report-feedback-thumbs-up"
- />
+ <span className="relative inline-flex">
+ <LemonButton
+ size="xsmall"
+ type={isPositive ? 'primary' : 'secondary'}
+ icon={isPositive ? <IconThumbsUpFilled /> : <IconThumbsUp />}
+ tooltip="Yes, this was useful"
+ aria-label="This report was useful"
+ aria-pressed={isPositive}
+ onClick={() => rate('positive')}
+ data-attr="inbox-report-feedback-thumbs-up"
+ />
+ {celebration}
+ </span>
<LemonButton
size="xsmall"
type={isNegative ? 'primary' : 'secondary'}
@@ -75,49 +108,64 @@ export function ReportFeedbackFooter({
data-attr="inbox-report-feedback-thumbs-down"
/>
</div>
- {feedbackSentiment && !feedbackNoteOpen && !feedbackNoteSent && (
- <LemonButton
- size="xsmall"
- type="tertiary"
- onClick={() => {
- setOpenedHere(true)
- openFeedbackNote()
- }}
- data-attr="inbox-report-feedback-add-note"
- >
- Add a note
- </LemonButton>
- )}
- {feedbackNoteSent && <span>Note added</span>}
</div>
- {feedbackNoteOpen && (
- <div className="flex w-full max-w-prose flex-col items-start gap-2">
- <LemonTextArea
- value={feedbackNoteDraft}
- onChange={setFeedbackNoteDraft}
- placeholder="What was useful or off?"
- // The placeholder is the only visible prompt and it disappears on the first
- // keystroke, so the field carries its own name for screen readers.
- aria-label="Add a note about this report"
- maxLength={FEEDBACK_NOTE_MAX_LENGTH}
- minRows={5}
- maxRows={12}
- autoFocus={openedHere}
- className="w-full"
- data-attr="inbox-report-feedback-note"
- />
- <LemonButton
- size="xsmall"
- type="primary"
- loading={feedbackNoteSubmitting}
- disabledReason={feedbackNoteDraft.trim() ? undefined : 'Write a note first'}
- onClick={() => submitFeedbackNote(feedbackNoteDraft)}
- data-attr="inbox-report-feedback-note-send"
- >
- Send
- </LemonButton>
+ {/* The question lives under the row so it never pushes the thumbs sideways. */}
+ {askingWhy && (
+ <div
+ className="flex w-full max-w-96 flex-col gap-1.5 rounded border border-primary p-2"
+ data-attr="inbox-report-feedback-question"
+ >
+ <div className="flex items-center gap-1">
+ <span className="grow text-xs font-medium text-primary">
+ {feedbackSentiment === 'positive' ? 'What made it useful?' : 'What was off?'}
+ </span>
+ <LemonButton
+ size="xsmall"
+ type="tertiary"
+ icon={<IconX />}
+ aria-label="Dismiss"
+ onClick={() => setQuestionDismissed(true)}
+ data-attr="inbox-report-feedback-question-dismiss"
+ />
+ </div>
+ <div className="flex items-end gap-1.5">
+ {/* `className` lands on the inner textarea too, so the flex sizing stays on a wrapper. */}
+ <div className="min-w-0 flex-1">
+ <LemonTextArea
+ value={feedbackNoteDraft}
+ // Capped here rather than with `maxLength`, whose counter footer would
+ // make the small field a block.
+ onChange={(value) => setFeedbackNoteDraft(value.slice(0, FEEDBACK_NOTE_MAX_LENGTH))}
+ onPressEnter={sendNote}
+ placeholder="Your note improves future reports"
+ aria-label="Add a note about this report"
+ minRows={2}
+ maxRows={8}
+ autoFocus={askedHere}
+ className="resize-none"
+ data-attr="inbox-report-feedback-note"
+ />
+ </div>
+ {/* Shown only once there is text, so there is never a disabled button to look at. */}
+ {feedbackNoteDraft.trim() && (
+ <LemonButton
+ size="medium"
+ type="primary"
+ loading={feedbackNoteSubmitting}
+ onClick={sendNote}
+ data-attr="inbox-report-feedback-note-send"
+ >
+ Send
+ </LemonButton>
+ )}
+ </div>
</div>
)}
+ {feedbackNoteSent && (
+ <p className={clsx('m-0 max-w-96 text-xs text-tertiary', align === 'end' && 'text-end')}>
+ Note added: {feedbackSentNote}
+ </p>
+ )}
</div>
)
}
diff --git a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
index 5ec523098664..686acb2068d4 100644
--- a/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
+++ b/products/signals/frontend/inbox/logics/inboxReportDetailLogic.ts
@@ -305,9 +305,9 @@ export interface inboxReportDetailLogicValues {
evidenceExpanded: boolean
expandedTaskIds: string[]
feedbackNoteDraft: string
- feedbackNoteOpen: boolean
feedbackNoteSent: boolean
feedbackNoteSubmitting: boolean
+ feedbackSentNote: string | null
feedbackSentiment: InboxReportFeedbackSentiment | null
hasImplementationPr: boolean
hasPersonalGithub: boolean
@@ -538,9 +538,6 @@ export interface inboxReportDetailLogicActions {
openDraftThread: (draft: DraftThread) => {
draft: DraftThread
}
- openFeedbackNote: () => {
- value: true
- }
postReviewComment: (payload: {
body: string
inReplyTo?: string
@@ -747,7 +744,6 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
surface,
}),
// Optional note, offered only after a rating is in. The rating is never held up waiting for it.
- openFeedbackNote: true,
setFeedbackNoteDraft: (draft: string) => ({ draft }),
// The note rides on the payload: the reducers below clear the draft, and listeners run after them.
submitFeedbackNote: (note: string, surface: InboxReportActionSurface = 'detail_footer') => ({ note, surface }),
@@ -1014,16 +1010,8 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
rateReport: (_, { sentiment }) => sentiment,
},
],
- // Whether the optional note field is showing. Switching the rating closes an unsent note so
- // the draft can't end up attached to a sentiment the reader has since changed their mind about.
- feedbackNoteOpen: [
- false,
- {
- openFeedbackNote: () => true,
- rateReport: () => false,
- submitFeedbackNote: () => false,
- },
- ],
+ // Switching the rating drops an unsent draft so it can't end up attached to a sentiment the
+ // reader has since changed their mind about.
feedbackNoteDraft: [
'',
{
@@ -1032,6 +1020,14 @@ export const inboxReportDetailLogic = kea<inboxReportDetailLogicType>([
submitFeedbackNote: () => '',
},
],
+ // The note as sent, so the row can show the reader what went through.
+ feedbackSentNote: [
+ null as string | null,
+ {
+ submitFeedbackNote: (_, { note }) => note.trim() || null,
+ rateReport: () => null,
+ },
+ ],
feedbackNoteSent: [
false,
{
diff --git a/products/signals/package.json b/products/signals/package.json
index 5a741e0d119f..6cc4306047ec 100644
--- a/products/signals/package.json
+++ b/products/signals/package.json
@@ -24,6 +24,7 @@
"msw": "^2.14.6"
},
"peerDependencies": {
+ "@posthog/brand": "catalog:",
"@posthog/icons": "catalog:",
"@posthog/lemon-ui": "*",
"@storybook/react": "catalog:",