: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(today): show branch and source in the session hover card like desktop (#109845)
Shy Alter88317d1c3986
diff --git a/frontend/src/layout/today/TodaySessionHoverCard.tsx b/frontend/src/layout/today/TodaySessionHoverCard.tsxindex 0a50071b6714..51df760835c4 100644--- a/frontend/src/layout/today/TodaySessionHoverCard.tsx+++ b/frontend/src/layout/today/TodaySessionHoverCard.tsx@@ -1,18 +1,33 @@+import { useActions } from 'kea'import { useEffect, useMemo } from 'react'-import { IconPinFilled, IconPullRequest } from '@posthog/icons'-import { Item, ItemContent, ItemSeparator, ItemTitle, Text, cn } from '@posthog/quill'+import { IconCopy, IconPinFilled, IconPullRequest } from '@posthog/icons'+import {+ Button,+ Item,+ ItemActions,+ ItemContent,+ ItemSeparator,+ ItemTitle,+ Text,+ Tooltip,+ TooltipContent,+ TooltipTrigger,+ cn,+} from '@posthog/quill'-import { dayjs } from 'lib/dayjs'import { LinkPrimitive } from 'lib/lemon-ui/Link'+import { TaskUserBasicInfoApi } from 'products/tasks/frontend/generated/api.schemas'import { pullRequestStateMeta } from 'products/tasks/frontend/spaces/TaskPullRequestChip'import { TaskUserAvatar, taskUserName } from 'products/tasks/frontend/spaces/TaskUserAvatar'import { cardMenuParts } from './todayMenuParts'import { TodaySessionPreview } from './todayPreviewCards'import { TodaySessionActionItems } from './TodaySessionActionItems'+import { todaySessionMenuLogic } from './todaySessionMenuLogic'import { TodaySessionStatusDot } from './TodaySessionStatusDot'+import { activityDetail } from './todayWorkItems'function Fact({ label, children }: { label: string; children: JSX.Element | string }): JSX.Element {return (@@ -25,6 +40,49 @@ function Fact({ label, children }: { label: string; children: JSX.Element | stri)}+function BranchLine({ branch }: { branch: string }): JSX.Element {+ const { copyBranchName } = useActions(todaySessionMenuLogic)+ return (+ <span className="flex min-w-0 items-center gap-1">+ <span className="truncate" title={branch}>+ {branch}+ </span>+ <Tooltip disableHoverablePopup>+ <TooltipTrigger+ delay={0}+ render={+ <Button+ size="icon-xs"+ aria-label="Copy branch name"+ onClick={() => copyBranchName(branch)}+ data-attr="today-session-hover-card-copy-branch"+ />+ }+ >+ <IconCopy />+ </TooltipTrigger>+ <TooltipContent side="top" className="pointer-events-none select-none">+ Copy branch name+ </TooltipContent>+ </Tooltip>+ </span>+ )+}++function AuthorFace({ author }: { author: TaskUserBasicInfoApi }): JSX.Element {+ const label = `Created by ${taskUserName(author)}`+ return (+ <Tooltip disableHoverablePopup>+ <TooltipTrigger delay={0} render={<span role="img" aria-label={label} className="flex shrink-0" />}>+ <TaskUserAvatar user={author} />+ </TooltipTrigger>+ <TooltipContent side="top" className="pointer-events-none select-none">+ {label}+ </TooltipContent>+ </Tooltip>+ )+}+interface TodaySessionHoverCardProps {preview: TodaySessionPreview/** Closes the card once an action is chosen. */@@ -47,9 +105,10 @@ export function TodaySessionHoverCard({// Base UI reports no close when the submenu unmounts with the card, which would keep the card open for good.useEffect(() => () => onSubmenuOpenChange(false), [onSubmenuOpenChange])const pullRequestState = pullRequestStateMeta(preview.pullRequestState)+ const updated = activityDetail(preview.timestamp)return (<div className="flex flex-col" data-attr="today-session-hover-card">- <Item size="xs" className="items-start">+ <Item size="xs" className="flex-nowrap items-start"><ItemContent className="min-w-0 gap-2">{/* `wrap-anywhere`: the title sizes to its content, so a long URL in it would widen the card. */}<ItemTitle className="flex items-start gap-2 wrap-anywhere">@@ -60,18 +119,25 @@ export function TodaySessionHoverCard({</ItemTitle><div className="flex flex-col gap-1 pl-6">{preview.repository && <Fact label="Repo">{preview.repository}</Fact>}+ {preview.branch && (+ <Fact label="Branch">+ <BranchLine branch={preview.branch} />+ </Fact>+ )}{preview.spaceName && <Fact label="Space">{preview.spaceName}</Fact>}- {author && (- <Fact label="Created by">- <span className="flex min-w-0 items-center gap-1.5">- <TaskUserAvatar user={author} />- <span className="truncate">{taskUserName(author)}</span>- </span>+ {updated && (+ <Fact label="Updated">+ <span title={updated.title}>{updated.text}</span></Fact>)}- {preview.timestamp && <Fact label="Updated">{dayjs(preview.timestamp).fromNow()}</Fact>}+ {preview.source && <Fact label="Source">{preview.source}</Fact>}</div></ItemContent>+ {author && (+ <ItemActions className="self-start">+ <AuthorFace author={author} />+ </ItemActions>+ )}</Item><ItemSeparator className="my-0" /><Item size="xs" className="items-start">diff --git a/frontend/src/layout/today/todayPreviewCards.test.ts b/frontend/src/layout/today/todayPreviewCards.test.tsindex a9b310a8bae5..70282495babd 100644--- a/frontend/src/layout/today/todayPreviewCards.test.ts+++ b/frontend/src/layout/today/todayPreviewCards.test.ts@@ -72,4 +72,26 @@ describe('todayPreviewCards', () => {})expect([preview.spaceName, preview.pullRequestState]).toEqual([expected, 'merged'])})++ it.each<[string, string | null, string | null, string | null, string | null]>([+ ['names a Slack origin and the branch', 'slack', 'feature/checkout', 'Slack', 'feature/checkout'],+ ['leaves out a session a person made by hand', 'user_created', null, null, null],+ ['leaves out a session with no origin', null, '', null, null],+ ])('session card %s', (_name, origin, branch, source, expectedBranch) => {+ const item = sessionItem({+ id: 's',+ title: 'Session',+ origin_product: origin,+ latest_run: { branch },+ } as unknown as TaskListItemApi)+ const preview = sessionPreview(item, {+ unread: false,+ pinned: false,+ pullRequestStates: {},+ spaceNames: {},+ menuId: 'menu-1',+ userId: null,+ })+ expect([preview.source, preview.branch]).toEqual([source, expectedBranch])+ })})diff --git a/frontend/src/layout/today/todayPreviewCards.ts b/frontend/src/layout/today/todayPreviewCards.tsindex bf21aa4ed6d3..7a848f8eacba 100644--- a/frontend/src/layout/today/todayPreviewCards.ts+++ b/frontend/src/layout/today/todayPreviewCards.ts@@ -2,6 +2,7 @@ import { ChannelDTOApi, PrStateEnumApi, TaskUserBasicInfoApi } from 'products/taimport { SpacePresence } from 'products/tasks/frontend/spaces/spacePresence'import { TaskPullRequest } from 'products/tasks/frontend/spaces/taskPullRequests'+import { recentSourceLabel } from './todayRecentFilters'import { TodaySessionDot, todaySessionDot } from './todaySessionDot'import { TodaySessionMenuTarget, TodayWorkItem, sessionMenuTarget } from './todayWorkItems'@@ -20,6 +21,9 @@ export interface TodaySessionPreview {pullRequestState: PrStateEnumApi | nullspaceName: string | nullrepository: string | null+ branch: string | null+ /** What filed the session, or null when a person made it by hand. */+ source: string | nullauthor: TaskUserBasicInfoApi | nulltimestamp: string | nullmessage: string | null@@ -80,6 +84,9 @@ export function sessionPreview(pullRequestState: pullRequest ? (pullRequestStates[pullRequest.url] ?? null) : null,spaceName: item.channel ? (spaceNames[item.channel] ?? null) : null,repository: item.repository,+ branch: item.branch,+ source:+ item.originProduct && item.originProduct !== 'user_created' ? recentSourceLabel(item.originProduct) : null,author: item.author,timestamp: item.timestamp,message: item.finalMessage,diff --git a/frontend/src/layout/today/todaySessionMenuLogic.ts b/frontend/src/layout/today/todaySessionMenuLogic.tsindex d7e1a842f9d9..b941f7e6d753 100644--- a/frontend/src/layout/today/todaySessionMenuLogic.ts+++ b/frontend/src/layout/today/todaySessionMenuLogic.ts@@ -77,6 +77,9 @@ export interface todaySessionMenuLogicActions {runId: stringsessionId: string}+ copyBranchName: (branch: string) => {+ branch: string+ }copySessionLink: (sessionId: string) => {sessionId: string}@@ -186,6 +189,7 @@ export const todaySessionMenuLogic = kea<todaySessionMenuLogicType>([handOffSession: (sessionId: string, user: UserBasicType) => ({ sessionId, user }),analyzeSession: (sessionId: string, runId: string) => ({ sessionId, runId }),openSessionInNewTab: (sessionId: string) => ({ sessionId }),+ copyBranchName: (branch: string) => ({ branch }),copySessionLink: (sessionId: string) => ({ sessionId }),stopSession: (sessionId: string, runId: string) => ({ sessionId, runId }),requestArchive: (sessionId: string, menuId: string, activeRunId: string | null) => ({@@ -326,6 +330,14 @@ export const todaySessionMenuLogic = kea<todaySessionMenuLogicType>([openSessionInNewTab: ({ sessionId }) => {window.open(sessionUrl(sessionId), '_blank', 'noopener')},+ copyBranchName: async ({ branch }) => {+ const outcome = await writeToClipboard(branch)+ if (outcome === 'copied') {+ toast.success({ title: 'Branch name copied' })+ } else {+ toast.error({ title: 'Couldn’t copy the branch name. Try again.' })+ }+ },copySessionLink: async ({ sessionId }) => {const outcome = await writeToClipboard(sessionUrl(sessionId))if (outcome === 'copied') {