: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
fix(notifications): fix layout and achievement grouping (#76089)
Alex Liderfa90967825b6
diff --git a/frontend/src/lib/components/NotificationsMenu/NotificationActionButton.tsx b/frontend/src/lib/components/NotificationsMenu/NotificationActionButton.tsxindex 60979731ca15..ba2e48f729da 100644--- a/frontend/src/lib/components/NotificationsMenu/NotificationActionButton.tsx+++ b/frontend/src/lib/components/NotificationsMenu/NotificationActionButton.tsx@@ -5,8 +5,10 @@ import { Tooltip } from '@posthog/lemon-ui'import { IconRadioButtonUnchecked } from 'lib/lemon-ui/icons'+// Hover reveal keeps rows quiet on desktop, but a device that can't hover would never see these+// actions at all, so they stay visible there.export const ROW_ACTION_REVEAL_CLASSES =- 'opacity-0 group-hover/row:opacity-100 group-focus-within/row:opacity-100 transition-opacity'+ 'opacity-0 group-hover/row:opacity-100 group-focus-within/row:opacity-100 pointer-coarse:opacity-100 transition-opacity'export function ReadToggleIcon({ read }: { read: boolean }): JSX.Element {if (read) {@@ -35,9 +37,11 @@ export function NotificationActionButton({ariaLabel?: stringclassName?: string}): JSX.Element {+ // Destructive actions rest at the same muted weight as the read toggle and only take on the+ // danger tone once the pointer is on them — archive shouldn't be the loudest thing on a card.const toneClasses =tone === 'danger'- ? 'text-secondary hover:text-danger hover:bg-fill-error-highlight'+ ? 'text-muted hover:text-danger hover:bg-fill-error-highlight': 'text-secondary hover:text-primary hover:bg-fill-highlight-200'const button = (diff --git a/frontend/src/lib/components/NotificationsMenu/NotificationGroupRow.tsx b/frontend/src/lib/components/NotificationsMenu/NotificationGroupRow.tsxindex 969b7a78e8e6..ef5ae26b6566 100644--- a/frontend/src/lib/components/NotificationsMenu/NotificationGroupRow.tsx+++ b/frontend/src/lib/components/NotificationsMenu/NotificationGroupRow.tsx@@ -19,49 +19,6 @@ import {sidePanelNotificationsLogic,} from '~/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic'-function NotificationGroupControls({- count,- allRead,- expanded,- readOnly,- hasArchivable,- onToggleRead,- onToggleExpand,- onArchive,-}: {- count: number- allRead: boolean- expanded: boolean- readOnly: boolean- hasArchivable: boolean- onToggleRead: (e: React.MouseEvent) => void- onToggleExpand: (e: React.MouseEvent) => void- onArchive: (e: React.MouseEvent) => void-}): JSX.Element {- return (- <div className="shrink-0 flex items-center gap-1">- <span className="text-[10px] text-muted bg-fill-highlight-100 px-1.5 py-px rounded">{count}</span>- {!readOnly && hasArchivable && (- <NotificationActionButton- icon={<IconArchive className="size-4" />}- tooltip="Archive group"- onClick={onArchive}- tone="danger"- className={ROW_ACTION_REVEAL_CLASSES}- />- )}- {!readOnly && <NotificationReadToggle read={allRead} onToggle={onToggleRead} target="group" />}- <button- className="shrink-0 flex size-5 items-center justify-center rounded text-secondary hover:bg-fill-highlight-200 hover:text-primary"- onClick={onToggleExpand}- aria-label={expanded ? 'Collapse group' : 'Expand group'}- >- <IconChevronRight className={`size-4 transition-transform ${expanded ? 'rotate-90' : ''}`} />- </button>- </div>- )-}-export function NotificationGroupRow({group,onNavigate,@@ -120,7 +77,7 @@ export function NotificationGroupRow({<div className="flex flex-col"><divref={autoMarkRef}- className={`group/row flex items-start gap-2 p-2 rounded cursor-pointer transition-colors ${+ className={`group/row relative flex items-start gap-2 p-2 rounded cursor-pointer transition-colors ${allRead ? 'hover:bg-fill-highlight-100' : 'bg-fill-highlight-50 hover:bg-fill-highlight-100'}`}onClick={handleExpand}@@ -130,20 +87,42 @@ export function NotificationGroupRow({notificationType={group.representative.notification_type}title={group.representative.title}/>- <div className="text-xs text-secondary mt-2 line-clamp-1">- {group.count} notifications · latest {dayjs(group.last_seen).fromNow()}+ {/* The count already reads in this line, so the actions carry no badge. They sit in+ flow at the end rather than pinned absolutely — reserving their width with+ padding would truncate the summary while space was still free. */}+ <div className="flex items-center gap-1 mt-2">+ <div className="min-w-0 flex-1 text-xs text-secondary truncate">+ {group.count} notifications · latest {dayjs(group.last_seen).fromNow()}+ </div>+ <div className="shrink-0 flex items-center gap-1">+ {!readOnly && (+ // Revealed as one unit, like a single row's cluster — a group's actions+ // shouldn't sit louder in the list than the rows it contains+ <div className={`flex items-center gap-1 ${ROW_ACTION_REVEAL_CLASSES}`}>+ {archivingEnabled && (+ <NotificationActionButton+ icon={<IconArchive className="size-4" />}+ tooltip="Archive group"+ onClick={handleArchive}+ tone="danger"+ />+ )}+ <NotificationReadToggle read={allRead} onToggle={handleToggleRead} target="group" />+ </div>+ )}+ {/* Stays visible: it's the only hint the row expands */}+ <button+ className="shrink-0 flex size-5 items-center justify-center rounded text-secondary hover:bg-fill-highlight-200 hover:text-primary"+ onClick={handleExpand}+ aria-label={isExpanded ? 'Collapse group' : 'Expand group'}+ >+ <IconChevronRight+ className={`size-4 transition-transform ${isExpanded ? 'rotate-90' : ''}`}+ />+ </button>+ </div></div></div>- <NotificationGroupControls- count={group.count}- allRead={allRead}- expanded={isExpanded}- readOnly={readOnly}- hasArchivable={archivingEnabled}- onToggleRead={handleToggleRead}- onToggleExpand={handleExpand}- onArchive={handleArchive}- /></div>{isExpanded && (<div className="ml-3 pl-3 flex flex-col gap-1 border-l-2 border-fill-highlight-100 my-1">diff --git a/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx b/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsxindex 3d7deb08bf6a..179f027b980e 100644--- a/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx+++ b/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx@@ -182,7 +182,7 @@ export function NotificationRow({return (<divref={autoMarkRef}- className={`group/row relative flex items-start gap-2 p-2 rounded cursor-pointer transition-colors ${+ className={`group/row @container/row relative flex items-start gap-2 p-2 rounded cursor-pointer transition-colors ${notification.read ? 'hover:bg-fill-highlight-100' : 'bg-fill-highlight-50 hover:bg-fill-highlight-100'}`}onClick={handleOpen}@@ -197,37 +197,62 @@ export function NotificationRow({: notification.body && (<div className="text-xs text-secondary mt-2 text-pretty">{notification.body}</div>)}- <div className="flex items-center gap-1.5 mt-2">- <span className="text-[10px] text-muted">{dayjs(notification.created_at).fromNow()}</span>- {otherProjectName && (- <Tooltip title={`Notified on project ${otherProjectName}`}>- <span className="text-[10px] text-muted bg-fill-highlight-100 px-1 py-px rounded truncate max-w-[240px]">- {otherProjectName}- </span>- </Tooltip>- )}- {hasNavigationTarget && (- <button- onClick={handleNavigate}- className="inline-flex items-center gap-0.5 text-[10px] text-secondary opacity-0 transition-opacity hover:text-primary group-hover/row:opacity-100"- >- {resourceLabel}- <IconOpenInNew className="size-3" />- </button>+ {/* Meta and actions sit side by side, and only the meta half wraps: the tag drops to a+ second line rather than squeezing the timestamp into "a / month / ago", while the+ actions can never claim a line of their own. Keeping the actions in flow also means+ the wrap point tracks their real width, where a fixed padding either wrapped early+ or left them overlapping. */}+ {/* items-end keeps the actions on the last line when the meta wraps, rather than+ floating them to the vertical middle of a two-line block */}+ <div className="flex items-end gap-1.5 mt-2">+ <div className="min-w-0 flex-1 flex flex-wrap items-center gap-x-1.5 gap-y-1">+ <span className="shrink-0 text-[10px] text-muted">+ {dayjs(notification.created_at).fromNow()}+ </span>+ {/* One flex item so the tag and the link wrap to the second line together,+ rather than the tag staying up beside the timestamp and stranding the icon */}+ {(otherProjectName || hasNavigationTarget) && (+ <div className="min-w-0 flex items-center gap-x-1.5">+ {otherProjectName && (+ <Tooltip title={`Notified on project ${otherProjectName}`}>+ <span className="text-[10px] text-muted bg-fill-highlight-100 px-1 py-px rounded truncate">+ {otherProjectName}+ </span>+ </Tooltip>+ )}+ {/* A narrow panel can't fit the label next to the timestamp and project+ tag, so it drops to an icon-only button rather than crowding the+ actions. The label stays as the accessible name and tooltip. */}+ {hasNavigationTarget && (+ <Tooltip title={resourceLabel}>+ <button+ onClick={handleNavigate}+ aria-label={resourceLabel}+ className="shrink-0 inline-flex items-center gap-0.5 text-[10px] text-secondary transition-colors hover:text-primary"+ >+ <span className="hidden @[20rem]:inline">{resourceLabel}</span>+ <IconOpenInNew className="size-3" />+ </button>+ </Tooltip>+ )}+ </div>+ )}+ </div>+ {!readOnly && (+ <div className={`shrink-0 flex items-center gap-1 ${ROW_ACTION_REVEAL_CLASSES}`}>+ {archivingEnabled && (+ <NotificationActionButton+ icon={<IconArchive className="size-4" />}+ tooltip="Archive"+ onClick={handleArchive}+ tone="danger"+ />+ )}+ <NotificationReadToggle read={notification.read} onToggle={handleToggleRead} />+ </div>)}</div></div>- <div className={`absolute bottom-1.5 right-1.5 flex items-center gap-1 ${ROW_ACTION_REVEAL_CLASSES}`}>- {archivingEnabled && !readOnly && (- <NotificationActionButton- icon={<IconArchive className="size-4" />}- tooltip="Archive"- onClick={handleArchive}- tone="danger"- />- )}- {!readOnly && <NotificationReadToggle read={notification.read} onToggle={handleToggleRead} />}- </div></div>)}diff --git a/frontend/src/lib/components/NotificationsMenu/notificationDescribers.tsx b/frontend/src/lib/components/NotificationsMenu/notificationDescribers.tsxindex 8f17bbc5e388..d76928cf71c0 100644--- a/frontend/src/lib/components/NotificationsMenu/notificationDescribers.tsx+++ b/frontend/src/lib/components/NotificationsMenu/notificationDescribers.tsx@@ -13,7 +13,8 @@ export interface NotificationDescriber {}function WebAnalyticsDigestDescriber({ notification }: NotificationDescriberProps): JSX.Element | null {- if (!notification.metadata) {+ // metadata is a free-form JSON blob — one malformed row would otherwise crash the whole panel+ if (!notification.metadata?.metrics) {return null}diff --git a/products/notifications/backend/logic.py b/products/notifications/backend/logic.pyindex ac74170c75f6..d80a4d110564 100644--- a/products/notifications/backend/logic.py+++ b/products/notifications/backend/logic.py@@ -36,6 +36,9 @@ def _publish_to_kafka(event: NotificationEvent) -> None:"title": event.title,"body": event.body,"resource_type": event.resource_type or "",+ # The client groups rows by (type, target, resource) — a live-pushed notification+ # without resource_id would land in the wrong group until the next refetch.+ "resource_id": event.resource_id or "","source_url": event.source_url,"source_type": event.source_type,"source_id": event.source_id,diff --git a/products/web_analytics/backend/achievements/tasks.py b/products/web_analytics/backend/achievements/tasks.pyindex 3546a22b23b0..fe74b8c871e0 100644--- a/products/web_analytics/backend/achievements/tasks.py+++ b/products/web_analytics/backend/achievements/tasks.py@@ -252,6 +252,10 @@ def _send_unlock_notification(ctx: EvalContext, track: TrackDefinition, stage: ibody=f"You reached {stage_name} on the {track.display_name} track in Web analytics.",target_type=target_type,target_id=target_id,+ resource_type="web_analytics",+ # Keyed per track so unlocks on different tracks stay separate rows in the inbox+ # instead of collapsing into one grouped row (see `groupKey` on the client).+ resource_id=str(track.key),priority=Priority.NORMAL,source_url=f"/project/{ctx.team.id}/web",)diff --git a/products/web_analytics/backend/test/test_achievements_tasks.py b/products/web_analytics/backend/test/test_achievements_tasks.pyindex 1ea8c40441b7..047389483085 100644--- a/products/web_analytics/backend/test/test_achievements_tasks.py+++ b/products/web_analytics/backend/test/test_achievements_tasks.py@@ -93,6 +93,11 @@ class TestRecomputeTask(BaseTest):with self.captureOnCommitCallbacks(execute=True):self._run_user(make_evaluators(loyal_days=lambda ctx: 5))self.assertEqual(mock_notify.call_count, 1)+ data = mock_notify.call_args[0][0]+ # (resource_type, resource_id) is the client's grouping key — without it every achievement+ # unlocked on the same day collapses into one inbox group regardless of track+ self.assertEqual(data.resource_type, "web_analytics")+ self.assertEqual(data.resource_id, "loyalty")def test_unlock_notification_skipped_when_achievements_flag_disabled(self) -> None:with patch("posthoganalytics.feature_enabled", return_value=False):