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 quill activity rows and list (#119077)

Adam Leith7e5cd164cc5f
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityList.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityList.tsx
new file mode 100644
index 000000000000..0cdf958ac9dc
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityList.tsx
@@ -0,0 +1,131 @@
+import { useActions, useValues } from 'kea'
+
+import { IconList } from '@posthog/icons'
+import {
+ Button,
+ Empty,
+ EmptyContent,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyMedia,
+ EmptyTitle,
+ Skeleton,
+ Spinner,
+ Text,
+} from '@posthog/quill'
+
+import { LinkPrimitive } from 'lib/lemon-ui/Link'
+import { urls } from 'scenes/urls'
+
+import { sidePanelActivityLogic } from '~/layout/navigation-3000/sidepanel/panels/activity/sidePanelActivityLogic'
+import { todayContextPanelLogic } from '~/layout/today/todayContextPanelLogic'
+
+import { QuillActivityLogRow } from './QuillActivityLogRow'
+
+function BrowseAllButton(): JSX.Element {
+ const { close } = useActions(todayContextPanelLogic)
+ return (
+ <Button
+ variant="outline"
+ onClick={close}
+ render={<LinkPrimitive to={urls.advancedActivityLogs()} data-attr="browse-all-activity-logs" />}
+ >
+ Browse all activity logs
+ </Button>
+ )
+}
+
+export function QuillActivityList(): JSX.Element {
+ const { allActivity, allActivityResponseLoading, allActivityHasNext, activeFilters, contextFromPage } =
+ useValues(sidePanelActivityLogic)
+ const { maybeLoadOlderActivity, setActiveFilters } = useActions(sidePanelActivityLogic)
+ const { close } = useActions(todayContextPanelLogic)
+
+ if (!contextFromPage?.scope) {
+ return (
+ <Empty>
+ <EmptyHeader>
+ <EmptyMedia variant="icon">
+ <IconList />
+ </EmptyMedia>
+ <EmptyTitle>Activity follows the page you're on</EmptyTitle>
+ <EmptyDescription>
+ Open a page like dashboards, or a specific dashboard, to see its activity here.
+ </EmptyDescription>
+ </EmptyHeader>
+ <EmptyContent>
+ <BrowseAllButton />
+ </EmptyContent>
+ </Empty>
+ )
+ }
+
+ if (allActivityResponseLoading && !allActivity.length) {
+ return (
+ <div className="flex flex-col gap-2">
+ {Array.from({ length: 6 }, (_, index) => (
+ <Skeleton key={index} className="h-12" />
+ ))}
+ </div>
+ )
+ }
+
+ if (!allActivity.length) {
+ return (
+ <Empty>
+ <EmptyHeader>
+ <EmptyTitle>No activity yet</EmptyTitle>
+ <EmptyDescription>
+ {activeFilters?.user
+ ? 'This member has made no changes here yet.'
+ : 'Changes made here show up in this list.'}
+ </EmptyDescription>
+ </EmptyHeader>
+ <EmptyContent className="flex-row flex-wrap justify-center">
+ {activeFilters?.user && (
+ <Button
+ variant="outline"
+ onClick={() => setActiveFilters({ ...activeFilters, user: undefined })}
+ >
+ Clear user filter
+ </Button>
+ )}
+ <BrowseAllButton />
+ </EmptyContent>
+ </Empty>
+ )
+ }
+
+ return (
+ <div className="flex flex-col gap-1">
+ {allActivity.map((logItem, index) => (
+ // Keyed by the activity, so a row's expanded state never carries over to a different entry.
+ <QuillActivityLogRow logItem={logItem} key={logItem.id ?? index} />
+ ))}
+ <div className="flex items-center justify-center py-2">
+ {allActivityResponseLoading ? (
+ <Text size="xs" variant="muted" render={<span className="m-0 flex items-center gap-2" />}>
+ <Spinner />
+ Loading older activity
+ </Text>
+ ) : allActivityHasNext ? (
+ <Button variant="outline" className="w-full" onClick={() => maybeLoadOlderActivity()}>
+ Load more
+ </Button>
+ ) : (
+ <Text size="xs" variant="muted" render={<span className="m-0" />}>
+ No more results
+ </Text>
+ )}
+ </div>
+ <Button
+ variant="link-muted"
+ className="self-center"
+ onClick={close}
+ render={<LinkPrimitive to={urls.advancedActivityLogs()} />}
+ >
+ Browse all activity logs
+ </Button>
+ </div>
+ )
+}
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityLogRow.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityLogRow.tsx
new file mode 100644
index 000000000000..35f27aa58650
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityLogRow.tsx
@@ -0,0 +1,214 @@
+import clsx from 'clsx'
+import { router } from 'kea-router'
+import { useId, useState } from 'react'
+
+import { IconCollapse, IconExpand } from '@posthog/icons'
+import {
+ Button,
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from '@posthog/quill'
+
+import { ActivityClientTag } from 'lib/components/ActivityLog/ActivityClientTag'
+import { ActivityLogDiff } from 'lib/components/ActivityLog/ActivityLogDiff'
+import { ACTIVITY_SEARCH_PARAM } from 'lib/components/ActivityLog/activityLogLogic'
+import { AgentAttribution } from 'lib/components/ActivityLog/AgentAttribution'
+import { HumanizedActivityLogItem } from 'lib/components/ActivityLog/humanizeActivity'
+import { TZLabel } from 'lib/components/TZLabel'
+import { IconLink } from 'lib/lemon-ui/icons'
+import { copyToClipboard } from 'lib/utils/copyToClipboard'
+
+import { QuillPersonAvatar } from '../../../components/QuillPersonAvatar'
+
+type ActivityLogTab = 'details' | 'extended description' | 'diff' | 'raw'
+
+function IconButton({
+ label,
+ onClick,
+ children,
+ ...props
+}: {
+ label: string
+ onClick: () => void
+ children: React.ReactNode
+ 'aria-expanded'?: boolean
+ 'aria-controls'?: string
+ 'data-attr'?: string
+ className?: string
+}): JSX.Element {
+ return (
+ <Tooltip>
+ <TooltipTrigger
+ delay={0}
+ render={<Button size="icon-xs" aria-label={label} onClick={onClick} {...props} />}
+ >
+ {children}
+ </TooltipTrigger>
+ <TooltipContent>{label}</TooltipContent>
+ </Tooltip>
+ )
+}
+
+// Serializes only when the Raw tab renders, since payloads can be large and most rows stay collapsed.
+function RawPayload({ value }: { value: unknown }): JSX.Element {
+ return <pre>{JSON.stringify(value, null, 2)}</pre>
+}
+
+export function QuillActivityLogRow({ logItem }: { logItem: HumanizedActivityLogItem }): JSX.Element {
+ const [expanded, setExpanded] = useState(false)
+ const [activeTab, setActiveTab] = useState<ActivityLogTab>(logItem.expandedView ? 'details' : 'diff')
+ const detailsId = useId()
+
+ const copyLink = (): void => {
+ if (!logItem.id) {
+ return
+ }
+ const { pathname, search, hash } = router.values.currentLocation
+ const url = new URL(pathname, window.location.origin)
+ url.search = search || ''
+ url.hash = hash || ''
+ url.searchParams.delete(ACTIVITY_SEARCH_PARAM)
+ url.searchParams.set(ACTIVITY_SEARCH_PARAM, logItem.id)
+ void copyToClipboard(url.toString(), 'activity link')
+ }
+
+ const avatar = (
+ <QuillPersonAvatar
+ name={logItem.name ?? ''}
+ email={logItem.email ?? undefined}
+ system={logItem.isSystem || logItem.wasImpersonated}
+ />
+ )
+
+ const heading = (
+ <div className="flex flex-wrap items-center gap-x-2 gap-y-0.5 text-xs">
+ {logItem.summary?.actor}
+ {logItem.client && <ActivityClientTag client={logItem.client} />}
+ <span className="text-muted-foreground">
+ <TZLabel time={logItem.created_at} />
+ </span>
+ </div>
+ )
+
+ const tabs = [
+ logItem.expandedView && {
+ key: 'details' as const,
+ label: logItem.expandedView.label,
+ content: logItem.expandedView.content,
+ },
+ logItem.extendedDescription && {
+ key: 'extended description' as const,
+ label: 'Extended description',
+ content: <div>{logItem.extendedDescription}</div>,
+ },
+ { key: 'diff' as const, label: 'Diff', content: <ActivityLogDiff logItem={logItem} /> },
+ {
+ key: 'raw' as const,
+ label: 'Raw',
+ content: <RawPayload value={logItem.unprocessed} />,
+ },
+ ].filter(Boolean) as { key: ActivityLogTab; label: string; content: React.ReactNode }[]
+
+ return (
+ <div
+ className={clsx(
+ 'group/activity flex flex-col rounded-md text-xs',
+ expanded && 'border border-border',
+ logItem.unread && 'bg-fill-selected'
+ )}
+ >
+ <div className="flex gap-2 p-2">
+ {logItem.emailToReveal ? (
+ <Tooltip>
+ <TooltipTrigger delay={200} render={<span className="flex shrink-0 self-start" />}>
+ {avatar}
+ </TooltipTrigger>
+ <TooltipContent className="ph-no-capture">{logItem.emailToReveal}</TooltipContent>
+ </Tooltip>
+ ) : (
+ <span className="flex shrink-0 self-start">{avatar}</span>
+ )}
+ {/* Long resource names have no spaces to break on, so they wrap anywhere to fit the panel. */}
+ <div className="flex min-w-0 flex-1 flex-col gap-1 [overflow-wrap:anywhere]">
+ {logItem.summary ? (
+ <>
+ {heading}
+ <div
+ className={clsx(
+ 'font-semibold first-letter:uppercase',
+ !expanded && 'line-clamp-2 focus-within:line-clamp-none'
+ )}
+ >
+ {logItem.summary.action}
+ </div>
+ <div className="text-muted-foreground">{logItem.summary.target}</div>
+ {logItem.summary.preview && (
+ <div className={clsx('text-muted-foreground', !expanded && 'line-clamp-2')}>
+ {logItem.summary.preview}
+ </div>
+ )}
+ </>
+ ) : (
+ <div>{logItem.description}</div>
+ )}
+ {logItem.extendedDescription && <div>{logItem.extendedDescription}</div>}
+ <div className="empty:hidden">
+ <AgentAttribution logItem={logItem} truncateIntent={!expanded} />
+ </div>
+ {!logItem.summary && heading}
+ </div>
+ <div className="flex shrink-0 items-start gap-0.5">
+ {logItem.id && (
+ <IconButton
+ label="Copy link to this activity"
+ onClick={copyLink}
+ className="opacity-0 group-focus-within/activity:opacity-100 group-hover/activity:opacity-100"
+ >
+ <IconLink />
+ </IconButton>
+ )}
+ <IconButton
+ label={expanded ? 'Collapse activity details' : 'Expand activity details'}
+ onClick={() => setExpanded(!expanded)}
+ aria-expanded={expanded}
+ aria-controls={expanded ? detailsId : undefined}
+ data-attr="activity-log-expand"
+ >
+ {expanded ? <IconCollapse /> : <IconExpand />}
+ </IconButton>
+ </div>
+ </div>
+ {expanded && (
+ <Tabs
+ id={detailsId}
+ value={activeTab}
+ onValueChange={(value) => setActiveTab(value as ActivityLogTab)}
+ className="min-w-0 gap-2 px-2 pb-2 [&_pre]:whitespace-pre-wrap [&_pre]:break-words"
+ >
+ <TabsList>
+ {tabs.map((tab) => (
+ <TabsTrigger key={tab.key} value={tab.key}>
+ {tab.label}
+ </TabsTrigger>
+ ))}
+ </TabsList>
+ {tabs.map((tab) => (
+ <TabsContent
+ key={tab.key}
+ value={tab.key}
+ // The shared diff titles each field with an h2, which reads as a page heading at this size.
+ className="min-w-0 overflow-x-auto [&_h2]:m-0 [&_h2]:text-xs [&_h2]:font-semibold"
+ >
+ {tab.content}
+ </TabsContent>
+ ))}
+ </Tabs>
+ )}
+ </div>
+ )
+}