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.

fix(today): bulk right-click on selected feed rows and escape closes menus first (#110420)

Shy Alteraa81e51e8f13
diff --git a/frontend/src/layout/today/TodaySessionBulkActionItems.tsx b/frontend/src/layout/today/TodaySessionBulkActionItems.tsx
index e632b08a09f9..6a675692a64e 100644
--- a/frontend/src/layout/today/TodaySessionBulkActionItems.tsx
+++ b/frontend/src/layout/today/TodaySessionBulkActionItems.tsx
@@ -1,30 +1,53 @@
-import { useActions, useValues } from 'kea'
+import { useValues } from 'kea'
import { IconArchive, IconFolder, IconPin, IconPinFilled } from '@posthog/icons'
import { TodayMenuParts } from './todayMenuParts'
import { sessionsLabel } from './todaySessionSelection'
-import { todaySessionSelectionLogic } from './todaySessionSelectionLogic'
+import type { TodayBulkAction } from './todaySessionSelectionLogic'
import { TodaySpaceFileList } from './TodaySpaceFileList'
import { todaySpacesLogic } from './todaySpacesLogic'
+/** The sidebar's selection, or one space feed's. Both offer the same bulk changes. */
+export interface TodayBulkSelection {
+ /** The space every selected session sits in, or `null` when the selection spans spaces. */
+ spaceId: string | null
+ selectedSessionIds: string[]
+ bulkPinDirection: 'pin' | 'unpin'
+ bulkAction: TodayBulkAction | null
+ runningSelectedCount: number
+ pinSelected: () => void
+ fileSelectedTo: (spaceId: string) => void
+ requestBulkArchive: () => void
+}
+
/** What the selection bar offers, as menu items, so a right-click on a selected row acts on the whole selection. */
export function TodaySessionBulkActionItems({
parts: { Item, Separator, Sub },
+ selection: {
+ spaceId,
+ selectedSessionIds,
+ bulkPinDirection,
+ bulkAction,
+ runningSelectedCount,
+ pinSelected,
+ fileSelectedTo,
+ requestBulkArchive,
+ },
dataAttrPrefix,
}: {
parts: TodayMenuParts
+ selection: TodayBulkSelection
/** Starts each item's `data-attr`, so every surface counts on its own. */
dataAttrPrefix: string
}): JSX.Element {
- const { selectedSessionIds, bulkPinDirection, bulkAction, runningSelectedCount } =
- useValues(todaySessionSelectionLogic)
- const { pinSelected, fileSelectedTo, requestBulkArchive } = useActions(todaySessionSelectionLogic)
const { spaces } = useValues(todaySpacesLogic)
const sessions = sessionsLabel(selectedSessionIds.length)
const pin = bulkPinDirection === 'pin'
// One bulk change at a time, like the selection bar. "File to…" hides, because a submenu can't be disabled here.
const busy = bulkAction !== null
+ // Filing needs a space other than the one the sessions already sit in.
+ const canFile = spaces.length > (spaceId ? 1 : 0)
const attr = (name: string): string => `${dataAttrPrefix}-${name}`
return (
@@ -33,7 +56,7 @@ export function TodaySessionBulkActionItems({
{pin ? <IconPin /> : <IconPinFilled />}
{`${pin ? 'Pin' : 'Unpin'} ${sessions}`}
</Item>
- {spaces.length > 0 && !busy && (
+ {canFile && !busy && (
<Sub
label={
<>
@@ -44,7 +67,7 @@ export function TodaySessionBulkActionItems({
dataAttr={attr('file')}
>
<TodaySpaceFileList
- currentSpaceId={null}
+ currentSpaceId={spaceId}
onSelect={fileSelectedTo}
itemDataAttr={attr('file-space')}
searchDataAttr={attr('file-search')}
diff --git a/frontend/src/layout/today/TodaySessionContextMenu.tsx b/frontend/src/layout/today/TodaySessionContextMenu.tsx
index 872b74be61c2..4d5580a4e115 100644
--- a/frontend/src/layout/today/TodaySessionContextMenu.tsx
+++ b/frontend/src/layout/today/TodaySessionContextMenu.tsx
@@ -1,4 +1,4 @@
-import { useActions, useValues } from 'kea'
+import { useActions } from 'kea'
import { ReactNode, useState } from 'react'
import { ContextMenu, ContextMenuContent, ContextMenuTrigger } from '@posthog/quill'
@@ -7,21 +7,31 @@ import { CONTEXT_PARTS } from './todayMenuParts'
import { useTodayPreviewMenuReport } from './todayPreviewCardContext'
import { TodaySessionActionItems } from './TodaySessionActionItems'
import { useTodayArchiveShortcut } from './todaySessionArchiveShortcut'
-import { TodaySessionBulkActionItems } from './TodaySessionBulkActionItems'
+import { TodayBulkSelection, TodaySessionBulkActionItems } from './TodaySessionBulkActionItems'
import { TodaySessionSurface, todaySessionMenuLogic } from './todaySessionMenuLogic'
import { rightClickActsOnSelection } from './todaySessionSelection'
-import { todaySessionSelectionLogic } from './todaySessionSelectionLogic'
import { TodaySessionMenuTarget } from './todayWorkItems'
+const BULK_DATA_ATTR_PREFIX: Record<TodaySessionSurface, string> = {
+ sidebar: 'today-session-context-bulk',
+ feed: 'today-space-feed-context-bulk',
+}
+
interface TodaySessionContextMenuProps {
target: TodaySessionMenuTarget
surface: TodaySessionSurface
+ /** The selection the row sits in. A right-click on a row inside it acts on the whole selection. */
+ selection: TodayBulkSelection
children: ReactNode
}
/** The session's actions on right-click, like PostHog Desktop. Its dialogs belong to the owner of `target.menuId`. */
-export function TodaySessionContextMenu({ target, surface, children }: TodaySessionContextMenuProps): JSX.Element {
- const { selectedSessionIds } = useValues(todaySessionSelectionLogic)
+export function TodaySessionContextMenu({
+ target,
+ surface,
+ selection,
+ children,
+}: TodaySessionContextMenuProps): JSX.Element {
const { requestArchive } = useActions(todaySessionMenuLogic)
const reportMenuOpen = useTodayPreviewMenuReport()
const [open, setOpen] = useState(false)
@@ -29,8 +39,7 @@ export function TodaySessionContextMenu({ target, surface, children }: TodaySess
setOpen(nextOpen)
reportMenuOpen(nextOpen)
}
- // The selection lives in the sidebar, so only its rows offer the selection's actions.
- const bulk = surface === 'sidebar' && rightClickActsOnSelection(selectedSessionIds, target.sessionId)
+ const bulk = rightClickActsOnSelection(selection.selectedSessionIds, target.sessionId)
useTodayArchiveShortcut(open && !bulk, () => {
setMenuOpen(false)
requestArchive(target.sessionId, target.menuId, target.activeRunId)
@@ -42,7 +51,11 @@ export function TodaySessionContextMenu({ target, surface, children }: TodaySess
{/* Wider for a selection, whose labels carry a count. */}
<ContextMenuContent className={bulk ? 'w-64' : 'w-56'}>
{bulk ? (
- <TodaySessionBulkActionItems parts={CONTEXT_PARTS} dataAttrPrefix="today-session-context-bulk" />
+ <TodaySessionBulkActionItems
+ parts={CONTEXT_PARTS}
+ selection={selection}
+ dataAttrPrefix={BULK_DATA_ATTR_PREFIX[surface]}
+ />
) : (
<TodaySessionActionItems
parts={CONTEXT_PARTS}
diff --git a/frontend/src/layout/today/TodaySessionRow.tsx b/frontend/src/layout/today/TodaySessionRow.tsx
index f386d037bb1a..9bbbced0d16d 100644
--- a/frontend/src/layout/today/TodaySessionRow.tsx
+++ b/frontend/src/layout/today/TodaySessionRow.tsx
@@ -17,6 +17,7 @@ import { TodaySessionStatusDot } from './TodaySessionStatusDot'
import { todaySpacesLogic } from './todaySpacesLogic'
import { TodaySpacesRow } from './TodaySpacesRow'
import { TodayWorkItem, sessionBadges, sessionDetails } from './todayWorkItems'
+import { useTodaySidebarBulkSelection } from './useTodaySidebarBulkSelection'
interface TodaySessionRowProps {
item: TodayWorkItem
@@ -47,6 +48,7 @@ export function TodaySessionRow({
const { pullRequestStates, spaceNames } = useValues(todaySpacesLogic)
const { fields } = useValues(todayListAppearanceLogic)
const menuId = useId()
+ const sidebarSelection = useTodaySidebarBulkSelection()
const userId = user?.id
const preview = useMemo(
() => sessionPreview(item, { unread, pinned, pullRequestStates, spaceNames, menuId, userId }),
@@ -90,7 +92,7 @@ export function TodaySessionRow({
// Like Desktop, the row's actions live in its hover card and its right-click menu, which open the dialogs on the row's behalf.
return (
<>
- <TodaySessionContextMenu target={preview.menu} surface={surface}>
+ <TodaySessionContextMenu target={preview.menu} surface={surface} selection={sidebarSelection}>
<TodayPreviewTrigger payload={preview}>{row}</TodayPreviewTrigger>
</TodaySessionContextMenu>
<TodaySessionDialogs target={preview.menu} />
diff --git a/frontend/src/layout/today/todaySessionSelection.ts b/frontend/src/layout/today/todaySessionSelection.ts
index d3459c196d02..1688d4fe3dcd 100644
--- a/frontend/src/layout/today/todaySessionSelection.ts
+++ b/frontend/src/layout/today/todaySessionSelection.ts
@@ -28,6 +28,14 @@ export function isEditableTarget(target: EventTarget | null): boolean {
)
}
+/** Base UI prevents the default of the Escape that closes a menu, so that press only closes the menu. */
+export function isMenuEscape(event: KeyboardEvent): boolean {
+ return (
+ event.defaultPrevented ||
+ (event.target instanceof Element && event.target.closest('[role="menu"][data-open]') !== null)
+ )
+}
+
export function selectionClick(event: Pick<MouseEvent, 'shiftKey' | 'metaKey' | 'ctrlKey'>): TodaySelectionClick {
return event.shiftKey ? 'range' : event.metaKey || event.ctrlKey ? 'toggle' : 'open'
}
diff --git a/frontend/src/layout/today/todaySessionSelectionLogic.test.ts b/frontend/src/layout/today/todaySessionSelectionLogic.test.ts
index 37ee48aaacca..0cd49b198791 100644
--- a/frontend/src/layout/today/todaySessionSelectionLogic.test.ts
+++ b/frontend/src/layout/today/todaySessionSelectionLogic.test.ts
@@ -23,6 +23,21 @@ const session = (id: string, lastActivityAt: string, run: Record<string, unknown
const PINNED = [session('task-p', '2026-09-28T12:00:00Z', { id: 'run-p', status: 'in_progress', environment: 'cloud' })]
const RECENT = [session('task-a', '2026-09-28T11:00:00Z'), session('task-b', '2026-09-28T10:00:00Z')]
+const escapeHandledByMenu = (): void => {
+ const event = new KeyboardEvent('keydown', { key: 'Escape', cancelable: true })
+ event.preventDefault()
+ window.dispatchEvent(event)
+}
+
+const escapeFromOpenMenu = (): void => {
+ const menu = document.createElement('div')
+ menu.setAttribute('role', 'menu')
+ menu.setAttribute('data-open', '')
+ document.body.append(menu)
+ menu.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
+ menu.remove()
+}
+
describe('todaySessionSelectionLogic', () => {
let logic: ReturnType<typeof todaySessionSelectionLogic.build>
let requests: string[]
@@ -120,4 +135,18 @@ describe('todaySessionSelectionLogic', () => {
expect(logic.values.selectedSessionIds).toEqual([])
})
+
+ it.each([
+ ['a menu already handled it', () => escapeHandledByMenu()],
+ ['it comes from inside an open menu', () => escapeFromOpenMenu()],
+ ])('keeps the selection on the first Escape when %s, and clears it on the next', (_, closeMenu) => {
+ logic.actions.setSelection({ ids: ['task-a', 'task-b'], anchorId: 'task-b' })
+ closeMenu()
+
+ expect(logic.values.selectedSessionIds).toEqual(['task-a', 'task-b'])
+
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
+
+ expect(logic.values.selectedSessionIds).toEqual([])
+ })
})
diff --git a/frontend/src/layout/today/todaySessionSelectionLogic.ts b/frontend/src/layout/today/todaySessionSelectionLogic.ts
index ed764b9edcaa..7558fb15633b 100644
--- a/frontend/src/layout/today/todaySessionSelectionLogic.ts
+++ b/frontend/src/layout/today/todaySessionSelectionLogic.ts
@@ -18,6 +18,7 @@ import {
computeBulkPinDirection,
computeRangeSelection,
isEditableTarget,
+ isMenuEscape,
orderedVisibleSessionIds,
pruneToVisible,
toggleSelection,
@@ -310,6 +311,7 @@ export const todaySessionSelectionLogic = kea<todaySessionSelectionLogicType>([
if (
event.key === 'Escape' &&
!isEditableTarget(event.target) &&
+ !isMenuEscape(event) &&
!values.bulkArchiveConfirm.open &&
values.selection.ids.length
) {
diff --git a/frontend/src/layout/today/useTodaySidebarBulkSelection.ts b/frontend/src/layout/today/useTodaySidebarBulkSelection.ts
new file mode 100644
index 000000000000..17f7e18f671a
--- /dev/null
+++ b/frontend/src/layout/today/useTodaySidebarBulkSelection.ts
@@ -0,0 +1,20 @@
+import { useActions, useValues } from 'kea'
+
+import { TodayBulkSelection } from './TodaySessionBulkActionItems'
+import { todaySessionSelectionLogic } from './todaySessionSelectionLogic'
+
+export function useTodaySidebarBulkSelection(): TodayBulkSelection {
+ const { selectedSessionIds, bulkPinDirection, bulkAction, runningSelectedCount } =
+ useValues(todaySessionSelectionLogic)
+ const { pinSelected, fileSelectedTo, requestBulkArchive } = useActions(todaySessionSelectionLogic)
+ return {
+ spaceId: null,
+ selectedSessionIds,
+ bulkPinDirection,
+ bulkAction,
+ runningSelectedCount,
+ pinSelected,
+ fileSelectedTo,
+ requestBulkArchive,
+ }
+}
diff --git a/products/tasks/frontend/spaces/SpaceFeedCard.tsx b/products/tasks/frontend/spaces/SpaceFeedCard.tsx
index 9f2b908d7721..d670bbb25b19 100644
--- a/products/tasks/frontend/spaces/SpaceFeedCard.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeedCard.tsx
@@ -41,6 +41,7 @@ import { TaskFile, VISIBLE_FILE_COUNT, taskFiles } from './taskFiles'
import { TASK_CHIP_CLASS, TaskPullRequestChip } from './TaskPullRequestChip'
import { pullRequestLabel, splitPullRequests } from './taskPullRequests'
import { TaskUserAvatar, taskUserName } from './TaskUserAvatar'
+import { useSpaceFeedBulkSelection } from './useSpaceFeedBulkSelection'
function TaskFileChip({ file }: { file: TaskFile }): JSX.Element {
return (
@@ -85,6 +86,7 @@ export function SpaceFeedCard({ spaceId, task, pinned, unread, repository }: Spa
const author = task.created_by
const authorName = author ? taskUserName(author) : null
const source = getOriginProductMeta(item.originProduct ?? undefined)
+ const selection = useSpaceFeedBulkSelection(spaceId)
const card = (
<Card
@@ -246,7 +248,7 @@ export function SpaceFeedCard({ spaceId, task, pinned, unread, repository }: Spa
// The dialogs sit outside the right-click area, so a right-click inside one does not reach the card's menu.
return (
<>
- <TodaySessionContextMenu target={menu} surface="feed">
+ <TodaySessionContextMenu target={menu} surface="feed" selection={selection}>
{card}
</TodaySessionContextMenu>
<TodaySessionDialogs target={menu} />
diff --git a/products/tasks/frontend/spaces/SpaceFeedListRow.tsx b/products/tasks/frontend/spaces/SpaceFeedListRow.tsx
index cc9a88644681..2f77844f1838 100644
--- a/products/tasks/frontend/spaces/SpaceFeedListRow.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeedListRow.tsx
@@ -22,6 +22,7 @@ import { SpaceFeedSelectCheckbox } from './SpaceFeedSelectCheckbox'
import { spaceFeedStatus } from './spaceFeedStatus'
import { SpaceFeedStatusIcon } from './SpaceFeedStatusIcon'
import { TaskUserAvatar, taskUserName } from './TaskUserAvatar'
+import { useSpaceFeedBulkSelection } from './useSpaceFeedBulkSelection'
interface SpaceFeedListRowProps {
spaceId: string
@@ -42,6 +43,7 @@ export function SpaceFeedListRow({ spaceId, task, pinned, unread }: SpaceFeedLis
const status = spaceFeedStatus(task.latest_run, mainPullRequest && pullRequestStates[mainPullRequest.url])
const author = task.created_by
const source = getOriginProductMeta(item.originProduct ?? undefined)
+ const selection = useSpaceFeedBulkSelection(spaceId)
if (renaming?.sessionId === task.id && renaming.surface === 'feed') {
return (
@@ -56,7 +58,7 @@ export function SpaceFeedListRow({ spaceId, task, pinned, unread }: SpaceFeedLis
}
return (
<>
- <TodaySessionContextMenu target={menu} surface="feed">
+ <TodaySessionContextMenu target={menu} surface="feed" selection={selection}>
<div className="group/row relative flex h-8 w-full items-center gap-2 rounded-md px-2 transition-colors hover:bg-fill-selected">
<SpaceFeedSelectCheckbox
spaceId={spaceId}
diff --git a/products/tasks/frontend/spaces/spaceFeedSelectionLogic.test.ts b/products/tasks/frontend/spaces/spaceFeedSelectionLogic.test.ts
index 3327c4033b24..76b9d93aa7f4 100644
--- a/products/tasks/frontend/spaces/spaceFeedSelectionLogic.test.ts
+++ b/products/tasks/frontend/spaces/spaceFeedSelectionLogic.test.ts
@@ -8,6 +8,21 @@ import { spaceFeedSelectionLogic } from './spaceFeedSelectionLogic'
import { spaceFeedViewLogic } from './spaceFeedViewLogic'
import { spaceSceneLogic } from './spaceSceneLogic'
+const escapeHandledByMenu = (): void => {
+ const event = new KeyboardEvent('keydown', { key: 'Escape', cancelable: true })
+ event.preventDefault()
+ window.dispatchEvent(event)
+}
+
+const escapeFromOpenMenu = (): void => {
+ const menu = document.createElement('div')
+ menu.setAttribute('role', 'menu')
+ menu.setAttribute('data-open', '')
+ document.body.append(menu)
+ menu.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
+ menu.remove()
+}
+
describe('spaceFeedSelectionLogic', () => {
let logic: ReturnType<typeof spaceFeedSelectionLogic.build>
let archivedIds: string[]
@@ -83,4 +98,18 @@ describe('spaceFeedSelectionLogic', () => {
expect(logic.values.selection.ids).toEqual([])
})
+
+ it.each([
+ ['a menu already handled it', () => escapeHandledByMenu()],
+ ['it comes from inside an open menu', () => escapeFromOpenMenu()],
+ ])('keeps the selection on the first Escape when %s, and clears it on the next', (_, closeMenu) => {
+ logic.actions.setSelection({ ids: ['task-1', 'task-2'], anchorId: 'task-2' })
+ closeMenu()
+
+ expect(logic.values.selection.ids).toEqual(['task-1', 'task-2'])
+
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
+
+ expect(logic.values.selection.ids).toEqual([])
+ })
})
diff --git a/products/tasks/frontend/spaces/spaceFeedSelectionLogic.ts b/products/tasks/frontend/spaces/spaceFeedSelectionLogic.ts
index 0418a6ff40ac..a9665303ba61 100644
--- a/products/tasks/frontend/spaces/spaceFeedSelectionLogic.ts
+++ b/products/tasks/frontend/spaces/spaceFeedSelectionLogic.ts
@@ -28,6 +28,7 @@ import {
computeBulkPinDirection,
computeRangeSelection,
isEditableTarget,
+ isMenuEscape,
pruneToVisible,
toggleSelection,
} from '~/layout/today/todaySessionSelection'
@@ -344,6 +345,7 @@ export const spaceFeedSelectionLogic: LogicWrapper<spaceFeedSelectionLogicType>
if (
event.key === 'Escape' &&
!isEditableTarget(event.target) &&
+ !isMenuEscape(event) &&
!values.bulkArchiveConfirm.open &&
values.selection.ids.length
) {
diff --git a/products/tasks/frontend/spaces/useSpaceFeedBulkSelection.ts b/products/tasks/frontend/spaces/useSpaceFeedBulkSelection.ts
new file mode 100644
index 000000000000..1de46fd52732
--- /dev/null
+++ b/products/tasks/frontend/spaces/useSpaceFeedBulkSelection.ts
@@ -0,0 +1,21 @@
+import { useActions, useValues } from 'kea'
+
+import { TodayBulkSelection } from '~/layout/today/TodaySessionBulkActionItems'
+
+import { spaceFeedSelectionLogic } from './spaceFeedSelectionLogic'
+
+export function useSpaceFeedBulkSelection(spaceId: string): TodayBulkSelection {
+ const logic = spaceFeedSelectionLogic({ id: spaceId })
+ const { selectedSessionIds, bulkPinDirection, bulkAction, runningSelectedCount } = useValues(logic)
+ const { pinSelected, fileSelectedTo, requestBulkArchive } = useActions(logic)
+ return {
+ spaceId,
+ selectedSessionIds,
+ bulkPinDirection,
+ bulkAction,
+ runningSelectedCount,
+ pinSelected,
+ fileSelectedTo,
+ requestBulkArchive,
+ }
+}