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(signals): simplify report verdict context menus (#97346)

posthog[bot]e39f9becea49
diff --git a/products/signals/frontend/inbox/components/cards/ReasonSubmenuItems.tsx b/products/signals/frontend/inbox/components/cards/ReasonSubmenuItems.tsx
new file mode 100644
index 000000000000..a9eb4c2ba852
--- /dev/null
+++ b/products/signals/frontend/inbox/components/cards/ReasonSubmenuItems.tsx
@@ -0,0 +1,66 @@
+import { Fragment } from 'react'
+
+import { IconPencil } from '@posthog/icons'
+
+import { ButtonGroupPrimitive, ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'
+import { ContextMenuGroup, ContextMenuItem, ContextMenuSeparator } from 'lib/ui/ContextMenu/ContextMenu'
+
+export function ReasonSubmenuItems<T extends string>({
+ options,
+ noteTooltip,
+ dataAttrPrefix,
+ onPick,
+ onPickWithNote,
+}: {
+ options: readonly { readonly value: T; readonly label: string }[]
+ noteTooltip: string
+ dataAttrPrefix: string
+ onPick: (reason: T) => void
+ onPickWithNote: (reason: T) => void
+}): JSX.Element {
+ return (
+ <ContextMenuGroup>
+ {options.map((option) =>
+ option.value === 'other' ? (
+ <Fragment key={option.value}>
+ <ContextMenuSeparator />
+ <ButtonGroupPrimitive fullWidth>
+ <ContextMenuItem asChild>
+ <ButtonPrimitive
+ menuItem
+ hasSideActionRight
+ onClick={() => onPick(option.value)}
+ data-attr={`${dataAttrPrefix}-reason`}
+ >
+ Other
+ </ButtonPrimitive>
+ </ContextMenuItem>
+ <ContextMenuItem asChild>
+ <ButtonPrimitive
+ iconOnly
+ isSideActionRight
+ tooltip={noteTooltip}
+ aria-label={noteTooltip}
+ onClick={() => onPickWithNote(option.value)}
+ data-attr={`${dataAttrPrefix}-note`}
+ >
+ <IconPencil />
+ </ButtonPrimitive>
+ </ContextMenuItem>
+ </ButtonGroupPrimitive>
+ </Fragment>
+ ) : (
+ <ContextMenuItem asChild key={option.value}>
+ <ButtonPrimitive
+ menuItem
+ onClick={() => onPick(option.value)}
+ data-attr={`${dataAttrPrefix}-reason`}
+ >
+ {option.label}
+ </ButtonPrimitive>
+ </ContextMenuItem>
+ )
+ )}
+ </ContextMenuGroup>
+ )
+}
diff --git a/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx b/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx
index eef8999cb5a2..20800ef33080 100644
--- a/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx
+++ b/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx
@@ -128,43 +128,75 @@ describe('ReportContextMenu', () => {
expect(menuRowText()).toEqual([])
})
- // The submenu's whole point: a reason click persists that reason. A miswired option (wrong
- // state, wrong reason value) would silently record the wrong verdict on every report.
- it('resolves with the picked reason through the state API', async () => {
- openMenu(makeReport())
-
- fireEvent.click(screen.getByText('Resolve'))
- fireEvent.click(await screen.findByText('PR was merged'))
-
- await waitFor(() => {
- expect(stateRequests).toEqual([
- { reportId: 'report-1', body: { state: 'resolved', dismissal_reason: 'pr_merged' } },
- ])
- })
- })
-
- it('dismisses with the picked reason through the state API', async () => {
+ // The submenu's whole point: a reason click persists that reason, with no dialog in the way.
+ // A miswired option (wrong state, wrong reason value) would silently record the wrong verdict on
+ // every report. The immediate catch-all action uses "Other" without an ellipsis so it does not
+ // imply that a dialog will open.
+ it.each([
+ {
+ submenu: 'Resolve',
+ reason: 'PR was merged',
+ body: { state: 'resolved', dismissal_reason: 'pr_merged' },
+ },
+ {
+ submenu: 'Resolve',
+ reason: 'Other',
+ body: { state: 'resolved', dismissal_reason: 'other' },
+ },
+ {
+ submenu: 'Dismiss',
+ reason: "Won't fix - intentional behavior",
+ body: { state: 'suppressed', dismissal_reason: 'wontfix_intentional' },
+ },
+ {
+ submenu: 'Dismiss',
+ reason: 'Other',
+ body: { state: 'suppressed', dismissal_reason: 'other' },
+ },
+ ])('$submenu > $reason applies through the state API', async ({ submenu, reason, body }) => {
openMenu(makeReport())
- fireEvent.click(screen.getByText('Dismiss'))
- fireEvent.click(await screen.findByText("Won't fix - intentional behavior"))
+ fireEvent.click(screen.getByText(submenu))
+ fireEvent.click(await screen.findByText(reason))
await waitFor(() => {
- expect(stateRequests).toEqual([
- { reportId: 'report-1', body: { state: 'suppressed', dismissal_reason: 'wontfix_intentional' } },
- ])
+ expect(stateRequests).toEqual([{ reportId: 'report-1', body }])
})
})
- // An instant wrong-repo dismissal would record the mistake without the corrected repository,
- // which is the half of the feedback the next repo selection learns from.
- it('routes the wrong repository reason through the dialog instead of applying it', async () => {
+ // Two reasons still need the dialog: an instant wrong-repo dismissal would record the mistake
+ // without the corrected repository, which is the half of the feedback the next repo selection
+ // learns from, and the pencil beside "Something else…" is the only way left to write a note.
+ it.each([
+ {
+ name: 'the wrong repository reason',
+ submenu: 'Dismiss',
+ pick: 'Agent picked the wrong repository',
+ byLabel: false,
+ dialog: 'Dismiss report "Report one"?',
+ },
+ {
+ name: "the dismiss submenu's note button",
+ submenu: 'Dismiss',
+ // The pencil carries no label text of its own, so it answers to its tooltip.
+ pick: 'Dismiss and write a note',
+ byLabel: true,
+ dialog: 'Dismiss report "Report one"?',
+ },
+ {
+ name: "the resolve submenu's note button",
+ submenu: 'Resolve',
+ pick: 'Resolve and write a note',
+ byLabel: true,
+ dialog: 'Resolve report "Report one"?',
+ },
+ ])('routes $name through the dialog instead of applying it', async ({ submenu, pick, byLabel, dialog }) => {
openMenu(makeReport())
- fireEvent.click(screen.getByText('Dismiss'))
- fireEvent.click(await screen.findByText('Agent picked the wrong repository'))
+ fireEvent.click(screen.getByText(submenu))
+ fireEvent.click(byLabel ? await screen.findByLabelText(pick) : await screen.findByText(pick))
- expect(await screen.findByText('Dismiss report "Report one"?')).toBeInTheDocument()
+ expect(await screen.findByText(dialog)).toBeInTheDocument()
expect(stateRequests).toEqual([])
})
})
diff --git a/products/signals/frontend/inbox/components/cards/ReportContextMenu.tsx b/products/signals/frontend/inbox/components/cards/ReportContextMenu.tsx
index 5ba389e45daf..50b94eb086c0 100644
--- a/products/signals/frontend/inbox/components/cards/ReportContextMenu.tsx
+++ b/products/signals/frontend/inbox/components/cards/ReportContextMenu.tsx
@@ -1,6 +1,6 @@
import { useActions } from 'kea'
import { router } from 'kea-router'
-import { Fragment, ReactNode, useRef } from 'react'
+import { ReactNode, useRef } from 'react'
import {
IconArrowUpRight,
@@ -45,16 +45,16 @@ import { displayConventionalCommitTitle } from '../../utils/reportPresentation'
import { ReviewerSearchList } from '../detail/ReviewerSearchList'
import { openDismissReportDialog } from '../shell/DismissReportDialog'
import { openResolveReportDialog } from '../shell/ResolveReportDialog'
+import { ReasonSubmenuItems } from './ReasonSubmenuItems'
/**
* Right-click menu on a report row in the flat inbox list: the report's major actions without
* opening its detail. Create PR, Resolve, Dismiss, and Reviewers follow the same eligibility rules
* as the detail pane (`utils/reportActions.ts`); a dismissed row offers Restore instead. Resolve
* and Dismiss nest their canonical reasons, and picking one applies immediately through the owning
- * section's list logic, except "Something else…", which opens the existing dialog to collect the
- * note that reason needs, and "wrong repository", whose dialog asks which repository it should have
- * been. Rows with no action (resolved, refunded) render without a menu, so the
- * browser's own menu still works there. On rows with a menu the trigger suppresses that native
+ * section's list logic. The dialog stays available for a note, a corrected repository, or an open
+ * implementation PR warning. Rows with no action (resolved, refunded) render without a menu, so
+ * the browser's own menu still works there. On rows with a menu the trigger suppresses that native
* menu over the row's link, so the standard link actions return as an explicit section at the
* bottom (open, open in new tab, copy link).
*/
@@ -89,8 +89,8 @@ export function ReportContextMenu({
<ContextMenuContent
loop
className="min-w-48"
- // The "Something else…" dialogs autofocus their note field, and the menu closes on
- // the same click. Its closing focus restore runs after the dialog opens and would
+ // The verdict dialogs autofocus their first field, and the menu closes on the same
+ // click. Its closing focus restore runs after the dialog opens and would
// pull focus back to the row, so skip the restore for exactly that close.
onCloseAutoFocus={(event) => {
if (openedDialogRef.current) {
@@ -129,20 +129,8 @@ function ReportContextMenuItems({
// Kept mounted by `ReportsTab` beyond this menu's lifetime, so the create-PR listener survives
// the menu closing on click.
const { createPrFromReport } = useActions(inboxTaskKickoffLogic)
-
const reportTitle = displayConventionalCommitTitle(report.title, 'Untitled report')
-
- const resolveWithReason = (reason: ResolveReasonValue, note: string): void => {
- // pinned: `dismissal_reason` is the persisted field the reason lands in, for both verdicts.
- // Only the structured reason — the free-form note can carry proprietary text.
- captureInboxReportAction({
- report,
- actionType: 'resolve',
- surface: 'context_menu',
- extra: { dismissal_reason: reason },
- })
- resolveReport(report.id, reason, note)
- }
+ const hasOpenPr = hasOpenImplementationPr(report)
const dismissWith = (dismissal: DismissalFeedback): void => {
const { reason, note, correctedRepository } = dismissal
@@ -159,38 +147,49 @@ function ReportContextMenuItems({
dismissReport(report.id, dismissal)
}
- // "Something else…" needs the note the other reasons don't, so it goes through the dialog. So does
- // any reason while the report still has an open implementation PR: resolving or dismissing closes
- // that PR, so the dialog's warning and its confirm step stand in for the instant apply. A wrong-repo
- // dismissal goes through it too, so the person can name the repository it should have been.
- const pickResolveReason = (reason: ResolveReasonValue): void => {
- if (reason === 'other' || hasOpenImplementationPr(report)) {
- onOpenDialog()
- openResolveReportDialog({
- reportTitle,
- hasOpenPr: hasOpenImplementationPr(report),
- initialReason: reason,
- onConfirm: ({ reason, note }) => resolveWithReason(reason, note),
- })
- return
- }
- resolveWithReason(reason, '')
+ const resolveWith = (reason: ResolveReasonValue, note: string): void => {
+ // pinned: `dismissal_reason` is the persisted field the reason lands in, for both verdicts.
+ // Only the structured reason is safe for analytics because the note can contain private text.
+ captureInboxReportAction({
+ report,
+ actionType: 'resolve',
+ surface: 'context_menu',
+ extra: { dismissal_reason: reason },
+ })
+ resolveReport(report.id, reason, note)
+ }
+
+ const openDismissDialog = (initialReason?: DismissalReasonValue): void => {
+ onOpenDialog()
+ openDismissReportDialog({ reportTitle, hasOpenPr, initialReason, onConfirm: dismissWith })
+ }
+
+ const openResolveDialog = (initialReason?: ResolveReasonValue): void => {
+ onOpenDialog()
+ openResolveReportDialog({
+ reportTitle,
+ hasOpenPr,
+ initialReason,
+ onConfirm: ({ reason, note }) => resolveWith(reason, note),
+ })
}
const pickDismissReason = (reason: DismissalReasonValue): void => {
- if (reason === 'other' || reason === 'wrong_repo' || hasOpenImplementationPr(report)) {
- onOpenDialog()
- openDismissReportDialog({
- reportTitle,
- hasOpenPr: hasOpenImplementationPr(report),
- initialReason: reason,
- onConfirm: dismissWith,
- })
+ if (reason === 'wrong_repo' || hasOpenPr) {
+ openDismissDialog(reason)
return
}
dismissWith({ reason, note: '', correctedRepository: null })
}
+ const pickResolveReason = (reason: ResolveReasonValue): void => {
+ if (hasOpenPr) {
+ openResolveDialog(reason)
+ return
+ }
+ resolveWith(reason, '')
+ }
+
// The menu only mounts in the redesign flat list, whose rows link to the reports tab with no
// back param, so the default detail URL is exactly the row's own href.
const detailUrl = inboxReportDetailUrl(report.id)
@@ -299,24 +298,13 @@ function ReportContextMenuItems({
{/* The base menu caps at 200px, which wraps the longer reason labels into the
buttons' fixed height. */}
<ContextMenuSubContent className="max-w-80">
- <ContextMenuGroup>
- {RESOLVE_REASON_OPTIONS.map((option) => (
- <Fragment key={option.value}>
- {/* The canned reasons apply instantly; "Something else…" opens
- the note dialog, so it sits apart. */}
- {option.value === 'other' && <ContextMenuSeparator />}
- <ContextMenuItem asChild>
- <ButtonPrimitive
- menuItem
- onClick={() => pickResolveReason(option.value)}
- data-attr="inbox-report-context-menu-resolve-reason"
- >
- {option.label}
- </ButtonPrimitive>
- </ContextMenuItem>
- </Fragment>
- ))}
- </ContextMenuGroup>
+ <ReasonSubmenuItems
+ options={RESOLVE_REASON_OPTIONS}
+ noteTooltip="Resolve and write a note"
+ dataAttrPrefix="inbox-report-context-menu-resolve"
+ onPick={pickResolveReason}
+ onPickWithNote={openResolveDialog}
+ />
</ContextMenuSubContent>
</ContextMenuSub>
)}
@@ -329,22 +317,13 @@ function ReportContextMenuItems({
</ButtonPrimitive>
</ContextMenuSubTrigger>
<ContextMenuSubContent className="max-w-80">
- <ContextMenuGroup>
- {DISMISSAL_REASON_OPTIONS.map((option) => (
- <Fragment key={option.value}>
- {option.value === 'other' && <ContextMenuSeparator />}
- <ContextMenuItem asChild>
- <ButtonPrimitive
- menuItem
- onClick={() => pickDismissReason(option.value)}
- data-attr="inbox-report-context-menu-dismiss-reason"
- >
- {option.label}
- </ButtonPrimitive>
- </ContextMenuItem>
- </Fragment>
- ))}
- </ContextMenuGroup>
+ <ReasonSubmenuItems
+ options={DISMISSAL_REASON_OPTIONS}
+ noteTooltip="Dismiss and write a note"
+ dataAttrPrefix="inbox-report-context-menu-dismiss"
+ onPick={pickDismissReason}
+ onPickWithNote={openDismissDialog}
+ />
</ContextMenuSubContent>
</ContextMenuSub>
<ContextMenuSub>