: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): rebuild the activity panel in quill (#119078)
Adam Leith853b29240fe4
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityControls.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityControls.tsxnew file mode 100644index 000000000000..de269af93245--- /dev/null+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityControls.tsx@@ -0,0 +1,62 @@+import { useActions, useValues } from 'kea'++import { Text } from '@posthog/quill'++import { humanizeScope } from 'lib/components/ActivityLog/humanizeActivity'++import {+ ActivityFilters,+ sidePanelActivityLogic,+} from '~/layout/navigation-3000/sidepanel/panels/activity/sidePanelActivityLogic'+import { todayContextPanelLogic } from '~/layout/today/todayContextPanelLogic'+import { PropertyFilterType, PropertyOperator } from '~/types'++import { QuillActivityMemberFilter } from './QuillActivityMemberFilter'+import { QuillActivitySubscribeMenu } from './QuillActivitySubscribeMenu'++export function QuillActivityControls({ contextFromPage }: { contextFromPage: ActivityFilters }): JSX.Element {+ const { activeFilters } = useValues(sidePanelActivityLogic)+ const { setActiveFilters } = useActions(sidePanelActivityLogic)+ const { close } = useActions(todayContextPanelLogic)+ const hasItemContext = Boolean(contextFromPage.item_id)++ return (+ <div className="flex items-center justify-between gap-2">+ <Text size="xs" variant="muted" render={<span className="m-0 min-w-0" />}>+ Activity on{' '}+ <span className="font-semibold text-foreground">+ {hasItemContext+ ? `this ${humanizeScope(contextFromPage.scope!, true).toLowerCase()}`+ : `all ${humanizeScope(contextFromPage.scope!).toLowerCase()}`}+ </span>+ </Text>+ <div className="flex min-w-0 items-center gap-1">+ <QuillActivitySubscribeMenu+ properties={[+ {+ key: 'scope',+ type: PropertyFilterType.Event,+ value: contextFromPage.scope!,+ operator: PropertyOperator.Exact,+ },+ ...(hasItemContext+ ? [+ {+ key: 'item_id',+ type: PropertyFilterType.Event as const,+ value: contextFromPage.item_id,+ operator: PropertyOperator.Exact,+ },+ ]+ : []),+ ]}+ onNavigate={close}+ />+ <QuillActivityMemberFilter+ value={activeFilters?.user ?? null}+ onChange={(user) => setActiveFilters({ ...activeFilters, user: user?.id ?? undefined })}+ />+ </div>+ </div>+ )+}diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityMemberFilter.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityMemberFilter.tsxnew file mode 100644index 000000000000..d15abe53b930--- /dev/null+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityMemberFilter.tsx@@ -0,0 +1,118 @@+import { useActions, useValues } from 'kea'+import { useEffect, useRef, useState } from 'react'++import {+ Button,+ Combobox,+ ComboboxContent,+ ComboboxEmpty,+ ComboboxInput,+ ComboboxItem,+ ComboboxList,+ SelectTriggerIcon,+ Spinner,+} from '@posthog/quill'++import { fullName } from 'lib/utils/strings'+import { membersLogic } from 'scenes/organization/membersLogic'++import { UserBasicType } from '~/types'++import { QuillPersonAvatar } from '../../../components/QuillPersonAvatar'++const ANY_USER = 'any'++interface QuillActivityMemberFilterProps {+ /** The selected member's user id, or null for anyone. */+ value: UserBasicType['id'] | null+ onChange: (user: UserBasicType | null) => void+}++export function QuillActivityMemberFilter({ value, onChange }: QuillActivityMemberFilterProps): JSX.Element {+ const { meFirstMembers, membersLoading } = useValues(membersLogic)+ const { ensureAllMembersLoaded } = useActions(membersLogic)+ const [open, setOpen] = useState(false)+ const triggerRef = useRef<HTMLButtonElement>(null)++ // The trigger opens the picker through the controlled prop, which never calls onOpenChange, so both paths load.+ const setPickerOpen = (next: boolean): void => {+ setOpen(next)+ if (next) {+ ensureAllMembersLoaded()+ }+ }++ // A value set from the URL needs the member list to show a name rather than "Any user".+ useEffect(() => {+ if (value) {+ ensureAllMembersLoaded()+ }+ }, [value]) // oxlint-disable-line react-hooks/exhaustive-deps++ // You come first, then everyone else, as in the other member pickers. The unfiltered list, because the shared+ // member search from settings would otherwise hide members here.+ const members = meFirstMembers+ const usersById = Object.fromEntries(members.map((member) => [String(member.user.id), member.user]))+ const selected = value ? usersById[String(value)] : null+ const items = [ANY_USER, ...members.map((member) => String(member.user.id))]++ return (+ <Combobox<string>+ items={items}+ open={open}+ onOpenChange={setPickerOpen}+ value={value ? String(value) : ANY_USER}+ onValueChange={(next) => {+ onChange(!next || next === ANY_USER ? null : (usersById[next] ?? null))+ setOpen(false)+ }}+ itemToStringLabel={(key: string) =>+ key === ANY_USER ? 'Any user' : `${fullName(usersById[key])} ${usersById[key]?.email ?? ''}`+ }+ >+ <Button+ ref={triggerRef}+ variant="outline"+ className="min-w-0 shrink"+ onClick={() => setPickerOpen(!open)}+ data-attr="activity-member-filter"+ >+ <span className="ph-no-capture min-w-0 truncate">{selected ? fullName(selected) : 'Any user'}</span>+ <SelectTriggerIcon />+ </Button>+ <ComboboxContent anchor={triggerRef} className="w-64">+ <ComboboxInput placeholder="Search members…" showTrigger={false} />+ <ComboboxEmpty>+ {membersLoading ? (+ <span className="flex items-center gap-2">+ <Spinner />+ Loading members…+ </span>+ ) : (+ 'No matching members'+ )}+ </ComboboxEmpty>+ <ComboboxList>+ {(key: string) =>+ key === ANY_USER ? (+ <ComboboxItem key={key} value={key}>+ Any user+ </ComboboxItem>+ ) : (+ <ComboboxItem key={key} value={key}>+ <span className="ph-no-capture flex min-w-0 items-center gap-2">+ <QuillPersonAvatar+ name={fullName(usersById[key])}+ email={usersById[key]?.email}+ size="xs"+ />+ <span className="truncate">{fullName(usersById[key])}</span>+ </span>+ </ComboboxItem>+ )+ }+ </ComboboxList>+ </ComboboxContent>+ </Combobox>+ )+}diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityMetalytics.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityMetalytics.tsxnew file mode 100644index 000000000000..13a92dcacdbf--- /dev/null+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityMetalytics.tsx@@ -0,0 +1,88 @@+import { useValues } from 'kea'++import { Item, ItemContent, ItemDescription, ItemTitle, Skeleton, Text } from '@posthog/quill'++import { humanizeScope } from 'lib/components/ActivityLog/humanizeActivity'+import { metalyticsLogic } from 'lib/components/Metalytics/metalyticsLogic'++import { QuillPeopleAvatars } from '../../../components/QuillPeopleAvatars'++function Stat({+ label,+ description,+ loading,+ children,+}: {+ label: string+ description: string+ loading: boolean+ children: React.ReactNode+}): JSX.Element {+ return (+ <Item variant="outline" size="sm">+ <ItemContent>+ <ItemDescription>{label}</ItemDescription>+ <ItemTitle className="text-base">{loading ? <Skeleton className="h-6 w-12" /> : children}</ItemTitle>+ <Text size="xs" variant="muted">+ {description}+ </Text>+ </ItemContent>+ </Item>+ )+}++export function QuillActivityMetalytics(): JSX.Element {+ const { scope, instanceId, viewCount, recentUserMembers, viewCountLoading, recentUsersLoading } =+ useValues(metalyticsLogic)++ if (!instanceId) {+ return (+ <Text size="xs" variant="muted">+ See how members of your organization use things like dashboards, insights, and playlists. Open one to+ see who views it.+ </Text>+ )+ }++ const humanizedScope = `this ${scope ? humanizeScope(scope, true).toLowerCase() : 'app'}`++ return (+ <div className="flex flex-col gap-2">+ <Text size="xs" variant="muted">+ How members of your organization interact with {humanizedScope}.+ </Text>+ <Stat+ label="Views"+ description={`Times members of your organization viewed ${humanizedScope}.`}+ loading={viewCountLoading}+ >+ {viewCount?.views ?? 0}+ </Stat>+ <Stat+ label="Viewers"+ description={`Members of your organization who viewed ${humanizedScope}.`}+ loading={viewCountLoading}+ >+ {viewCount?.users ?? 0}+ </Stat>+ <Stat+ label="Recent viewers (30 days)"+ description={`The latest 30 members who viewed ${humanizedScope}.`}+ loading={recentUsersLoading}+ >+ {recentUserMembers.length > 0 ? (+ <QuillPeopleAvatars+ people={recentUserMembers.map((member) => ({+ email: member.user.email,+ name: member.user.first_name,+ }))}+ />+ ) : (+ <Text size="xs" variant="muted" render={<span className="m-0" />}>+ No recent viewers+ </Text>+ )}+ </Stat>+ </div>+ )+}diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityPanel.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityPanel.tsxnew file mode 100644index 000000000000..e88166bfd16e--- /dev/null+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityPanel.tsx@@ -0,0 +1,108 @@+import { useActions, useValues } from 'kea'+import { useRef } from 'react'++import { IconNotification } from '@posthog/icons'+import {+ Empty,+ EmptyDescription,+ EmptyHeader,+ EmptyMedia,+ EmptyTitle,+ Tabs,+ TabsList,+ TabsTrigger,+} from '@posthog/quill'++import { PayGateMini } from 'lib/components/PayGateMini/PayGateMini'+import { FEATURE_FLAGS } from 'lib/constants'+import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { userHasAccess } from 'lib/utils/accessControlUtils'+import { userLogic } from 'scenes/userLogic'++import {+ SidePanelActivityTab,+ sidePanelActivityLogic,+} from '~/layout/navigation-3000/sidepanel/panels/activity/sidePanelActivityLogic'+import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'+import { AccessControlLevel, AccessControlResourceType, AvailableFeature } from '~/types'++import { QuillActivityControls } from './QuillActivityControls'+import { QuillActivityList } from './QuillActivityList'+import { QuillActivityMetalytics } from './QuillActivityMetalytics'++const SCROLL_TRIGGER_OFFSET = 100++export function QuillActivityPanel(): JSX.Element {+ const { activeTab, contextFromPage } = useValues(sidePanelActivityLogic)+ const { setActiveTab, maybeLoadOlderActivity } = useActions(sidePanelActivityLogic)+ const { user } = useValues(userLogic)+ const { featureFlags } = useValues(featureFlagLogic)+ const { selectedTabOptions } = useValues(sidePanelStateLogic)+ const lastScrollTopRef = useRef(0)+ const showAnalytics = !!featureFlags[FEATURE_FLAGS.METALYTICS]+ // The tab is persisted, so it can hold one this panel doesn't show. Anything else lands on Activity.+ const shownTab =+ activeTab === SidePanelActivityTab.Metalytics && showAnalytics ? activeTab : SidePanelActivityTab.All++ // Each open starts on Activity, unless the panel was opened straight to Analytics.+ useOnMountEffect(() => {+ if (!(showAnalytics && selectedTabOptions === SidePanelActivityTab.Metalytics)) {+ setActiveTab(SidePanelActivityTab.All)+ }+ })++ if (!userHasAccess(AccessControlResourceType.ActivityLog, AccessControlLevel.Viewer)) {+ return (+ <Empty className="flex-1">+ <EmptyHeader>+ <EmptyMedia variant="icon">+ <IconNotification />+ </EmptyMedia>+ <EmptyTitle>You can't view activity logs</EmptyTitle>+ <EmptyDescription>Ask a project admin to give you access to activity logs.</EmptyDescription>+ </EmptyHeader>+ </Empty>+ )+ }++ const onScroll = (event: React.UIEvent<HTMLDivElement>): void => {+ const { scrollTop, clientHeight, scrollHeight } = event.currentTarget+ // Only scrolling down toward the end loads older entries.+ if (scrollTop > lastScrollTopRef.current && scrollHeight - (scrollTop + clientHeight) < SCROLL_TRIGGER_OFFSET) {+ maybeLoadOlderActivity()+ }+ lastScrollTopRef.current = scrollTop+ }++ return (+ <PayGateMini+ feature={AvailableFeature.AUDIT_LOGS}+ featureDetail="activity-log-side-panel"+ className="flex min-h-0 flex-1 flex-col"+ overrideShouldShowGate={user?.is_impersonated || !!featureFlags[FEATURE_FLAGS.AUDIT_LOGS_ACCESS]}+ >+ <div className="flex min-h-0 flex-1 flex-col">+ <div className="flex shrink-0 flex-col gap-2 p-3 pb-2">+ {showAnalytics && (+ <Tabs value={shownTab} onValueChange={(value) => setActiveTab(value as SidePanelActivityTab)}>+ <TabsList className="w-full">+ <TabsTrigger value={SidePanelActivityTab.All}>Activity</TabsTrigger>+ <TabsTrigger value={SidePanelActivityTab.Metalytics}>Analytics</TabsTrigger>+ </TabsList>+ </Tabs>+ )}+ {shownTab === SidePanelActivityTab.All && contextFromPage?.scope && (+ <QuillActivityControls contextFromPage={contextFromPage} />+ )}+ </div>+ <div+ className="min-h-0 flex-1 overflow-y-auto scroll-mask-y-4 scroll-py-4 px-3 pb-3"+ onScroll={onScroll}+ >+ {shownTab === SidePanelActivityTab.Metalytics ? <QuillActivityMetalytics /> : <QuillActivityList />}+ </div>+ </div>+ </PayGateMini>+ )+}diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivitySubscribeMenu.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivitySubscribeMenu.tsxnew file mode 100644index 000000000000..d2132024ac08--- /dev/null+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivitySubscribeMenu.tsx@@ -0,0 +1,80 @@+import { combineUrl, router } from 'kea-router'++import { IconBell } from '@posthog/icons'+import {+ Button,+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuGroup,+ DropdownMenuItem,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@posthog/quill'++import { HOG_FUNCTION_SUB_TEMPLATES } from 'scenes/hog-functions/sub-templates/sub-templates'+import { urls } from 'scenes/urls'++import { CyclotronJobFilterPropertyFilter } from '~/types'++interface QuillActivitySubscribeMenuProps {+ properties: CyclotronJobFilterPropertyFilter[]+ onNavigate?: () => void+}++export function QuillActivitySubscribeMenu({ properties, onNavigate }: QuillActivitySubscribeMenuProps): JSX.Element {+ const go = (url: string): void => {+ onNavigate?.()+ router.actions.push(url)+ }++ return (+ <DropdownMenu>+ <Tooltip>+ <TooltipTrigger+ delay={0}+ render={+ <DropdownMenuTrigger render={<Button variant="outline" size="icon" aria-label="Subscribe" />} />+ }+ >+ <IconBell />+ </TooltipTrigger>+ <TooltipContent>Subscribe</TooltipContent>+ </Tooltip>+ <DropdownMenuContent align="end" className="w-60">+ <DropdownMenuGroup>+ {HOG_FUNCTION_SUB_TEMPLATES['activity-log'].map((subTemplate) => {+ const filters = {+ events: subTemplate.filters?.events || [+ { id: '$activity_log_entry_created', type: 'events' as const },+ ],+ properties,+ }+ const configuration = { ...subTemplate, filters }+ return (+ <DropdownMenuItem+ key={subTemplate.template_id + (subTemplate.name ?? '')}+ onClick={() =>+ go(+ combineUrl(urls.hogFunctionNew(subTemplate.template_id), {}, { configuration })+ .url+ )+ }+ >+ {subTemplate.name || 'Subscribe'}+ </DropdownMenuItem>+ )+ })}+ </DropdownMenuGroup>+ <DropdownMenuSeparator />+ <DropdownMenuItem+ onClick={() => go(urls.settings('environment-activity-logs', 'activity-log-notifications'))}+ >+ View all notifications+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ )+}diff --git a/frontend/src/layout/today/TodayContextPanelContent.tsx b/frontend/src/layout/today/TodayContextPanelContent.tsxindex 93e9265e265a..228806332270 100644--- a/frontend/src/layout/today/TodayContextPanelContent.tsx+++ b/frontend/src/layout/today/TodayContextPanelContent.tsx@@ -20,6 +20,11 @@ const QUILL_TAB_PANELS: Partial<Record<SidePanelTab, ComponentType>> = {[SidePanelTab.Support]: lazyWithRetry(() =>import('./TodaySupportPanel').then((m) => ({ default: m.TodaySupportPanel }))),+ [SidePanelTab.Activity]: lazyWithRetry(() =>+ import('~/layout/navigation-3000/sidepanel/panels/activity/quill/QuillActivityPanel').then((m) => ({+ default: m.QuillActivityPanel,+ }))+ ),[SidePanelTab.AccessControl]: lazyWithRetry(() =>import('~/layout/navigation-3000/sidepanel/panels/access_control/quill/QuillAccessControlPanel').then((m) => ({default: m.QuillAccessControlPanel,