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): multi-select inbox report cards to dismiss or resolve in one go (#98347)

posthog[bot]a90e6b97d6d7
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index e7badb70b7d6..4ae2b47b9a05 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -7785,9 +7785,9 @@ snapshots:
scenes-app-inbox-scene--self-driving-onboarding--light:
hash: v1.k794b7964.5268ad52b39cdc5bb1d699e6a1a839a552ce397134d6773714e1f5a2d95994b6.hgkYOJDE9ZNZ0mMtcj9cpcDCtmas-opelntO_tyQ9Ig
scenes-app-inbox-scene--self-driving-paused--dark:
- hash: v1.k794b7964.b5432aa0409fb72bd8df3c1c914d7303bfa4b13bcad3ea72474526986bc53d1f.ifHdPrnNKpfuPKc_en16o1gOogrh3vh7vjM8D2eBZw0
+ hash: v1.k794b7964.6f6de2a01c5398c97c8ddd0281400631d6ba29d103597b77105c801643a409bc.-TaozrVEIt_uo8VyQ6nVEBHm963WvHGLzUHxi8wp26Y
scenes-app-inbox-scene--self-driving-paused--light:
- hash: v1.k794b7964.68c5a0b4b3a71f9d57ebd22d85c5aedfc6704872ee036cf00c7ba2cf83e4f0c8.k5ktgrWKHvJI9sH0wPbcQ4YI64a33tQ-5oSG_YpCjXw
+ hash: v1.k794b7964.9efe93134b008b672d863eea64d6df50e116fc062382640487cf7abe064da8a3.4iJCYRKBIvpPuk4gUo05pIcps0bn_D2Kc7i2UpldvYw
scenes-app-inbox-scene--self-driving-verdict-pending--dark:
hash: v1.k794b7964.3d6c42afbe79033f9c7dad5ca09eb0e34d874aa4c73837d6d6f91fefe37b10df.MxJN_DArFyn1VpR8nheZ1FLPtFcbL2StXF9tha9Tk4o
scenes-app-inbox-scene--self-driving-verdict-pending--light:
@@ -8069,9 +8069,9 @@ snapshots:
scenes-app-inbox-tabs--pull-requests-legacy--light:
hash: v1.k794b7964.d66d0f73814191c857a64891ddd73dbbca609b40f71b80b5a97b95b1d0ed5d0d.coTm8czKJGGrvOoP28HGqgyV0I1HTpvp14uWHt7b4dQ
scenes-app-inbox-tabs--reports--dark:
- hash: v1.k794b7964.fe27a895558915d24de4ef9f9511479ebcd0782da864a5d1b85f81b5263327a3.wCHia_XS0ZgsPveDc9FPERSvKwbu8uzGer6NY7jUvG8
+ hash: v1.k794b7964.b1db9bb0142b3483849bfe5e58d3f28f30ebff35b182334908744be186401445.nbPIXcHKsEmF7_o13nUuwjXNdkI5MZ05uaU6kCMQHGc
scenes-app-inbox-tabs--reports--light:
- hash: v1.k794b7964.3de600060cd59ed20fe68fe175911b3ca30a42e434c72258b6e45054d3777e6b.RJUlFpkeZ-ZdCFpGYrESLRPVmSAfz8PBUJTRJ50nhVw
+ hash: v1.k794b7964.52016d79921c15036bc3c37a8184e6e077b5b2e2069ec1cafb9c5dd9bf38c52b.vPZ1XXLbha6Uiwe2_OE-EO_sr__aY8etd3z2Zq-QzVA
scenes-app-inbox-tabs--reports-empty--dark:
hash: v1.k794b7964.a84b301c5e7b2f3b614ae70fd79cb33521d4702790bdfe4a4dcad0816a78152e.y29PsyMQdbg-pSBHIijqi2DdHAXSdJTGVyGKvsnPn1E
scenes-app-inbox-tabs--reports-empty--light:
@@ -8081,9 +8081,9 @@ snapshots:
scenes-app-inbox-tabs--reports-legacy--light:
hash: v1.k794b7964.7864bdacc54e80bd704a403fb813da48779160b95ad014df7bbae8a84a5d24a3.7J1YPQyUSF6iat2oGdHpGn1E3Ml0eTRtyb64GwDL334
scenes-app-inbox-tabs--reports-state-filtered--dark:
- hash: v1.k794b7964.07fcb6553c47520c1766a69337feadface4958b28773600ba13c08dd59832b8b.4mws9NjCYtzE7-PnmMW5eqGpEdk7tXixAXvASeFveLE
+ hash: v1.k794b7964.812a63c8b33d45d4e64a37d04674608b0a2fea71f272bdc9dcc038f1fe89962a.qAteZLOJc-E4Y-DaNkuLqAP_0VEWRoggMCwkHZucrT8
scenes-app-inbox-tabs--reports-state-filtered--light:
- hash: v1.k794b7964.31a1d83607d003d30e3aa348ac4323b03fcc22ebcb1ba1a1d1617970596d52db.Nw_djmZopFPyc_6tj_hyUqVh_oo5Ytz6kmSluwo8S0I
+ hash: v1.k794b7964.b1d639cf97e75540e32017e881a0e28c78b5fa25bdb0d9b5cb177810af01c308.LpK3TIDfV6ChorAgMDxdv4wso9VdLAuRgV7tiyDKo8k
scenes-app-inbox-tabs--runs--dark:
hash: v1.k794b7964.4ece3bdc6be5207a77eafc6d9005ce3a065539767d7a4da5f3f2f5f913bb3567.Wu4dnjXImAjEXPa2f8AdBAeJIwpnA-ak02ZeHI87kBo
scenes-app-inbox-tabs--runs--light:
diff --git a/products/signals/frontend/inbox/components/InboxReportList.tsx b/products/signals/frontend/inbox/components/InboxReportList.tsx
index 2c740dea0ff7..2c8193f5e711 100644
--- a/products/signals/frontend/inbox/components/InboxReportList.tsx
+++ b/products/signals/frontend/inbox/components/InboxReportList.tsx
@@ -199,7 +199,7 @@ function InboxReportListInner({ tabKey, Card, emptyState }: InboxReportListProps
return (
<div className="@container mx-auto max-w-4xl flex flex-col gap-4 px-6 py-4">
<InboxSearchFilterBar onRefresh={() => refresh()} refreshing={reportsResponseLoading} />
- <InboxBulkSelectionBar />
+ <InboxBulkSelectionBar reports={reports} />
{showSkeleton ? (
<CardSkeleton count={Math.min(count ?? 4, 6)} variant="cards" dashed={tabKey !== 'pulls'} />
diff --git a/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx b/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx
index 8053b9708c50..3413f9949471 100644
--- a/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx
+++ b/products/signals/frontend/inbox/components/cards/ReportCard.test.tsx
@@ -1,24 +1,26 @@
import '@testing-library/jest-dom'
-import { cleanup, render } from '@testing-library/react'
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { router } from 'kea-router'
+import posthog from 'posthog-js'
-import { FEATURE_FLAGS } from 'lib/constants'
-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import api from 'lib/api'
import { initKeaTests } from '~/test/init'
+import { INBOX_EVENTS } from '../../inboxAnalytics'
+import { inboxBulkActionsLogic } from '../../logics/inboxBulkActionsLogic'
import { SignalReport, SignalReportStatus } from '../../types'
+import { SELECTION_HOLD_MS } from '../../utils/reportSelection'
import { ReportCard } from './ReportCard'
-jest.mock('lib/components/TZLabel', () => ({
- TZLabel: ({ time }: { time: string }) => <span>{time}</span>,
-}))
+jest.mock('posthog-js')
-function makeReport(overrides: Partial<SignalReport> = {}): SignalReport {
+function makeReport(id: string, overrides: Partial<SignalReport> = {}): SignalReport {
return {
- id: 'report-1',
- title: 'Hooli traffic is hammering the beta',
- summary: 'Sign-ups from Hooli IP ranges jumped overnight.',
+ id,
+ title: `Report ${id}`,
+ summary: 'summary',
status: SignalReportStatus.READY,
total_weight: 0,
signal_count: 1,
@@ -30,56 +32,152 @@ function makeReport(overrides: Partial<SignalReport> = {}): SignalReport {
created_at: '2026-06-11T10:00:00Z',
updated_at: '2026-06-11T10:00:00Z',
...overrides,
- } as SignalReport
+ } satisfies SignalReport
}
describe('ReportCard', () => {
+ let logic: ReturnType<typeof inboxBulkActionsLogic.build>
+
beforeEach(() => {
initKeaTests()
- featureFlagLogic.mount()
+ logic = inboxBulkActionsLogic()
+ logic.mount()
+ render(<ReportCard report={makeReport('r-1')} selectable />)
+ })
+
+ afterEach(() => {
+ cleanup()
+ jest.useRealTimers()
+ logic.unmount()
+ })
+
+ /** True once a click has followed the card's link through to the report detail. */
+ function openedReport(): boolean {
+ return router.values.location.pathname.includes('r-1')
+ }
+
+ /**
+ * jsdom has no `PointerEvent`, and `fireEvent.pointerDown` drops the button and the
+ * coordinates the hold reads, so dispatch a `MouseEvent` under the pointer event's name.
+ */
+ function firePointer(type: string, init: MouseEventInit): void {
+ fireEvent(cardLink(), new MouseEvent(type, { bubbles: true, ...init }))
+ }
+
+ /** Properties of the last `Inbox selection mode entered` event, if one was captured. */
+ function lastSelectionEntry(): Record<string, unknown> | undefined {
+ const calls = (posthog.capture as jest.Mock).mock.calls.filter(
+ ([event]) => event === INBOX_EVENTS.SELECTION_MODE_ENTERED
+ )
+ return calls[calls.length - 1]?.[1]
+ }
+
+ /** The card body, which is the link a plain click follows. */
+ function cardLink(): HTMLElement {
+ return screen.getByText('Report r-1').closest('a') as HTMLElement
+ }
+
+ it('opens the report on a plain click, leaving the selection empty', () => {
+ fireEvent.click(cardLink())
+
+ expect(openedReport()).toBe(true)
+ expect(logic.values.selectedReportIds).toEqual([])
+ })
+
+ it('selects on cmd-click instead of opening the report', () => {
+ fireEvent.click(cardLink(), { metaKey: true })
+
+ expect(openedReport()).toBe(false)
+ expect(logic.values.selectedReportIds).toEqual(['r-1'])
+ })
+
+ it('toggles on a plain click once the list is in selection mode', () => {
+ fireEvent.click(cardLink(), { metaKey: true })
+ fireEvent.click(cardLink())
+
+ expect(openedReport()).toBe(false)
+ expect(logic.values.selectedReportIds).toEqual([])
+ })
+
+ it('selects on a press and hold, and swallows the click that ends it', () => {
+ jest.useFakeTimers()
+ firePointer('pointerdown', { button: 0, clientX: 10, clientY: 10 })
+ jest.advanceTimersByTime(SELECTION_HOLD_MS)
+ firePointer('pointerup', {})
+
+ expect(logic.values.selectedReportIds).toEqual(['r-1'])
+
+ fireEvent.click(cardLink())
+ expect(openedReport()).toBe(false)
})
- afterEach(cleanup)
-
- // The redesign makes the linked row the only way in and leaves the status / actionability chips
- // to the section headers; the legacy list keeps Dismiss, the Review button, and the chips.
- it.each([[true], [false]])(
- 'with the redesign flag %p shows Review and Dismiss and chips only on the legacy list',
- (redesign) => {
- const legacyChrome = !redesign
- featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.INBOX_REDESIGN], {
- [FEATURE_FLAGS.INBOX_REDESIGN]: redesign,
- })
- const report = makeReport({
- status: SignalReportStatus.CANDIDATE,
- actionability: 'immediately_actionable',
- })
- const { queryByText } = render(<ReportCard report={report} />)
- expect(queryByText('Review') !== null).toBe(legacyChrome)
- expect(queryByText('View report')).toBeNull()
- expect(queryByText('Dismiss') !== null).toBe(legacyChrome)
- expect(queryByText('Queued') !== null).toBe(legacyChrome)
- expect(queryByText('Actionable') !== null).toBe(legacyChrome)
- }
- )
-
- it('links the card to the report detail by default', () => {
- const { container } = render(<ReportCard report={makeReport()} />)
- expect(container.querySelector('a')).toHaveAttribute('href', expect.stringContaining('report-1'))
+
+ it('cancels the hold when the pointer travels, so a scroll never selects', () => {
+ jest.useFakeTimers()
+ firePointer('pointerdown', { button: 0, clientX: 10, clientY: 10 })
+ firePointer('pointermove', { clientX: 10, clientY: 60 })
+ jest.advanceTimersByTime(SELECTION_HOLD_MS)
+
+ expect(logic.values.selectedReportIds).toEqual([])
})
- it('exposes no routable link in preview mode (the placeholder id 404s)', () => {
- const { container, getByText } = render(<ReportCard report={makeReport()} preview />)
- // Card still renders, but nothing navigates to the detail route.
- expect(getByText('Hooli traffic is hammering the beta')).toBeInTheDocument()
- expect(container.querySelector('a')).toBeNull()
+ test.each([
+ ['cmd-click', { metaKey: true }, 'meta_click'],
+ ['shift-click', { shiftKey: true }, 'shift_click'],
+ ])('records the entry method when a %s starts the selection', (_name, modifiers, entryMethod) => {
+ // The rendered order, which a shift-range measures itself against.
+ logic.actions.setVisibleReportIds(['r-1'])
+
+ fireEvent.click(cardLink(), modifiers)
+
+ expect(logic.values.selectedReportIds).toEqual(['r-1'])
+ expect(lastSelectionEntry()).toMatchObject({ entry_method: entryMethod })
})
- it('exposes no link on a preview PR card either (the PR badge url is fabricated)', () => {
- const report = makeReport({
- title: 'fix(compression): stop 4K streams dropping to single-threaded encode',
- implementation_pr_url: 'https://github.com/PiedPiper/pipernet/pull/486',
+ it('leaves a cmd-click on the nested scout link to the browser', () => {
+ // The card rendered for every other test names no scout, so it carries no nested link.
+ cleanup()
+ render(
+ <ReportCard
+ report={{
+ ...makeReport('r-2'),
+ source_products: ['signals_scout'],
+ scout_name: 'signals-scout-web-vitals',
+ }}
+ selectable
+ />
+ )
+ const scoutLink = screen.getByText('Web vitals').closest('a') as HTMLElement
+
+ // `fireEvent` returns false once anything calls `preventDefault`, which is what would
+ // cancel the browser's open-in-a-new-tab gesture.
+ expect(fireEvent.click(scoutLink, { metaKey: true })).toBe(true)
+ expect(logic.values.selectedReportIds).toEqual([])
+ })
+
+ it('selects from the gutter checkbox', () => {
+ fireEvent.click(screen.getByLabelText('Select report: Report r-1'))
+
+ expect(logic.values.selectedReportIds).toEqual(['r-1'])
+ })
+
+ it('does not offer selection for a resolved report', () => {
+ cleanup()
+ render(<ReportCard report={makeReport('r-2', { status: SignalReportStatus.RESOLVED })} selectable />)
+
+ expect(screen.queryByLabelText('Select report: Report r-2')).not.toBeInTheDocument()
+ })
+
+ it('locks the selection while a bulk action is running', () => {
+ const setState = jest.spyOn(api.signalReports, 'setState').mockReturnValue(new Promise<never>(() => {}))
+ act(() => {
+ logic.actions.setSelectedReportIds(['r-1'])
+ logic.actions.bulkDismiss({ reason: 'other', note: '', correctedRepository: null })
})
- const { container } = render(<ReportCard report={report} preview />)
- expect(container.querySelector('a')).toBeNull()
+
+ const checkbox = screen.getByLabelText('Select report: Report r-1')
+ expect(checkbox).toBeDisabled()
+ fireEvent.click(checkbox)
+ expect(logic.values.selectedReportIds).toEqual(['r-1'])
+ setState.mockRestore()
})
})
diff --git a/products/signals/frontend/inbox/components/cards/ReportCard.tsx b/products/signals/frontend/inbox/components/cards/ReportCard.tsx
index 6e6be64ee78b..914b770ca2ad 100644
--- a/products/signals/frontend/inbox/components/cards/ReportCard.tsx
+++ b/products/signals/frontend/inbox/components/cards/ReportCard.tsx
@@ -3,7 +3,7 @@ import { useValues } from 'kea'
import { router } from 'kea-router'
import { IconHide, IconUndo } from '@posthog/icons'
-import { LemonButton, LemonTag, Link, Tooltip } from '@posthog/lemon-ui'
+import { LemonButton, LemonCheckbox, LemonTag, Link, Tooltip } from '@posthog/lemon-ui'
import { TZLabel } from 'lib/components/TZLabel'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
@@ -39,6 +39,7 @@ import {
sourceProductsTooltipTitle,
} from '../badges/sourceProductIcons'
import { inboxCardRowClassName } from './inboxCardRowClassName'
+import { useReportCardSelection } from './useReportCardSelection'
import { useReportDismiss } from './useReportDismiss'
// ── Shared card sub-components ────────────────────────────────────────────────
@@ -118,6 +119,7 @@ export function ReportCard({
onRestore,
backUrl,
preview = false,
+ selectable = false,
}: {
report: SignalReport
sectionKey?: InboxReportSectionKey
@@ -130,6 +132,8 @@ export function ReportCard({
/** Onboarding sample: render as a static card with no detail link and no focusable actions, so its
* placeholder report id can never be opened (it 404s). */
preview?: boolean
+ /** Offer multi-select on this row: the gutter checkbox, press and hold, and modifier clicks. */
+ selectable?: boolean
}): JSX.Element {
// Keyed on status, not the section: the legacy Archive tab lists dismissed and resolved rows
// through one section key, and the two need different affordances.
@@ -155,6 +159,15 @@ export function ReportCard({
redesign ? 'reports' : INBOX_SECTION_LEGACY_TAB[sectionKey]
)
+ const {
+ isSelected,
+ selectionMode,
+ isHolding,
+ selectionDisabled,
+ toggle: toggleSelection,
+ cardHandlers,
+ } = useReportCardSelection(report.id, selectable && !preview && !isResolved)
+
const { isDismissing, onDismissClick } = useReportDismiss({
reportId: report.id,
cardTitle,
@@ -278,10 +291,29 @@ export function ReportCard({
inboxCardRowClassName(attached, { dashed: !hasPr }),
// Closed rows recede so open work stands out in the mixed flat list; hover restores
// full opacity for reading. Matches the disabled-scout treatment in ScoutRosterCard.
- (isDismissed || isResolved) && 'opacity-55 hover:opacity-100'
+ (isDismissed || isResolved) && 'opacity-55 hover:opacity-100',
+ isSelected && 'ring-1 ring-accent',
+ // A long press must not paint the title as selected text under the finger.
+ isHolding && 'select-none'
)}
>
<div className="relative flex min-w-0 flex-1">
+ {selectable && !preview && !isResolved && (
+ <div
+ className={clsx(
+ 'mr-3 flex shrink-0 items-start pt-0.5 transition-opacity',
+ selectionMode ? 'opacity-100' : 'opacity-0 group-hover:opacity-100 focus-within:opacity-100'
+ )}
+ >
+ <LemonCheckbox
+ checked={isSelected}
+ disabledReason={selectionDisabled ? 'Wait for the bulk action to finish' : undefined}
+ onChange={() => toggleSelection('checkbox')}
+ label={<span className="sr-only">Select report: {cardTitle}</span>}
+ data-attr="inbox-report-select"
+ />
+ </div>
+ )}
{hasPr && prNumber != null ? (
<div className="absolute right-0 top-0 z-10">
<PrBadge
@@ -298,9 +330,13 @@ export function ReportCard({
{preview ? (
<div className={cardBodyClassName}>{cardBody}</div>
) : (
- <Link to={detailUrl} className={cardBodyClassName}>
- {cardBody}
- </Link>
+ // The gestures sit on this wrapper, not on the link: a selecting click has to
+ // be caught before the link acts on it.
+ <div className="flex min-w-0 flex-1" {...cardHandlers}>
+ <Link to={detailUrl} className={cardBodyClassName}>
+ {cardBody}
+ </Link>
+ </div>
)}
</div>
diff --git a/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx b/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx
index 20800ef33080..03ee38875df2 100644
--- a/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx
+++ b/products/signals/frontend/inbox/components/cards/ReportContextMenu.test.tsx
@@ -79,22 +79,22 @@ describe('ReportContextMenu', () => {
{
name: 'a ready actionable report offers every action',
report: makeReport(),
- expected: ['Create PR', 'Resolve', 'Dismiss', 'Reviewers'],
+ expected: ['Select', 'Create PR', 'Resolve', 'Dismiss', 'Reviewers'],
},
{
name: 'a report with a PR does not offer creating another',
report: makeReport({ implementation_pr_url: 'https://github.com/posthog/posthog/pull/1' }),
- expected: ['Resolve', 'Dismiss', 'Reviewers'],
+ expected: ['Select', 'Resolve', 'Dismiss', 'Reviewers'],
},
{
name: 'an in-progress report cannot be resolved yet',
report: makeReport({ status: SignalReportStatus.IN_PROGRESS, actionability: null }),
- expected: ['Dismiss', 'Reviewers'],
+ expected: ['Select', 'Dismiss', 'Reviewers'],
},
{
name: 'a dismissed report only offers restore',
report: makeReport({ status: SignalReportStatus.SUPPRESSED }),
- expected: ['Restore'],
+ expected: ['Select', 'Restore'],
},
])('$name', ({ report, expected }) => {
openMenu(report)
diff --git a/products/signals/frontend/inbox/components/cards/ReportContextMenu.tsx b/products/signals/frontend/inbox/components/cards/ReportContextMenu.tsx
index 636bc2367805..3a1ccf44ada3 100644
--- a/products/signals/frontend/inbox/components/cards/ReportContextMenu.tsx
+++ b/products/signals/frontend/inbox/components/cards/ReportContextMenu.tsx
@@ -4,6 +4,7 @@ import { ReactNode, useRef } from 'react'
import {
IconArrowUpRight,
+ IconCheckbox,
IconCheckCircle,
IconChevronRight,
IconCopy,
@@ -46,6 +47,7 @@ import { ReviewerSearchList } from '../detail/ReviewerSearchList'
import { openDismissReportDialog } from '../shell/DismissReportDialog'
import { openResolveReportDialog } from '../shell/ResolveReportDialog'
import { ReasonSubmenuItems } from './ReasonSubmenuItems'
+import { useReportCardSelection } from './useReportCardSelection'
/**
* Right-click menu on a report row in the flat inbox list: the report's major actions without
@@ -132,6 +134,22 @@ function ReportContextMenuItems({
const { createPrDisabledReason } = useValues(inboxTaskKickoffLogic)
const reportTitle = displayConventionalCommitTitle(report.title, 'Untitled report')
const hasOpenPr = hasOpenImplementationPr(report)
+ const { isSelected, toggle: toggleSelection } = useReportCardSelection(report.id, true)
+
+ // The row's own affordances (hold, Cmd-click, checkbox) are easy to miss, so the menu names
+ // the feature outright.
+ const selectItem = (
+ <ContextMenuItem asChild>
+ <ButtonPrimitive
+ menuItem
+ onClick={() => toggleSelection('context_menu')}
+ data-attr="inbox-report-context-menu-select"
+ >
+ <IconCheckbox />
+ {isSelected ? 'Deselect' : 'Select'}
+ </ButtonPrimitive>
+ </ContextMenuItem>
+ )
const dismissWith = (dismissal: DismissalFeedback): void => {
const { reason, note, correctedRepository } = dismissal
@@ -252,6 +270,7 @@ function ReportContextMenuItems({
return (
<>
<ContextMenuGroup>
+ {selectItem}
<ContextMenuItem asChild>
<ButtonPrimitive
menuItem
@@ -271,6 +290,7 @@ function ReportContextMenuItems({
return (
<>
<ContextMenuGroup>
+ {selectItem}
{canCreateImplementationPr(report) && (
<>
<ContextMenuItem asChild disabled={!!createPrDisabledReason}>
diff --git a/products/signals/frontend/inbox/components/cards/useReportCardSelection.ts b/products/signals/frontend/inbox/components/cards/useReportCardSelection.ts
new file mode 100644
index 000000000000..23a088f463b7
--- /dev/null
+++ b/products/signals/frontend/inbox/components/cards/useReportCardSelection.ts
@@ -0,0 +1,185 @@
+import { useActions, useValues } from 'kea'
+import { MouseEvent, PointerEvent, useCallback, useEffect, useRef, useState } from 'react'
+
+import { captureInboxSelectionModeEntered, InboxSelectionEntryMethod } from '../../inboxAnalytics'
+import { inboxBulkActionsLogic } from '../../logics/inboxBulkActionsLogic'
+import {
+ isNestedControlClick,
+ resolveReportCardClickIntent,
+ SELECTION_HOLD_MOVE_TOLERANCE_PX,
+ SELECTION_HOLD_MS,
+} from '../../utils/reportSelection'
+
+export interface ReportCardSelection {
+ isSelected: boolean
+ /** True once anything is selected: every card then shows its checkbox and toggles on click. */
+ selectionMode: boolean
+ /** Set while a hold is running, so the card suppresses text selection under the finger. */
+ isHolding: boolean
+ /** True while a bulk request owns the current selection. */
+ selectionDisabled: boolean
+ /** Select or deselect this report, naming the affordance the person used. */
+ toggle: (method: InboxSelectionEntryMethod) => void
+ /**
+ * Handlers for the wrapper around the card body. The click is handled in the capture phase,
+ * because the body is a `Link` that answers a Cmd-click itself and never calls a handler
+ * passed to it.
+ */
+ cardHandlers: {
+ onClickCapture: (event: MouseEvent) => void
+ onPointerDown: (event: PointerEvent) => void
+ onPointerMove: (event: PointerEvent) => void
+ onPointerUp: () => void
+ onPointerLeave: () => void
+ onPointerCancel: () => void
+ }
+}
+
+/**
+ * Multi-select gestures for one report row: press and hold, Cmd / Ctrl-click, shift-range, and the
+ * gutter checkbox. The selection itself lives in `inboxBulkActionsLogic`; this hook only turns
+ * pointer events into its actions, and it does nothing at all on a row the list marks unselectable.
+ */
+export function useReportCardSelection(reportId: string, enabled: boolean): ReportCardSelection {
+ const { selectedReportIds, hasSelection, isDismissing, isResolving } = useValues(inboxBulkActionsLogic)
+ const { toggleReportSelection, selectRange } = useActions(inboxBulkActionsLogic)
+ const selectionDisabled = isDismissing || isResolving
+
+ const holdTimerRef = useRef<number | null>(null)
+ const holdOriginRef = useRef<{ x: number; y: number } | null>(null)
+ // A hold selects on pointerup's own click too, so that click must not also open the report.
+ const suppressClickRef = useRef(false)
+ const [isHolding, setIsHolding] = useState(false)
+
+ const cancelHold = useCallback((): void => {
+ if (holdTimerRef.current !== null) {
+ window.clearTimeout(holdTimerRef.current)
+ holdTimerRef.current = null
+ }
+ holdOriginRef.current = null
+ setIsHolding(false)
+ }, [])
+ useEffect(() => cancelHold, [cancelHold])
+
+ const toggle = useCallback(
+ (method: InboxSelectionEntryMethod): void => {
+ if (selectionDisabled) {
+ return
+ }
+ if (!hasSelection) {
+ captureInboxSelectionModeEntered({ method })
+ }
+ toggleReportSelection(reportId)
+ },
+ [hasSelection, reportId, selectionDisabled, toggleReportSelection]
+ )
+
+ const onPointerDown = useCallback(
+ (event: PointerEvent): void => {
+ // A touch that never produces a click would otherwise leave the suppression armed for
+ // the next press.
+ suppressClickRef.current = false
+ // Only the primary button holds; a modifier click is already a selection of its own.
+ if (
+ !enabled ||
+ selectionDisabled ||
+ event.button !== 0 ||
+ event.shiftKey ||
+ event.metaKey ||
+ event.ctrlKey
+ ) {
+ return
+ }
+ holdOriginRef.current = { x: event.clientX, y: event.clientY }
+ setIsHolding(true)
+ holdTimerRef.current = window.setTimeout(() => {
+ holdTimerRef.current = null
+ holdOriginRef.current = null
+ setIsHolding(false)
+ suppressClickRef.current = true
+ toggle('long_press')
+ }, SELECTION_HOLD_MS)
+ },
+ [enabled, selectionDisabled, toggle]
+ )
+
+ const onPointerMove = useCallback(
+ (event: PointerEvent): void => {
+ const origin = holdOriginRef.current
+ if (!origin) {
+ return
+ }
+ const travelled = Math.hypot(event.clientX - origin.x, event.clientY - origin.y)
+ if (travelled > SELECTION_HOLD_MOVE_TOLERANCE_PX) {
+ cancelHold()
+ }
+ },
+ [cancelHold]
+ )
+
+ const onClick = useCallback(
+ (event: MouseEvent): void => {
+ if (!enabled) {
+ return
+ }
+ if (suppressClickRef.current) {
+ suppressClickRef.current = false
+ event.preventDefault()
+ event.stopPropagation()
+ return
+ }
+ // Keep the current selection stable until its request finishes. A row click must not
+ // open the report while the list still shows selection mode.
+ if (selectionDisabled) {
+ if (hasSelection) {
+ event.preventDefault()
+ event.stopPropagation()
+ }
+ return
+ }
+ // A modifier click on a link nested in the row, such as the scout's name, belongs to
+ // that link: Cmd or Ctrl opens it in a new tab. The link cannot keep the click for
+ // itself here, because a capture handler runs before the target's own handlers.
+ if (
+ (event.shiftKey || event.metaKey || event.ctrlKey) &&
+ isNestedControlClick(event.target, event.currentTarget)
+ ) {
+ return
+ }
+ const intent = resolveReportCardClickIntent(event, hasSelection)
+ if (intent === 'open') {
+ return
+ }
+ // The card body is a link, so every selecting click has to stop the navigation.
+ event.preventDefault()
+ event.stopPropagation()
+ if (intent === 'range') {
+ // A shift-click can open selection mode on its own, and it never goes through
+ // `toggle`, so it records its own entry.
+ if (!hasSelection) {
+ captureInboxSelectionModeEntered({ method: 'shift_click' })
+ }
+ selectRange(reportId)
+ return
+ }
+ toggle('meta_click')
+ },
+ [enabled, hasSelection, reportId, selectRange, selectionDisabled, toggle]
+ )
+
+ return {
+ isSelected: enabled && selectedReportIds.includes(reportId),
+ selectionMode: enabled && hasSelection,
+ isHolding,
+ selectionDisabled,
+ toggle,
+ cardHandlers: {
+ onClickCapture: onClick,
+ onPointerDown,
+ onPointerMove,
+ onPointerUp: cancelHold,
+ onPointerLeave: cancelHold,
+ onPointerCancel: cancelHold,
+ },
+ }
+}
diff --git a/products/signals/frontend/inbox/components/shell/DismissReportDialog.tsx b/products/signals/frontend/inbox/components/shell/DismissReportDialog.tsx
index 6cd0aecb3082..0e103bb1349e 100644
--- a/products/signals/frontend/inbox/components/shell/DismissReportDialog.tsx
+++ b/products/signals/frontend/inbox/components/shell/DismissReportDialog.tsx
@@ -8,9 +8,9 @@ import { DismissCorrectedRepoField } from './DismissCorrectedRepoField'
import { HotkeyRadio } from './HotkeyRadio'
interface OpenDismissReportDialogParams {
- /** Report title for single-report copy. Ignored when `selectedCount > 1`. */
+ /** Report title for single-report copy. Ignored when `selectedCount` is set. */
reportTitle?: string | null
- /** When greater than 1, copy reflects a bulk dismiss of the current selection. */
+ /** How many reports the selection bar holds. When set, the copy counts reports instead of naming one. */
selectedCount?: number
/** Whether the report has an implementation PR that is still open. Dismissing closes it, so the copy says so. */
hasOpenPr?: boolean
@@ -37,17 +37,20 @@ const REASON_RADIO_OPTIONS: LemonRadioOption<DismissalReasonValue>[] = DISMISSAL
*/
export function openDismissReportDialog({
reportTitle,
- selectedCount = 1,
+ selectedCount,
hasOpenPr = false,
hotkeys = false,
initialReason,
onConfirm,
}: OpenDismissReportDialogParams): void {
- const isBulk = selectedCount > 1
- const title = isBulk
- ? `Dismiss ${selectedCount} reports?`
+ // The selection bar knows the count and no titles, so its copy counts reports even when one
+ // report is selected. Every other caller names the report instead.
+ const isSelection = selectedCount !== undefined
+ const isPlural = (selectedCount ?? 1) > 1
+ const title = isSelection
+ ? `Dismiss ${selectedCount} ${isPlural ? 'reports' : 'report'}?`
: `Dismiss report "${reportTitle?.trim() ? reportTitle : 'Untitled report'}"?`
- const description = isBulk
+ const description = isPlural
? `These reports leave your inbox. Your feedback is saved on each report, and your note goes to the agents that filed them.${
hasOpenPr ? ' Any open pull request for these reports is closed.' : ''
}`
diff --git a/products/signals/frontend/inbox/components/shell/InboxBulkSelectionBar.test.tsx b/products/signals/frontend/inbox/components/shell/InboxBulkSelectionBar.test.tsx
new file mode 100644
index 000000000000..674f019d2f53
--- /dev/null
+++ b/products/signals/frontend/inbox/components/shell/InboxBulkSelectionBar.test.tsx
@@ -0,0 +1,73 @@
+import '@testing-library/jest-dom'
+
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+
+import { initKeaTests } from '~/test/init'
+
+import { inboxBulkActionsLogic } from '../../logics/inboxBulkActionsLogic'
+import { type SignalReport, SignalReportStatus } from '../../types'
+import { InboxBulkSelectionBar } from './InboxBulkSelectionBar'
+
+function makeReport(id: string, overrides: Partial<SignalReport> = {}): SignalReport {
+ return {
+ id,
+ title: `Report ${id}`,
+ summary: 'summary',
+ status: SignalReportStatus.READY,
+ total_weight: 0,
+ signal_count: 1,
+ relevant_user_count: null,
+ artefact_count: 0,
+ is_suggested_reviewer: false,
+ created_at: '2026-06-11T10:00:00Z',
+ updated_at: '2026-06-11T10:00:00Z',
+ ...overrides,
+ }
+}
+
+describe('InboxBulkSelectionBar', () => {
+ let logic: ReturnType<typeof inboxBulkActionsLogic.build>
+
+ beforeEach(() => {
+ initKeaTests()
+ logic = inboxBulkActionsLogic()
+ logic.mount()
+ })
+
+ afterEach(() => {
+ cleanup()
+ logic.unmount()
+ })
+
+ // The bar holds a count and no titles, so its dialogs have to count reports at every size. The
+ // single-report copy would print the "Untitled report" placeholder over a report that has a title.
+ it.each([
+ { button: 'Dismiss', reportIds: ['a'], heading: 'Dismiss 1 report?' },
+ { button: 'Dismiss', reportIds: ['a', 'b'], heading: 'Dismiss 2 reports?' },
+ { button: 'Resolve', reportIds: ['a'], heading: 'Resolve 1 report?' },
+ { button: 'Resolve', reportIds: ['a', 'b'], heading: 'Resolve 2 reports?' },
+ ])(
+ '$button counts the selection in its dialog at $reportIds.length selected',
+ async ({ button, reportIds, heading }) => {
+ logic.actions.setSelectedReportIds(reportIds)
+ render(<InboxBulkSelectionBar reports={reportIds.map((id) => makeReport(id))} />)
+
+ fireEvent.click(screen.getByText(button))
+
+ expect(await screen.findByText(heading)).toBeInTheDocument()
+ }
+ )
+
+ it('warns when bulk dismissal closes a selected pull request', async () => {
+ logic.actions.setSelectedReportIds(['a'])
+ render(
+ <InboxBulkSelectionBar
+ reports={[makeReport('a', { implementation_pr_url: 'https://github.com/PostHog/posthog/pull/1' })]}
+ />
+ )
+
+ fireEvent.click(screen.getByText('Dismiss'))
+
+ expect(await screen.findByText(/The pull request opened for this report is closed/)).toBeInTheDocument()
+ })
+})
diff --git a/products/signals/frontend/inbox/components/shell/InboxBulkSelectionBar.tsx b/products/signals/frontend/inbox/components/shell/InboxBulkSelectionBar.tsx
index abc14ee65438..d70794cbf6d6 100644
--- a/products/signals/frontend/inbox/components/shell/InboxBulkSelectionBar.tsx
+++ b/products/signals/frontend/inbox/components/shell/InboxBulkSelectionBar.tsx
@@ -4,6 +4,8 @@ import { IconCheckCircle, IconHide, IconX } from '@posthog/icons'
import { LemonButton } from '@posthog/lemon-ui'
import { inboxBulkActionsLogic } from '../../logics/inboxBulkActionsLogic'
+import type { SignalReport } from '../../types'
+import { hasOpenImplementationPr } from '../../utils/reportActions'
import { openDismissReportDialog } from './DismissReportDialog'
import { openResolveReportDialog } from './ResolveReportDialog'
@@ -13,14 +15,16 @@ import { openResolveReportDialog } from './ResolveReportDialog'
* and the bulk state calls live in `inboxBulkActionsLogic`; delete / reingest
* remain on `inboxSceneLogic` per-report.
*/
-export function InboxBulkSelectionBar(): JSX.Element | null {
- const { selectedCount, isDismissing, isResolving } = useValues(inboxBulkActionsLogic)
+export function InboxBulkSelectionBar({ reports }: { reports: SignalReport[] }): JSX.Element | null {
+ const { selectedCount, selectedReportIds, isDismissing, isResolving } = useValues(inboxBulkActionsLogic)
const { clearSelection, bulkDismiss, bulkResolve } = useActions(inboxBulkActionsLogic)
if (selectedCount === 0) {
return null
}
const busy = isDismissing || isResolving
+ const selectedIds = new Set(selectedReportIds)
+ const hasOpenPr = reports.some((report) => selectedIds.has(report.id) && hasOpenImplementationPr(report))
return (
<div className="flex items-center justify-between gap-3 flex-wrap rounded border border-accent bg-accent-highlight-secondary px-3 py-2">
@@ -39,6 +43,7 @@ export function InboxBulkSelectionBar(): JSX.Element | null {
onClick={() =>
openResolveReportDialog({
selectedCount,
+ hasOpenPr,
onConfirm: ({ reason, note }) => bulkResolve(reason, note),
})
}
@@ -55,6 +60,7 @@ export function InboxBulkSelectionBar(): JSX.Element | null {
onClick={() =>
openDismissReportDialog({
selectedCount,
+ hasOpenPr,
onConfirm: (dismissal) => bulkDismiss(dismissal),
})
}
diff --git a/products/signals/frontend/inbox/components/shell/ResolveReportDialog.tsx b/products/signals/frontend/inbox/components/shell/ResolveReportDialog.tsx
index e31965f10103..a1b9272b4668 100644
--- a/products/signals/frontend/inbox/components/shell/ResolveReportDialog.tsx
+++ b/products/signals/frontend/inbox/components/shell/ResolveReportDialog.tsx
@@ -12,9 +12,9 @@ export interface ResolveReportDialogResult {
}
interface OpenResolveReportDialogParams {
- /** Report title for single-report copy. Ignored when `selectedCount > 1`. */
+ /** Report title for single-report copy. Ignored when `selectedCount` is set. */
reportTitle?: string | null
- /** When greater than 1, copy reflects a bulk resolve of the current selection. */
+ /** How many reports the selection bar holds. When set, the copy counts reports instead of naming one. */
selectedCount?: number
/** Whether the report has an implementation PR that is still open. Resolving closes it, so the copy says so. */
hasOpenPr?: boolean
@@ -41,17 +41,20 @@ const REASON_RADIO_OPTIONS: LemonRadioOption<ResolveReasonValue>[] = RESOLVE_REA
*/
export function openResolveReportDialog({
reportTitle,
- selectedCount = 1,
+ selectedCount,
hasOpenPr = false,
hotkeys = false,
initialReason,
onConfirm,
}: OpenResolveReportDialogParams): void {
- const isBulk = selectedCount > 1
- const title = isBulk
- ? `Resolve ${selectedCount} reports?`
+ // The selection bar knows the count and no titles, so its copy counts reports even when one
+ // report is selected. Every other caller names the report instead.
+ const isSelection = selectedCount !== undefined
+ const isPlural = (selectedCount ?? 1) > 1
+ const title = isSelection
+ ? `Resolve ${selectedCount} ${isPlural ? 'reports' : 'report'}?`
: `Resolve report "${reportTitle?.trim() ? reportTitle : 'Untitled report'}"?`
- const description = isBulk
+ const description = isPlural
? 'These reports are marked as done. If an issue comes back, you get a new report linked to the old one. Any open pull request for these reports is closed.'
: `This marks the report as done. If the issue comes back, you get a new report linked to this one.${
hasOpenPr ? ' The pull request opened for this report is closed.' : ''
@@ -97,7 +100,7 @@ export function openResolveReportDialog({
errors: {
reason: (reason) => (!reason ? "You haven't picked a reason" : undefined),
},
- primaryButtonProps: { children: isBulk ? 'Resolve reports' : 'Resolve report' },
+ primaryButtonProps: { children: isPlural ? 'Resolve reports' : 'Resolve report' },
shouldAwaitSubmit: true,
onSubmit: async ({ reason, note }) => {
if (!reason) {
diff --git a/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx b/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx
index a96b98c2ed3b..dd96971f784d 100644
--- a/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx
+++ b/products/signals/frontend/inbox/components/tabs/ReportsTab.tsx
@@ -31,6 +31,7 @@ import { InboxBulkSelectionBar } from '../shell/InboxBulkSelectionBar'
import { InboxReportFilters } from '../shell/InboxReportFilters'
import { InboxScopeFilter } from '../shell/InboxScopeFilter'
import { useReportImpressions } from '../useReportImpressions'
+import { useSelectableReportList } from '../useSelectableReportList'
/**
* The states that make up "the inbox" for the `Inbox viewed` event. Not actionable is left out: it
@@ -228,6 +229,8 @@ export function ReportsTab(): JSX.Element {
>
const rows = mergeReportRows(reportsBySection, selectedSections, sortField, sortDirection)
useReportImpressions(rows, selectedSections)
+ // Multi-select ranges over this order, and drops any id the merged list no longer holds.
+ useSelectableReportList(rows.map(({ report }) => report.id))
// Rows are fetched once a state is part of the rendered list — a deselected state costs one
// count request only. `ensureLoaded` no-ops on states that already loaded or are in flight.
@@ -325,7 +328,7 @@ export function ReportsTab(): JSX.Element {
<InboxScopeFilter />
</div>
</div>
- <InboxBulkSelectionBar />
+ <InboxBulkSelectionBar reports={rows.map(({ report }) => report)} />
{inboxIsEmpty ? (
<ReportsEmptyState />
@@ -358,6 +361,7 @@ export function ReportsTab(): JSX.Element {
<ReportCard
report={report}
sectionKey={sectionKey}
+ selectable
onRestore={() =>
reportListLogic(sectionListLogicProps(sectionKey)).actions.restoreReport(
report.id,
diff --git a/products/signals/frontend/inbox/components/useSelectableReportList.ts b/products/signals/frontend/inbox/components/useSelectableReportList.ts
new file mode 100644
index 000000000000..65b703f8135d
--- /dev/null
+++ b/products/signals/frontend/inbox/components/useSelectableReportList.ts
@@ -0,0 +1,35 @@
+import { useActions } from 'kea'
+import { useEffect } from 'react'
+
+import { inboxBulkActionsLogic } from '../logics/inboxBulkActionsLogic'
+import { isTextEntryTarget } from '../utils/reportSelection'
+
+/**
+ * List side of the multi-select: tells the selection which rows are on screen and in what order,
+ * so a shift-click ranges over the rendered list and stale ids are dropped when the list reloads
+ * or the filters change. Esc clears the selection, and so does leaving the list.
+ */
+export function useSelectableReportList(orderedReportIds: string[]): void {
+ const { setVisibleReportIds, clearSelection } = useActions(inboxBulkActionsLogic)
+
+ // Keyed on the joined ids: the list rebuilds its row array on every render, and the array
+ // identity alone would re-prune (and re-render every card) each time.
+ const orderKey = orderedReportIds.join(',')
+ useEffect(() => {
+ setVisibleReportIds(orderKey === '' ? [] : orderKey.split(','))
+ }, [orderKey, setVisibleReportIds])
+
+ useEffect(() => {
+ const onKeyDown = (event: KeyboardEvent): void => {
+ if (event.key !== 'Escape' || isTextEntryTarget(event.target)) {
+ return
+ }
+ clearSelection()
+ }
+ window.addEventListener('keydown', onKeyDown)
+ return () => window.removeEventListener('keydown', onKeyDown)
+ }, [clearSelection])
+
+ // A selection means nothing on another tab or another scene.
+ useEffect(() => clearSelection, [clearSelection])
+}
diff --git a/products/signals/frontend/inbox/inboxAnalytics.ts b/products/signals/frontend/inbox/inboxAnalytics.ts
index 8a673272f84a..d5b24ca64783 100644
--- a/products/signals/frontend/inbox/inboxAnalytics.ts
+++ b/products/signals/frontend/inbox/inboxAnalytics.ts
@@ -34,6 +34,7 @@ export const INBOX_EVENTS = {
REPORT_CLOSED: 'Inbox report closed',
REPORT_SCROLLED: 'Inbox report scrolled',
REPORT_ACTION: 'Inbox report action',
+ SELECTION_MODE_ENTERED: 'Inbox selection mode entered',
REPORT_ACTION_COMPLETED: 'Inbox report action completed',
REPORT_FEEDBACK: 'Inbox report feedback',
REPORT_FEEDBACK_NOTE: 'Inbox report feedback note',
@@ -72,6 +73,12 @@ export type InboxReportActionSurface =
| 'triage_mode'
| 'context_menu'
+/**
+ * Affordance that put the first report into a multi-select. Tells us which ones people find, so
+ * the ones nobody uses can go.
+ */
+export type InboxSelectionEntryMethod = 'long_press' | 'meta_click' | 'shift_click' | 'checkbox' | 'context_menu'
+
/** How a report detail was opened. `triage` is the open-report shortcut in triage mode. */
export type InboxReportOpenMethod = 'click' | 'deeplink' | 'triage' | 'unknown'
@@ -472,6 +479,11 @@ export function captureInboxReportAction(params: {
* ranking work trains against, so it carries the same report classification as the impression and
* open events. `note` is optional — the thumbs submit on one click, with no note.
*/
+/** Fired once per selection, when an empty selection gains its first report. */
+export function captureInboxSelectionModeEntered(params: { method: InboxSelectionEntryMethod }): void {
+ captureInboxEvent(INBOX_EVENTS.SELECTION_MODE_ENTERED, { entry_method: params.method })
+}
+
export function captureInboxReportFeedback(params: {
report: SignalReport
sentiment: InboxReportFeedbackSentiment
diff --git a/products/signals/frontend/inbox/logics/inboxBulkActionsLogic.test.ts b/products/signals/frontend/inbox/logics/inboxBulkActionsLogic.test.ts
new file mode 100644
index 000000000000..15c426231dd3
--- /dev/null
+++ b/products/signals/frontend/inbox/logics/inboxBulkActionsLogic.test.ts
@@ -0,0 +1,103 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { initKeaTests } from '~/test/init'
+
+import { inboxBulkActionsLogic } from './inboxBulkActionsLogic'
+
+describe('inboxBulkActionsLogic', () => {
+ let logic: ReturnType<typeof inboxBulkActionsLogic.build>
+
+ beforeEach(() => {
+ initKeaTests()
+ logic = inboxBulkActionsLogic()
+ logic.mount()
+ })
+
+ afterEach(() => {
+ logic.unmount()
+ })
+
+ it('toggles a report in and out of the selection', async () => {
+ await expectLogic(logic, () => {
+ logic.actions.toggleReportSelection('a')
+ logic.actions.toggleReportSelection('b')
+ }).toMatchValues({ selectedReportIds: ['a', 'b'], selectedCount: 2, hasSelection: true })
+
+ await expectLogic(logic, () => logic.actions.toggleReportSelection('a')).toMatchValues({
+ selectedReportIds: ['b'],
+ hasSelection: true,
+ })
+ })
+
+ it('drops selected ids that are no longer in the list', async () => {
+ logic.actions.setVisibleReportIds(['a', 'b', 'c'])
+ logic.actions.toggleReportSelection('a')
+ logic.actions.toggleReportSelection('c')
+
+ await expectLogic(logic, () => logic.actions.setVisibleReportIds(['a', 'b'])).toMatchValues({
+ selectedReportIds: ['a'],
+ })
+ })
+
+ it('keeps the selection when the list only grows, as an extra page appends', async () => {
+ logic.actions.setVisibleReportIds(['a', 'b'])
+ logic.actions.toggleReportSelection('b')
+
+ await expectLogic(logic, () => logic.actions.setVisibleReportIds(['a', 'b', 'c', 'd'])).toMatchValues({
+ selectedReportIds: ['b'],
+ })
+ })
+
+ it('selects the range between the anchor and the shift-clicked row, in either direction', async () => {
+ logic.actions.setVisibleReportIds(['a', 'b', 'c', 'd'])
+ logic.actions.toggleReportSelection('c')
+
+ await expectLogic(logic, () => logic.actions.selectRange('a')).toMatchValues({
+ selectedReportIds: ['c', 'a', 'b'],
+ selectedCount: 3,
+ })
+
+ logic.actions.clearSelection()
+ logic.actions.toggleReportSelection('b')
+ await expectLogic(logic, () => logic.actions.selectRange('d')).toMatchValues({
+ selectedReportIds: ['b', 'c', 'd'],
+ })
+ })
+
+ it('treats a shift-click with no anchor as a plain toggle', async () => {
+ logic.actions.setVisibleReportIds(['a', 'b', 'c'])
+
+ await expectLogic(logic, () => logic.actions.selectRange('b')).toMatchValues({
+ selectedReportIds: ['b'],
+ selectionAnchorId: 'b',
+ })
+ })
+
+ it('treats a shift-click as a plain toggle once a deselect emptied the selection', async () => {
+ logic.actions.setVisibleReportIds(['a', 'b', 'c', 'd'])
+ logic.actions.toggleReportSelection('a')
+ logic.actions.toggleReportSelection('a')
+
+ await expectLogic(logic, () => logic.actions.selectRange('d')).toMatchValues({
+ selectedReportIds: ['d'],
+ })
+ })
+
+ it('ranges only over the rows that are loaded', async () => {
+ logic.actions.setVisibleReportIds(['a', 'b'])
+ logic.actions.toggleReportSelection('a')
+
+ // 'z' is on a page that has not been fetched, so there is no range to extend to.
+ await expectLogic(logic, () => logic.actions.selectRange('z')).toMatchValues({ selectedReportIds: ['a'] })
+ })
+
+ it('clears the anchor when the anchor row leaves the list', async () => {
+ logic.actions.setVisibleReportIds(['a', 'b', 'c'])
+ logic.actions.toggleReportSelection('a')
+
+ logic.actions.setVisibleReportIds(['b', 'c'])
+ await expectLogic(logic, () => logic.actions.selectRange('c')).toMatchValues({
+ selectedReportIds: ['c'],
+ })
+ })
+})
diff --git a/products/signals/frontend/inbox/logics/inboxBulkActionsLogic.ts b/products/signals/frontend/inbox/logics/inboxBulkActionsLogic.ts
index 2650434f54a2..a744b7bbbdcc 100644
--- a/products/signals/frontend/inbox/logics/inboxBulkActionsLogic.ts
+++ b/products/signals/frontend/inbox/logics/inboxBulkActionsLogic.ts
@@ -29,6 +29,8 @@ export interface inboxBulkActionsLogicValues {
isResolving: boolean
selectedCount: number
selectedReportIds: string[]
+ selectionAnchorId: string | null
+ visibleReportIds: string[]
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -64,9 +66,15 @@ export interface inboxBulkActionsLogicActions {
selectAll: (reportIds: string[]) => {
reportIds: string[]
}
+ selectRange: (reportId: string) => {
+ reportId: string
+ }
setSelectedReportIds: (reportIds: string[]) => {
reportIds: string[]
}
+ setVisibleReportIds: (reportIds: string[]) => {
+ reportIds: string[]
+ }
toggleReportSelection: (reportId: string) => {
reportId: string
}
@@ -90,9 +98,9 @@ export type inboxBulkActionsLogicType = MakeLogicType<
/**
* Multi-select + bulk dismiss / resolve for the inbox report list. Mirrors desktop
* `inboxReportSelectionStore` (selection state) and `useInboxBulkActions`
- * (bulk suppress via `updateSignalReportState`). Kept deliberately thin: shift /
- * range selection lives in the list component; this logic owns the id set and
- * the state calls.
+ * (bulk suppress via `updateSignalReportState`). It owns the selected id set, the rendered row
+ * order a shift-click ranges over, and the state calls; the card components own the pointer
+ * gestures that feed it.
*/
export const inboxBulkActionsLogic = kea<inboxBulkActionsLogicType>([
path(['scenes', 'inbox', 'logics', 'inboxBulkActionsLogic']),
@@ -101,6 +109,10 @@ export const inboxBulkActionsLogic = kea<inboxBulkActionsLogicType>([
toggleReportSelection: (reportId: string) => ({ reportId }),
setSelectedReportIds: (reportIds: string[]) => ({ reportIds }),
selectAll: (reportIds: string[]) => ({ reportIds }),
+ /** Extend the selection from the anchor row to this one, over the rendered order. */
+ selectRange: (reportId: string) => ({ reportId }),
+ /** The rows the list currently renders, in order. Also drops selected ids that left the list. */
+ setVisibleReportIds: (reportIds: string[]) => ({ reportIds }),
clearSelection: true,
/** Suppress every selected report with the chosen reason/note, then clear. */
bulkDismiss: (dismissal: DismissalFeedback) => ({ dismissal }),
@@ -124,7 +136,34 @@ export const inboxBulkActionsLogic = kea<inboxBulkActionsLogicType>([
state.includes(reportId) ? state.filter((id) => id !== reportId) : [...state, reportId],
setSelectedReportIds: (_, { reportIds }) => Array.from(new Set(reportIds)),
selectAll: (_, { reportIds }) => Array.from(new Set(reportIds)),
- clearSelection: () => [],
+ // Keep the same array when there was nothing to clear, so an Esc with no selection
+ // costs no re-render.
+ clearSelection: (state) => (state.length === 0 ? state : []),
+ // A reload, a filter change, or a report leaving the list must not leave a stale id
+ // behind: a bulk action on it would fail. Keep the same array when nothing was
+ // dropped, so an unchanged list does not re-render every card.
+ setVisibleReportIds: (state, { reportIds }) => {
+ const visible = new Set(reportIds)
+ const kept = state.filter((id) => visible.has(id))
+ return kept.length === state.length ? state : kept
+ },
+ },
+ ],
+ /** The row a shift-click measures its range from: the last row selected without shift. */
+ selectionAnchorId: [
+ null as string | null,
+ {
+ toggleReportSelection: (_, { reportId }) => reportId,
+ selectAll: () => null,
+ clearSelection: () => null,
+ setVisibleReportIds: (state, { reportIds }) =>
+ state !== null && !reportIds.includes(state) ? null : state,
+ },
+ ],
+ visibleReportIds: [
+ [] as string[],
+ {
+ setVisibleReportIds: (_, { reportIds }) => reportIds,
},
],
isDismissing: [
@@ -157,6 +196,26 @@ export const inboxBulkActionsLogic = kea<inboxBulkActionsLogicType>([
}),
listeners(({ actions, values }) => ({
+ selectRange: ({ reportId }) => {
+ const { visibleReportIds, selectionAnchorId, selectedReportIds } = values
+ const end = visibleReportIds.indexOf(reportId)
+ if (end === -1) {
+ return
+ }
+ // The anchor only counts while something is selected, because the toggle that removed
+ // the last selected row still wrote its own id there.
+ const anchorId = selectedReportIds.length > 0 ? selectionAnchorId : null
+ // No anchor yet (a shift-click as the first click): treat it as a plain toggle, which
+ // also sets the anchor for the next shift-click.
+ const start = anchorId === null ? -1 : visibleReportIds.indexOf(anchorId)
+ if (start === -1) {
+ actions.toggleReportSelection(reportId)
+ return
+ }
+ const [from, to] = start <= end ? [start, end] : [end, start]
+ // The range only covers loaded rows, because `visibleReportIds` is the rendered list.
+ actions.setSelectedReportIds([...selectedReportIds, ...visibleReportIds.slice(from, to + 1)])
+ },
bulkDismiss: async ({ dismissal }) => {
const reportIds = values.selectedReportIds
if (reportIds.length === 0) {
diff --git a/products/signals/frontend/inbox/utils/reportSelection.test.ts b/products/signals/frontend/inbox/utils/reportSelection.test.ts
new file mode 100644
index 000000000000..85ba0171f23a
--- /dev/null
+++ b/products/signals/frontend/inbox/utils/reportSelection.test.ts
@@ -0,0 +1,30 @@
+import { isTextEntryTarget, resolveReportCardClickIntent } from './reportSelection'
+
+describe('resolveReportCardClickIntent', () => {
+ const plain = { shiftKey: false, metaKey: false, ctrlKey: false }
+
+ test.each([
+ ['plain click with nothing selected opens the report', plain, false, 'open'],
+ ['plain click in selection mode toggles instead of opening', plain, true, 'toggle'],
+ ['cmd-click toggles from an empty selection', { ...plain, metaKey: true }, false, 'toggle'],
+ ['ctrl-click toggles from an empty selection', { ...plain, ctrlKey: true }, false, 'toggle'],
+ ['shift-click ranges', { ...plain, shiftKey: true }, true, 'range'],
+ ['shift wins over cmd', { shiftKey: true, metaKey: true, ctrlKey: false }, true, 'range'],
+ ])('%s', (_name, modifiers, hasSelection, expected) => {
+ expect(resolveReportCardClickIntent(modifiers, hasSelection)).toBe(expected)
+ })
+})
+
+describe('isTextEntryTarget', () => {
+ it('does not treat a checkbox as text entry', () => {
+ const checkbox = document.createElement('input')
+ checkbox.type = 'checkbox'
+
+ expect(isTextEntryTarget(checkbox)).toBe(false)
+ })
+
+ it('treats text inputs and text areas as text entry', () => {
+ expect(isTextEntryTarget(document.createElement('input'))).toBe(true)
+ expect(isTextEntryTarget(document.createElement('textarea'))).toBe(true)
+ })
+})
diff --git a/products/signals/frontend/inbox/utils/reportSelection.ts b/products/signals/frontend/inbox/utils/reportSelection.ts
new file mode 100644
index 000000000000..a81ed4d56850
--- /dev/null
+++ b/products/signals/frontend/inbox/utils/reportSelection.ts
@@ -0,0 +1,55 @@
+/** How long a pointer must rest on a card before the hold selects it. */
+export const SELECTION_HOLD_MS = 400
+
+/** A hold that travels further than this is a scroll or a drag, so it never selects. */
+export const SELECTION_HOLD_MOVE_TOLERANCE_PX = 8
+
+/** What a click on a report row means. `open` follows the row's link to the report detail. */
+export type ReportCardClickIntent = 'open' | 'toggle' | 'range'
+
+/**
+ * A plain click opens the report until something is selected; from then on the list is in
+ * selection mode and the same click toggles instead. Cmd / Ctrl always toggles, shift always
+ * ranges, so a selection can start from an empty list.
+ */
+export function resolveReportCardClickIntent(
+ modifiers: { shiftKey: boolean; metaKey: boolean; ctrlKey: boolean },
+ hasSelection: boolean
+): ReportCardClickIntent {
+ if (modifiers.shiftKey) {
+ return 'range'
+ }
+ if (modifiers.metaKey || modifiers.ctrlKey) {
+ return 'toggle'
+ }
+ return hasSelection ? 'toggle' : 'open'
+}
+
+/** Controls a report row can nest inside its own link, such as the authoring scout's name. */
+const ROW_CONTROL_SELECTOR = 'a, button, [role="button"], input, select, textarea'
+
+/**
+ * True when a click landed on a control nested inside the row's own link. The row's link is the
+ * first control in the wrapper, so any other control is one the person aimed at directly.
+ */
+export function isNestedControlClick(target: EventTarget | null, wrapper: Element): boolean {
+ if (!(target instanceof Element)) {
+ return false
+ }
+ const clicked = target.closest(ROW_CONTROL_SELECTOR)
+ return clicked !== null && clicked !== wrapper.querySelector(ROW_CONTROL_SELECTOR)
+}
+
+/** True while the keyboard is in a field, where Esc belongs to the field and not to the list. */
+export function isTextEntryTarget(target: EventTarget | null): boolean {
+ if (!(target instanceof HTMLElement)) {
+ return false
+ }
+ if (target.isContentEditable || target.tagName === 'TEXTAREA' || target.tagName === 'SELECT') {
+ return true
+ }
+ if (target instanceof HTMLInputElement) {
+ return !['button', 'checkbox', 'color', 'file', 'radio', 'range', 'reset', 'submit'].includes(target.type)
+ }
+ return false
+}