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(today): add right-click menus to sidebar rows and feed cards, like desktop (#109667)

Shy Alterd16014c626ad
diff --git a/frontend/src/layout/today/TodayPreviewCardProvider.tsx b/frontend/src/layout/today/TodayPreviewCardProvider.tsx
index b4e1f1ec1d4a..270e35908b3a 100644
--- a/frontend/src/layout/today/TodayPreviewCardProvider.tsx
+++ b/frontend/src/layout/today/TodayPreviewCardProvider.tsx
@@ -8,6 +8,7 @@ import { TodayPreviewCard, TodayPreviewCardContext } from './todayPreviewCardCon
import { TodayPreviewPayload } from './todayPreviewCards'
import { TodaySessionHoverCard } from './TodaySessionHoverCard'
import { todaySessionMenuLogic } from './todaySessionMenuLogic'
+import { todaySessionSelectionLogic } from './todaySessionSelectionLogic'
import { TodaySpaceHoverCard } from './TodaySpaceHoverCard'
/**
@@ -21,6 +22,8 @@ export function TodayPreviewCardProvider({ children }: { children: ReactNode }):
// "File to…" opens outside the card, so the pointer moving there reads as leaving it.
const [submenuOpen, setSubmenuOpen] = useState(false)
const { sessionDialogOpen } = useValues(todaySessionMenuLogic)
+ const { bulkArchiveConfirm } = useValues(todaySessionSelectionLogic)
+ const dialogOpen = sessionDialogOpen || bulkArchiveConfirm.open
// A ref, so a hover that lands while a menu is open is refused on the same event.
const menuOpen = useRef(false)
const card = useMemo<TodayPreviewCard>(
@@ -45,9 +48,9 @@ export function TodayPreviewCardProvider({ children }: { children: ReactNode }):
{children}
<PreviewCard.Root
handle={handle}
- // A session dialog keeps the card shut, so the card can't open over it.
- open={(open || submenuOpen) && !sessionDialogOpen}
- onOpenChange={(next) => setOpen(next && !menuOpen.current && !sessionDialogOpen)}
+ // A session dialog or the bulk archive confirm keeps the card shut, so the card cannot open over it.
+ open={(open || submenuOpen) && !dialogOpen}
+ onOpenChange={(next) => setOpen(next && !menuOpen.current && !dialogOpen)}
>
{({ payload }) =>
payload ? (
diff --git a/frontend/src/layout/today/TodaySessionBulkActionItems.tsx b/frontend/src/layout/today/TodaySessionBulkActionItems.tsx
new file mode 100644
index 000000000000..e632b08a09f9
--- /dev/null
+++ b/frontend/src/layout/today/TodaySessionBulkActionItems.tsx
@@ -0,0 +1,62 @@
+import { useActions, useValues } from 'kea'
+
+import { IconArchive, IconFolder, IconPin, IconPinFilled } from '@posthog/icons'
+
+import { TodayMenuParts } from './todayMenuParts'
+import { sessionsLabel } from './todaySessionSelection'
+import { todaySessionSelectionLogic } from './todaySessionSelectionLogic'
+import { TodaySpaceFileList } from './TodaySpaceFileList'
+import { todaySpacesLogic } from './todaySpacesLogic'
+
+/** 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 },
+ dataAttrPrefix,
+}: {
+ parts: TodayMenuParts
+ /** 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
+ const attr = (name: string): string => `${dataAttrPrefix}-${name}`
+
+ return (
+ <>
+ <Item onClick={pinSelected} disabled={busy} dataAttr={attr('pin')}>
+ {pin ? <IconPin /> : <IconPinFilled />}
+ {`${pin ? 'Pin' : 'Unpin'} ${sessions}`}
+ </Item>
+ {spaces.length > 0 && !busy && (
+ <Sub
+ label={
+ <>
+ <IconFolder />
+ {`File ${sessions} to…`}
+ </>
+ }
+ dataAttr={attr('file')}
+ >
+ <TodaySpaceFileList
+ currentSpaceId={null}
+ onSelect={fileSelectedTo}
+ itemDataAttr={attr('file-space')}
+ searchDataAttr={attr('file-search')}
+ />
+ </Sub>
+ )}
+ <Separator />
+ <Item onClick={requestBulkArchive} disabled={busy} dataAttr={attr('archive')}>
+ <IconArchive />
+ {/* Only a selection with a running session asks first, so only then does the label promise a next step. */}
+ {`Archive ${sessions}${runningSelectedCount > 0 ? '…' : ''}`}
+ </Item>
+ </>
+ )
+}
diff --git a/frontend/src/layout/today/TodaySessionContextMenu.tsx b/frontend/src/layout/today/TodaySessionContextMenu.tsx
new file mode 100644
index 000000000000..a4f8d57dd6b3
--- /dev/null
+++ b/frontend/src/layout/today/TodaySessionContextMenu.tsx
@@ -0,0 +1,46 @@
+import { useValues } from 'kea'
+import { ReactNode } from 'react'
+
+import { ContextMenu, ContextMenuContent, ContextMenuTrigger } from '@posthog/quill'
+
+import { CONTEXT_PARTS } from './todayMenuParts'
+import { useTodayPreviewMenuReport } from './todayPreviewCardContext'
+import { TodaySessionActionItems } from './TodaySessionActionItems'
+import { TodaySessionBulkActionItems } from './TodaySessionBulkActionItems'
+import { TodaySessionSurface } from './todaySessionMenuLogic'
+import { rightClickActsOnSelection } from './todaySessionSelection'
+import { todaySessionSelectionLogic } from './todaySessionSelectionLogic'
+import { TodaySessionMenuTarget } from './todayWorkItems'
+
+interface TodaySessionContextMenuProps {
+ target: TodaySessionMenuTarget
+ surface: TodaySessionSurface
+ 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)
+ const reportMenuOpen = useTodayPreviewMenuReport()
+ // The selection lives in the sidebar, so only its rows offer the selection's actions.
+ const bulk = surface === 'sidebar' && rightClickActsOnSelection(selectedSessionIds, target.sessionId)
+
+ return (
+ <ContextMenu onOpenChange={reportMenuOpen}>
+ <ContextMenuTrigger render={<div className="min-w-0" />}>{children}</ContextMenuTrigger>
+ {/* 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" />
+ ) : (
+ <TodaySessionActionItems
+ parts={CONTEXT_PARTS}
+ target={target}
+ surface={surface}
+ dataAttrPrefix="today-session-context"
+ />
+ )}
+ </ContextMenuContent>
+ </ContextMenu>
+ )
+}
diff --git a/frontend/src/layout/today/TodaySessionMenu.tsx b/frontend/src/layout/today/TodaySessionMenu.tsx
index b87838390151..d54ae26e6cd8 100644
--- a/frontend/src/layout/today/TodaySessionMenu.tsx
+++ b/frontend/src/layout/today/TodaySessionMenu.tsx
@@ -1,189 +1,64 @@
-import { useActions, useValues } from 'kea'
-import { useId } from 'react'
+import { useValues } from 'kea'
-import {
- IconArchive,
- IconCopy,
- IconEllipsis,
- IconExternal,
- IconFolder,
- IconPencil,
- IconPin,
- IconPinFilled,
- IconSearch,
- IconSend,
- IconStopFilled,
-} from '@posthog/icons'
+import { IconEllipsis } from '@posthog/icons'
import {
Button,
DropdownMenu,
DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuSeparator,
- DropdownMenuSub,
- DropdownMenuSubContent,
- DropdownMenuSubTrigger,
DropdownMenuTrigger,
Tooltip,
TooltipContent,
TooltipTrigger,
} from '@posthog/quill'
-import { FEATURE_FLAGS } from 'lib/constants'
-import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
-
+import { DROPDOWN_PARTS } from './todayMenuParts'
import { useTodayPreviewMenuReport } from './todayPreviewCardContext'
-import { TodaySessionArchiveDialog } from './TodaySessionArchiveDialog'
-import { TodaySessionHandoffDialog } from './TodaySessionHandoffDialog'
+import { TodaySessionActionItems } from './TodaySessionActionItems'
import { TodaySessionSurface, todaySessionMenuLogic } from './todaySessionMenuLogic'
-import { TodaySpaceFileList } from './TodaySpaceFileList'
-import { todaySpacesLogic } from './todaySpacesLogic'
+import { TodaySessionMenuTarget } from './todayWorkItems'
interface TodaySessionMenuProps {
- sessionId: string
- title: string
- pinned: boolean
- spaceId: string | null
+ target: TodaySessionMenuTarget
surface: TodaySessionSurface
- canHandOff?: boolean
- analysisRunId?: string | null
- /** The latest run while it is an active cloud run: it can be stopped, and archiving asks first. */
- activeRunId?: string | null
}
-export function TodaySessionMenu({
- sessionId,
- title,
- pinned,
- spaceId,
- surface,
- canHandOff = false,
- analysisRunId = null,
- activeRunId = null,
-}: TodaySessionMenuProps): JSX.Element {
- const menuId = useId()
- const { featureFlags } = useValues(featureFlagLogic)
- const { spaces } = useValues(todaySpacesLogic)
- const { pendingSessionIds, handoffMenuId, archiveConfirmMenuId } = useValues(todaySessionMenuLogic)
- const {
- setSessionPinned,
- startRenaming,
- requestArchive,
- moveSession,
- openHandoff,
- analyzeSession,
- openSessionInNewTab,
- copySessionLink,
- stopSession,
- } = useActions(todaySessionMenuLogic)
+/** The "…" menu. Its dialogs belong to whoever owns `target.menuId`, which renders `TodaySessionDialogs`. */
+export function TodaySessionMenu({ target, surface }: TodaySessionMenuProps): JSX.Element {
+ const { pendingSessionIds } = useValues(todaySessionMenuLogic)
const reportMenuOpen = useTodayPreviewMenuReport()
- const runId = featureFlags[FEATURE_FLAGS.POSTHOG_CODE_TASK_ANALYSIS] ? analysisRunId : null
- const saving = pendingSessionIds.includes(sessionId)
+ const saving = pendingSessionIds.includes(target.sessionId)
const label = saving ? 'Saving your last change' : 'More actions'
return (
- <>
- <DropdownMenu onOpenChange={reportMenuOpen}>
- <Tooltip>
- <TooltipTrigger
- delay={0}
- render={
- <DropdownMenuTrigger
- render={
- <Button
- size="icon-xs"
- aria-label={label}
- loading={saving}
- data-attr="today-session-menu"
- />
- }
- />
- }
- >
- <IconEllipsis />
- </TooltipTrigger>
- <TooltipContent>{label}</TooltipContent>
- </Tooltip>
- <DropdownMenuContent align="end" className="w-56">
- <DropdownMenuItem
- onClick={() => openSessionInNewTab(sessionId)}
- data-attr="today-session-open-new-tab"
- >
- <IconExternal />
- Open in new tab
- </DropdownMenuItem>
- <DropdownMenuItem onClick={() => copySessionLink(sessionId)} data-attr="today-session-copy-link">
- <IconCopy />
- Copy link
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={() => setSessionPinned(sessionId, !pinned)}
- data-attr="today-session-pin"
- >
- {pinned ? <IconPinFilled /> : <IconPin />}
- {pinned ? 'Unpin' : 'Pin'}
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={() => startRenaming(sessionId, surface)}
- data-attr="today-session-rename"
- >
- <IconPencil />
- Rename
- </DropdownMenuItem>
- {runId && (
- <DropdownMenuItem
- onClick={() => analyzeSession(sessionId, runId)}
- data-attr="today-session-analyze"
- >
- <IconSearch />
- Run analysis
- </DropdownMenuItem>
- )}
- {activeRunId && (
- <DropdownMenuItem
- onClick={() => stopSession(sessionId, activeRunId)}
- data-attr="today-session-stop"
- >
- <IconStopFilled />
- Stop session
- </DropdownMenuItem>
- )}
- {spaces.length > 0 && (
- <DropdownMenuSub>
- <DropdownMenuSubTrigger>
- <IconFolder />
- File to…
- </DropdownMenuSubTrigger>
- <DropdownMenuSubContent className="max-h-80 w-64">
- <TodaySpaceFileList
- currentSpaceId={spaceId}
- onSelect={(value) => moveSession(sessionId, value)}
- itemDataAttr="today-session-move"
- searchDataAttr="today-session-move-search"
+ <DropdownMenu onOpenChange={reportMenuOpen}>
+ <Tooltip>
+ <TooltipTrigger
+ delay={0}
+ render={
+ <DropdownMenuTrigger
+ render={
+ <Button
+ size="icon-xs"
+ aria-label={label}
+ loading={saving}
+ data-attr="today-session-menu"
/>
- </DropdownMenuSubContent>
- </DropdownMenuSub>
- )}
- {canHandOff && (
- <DropdownMenuItem onClick={() => openHandoff(menuId)} data-attr="today-session-handoff">
- <IconSend />
- Hand off…
- </DropdownMenuItem>
- )}
- <DropdownMenuSeparator />
- <DropdownMenuItem
- onClick={() => requestArchive(sessionId, menuId, activeRunId)}
- data-attr="today-session-archive"
- >
- <IconArchive />
- Archive
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- {canHandOff && handoffMenuId === menuId && <TodaySessionHandoffDialog sessionId={sessionId} />}
- {activeRunId && archiveConfirmMenuId === menuId && (
- <TodaySessionArchiveDialog sessionId={sessionId} title={title} runId={activeRunId} />
- )}
- </>
+ }
+ />
+ }
+ >
+ <IconEllipsis />
+ </TooltipTrigger>
+ <TooltipContent>{label}</TooltipContent>
+ </Tooltip>
+ <DropdownMenuContent align="end" className="w-56">
+ <TodaySessionActionItems
+ parts={DROPDOWN_PARTS}
+ target={target}
+ surface={surface}
+ dataAttrPrefix="today-session"
+ />
+ </DropdownMenuContent>
+ </DropdownMenu>
)
}
diff --git a/frontend/src/layout/today/TodaySessionRow.tsx b/frontend/src/layout/today/TodaySessionRow.tsx
index 0436803aca50..e9f7c6d51ebb 100644
--- a/frontend/src/layout/today/TodaySessionRow.tsx
+++ b/frontend/src/layout/today/TodaySessionRow.tsx
@@ -8,6 +8,7 @@ import { userLogic } from 'scenes/userLogic'
import { sessionPreview } from './todayPreviewCards'
import { TodayPreviewTrigger } from './TodayPreviewTrigger'
import { TodaySessionBadges } from './TodaySessionBadges'
+import { TodaySessionContextMenu } from './TodaySessionContextMenu'
import { TodaySessionDialogs } from './TodaySessionDialogs'
import { TodaySessionSurface, todaySessionMenuLogic } from './todaySessionMenuLogic'
import { TodaySessionRenameInput } from './TodaySessionRenameInput'
@@ -80,10 +81,12 @@ export function TodaySessionRow({
onClickCapture={onSelectClick}
/>
)
- // Like Desktop, the row's actions live in its hover card, which opens the dialogs on the row's behalf.
+ // 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 (
<>
- <TodayPreviewTrigger payload={preview}>{row}</TodayPreviewTrigger>
+ <TodaySessionContextMenu target={preview.menu} surface={surface}>
+ <TodayPreviewTrigger payload={preview}>{row}</TodayPreviewTrigger>
+ </TodaySessionContextMenu>
<TodaySessionDialogs target={preview.menu} />
</>
)
diff --git a/frontend/src/layout/today/TodaySpaceContextMenu.tsx b/frontend/src/layout/today/TodaySpaceContextMenu.tsx
new file mode 100644
index 000000000000..71470a5bc7da
--- /dev/null
+++ b/frontend/src/layout/today/TodaySpaceContextMenu.tsx
@@ -0,0 +1,22 @@
+import { ReactNode } from 'react'
+
+import { ContextMenu, ContextMenuContent, ContextMenuTrigger } from '@posthog/quill'
+
+import { ChannelDTOApi } from 'products/tasks/frontend/generated/api.schemas'
+
+import { CONTEXT_PARTS } from './todayMenuParts'
+import { useTodayPreviewMenuReport } from './todayPreviewCardContext'
+import { TodaySpaceActions } from './TodaySpaceActions'
+
+/** A space row's actions on right-click, the same list its hover card shows, like PostHog Desktop. */
+export function TodaySpaceContextMenu({ space, children }: { space: ChannelDTOApi; children: ReactNode }): JSX.Element {
+ const reportMenuOpen = useTodayPreviewMenuReport()
+ return (
+ <ContextMenu onOpenChange={reportMenuOpen}>
+ <ContextMenuTrigger render={<div className="min-w-0" />}>{children}</ContextMenuTrigger>
+ <ContextMenuContent className="w-56">
+ <TodaySpaceActions parts={CONTEXT_PARTS} space={space} dataAttrPrefix="today-space-context" />
+ </ContextMenuContent>
+ </ContextMenu>
+ )
+}
diff --git a/frontend/src/layout/today/TodaySpacesSidebar.tsx b/frontend/src/layout/today/TodaySpacesSidebar.tsx
index 1b8266a01049..c59bfbb65805 100644
--- a/frontend/src/layout/today/TodaySpacesSidebar.tsx
+++ b/frontend/src/layout/today/TodaySpacesSidebar.tsx
@@ -19,6 +19,7 @@ import { TodaySessionBulkBar } from './TodaySessionBulkBar'
import { TodaySessionRow } from './TodaySessionRow'
import { selectionClick } from './todaySessionSelection'
import { todaySessionSelectionLogic } from './todaySessionSelectionLogic'
+import { TodaySpaceContextMenu } from './TodaySpaceContextMenu'
import { TodaySpaceGlyph } from './TodaySpaceGlyph'
import { TodayWorkSectionId, isLockedSpace, spaceLabel, todaySpacesLogic } from './todaySpacesLogic'
import { TodaySpacesRow } from './TodaySpacesRow'
@@ -298,23 +299,27 @@ export function TodaySpacesSidebar(): JSX.Element {
{visibleSpaces.map((space) => {
const presence = spacePresence[space.id]
return (
- <TodayPreviewTrigger key={space.id} payload={spacePreviews[space.id]}>
- <TodaySpacesRow
- label={spaceLabel(space)}
- icon={
- <TodaySpaceGlyph
- locked={isLockedSpace(space)}
- className="text-muted-foreground"
- />
- }
- to={urls.taskSpace(space.id)}
- active={location.pathname.includes(urls.taskSpace(space.id))}
- dataAttr="today-space-row"
- badge={presence ? <SpacePresenceAvatars presence={presence} /> : null}
- badgeCount={Math.min(presence?.people.length ?? 1, 3) as 1 | 2 | 3}
- unread={unreadSpaceIds.has(space.id)}
- />
- </TodayPreviewTrigger>
+ <TodaySpaceContextMenu key={space.id} space={space}>
+ <TodayPreviewTrigger payload={spacePreviews[space.id]}>
+ <TodaySpacesRow
+ label={spaceLabel(space)}
+ icon={
+ <TodaySpaceGlyph
+ locked={isLockedSpace(space)}
+ className="text-muted-foreground"
+ />
+ }
+ to={urls.taskSpace(space.id)}
+ active={location.pathname.includes(urls.taskSpace(space.id))}
+ dataAttr="today-space-row"
+ badge={
+ presence ? <SpacePresenceAvatars presence={presence} /> : null
+ }
+ badgeCount={Math.min(presence?.people.length ?? 1, 3) as 1 | 2 | 3}
+ unread={unreadSpaceIds.has(space.id)}
+ />
+ </TodayPreviewTrigger>
+ </TodaySpaceContextMenu>
)
})}
{visibleSpaces.length <= 1 && (
diff --git a/frontend/src/layout/today/todayMenuParts.tsx b/frontend/src/layout/today/todayMenuParts.tsx
index 4eedaedb7480..200c2af55a33 100644
--- a/frontend/src/layout/today/todayMenuParts.tsx
+++ b/frontend/src/layout/today/todayMenuParts.tsx
@@ -1,7 +1,22 @@
import { ReactNode } from 'react'
import { IconChevronRight } from '@posthog/icons'
-import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@posthog/quill'
+import {
+ Button,
+ ContextMenuItem,
+ ContextMenuSeparator,
+ ContextMenuSub,
+ ContextMenuSubContent,
+ ContextMenuSubTrigger,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuSeparator,
+ DropdownMenuSub,
+ DropdownMenuSubContent,
+ DropdownMenuSubTrigger,
+ DropdownMenuTrigger,
+} from '@posthog/quill'
import { LinkPrimitive } from 'lib/lemon-ui/Link'
@@ -11,6 +26,7 @@ export interface TodayMenuItemProps {
onClick?: () => void
/** Navigates instead of acting. */
to?: string
+ disabled?: boolean
}
export interface TodayMenuSubProps {
@@ -31,6 +47,47 @@ export interface TodayMenuParts {
const SUB_CONTENT_CLASS = 'max-h-80 w-64'
+export const DROPDOWN_PARTS: TodayMenuParts = {
+ Item: ({ children, dataAttr, onClick, to, disabled }) => (
+ <DropdownMenuItem
+ onClick={onClick}
+ disabled={disabled}
+ // quill draws the item as a row button by default, so a link keeps that look by rendering through one.
+ {...(to ? { render: <Button size="row" left render={<LinkPrimitive to={to} />} /> } : {})}
+ data-attr={dataAttr}
+ >
+ {children}
+ </DropdownMenuItem>
+ ),
+ Separator: () => <DropdownMenuSeparator />,
+ Sub: ({ label, dataAttr, children }) => (
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger data-attr={dataAttr}>{label}</DropdownMenuSubTrigger>
+ <DropdownMenuSubContent className={SUB_CONTENT_CLASS}>{children}</DropdownMenuSubContent>
+ </DropdownMenuSub>
+ ),
+}
+
+export const CONTEXT_PARTS: TodayMenuParts = {
+ Item: ({ children, dataAttr, onClick, to, disabled }) => (
+ <ContextMenuItem
+ onClick={onClick}
+ disabled={disabled}
+ {...(to ? { render: <Button size="row" left render={<LinkPrimitive to={to} />} /> } : {})}
+ data-attr={dataAttr}
+ >
+ {children}
+ </ContextMenuItem>
+ ),
+ Separator: () => <ContextMenuSeparator />,
+ Sub: ({ label, dataAttr, children }) => (
+ <ContextMenuSub>
+ <ContextMenuSubTrigger data-attr={dataAttr}>{label}</ContextMenuSubTrigger>
+ <ContextMenuSubContent className={SUB_CONTENT_CLASS}>{children}</ContextMenuSubContent>
+ </ContextMenuSub>
+ ),
+}
+
/**
* The parts for a hover card's action list. The card is not a menu, so its rows are plain buttons.
* `onAction` closes the card after a choice. `onSubmenuOpenChange` reports "File to…", whose menu opens
@@ -38,10 +95,11 @@ const SUB_CONTENT_CLASS = 'max-h-80 w-64'
*/
export function cardMenuParts(onAction: () => void, onSubmenuOpenChange: (open: boolean) => void): TodayMenuParts {
return {
- Item: ({ children, dataAttr, onClick, to }) => (
+ Item: ({ children, dataAttr, onClick, to, disabled }) => (
<Button
left
className="w-full"
+ disabled={disabled}
onClick={() => {
onClick?.()
onAction()
diff --git a/frontend/src/layout/today/todaySessionSelection.test.ts b/frontend/src/layout/today/todaySessionSelection.test.ts
index 800c0787b535..d4ca762bfd71 100644
--- a/frontend/src/layout/today/todaySessionSelection.test.ts
+++ b/frontend/src/layout/today/todaySessionSelection.test.ts
@@ -4,6 +4,7 @@ import {
computeBulkPinDirection,
computeRangeSelection,
orderedVisibleSessionIds,
+ rightClickActsOnSelection,
toggleSelection,
} from './todaySessionSelection'
import { TodayWorkSectionId } from './todaySpacesLogic'
@@ -16,6 +17,14 @@ function item(id: string, kind: TodayWorkItem['kind'] = 'session'): TodayWorkIte
}
describe('todaySessionSelection', () => {
+ it.each<[string, string[], string, boolean]>([
+ ['a row inside a selection gets the selection menu', ['t1', 't2'], 't2', true],
+ ['a row outside the selection gets its own menu', ['t1', 't2'], 't3', false],
+ ['a lone picked row gets its own menu', ['t1'], 't1', false],
+ ])('right-click: %s', (_, selected, target, expected) => {
+ expect(rightClickActsOnSelection(selected, target)).toBe(expected)
+ })
+
it.each<[string, string | null, string, string[], TodaySessionSelection]>([
['selects a forward range', 't2', 't4', [], { ids: ['t2', 't3', 't4'], anchorId: 't4' }],
['selects a backward range', 't4', 't2', [], { ids: ['t2', 't3', 't4'], anchorId: 't2' }],
diff --git a/frontend/src/layout/today/todaySessionSelection.ts b/frontend/src/layout/today/todaySessionSelection.ts
index 56727ee8eef0..2cc9db169cc9 100644
--- a/frontend/src/layout/today/todaySessionSelection.ts
+++ b/frontend/src/layout/today/todaySessionSelection.ts
@@ -62,6 +62,11 @@ export function computeRangeSelection(
return { ids: Array.from(new Set([...current, ...range])), anchorId: toId }
}
+/** Like Desktop, a right-click on a row inside a selection acts on the selection, not on that one row. */
+export function rightClickActsOnSelection(selectedIds: string[], sessionId: string): boolean {
+ return selectedIds.length > 1 && selectedIds.includes(sessionId)
+}
+
export function pruneToVisible(ids: string[], visibleIds: string[]): string[] {
const visible = new Set(visibleIds)
return ids.filter((id) => visible.has(id))
diff --git a/frontend/src/scenes/project-homepage/today/Today.stories.tsx b/frontend/src/scenes/project-homepage/today/Today.stories.tsx
index ebc9994fa3f6..ee6fec0d7a2b 100644
--- a/frontend/src/scenes/project-homepage/today/Today.stories.tsx
+++ b/frontend/src/scenes/project-homepage/today/Today.stories.tsx
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from '@storybook/react'
-import { within } from '@testing-library/dom'
+import { fireEvent, within } from '@testing-library/dom'
import userEvent from '@testing-library/user-event'
import { ReactNode } from 'react'
@@ -497,6 +497,67 @@ export const SpacePageFiltered: Story = {
parameters: { pageUrl: urls.taskSpace('space-checkout') },
}
+// Right-click at the target's corner, where a person would, so the menu opens beside it.
+function rightClick(target: Element): void {
+ const { left, top } = target.getBoundingClientRect()
+ fireEvent.contextMenu(target, { clientX: left + 8, clientY: top + 8 })
+}
+
+async function sidebarRow(canvasElement: HTMLElement, label: string, rowAttr: string): Promise<Element | undefined> {
+ const labels = await within(canvasElement).findAllByText(label)
+ return labels.find((element) => element.closest(`[data-attr="${rowAttr}"]`))
+}
+
+// Right-clicking a session row opens the same actions as its hover card.
+export const SpacesPaneSessionContextMenu: Story = {
+ play: async ({ canvasElement }) => {
+ await userEvent.click(await within(canvasElement).findByLabelText('Spaces'))
+ const row = await sidebarRow(canvasElement, 'Add a retry to the billing webhook', 'today-recent-session')
+ if (row) {
+ rightClick(row)
+ await within(document.body).findByText('Open in new tab')
+ }
+ },
+}
+
+// Right-clicking a space row opens its actions, New session first, like its hover card.
+export const SpacesPaneSpaceContextMenu: Story = {
+ play: async ({ canvasElement }) => {
+ await userEvent.click(await within(canvasElement).findByLabelText('Spaces'))
+ const row = await sidebarRow(canvasElement, 'checkout', 'today-space-row')
+ if (row) {
+ rightClick(row)
+ await within(document.body).findByText('New session')
+ }
+ },
+}
+
+// With two sessions picked, right-clicking one of them offers the selection's actions instead of the row's.
+export const SpacesPaneSelectedSessionsContextMenu: Story = {
+ parameters: { pageUrl: urls.taskSpace('space-checkout') },
+ play: async ({ canvasElement }) => {
+ await within(canvasElement).findAllByText('Add a retry to the billing webhook')
+ todaySessionSelectionLogic.actions.setSelection({ ids: ['task-pinned', 'task-1'], anchorId: 'task-1' })
+ const row = await sidebarRow(canvasElement, 'Add a retry to the billing webhook', 'today-recent-session')
+ if (row) {
+ rightClick(row)
+ await within(document.body).findByText('Pin 2 sessions')
+ }
+ },
+}
+
+// Right-clicking a card in a space's feed opens the same actions as its "…" menu.
+export const SpaceFeedCardContextMenu: Story = {
+ parameters: { pageUrl: urls.taskSpace('space-checkout') },
+ play: async ({ canvasElement }) => {
+ const row = await sidebarRow(canvasElement, 'Add a retry to the billing webhook', 'today-space-feed-card')
+ if (row) {
+ rightClick(row)
+ await within(document.body).findByText('Open in new tab')
+ }
+ },
+}
+
export const SpacesBrowse: Story = {
parameters: { pageUrl: urls.taskSpaces() },
}
diff --git a/products/tasks/frontend/spaces/SpaceFeedCard.tsx b/products/tasks/frontend/spaces/SpaceFeedCard.tsx
index e7a80c07213b..550947745f6c 100644
--- a/products/tasks/frontend/spaces/SpaceFeedCard.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeedCard.tsx
@@ -1,4 +1,5 @@
import { useValues } from 'kea'
+import { useId } from 'react'
import { IconGitBranch } from '@posthog/icons'
import {
@@ -20,11 +21,13 @@ import { LinkPrimitive } from 'lib/lemon-ui/Link'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
+import { TodaySessionContextMenu } from '~/layout/today/TodaySessionContextMenu'
+import { TodaySessionDialogs } from '~/layout/today/TodaySessionDialogs'
import { TodaySessionMenu } from '~/layout/today/TodaySessionMenu'
import { todaySessionMenuLogic } from '~/layout/today/todaySessionMenuLogic'
import { TodaySessionRenameInput } from '~/layout/today/TodaySessionRenameInput'
import { todaySpacesLogic } from '~/layout/today/todaySpacesLogic'
-import { activeCloudRunId, analysisRunId, canHandOff, sessionItem, shortTimeAgo } from '~/layout/today/todayWorkItems'
+import { sessionItem, sessionMenuTarget, shortTimeAgo } from '~/layout/today/todayWorkItems'
import { TaskListItemApi } from '../generated/api.schemas'
import { spaceFeedPreview } from './spaceFeedPreview'
@@ -46,7 +49,10 @@ export function SpaceFeedCard({ task, pinned, unread, repository }: SpaceFeedCar
const { renaming } = useValues(todaySessionMenuLogic)
const { user } = useValues(userLogic)
const { pullRequestStates } = useValues(todaySpacesLogic)
+ const menuId = useId()
const item = sessionItem(task)
+ // The "…" menu and the right-click menu share one menu id, so either one opens the same dialogs.
+ const menu = sessionMenuTarget(item, { menuId, pinned, userId: user?.id })
const [mainPullRequest] = item.pullRequests
const status = spaceFeedStatus(task.latest_run, mainPullRequest && pullRequestStates[mainPullRequest.url])
const pullRequests = splitPullRequests(item.pullRequests)
@@ -54,7 +60,7 @@ export function SpaceFeedCard({ task, pinned, unread, repository }: SpaceFeedCar
const author = task.created_by
const authorName = author ? taskUserName(author) : null
- return (
+ const card = (
<Card
size="sm"
className="group/card relative my-1.5 gap-0 rounded-xl px-4 pt-3.5 pb-3 transition-colors hover:bg-fill-hover"
@@ -100,16 +106,7 @@ export function SpaceFeedCard({ task, pinned, unread, repository }: SpaceFeedCar
{status.label}
</Badge>
)}
- <TodaySessionMenu
- sessionId={task.id}
- title={item.title}
- pinned={pinned}
- spaceId={item.channel}
- surface="feed"
- canHandOff={canHandOff(item, user?.id)}
- analysisRunId={analysisRunId(item)}
- activeRunId={activeCloudRunId(item)}
- />
+ <TodaySessionMenu target={menu} surface="feed" />
</div>
</div>
{preview && (
@@ -184,4 +181,13 @@ export function SpaceFeedCard({ task, pinned, unread, repository }: SpaceFeedCar
)}
</Card>
)
+ // 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">
+ {card}
+ </TodaySessionContextMenu>
+ <TodaySessionDialogs target={menu} />
+ </>
+ )
}
diff --git a/products/tasks/frontend/spaces/SpaceFeedListRow.tsx b/products/tasks/frontend/spaces/SpaceFeedListRow.tsx
index b5f1db074907..08d331c4dfaa 100644
--- a/products/tasks/frontend/spaces/SpaceFeedListRow.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeedListRow.tsx
@@ -1,4 +1,5 @@
import { useValues } from 'kea'
+import { useId } from 'react'
import { Badge, Spinner, Text } from '@posthog/quill'
@@ -6,11 +7,12 @@ import { LinkPrimitive } from 'lib/lemon-ui/Link'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
+import { TodaySessionDialogs } from '~/layout/today/TodaySessionDialogs'
import { TodaySessionMenu } from '~/layout/today/TodaySessionMenu'
import { todaySessionMenuLogic } from '~/layout/today/todaySessionMenuLogic'
import { TodaySessionRenameInput } from '~/layout/today/TodaySessionRenameInput'
import { todaySpacesLogic } from '~/layout/today/todaySpacesLogic'
-import { activeCloudRunId, analysisRunId, canHandOff, sessionItem, shortTimeAgo } from '~/layout/today/todayWorkItems'
+import { sessionItem, sessionMenuTarget, shortTimeAgo } from '~/layout/today/todayWorkItems'
import { TaskListItemApi } from '../generated/api.schemas'
import { spaceFeedStatus } from './spaceFeedStatus'
@@ -29,6 +31,8 @@ export function SpaceFeedListRow({ task, pinned, unread }: SpaceFeedListRowProps
const { user } = useValues(userLogic)
const { pullRequestStates } = useValues(todaySpacesLogic)
const item = sessionItem(task)
+ const menuId = useId()
+ const menu = sessionMenuTarget(item, { menuId, pinned, userId: user?.id })
const [mainPullRequest] = item.pullRequests
const status = spaceFeedStatus(task.latest_run, mainPullRequest && pullRequestStates[mainPullRequest.url])
const author = task.created_by
@@ -85,17 +89,9 @@ export function SpaceFeedListRow({ task, pinned, unread }: SpaceFeedListRowProps
</Text>
)}
<span className="absolute right-1 opacity-0 transition-opacity group-focus-within/row:opacity-100 group-hover/row:opacity-100">
- <TodaySessionMenu
- sessionId={task.id}
- title={item.title}
- pinned={pinned}
- spaceId={item.channel}
- surface="feed"
- canHandOff={canHandOff(item, user?.id)}
- analysisRunId={analysisRunId(item)}
- activeRunId={activeCloudRunId(item)}
- />
+ <TodaySessionMenu target={menu} surface="feed" />
</span>
+ <TodaySessionDialogs target={menu} />
</div>
)
}