: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(notifications): conditional mark-all-read + larger page size (#67732)
Yasenfae84fa8797c
diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.test.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.test.tsindex 29a3c3c21d63..941f29147c3d 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.test.ts+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.test.ts@@ -227,3 +227,36 @@ describe('sidePanelNotificationsLogic.mainListOffset', () => {expect(logic.values.mainListOffset).toBe(40)})})++describe('sidePanelNotificationsLogic.manuallyToggledIds', () => {+ let logic: ReturnType<typeof sidePanelNotificationsLogic.build>++ beforeEach(() => {+ useMocks({+ post: {+ '/api/projects/:tid/notifications/:id/mark_read/': () => [200, { status: 'ok' }],+ '/api/projects/:tid/notifications/:id/mark_unread/': () => [200, { status: 'ok' }],+ '/api/projects/:tid/notifications/mark_all_read/': () => [200, { updated: 0 }],+ },+ })+ initKeaTests()+ logic = sidePanelNotificationsLogic()+ logic.mount()+ })++ afterEach(() => logic.unmount())++ // Guards bug fix: without this set, auto-mark-on-view would re-read a notification the user+ // just manually toggled unread.+ it('records ids the user manually toggles so auto-mark can skip them', () => {+ logic.actions.toggleRead('a')+ logic.actions.toggleRead('b')+ expect(logic.values.manuallyToggledIds).toEqual(new Set(['a', 'b']))+ })++ it('clears the set when everything is marked read', () => {+ logic.actions.toggleRead('a')+ logic.actions.markAllAsRead()+ expect(logic.values.manuallyToggledIds.size).toBe(0)+ })+})diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsxindex 82fcaeafd6d5..2198173478ad 100644--- a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsx+++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic.tsx@@ -46,6 +46,9 @@ const SSE_RETRY_ATTEMPTS = 3const SSE_RETRY_INITIAL_DELAY_MS = 30000const SSE_RETRY_BACKOFF_MULTIPLIER = 4+// Notifications fetched per page for the in-app list (initial load + "Load more"). Backend max_limit is 100.+const NOTIFICATION_PAGE_SIZE = 30+// Maps each source type to a path builder from `source_id`, or `null` to fall through to the// backend-provided `source_url` (customer_analytics carries a precise account deep-link a// source_id→path mapping can't build). Kept as a full `Record` — not `Partial` — so adding a@@ -230,6 +233,20 @@ export const sidePanelNotificationsLogic = kea<sidePanelNotificationsLogicType>(markAllAsRead: () => 0,},],+ // Notifications the user explicitly toggled read/unread this session. They're exempt from+ // auto-mark-on-view, so a deliberate "keep this unread" isn't silently undone 3s later.+ // In-memory only, so a page reload clears it and auto-mark resumes for everything.+ manuallyToggledIds: [+ new Set<string>() as Set<string>,+ {+ toggleRead: (state, { id }) => {+ const next = new Set(state)+ next.add(id)+ return next+ },+ markAllAsRead: () => new Set<string>(),+ },+ ],loadedGroupKeys: [new Set<string>() as Set<string>,{@@ -616,7 +633,7 @@ export const sidePanelNotificationsLogic = kea<sidePanelNotificationsLogicType>(}try {const resp = await notificationsList((values.currentProjectId ?? '').toString(), {- limit: 20,+ limit: NOTIFICATION_PAGE_SIZE,offset: values.mainListOffset,})const results = resp.results as InAppNotification[]@@ -817,7 +834,9 @@ export const sidePanelNotificationsLogic = kea<sidePanelNotificationsLogicType>(if (values.realTimeNotificationsEnabled) {void (async () => {try {- const resp = await notificationsList((values.currentProjectId ?? '').toString(), { limit: 20 })+ const resp = await notificationsList((values.currentProjectId ?? '').toString(), {+ limit: NOTIFICATION_PAGE_SIZE,+ })actions.setInAppNotifications(resp.results as InAppNotification[], !!resp.next)} catch {// Swallowdiff --git a/frontend/src/lib/components/NotificationsMenu/NotificationGroupRow.tsx b/frontend/src/lib/components/NotificationsMenu/NotificationGroupRow.tsxindex 21acb9cc0594..7d20edfbec1b 100644--- a/frontend/src/lib/components/NotificationsMenu/NotificationGroupRow.tsx+++ b/frontend/src/lib/components/NotificationsMenu/NotificationGroupRow.tsx@@ -50,14 +50,18 @@ export function NotificationGroupRow({group: NotificationGrouponNavigate?: () => void}): JSX.Element {- const { expandedGroupKeys, loadingGroupKeys } = useValues(sidePanelNotificationsLogic)+ const { expandedGroupKeys, loadingGroupKeys, manuallyToggledIds } = useValues(sidePanelNotificationsLogic)const { toggleGroupExpanded, loadGroupChildren, toggleGroupRead } = useActions(sidePanelNotificationsLogic)const isExpanded = expandedGroupKeys.has(group.group_key)const isLoading = loadingGroupKeys.has(group.group_key)+ // Don't let a collapsed group's auto-mark undo a child the user deliberately toggled this session.+ const hasManualChild =+ manuallyToggledIds.has(group.representative.id) || group.children.some((c) => manuallyToggledIds.has(c.id))+// Dwelling on a collapsed, unread group marks the whole group read. When expanded,// the individual child rows mark themselves read instead, so disarm here.- const autoMarkRef = useAutoMarkRead(group.count > 1 && group.has_unread && !isExpanded, () =>+ const autoMarkRef = useAutoMarkRead(group.count > 1 && group.has_unread && !isExpanded && !hasManualChild, () =>toggleGroupRead(group))diff --git a/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx b/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsxindex 7d57e1a3b5f6..46696fccf1d6 100644--- a/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx+++ b/frontend/src/lib/components/NotificationsMenu/NotificationRow.tsx@@ -7,7 +7,7 @@ import { getNotificationDescriber } from 'lib/components/NotificationsMenu/notifimport { getNotificationIcon } from 'lib/components/NotificationsMenu/notificationToasts'import { useAutoMarkRead } from 'lib/components/NotificationsMenu/useAutoMarkRead'import { dayjs } from 'lib/dayjs'-import { IconRadioButtonUnchecked } from 'lib/lemon-ui/icons'+import { IconOpenInNew, IconRadioButtonUnchecked } from 'lib/lemon-ui/icons'import { sidePanelNotificationsLogic } from '~/layout/navigation-3000/sidepanel/panels/activity/sidePanelNotificationsLogic'import { InAppNotification } from '~/types'@@ -124,9 +124,13 @@ export function NotificationRow({onNavigate?: () => void}): JSX.Element {const { navigateToNotification, toggleRead, markAsRead } = useActions(sidePanelNotificationsLogic)- const { projectNameForNotification, sourcePathForNotification } = useValues(sidePanelNotificationsLogic)+ const { projectNameForNotification, sourcePathForNotification, manuallyToggledIds } =+ useValues(sidePanelNotificationsLogic)- const autoMarkRef = useAutoMarkRead(!notification.read, () => markAsRead(notification.id))+ // Don't auto-mark a notification the user deliberately toggled this session — respect their intent.+ const autoMarkRef = useAutoMarkRead(!notification.read && !manuallyToggledIds.has(notification.id), () =>+ markAsRead(notification.id)+ )const otherProjectName = projectNameForNotification(notification)const describer = getNotificationDescriber(notification)@@ -150,10 +154,19 @@ export function NotificationRow({toggleRead(notification.id)}+ const handleNavigate = (e: React.MouseEvent): void => {+ e.stopPropagation()+ handleOpen()+ }++ const resourceLabel = notification.resource_type+ ? `View ${notification.resource_type.replace(/_/g, ' ')}`+ : 'Go to source'+return (<divref={autoMarkRef}- className={`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 ${notification.read ? 'hover:bg-fill-highlight-100' : 'bg-fill-highlight-50 hover:bg-fill-highlight-100'}`}onClick={handleOpen}@@ -177,9 +190,20 @@ export function NotificationRow({</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>+ )}</div></div>- <NotificationReadToggle read={notification.read} onToggle={handleToggleRead} />+ <div className="absolute bottom-1.5 right-1.5 opacity-0 transition-opacity group-hover/row:opacity-100">+ <NotificationReadToggle read={notification.read} onToggle={handleToggleRead} />+ </div></div>)}diff --git a/frontend/src/lib/components/NotificationsMenu/NotificationsPanel.tsx b/frontend/src/lib/components/NotificationsMenu/NotificationsPanel.tsxindex 6e2008e9fcb0..e3d8d5204fd6 100644--- a/frontend/src/lib/components/NotificationsMenu/NotificationsPanel.tsx+++ b/frontend/src/lib/components/NotificationsMenu/NotificationsPanel.tsx@@ -1,6 +1,6 @@import { useActions, useValues } from 'kea'-import { IconCheckCircle, IconNotification } from '@posthog/icons'+import { IconNotification } from '@posthog/icons'import { LemonButton, LemonSkeleton } from '@posthog/lemon-ui'import { ScrollableShadows } from 'lib/components/ScrollableShadows/ScrollableShadows'@@ -18,8 +18,14 @@ import { notificationsMenuLogic } from './notificationsMenuLogic'export function NotificationsPanel(): JSX.Element {const { activeTab } = useValues(notificationsMenuLogic)const { setActiveTab } = useActions(notificationsMenuLogic)- const { groups, loadedUnreadCount, importantChangesLoading, hasMoreNotifications, isLoadingMore } =- useValues(sidePanelNotificationsLogic)+ const {+ groups,+ loadedUnreadCount,+ inAppUnreadCount,+ importantChangesLoading,+ hasMoreNotifications,+ isLoadingMore,+ } = useValues(sidePanelNotificationsLogic)const { markAllAsRead, loadMoreNotifications } = useActions(sidePanelNotificationsLogic)const { closePanel } = useActions(panelLayoutLogic)@@ -51,29 +57,24 @@ export function NotificationsPanel(): JSX.Element {)}</button></div>+ {/* Only surface "Mark all read" when unread items sit on not-yet-loaded pages — the ones+ already loaded get cleared by the 3s auto-mark-on-view as the user scrolls. */}+ {hasMoreNotifications && inAppUnreadCount > loadedUnreadCount && (+ <LemonButton+ size="xsmall"+ type="secondary"+ onClick={() => markAllAsRead()}+ className="ml-auto"+ data-attr="notifications-mark-all-read"+ >+ Mark all read+ </LemonButton>+ )}</div>)- // "Mark all as read" is a rare action, so tuck it into the panel's overflow (⋯) menu- // rather than pinning a button in the header. Only surfaced when there's something to clear.- const panelActions =- loadedUnreadCount > 0- ? [- {- 'data-attr': 'notifications-mark-all-read',- onClick: () => markAllAsRead(),- children: (- <>- <IconCheckCircle />- Mark all as read- </>- ),- },- ]- : undefined-return (- <PanelLayoutPanel searchField={header} panelActionsNewSceneLayout={panelActions}>+ <PanelLayoutPanel searchField={header}><ScrollableShadowsdirection="vertical"styledScrollbars