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): show source and local badges on sidebar sessions like desktop (#109844)

Shy Alteraabd8a4c70e0
diff --git a/frontend/src/layout/today/TodaySessionBadges.tsx b/frontend/src/layout/today/TodaySessionBadges.tsx
index e6275632e0c5..782eaa67e8c9 100644
--- a/frontend/src/layout/today/TodaySessionBadges.tsx
+++ b/frontend/src/layout/today/TodaySessionBadges.tsx
@@ -1,64 +1,109 @@
-import { IconPinFilled, IconPullRequest } from '@posthog/icons'
+import { IconArrowRightDown, IconLaptop, IconPinFilled, IconPullRequest } from '@posthog/icons'
import { Avatar, AvatarFallback, AvatarGroup, Tooltip, TooltipContent, TooltipTrigger, cn } from '@posthog/quill'
+import { IconSlack } from 'lib/lemon-ui/icons'
import { LinkPrimitive } from 'lib/lemon-ui/Link'
import { PrStateEnumApi } from 'products/tasks/frontend/generated/api.schemas'
import { pullRequestLinkLabel, pullRequestStateMeta } from 'products/tasks/frontend/spaces/TaskPullRequestChip'
import { TaskPullRequest } from 'products/tasks/frontend/spaces/taskPullRequests'
+import { recentSourceLabel } from './todayRecentFilters'
+import { TodaySessionBadge } from './todayWorkItems'
+
// The ring keeps two overlapping badges apart, so they do not read as one glyph.
const BADGE_CLASS = 'ring-1 ring-border'
interface TodaySessionBadgesProps {
- pullRequest: TaskPullRequest | null
+ badges: TodaySessionBadge[]
pullRequestState: PrStateEnumApi | null | undefined
pinned: boolean
}
-/** A session row's trailing stack, like PostHog Desktop: the pin, then the pull request colored by its state. */
-export function TodaySessionBadges({ pullRequest, pullRequestState, pinned }: TodaySessionBadgesProps): JSX.Element {
- const known = pullRequestStateMeta(pullRequestState)
+/** A session row's trailing stack, like PostHog Desktop: the pin, the source, then the pull request colored by its state. */
+export function TodaySessionBadges({ badges, pullRequestState, pinned }: TodaySessionBadgesProps): JSX.Element {
return (
<AvatarGroup stacked reverse size="xs" className="shrink-0">
{pinned && (
- <Tooltip>
- <TooltipTrigger
- delay={200}
- render={<Avatar size="xs" role="img" aria-label="Pinned" className={BADGE_CLASS} />}
- >
- <AvatarFallback className="bg-transparent">
- <IconPinFilled className="size-2.5 text-muted-foreground" />
- </AvatarFallback>
- </TooltipTrigger>
- <TooltipContent>Pinned</TooltipContent>
- </Tooltip>
+ <IconBadge label="Pinned">
+ <IconPinFilled className="size-2.5 text-primary" />
+ </IconBadge>
)}
- {pullRequest && (
- <Tooltip>
- <TooltipTrigger
- delay={200}
- render={
- <Avatar
- size="xs"
- render={<LinkPrimitive to={pullRequest.url} target="_blank" />}
- aria-label={pullRequestLinkLabel(pullRequest, pullRequestState)}
- data-attr="today-pr-chip-sidebar"
- className={BADGE_CLASS}
+ {badges.map((badge) => {
+ switch (badge.kind) {
+ case 'source':
+ return (
+ <IconBadge key={badge.kind} label={`Source: ${recentSourceLabel(badge.source)}`}>
+ {badge.source === 'slack' ? (
+ <IconSlack className="size-2.5" />
+ ) : (
+ <IconArrowRightDown className="size-2.5 text-muted-foreground" />
+ )}
+ </IconBadge>
+ )
+ case 'pullRequest':
+ return (
+ <PullRequestBadge
+ key={badge.kind}
+ pullRequest={badge.pullRequest}
+ pullRequestState={pullRequestState}
/>
- }
- >
- <AvatarFallback className="bg-transparent">
- <IconPullRequest
- className={cn('size-2.5', known?.iconClassName ?? 'text-muted-foreground')}
- />
- </AvatarFallback>
- </TooltipTrigger>
- <TooltipContent>
- {`${known?.label ?? 'Pull request'} · ${pullRequest.repository}#${pullRequest.number}`}
- </TooltipContent>
- </Tooltip>
- )}
+ )
+ case 'local':
+ return (
+ <IconBadge key={badge.kind} label="Local">
+ <IconLaptop className="size-2.5 text-muted-foreground" />
+ </IconBadge>
+ )
+ }
+ })}
</AvatarGroup>
)
}
+
+function IconBadge({ label, children }: { label: string; children: React.ReactNode }): JSX.Element {
+ return (
+ <Tooltip>
+ <TooltipTrigger
+ delay={200}
+ render={<Avatar size="xs" role="img" aria-label={label} className={BADGE_CLASS} />}
+ >
+ <AvatarFallback className="bg-transparent">{children}</AvatarFallback>
+ </TooltipTrigger>
+ <TooltipContent>{label}</TooltipContent>
+ </Tooltip>
+ )
+}
+
+function PullRequestBadge({
+ pullRequest,
+ pullRequestState,
+}: {
+ pullRequest: TaskPullRequest
+ pullRequestState: PrStateEnumApi | null | undefined
+}): JSX.Element {
+ const known = pullRequestStateMeta(pullRequestState)
+ return (
+ <Tooltip>
+ <TooltipTrigger
+ delay={200}
+ render={
+ <Avatar
+ size="xs"
+ render={<LinkPrimitive to={pullRequest.url} target="_blank" />}
+ aria-label={pullRequestLinkLabel(pullRequest, pullRequestState)}
+ data-attr="today-pr-chip-sidebar"
+ className={BADGE_CLASS}
+ />
+ }
+ >
+ <AvatarFallback className="bg-transparent">
+ <IconPullRequest className={cn('size-2.5', known?.iconClassName ?? 'text-muted-foreground')} />
+ </AvatarFallback>
+ </TooltipTrigger>
+ <TooltipContent>
+ {`${known?.label ?? 'Pull request'} · ${pullRequest.repository}#${pullRequest.number}`}
+ </TooltipContent>
+ </Tooltip>
+ )
+}
diff --git a/frontend/src/layout/today/TodaySessionRow.tsx b/frontend/src/layout/today/TodaySessionRow.tsx
index c9c69c3d6aed..647acbad5057 100644
--- a/frontend/src/layout/today/TodaySessionRow.tsx
+++ b/frontend/src/layout/today/TodaySessionRow.tsx
@@ -16,7 +16,7 @@ import { TodaySessionRenameInput } from './TodaySessionRenameInput'
import { TodaySessionStatusDot } from './TodaySessionStatusDot'
import { todaySpacesLogic } from './todaySpacesLogic'
import { TodaySpacesRow } from './TodaySpacesRow'
-import { TodayWorkItem, sessionDetails } from './todayWorkItems'
+import { TodayWorkItem, sessionBadges, sessionDetails } from './todayWorkItems'
interface TodaySessionRowProps {
item: TodayWorkItem
@@ -54,9 +54,10 @@ export function TodaySessionRow({
)
const details = useMemo(() => sessionDetails(item, fields, spaceNames), [item, fields, spaceNames])
+ const badges = useMemo(() => sessionBadges(item), [item])
const [pullRequest] = item.pullRequests
const pinBadge = pinned && showPinBadge
- const badgeCount = (pullRequest ? 1 : 0) + (pinBadge ? 1 : 0)
+ const badgeCount = badges.length + (pinBadge ? 1 : 0)
if (renaming?.sessionId === item.id && renaming.surface === surface) {
return <TodaySessionRenameInput sessionId={item.id} title={item.title} />
@@ -72,13 +73,13 @@ export function TodaySessionRow({
badge={
badgeCount > 0 ? (
<TodaySessionBadges
- pullRequest={pullRequest ?? null}
+ badges={badges}
pullRequestState={pullRequest ? pullRequestStates[pullRequest.url] : null}
pinned={pinBadge}
/>
) : null
}
- badgeCount={badgeCount === 2 ? 2 : 1}
+ badgeCount={badgeCount >= 3 ? 3 : badgeCount === 2 ? 2 : 1}
ticker
selected={selected}
onClickCapture={onSelectClick}
diff --git a/frontend/src/layout/today/todayWorkItems.test.ts b/frontend/src/layout/today/todayWorkItems.test.ts
index c0e1c642a603..6cd62fdfcd71 100644
--- a/frontend/src/layout/today/todayWorkItems.test.ts
+++ b/frontend/src/layout/today/todayWorkItems.test.ts
@@ -19,6 +19,7 @@ import {
canHandOff,
chatItem,
groupByDay,
+ sessionBadges,
sessionDetails,
sessionItem,
shortTimeAgo,
@@ -210,6 +211,37 @@ describe('todayWorkItems', () => {
expect(activeCloudRunId(item)).toBe(runId)
})
+ it.each<[string, string, string, Record<string, unknown>, string[]]>([
+ [
+ 'the Slack source before the pull request',
+ 'slack',
+ 'cloud',
+ { pr_url: 'https://github.com/a/b/pull/1' },
+ ['source:slack', 'pullRequest'],
+ ],
+ ['the source of another product', 'error_tracking', 'cloud', {}, ['source:error_tracking']],
+ ['nothing for a session someone started', 'user_created', 'cloud', {}, []],
+ ['Local when nothing else shows', 'user_created', 'local', {}, ['local']],
+ [
+ 'only the pull request for a local run that has one',
+ 'user_created',
+ 'local',
+ { pr_url: 'https://github.com/a/b/pull/1' },
+ ['pullRequest'],
+ ],
+ ])('shows %s as session badges', (_name, origin, environment, output, expected) => {
+ const item = sessionItem({
+ id: 's',
+ title: 'Session',
+ origin_product: origin,
+ latest_run: { environment, output },
+ } as unknown as TaskListItemApi)
+
+ expect(
+ sessionBadges(item).map((badge) => (badge.kind === 'source' ? `source:${badge.source}` : badge.kind))
+ ).toEqual(expected)
+ })
+
it.each([
['the closing message, trimmed', { final_message: ' Opened the pull request.\n' }, 'Opened the pull request.'],
['nothing when the run saved no message', { pr_url: 'https://github.com/a/b/pull/1' }, null],
diff --git a/frontend/src/layout/today/todayWorkItems.ts b/frontend/src/layout/today/todayWorkItems.ts
index 6eff2bd17ca3..73c5c7f0fc9d 100644
--- a/frontend/src/layout/today/todayWorkItems.ts
+++ b/frontend/src/layout/today/todayWorkItems.ts
@@ -45,6 +45,22 @@ export interface TodayWorkGroup {
items: TodayWorkItem[]
}
+export type TodaySessionBadge =
+ | { kind: 'source'; source: string }
+ | { kind: 'pullRequest'; pullRequest: TaskPullRequest }
+ | { kind: 'local' }
+
+const BADGE_SOURCES = new Set([
+ 'slack',
+ 'signal_report',
+ 'signals_scout',
+ 'support_queue',
+ 'session_summaries',
+ 'error_tracking',
+ 'eval_clusters',
+ 'task_analysis',
+])
+
const FINISHED_RUN_STATUSES = new Set(['completed', 'failed', 'cancelled'])
const ACTIVE_RUN_STATUSES = new Set(['not_started', 'queued', 'in_progress'])
@@ -147,6 +163,21 @@ export function chatItem(conversation: ConversationDetail): TodayWorkItem {
}
}
+export function sessionBadges(item: TodayWorkItem): TodaySessionBadge[] {
+ const badges: TodaySessionBadge[] = []
+ if (item.originProduct && BADGE_SOURCES.has(item.originProduct)) {
+ badges.push({ kind: 'source', source: item.originProduct })
+ }
+ const [pullRequest] = item.pullRequests
+ if (pullRequest) {
+ badges.push({ kind: 'pullRequest', pullRequest })
+ }
+ if (badges.length === 0 && item.runEnvironment === 'local') {
+ badges.push({ kind: 'local' })
+ }
+ return badges
+}
+
/** "2h ago", with the exact time for the tooltip. The same scale as PostHog Desktop's row details. */
export function activityDetail(
timestamp: string | null,