: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): search, filter, sort and group the recent list (#109247)
Shy Alter3699c713485d
diff --git a/frontend/src/layout/today/TodayPaneSection.tsx b/frontend/src/layout/today/TodayPaneSection.tsxindex 91d2f9fdca0d..08d013edd291 100644--- a/frontend/src/layout/today/TodayPaneSection.tsx+++ b/frontend/src/layout/today/TodayPaneSection.tsx@@ -12,6 +12,8 @@ export interface TodayPaneSectionProps {count: numberonToggle: () => voidactions?: JSX.Element | null+ /** Replaces the label while set, for example with a search field. */+ heading?: JSX.Element | nulldivider?: booleandataAttr: stringheight: number@@ -28,6 +30,7 @@ export function TodayPaneSection({count,onToggle,actions,+ heading,divider = false,dataAttr,height,@@ -47,17 +50,19 @@ export function TodayPaneSection({)}>{resizer && <TodayPaneSectionResizeHandle label={label} active={resizing} resizer={resizer} />}- <MenuLabel- render={<button type="button" />}- aria-expanded={open}- data-attr={dataAttr}- onClick={onToggle}- className="flex min-w-0 flex-1 cursor-pointer items-center gap-1 rounded-sm text-left"- >- <span>{label}</span>- <Caret className="size-3" />- {!open && count > 0 && <span className="tabular-nums">{count}</span>}- </MenuLabel>+ {heading ?? (+ <MenuLabel+ render={<button type="button" />}+ aria-expanded={open}+ data-attr={dataAttr}+ onClick={onToggle}+ className="flex min-w-0 flex-1 cursor-pointer items-center gap-1 rounded-sm text-left"+ >+ <span>{label}</span>+ <Caret className="size-3" />+ {!open && count > 0 && <span className="tabular-nums">{count}</span>}+ </MenuLabel>+ )}{open && actions && <div className="flex shrink-0 items-center">{actions}</div>}</div><divdiff --git a/frontend/src/layout/today/TodayRecentFilterMenu.tsx b/frontend/src/layout/today/TodayRecentFilterMenu.tsxnew file mode 100644index 000000000000..3ecfc776f68b--- /dev/null+++ b/frontend/src/layout/today/TodayRecentFilterMenu.tsx@@ -0,0 +1,158 @@+import { useActions, useValues } from 'kea'++import { IconFilter } from '@posthog/icons'+import {+ Button,+ Dot,+ DropdownMenu,+ DropdownMenuCheckboxItem,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+ Tooltip,+ TooltipContent,+ TooltipTrigger,+ cn,+} from '@posthog/quill'++import { DEFAULT_RECENT_FILTERS, TodayRecentCreatedByFilter, recentSourceLabel } from './todayRecentFilters'+import { TodayRecentFilterSubmenu } from './TodayRecentFilterSubmenu'+import { DEFAULT_RECENT_GROUPING, DEFAULT_RECENT_SORT, TodayRecentGrouping, TodayRecentSort } from './todayRecentOrder'+import { TodayRecentRadioSubmenu } from './TodayRecentRadioSubmenu'+import { todaySpacesLogic } from './todaySpacesLogic'++const CREATED_BY_OPTIONS: { value: TodayRecentCreatedByFilter; label: string }[] = [+ { value: 'anyone', label: 'Anyone' },+ { value: 'me', label: 'Me' },+ { value: 'others', label: 'Other people' },+]++const GROUPING_OPTIONS: { value: TodayRecentGrouping; label: string }[] = [+ { value: 'date', label: 'Date' },+ { value: 'space', label: 'Space' },+ { value: 'repository', label: 'Repository' },+]++const SORT_OPTIONS: { value: TodayRecentSort; label: string }[] = [+ { value: 'recent', label: 'Recent activity' },+ { value: 'created', label: 'Date created' },+ { value: 'alpha', label: 'Name' },+]++function sourcesLabel(sources: string[]): string {+ if (!sources.length) {+ return 'Any source'+ }+ return sources.length > 2 ? `${sources.length} sources` : sources.map(recentSourceLabel).join(', ')+}++export function TodayRecentFilterMenu(): JSX.Element {+ const {+ recentFilters: filters,+ recentFiltersActive: active,+ recentSourceOptions,+ recentSort,+ recentGrouping,+ } = useValues(todaySpacesLogic)+ const { setRecentFilters, clearRecentFilters, setRecentSort, setRecentGrouping } = useActions(todaySpacesLogic)+ const label = active ? 'Filters on' : 'Filter'++ return (+ <DropdownMenu>+ <Tooltip>+ <TooltipTrigger+ delay={0}+ render={+ <DropdownMenuTrigger+ render={+ <Button+ size="icon-sm"+ aria-label={label}+ className={cn('relative', active && 'bg-fill-selected')}+ data-attr="today-recent-filter"+ />+ }+ />+ }+ >+ <IconFilter />+ {active && <Dot aria-hidden className="absolute top-0 right-0" />}+ </TooltipTrigger>+ <TooltipContent>{label}</TooltipContent>+ </Tooltip>+ <DropdownMenuContent align="end" className="min-w-56">+ <TodayRecentRadioSubmenu+ label="Group by"+ options={GROUPING_OPTIONS}+ value={recentGrouping}+ defaultValue={DEFAULT_RECENT_GROUPING}+ onChange={setRecentGrouping}+ dataAttr="today-recent-group-by"+ />+ <TodayRecentRadioSubmenu+ label="Sort by"+ options={SORT_OPTIONS}+ value={recentSort}+ defaultValue={DEFAULT_RECENT_SORT}+ onChange={setRecentSort}+ dataAttr="today-recent-sort-by"+ />+ <DropdownMenuSeparator />+ <TodayRecentRadioSubmenu+ label="Created by"+ options={CREATED_BY_OPTIONS}+ value={filters.createdBy}+ defaultValue={DEFAULT_RECENT_FILTERS.createdBy}+ onChange={(createdBy) => setRecentFilters({ ...filters, createdBy })}+ dataAttr="today-recent-filter-created-by"+ />+ <TodayRecentFilterSubmenu+ label="Source"+ value={sourcesLabel(filters.sources)}+ narrowed={filters.sources.length > 0}+ >+ <DropdownMenuCheckboxItem+ checked={!filters.sources.length}+ closeOnClick={false}+ onCheckedChange={() => setRecentFilters({ ...filters, sources: [] })}+ data-attr="today-recent-filter-source-any"+ >+ Any source+ </DropdownMenuCheckboxItem>+ <DropdownMenuSeparator />+ {recentSourceOptions.map((source) => (+ <DropdownMenuCheckboxItem+ key={source}+ checked={filters.sources.includes(source)}+ closeOnClick={false}+ onCheckedChange={(checked) =>+ setRecentFilters({+ ...filters,+ sources: checked+ ? [...filters.sources, source]+ : filters.sources.filter((selected) => selected !== source),+ })+ }+ data-attr="today-recent-filter-source"+ >+ {recentSourceLabel(source)}+ </DropdownMenuCheckboxItem>+ ))}+ </TodayRecentFilterSubmenu>+ {active && (+ <>+ <DropdownMenuSeparator />+ <DropdownMenuItem+ variant="destructive"+ onClick={clearRecentFilters}+ data-attr="today-recent-filter-clear"+ >+ Clear filters+ </DropdownMenuItem>+ </>+ )}+ </DropdownMenuContent>+ </DropdownMenu>+ )+}diff --git a/frontend/src/layout/today/TodayRecentFilterSubmenu.tsx b/frontend/src/layout/today/TodayRecentFilterSubmenu.tsxnew file mode 100644index 000000000000..7bbc68fba498--- /dev/null+++ b/frontend/src/layout/today/TodayRecentFilterSubmenu.tsx@@ -0,0 +1,36 @@+import { ReactNode } from 'react'++import { DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, cn } from '@posthog/quill'++interface TodayRecentFilterSubmenuProps {+ label: string+ /** The choice in force, shown beside the label. */+ value: string+ /** The choice differs from the default, so the value stands out. */+ narrowed?: boolean+ children: ReactNode+}++export function TodayRecentFilterSubmenu({+ label,+ value,+ narrowed = false,+ children,+}: TodayRecentFilterSubmenuProps): JSX.Element {+ return (+ <DropdownMenuSub>+ <DropdownMenuSubTrigger>+ <span>{label}</span>+ <span+ className={cn(+ 'flex-1 truncate pl-4 text-right',+ narrowed ? 'text-foreground' : 'text-muted-foreground'+ )}+ >+ {value}+ </span>+ </DropdownMenuSubTrigger>+ <DropdownMenuSubContent>{children}</DropdownMenuSubContent>+ </DropdownMenuSub>+ )+}diff --git a/frontend/src/layout/today/TodayRecentRadioSubmenu.tsx b/frontend/src/layout/today/TodayRecentRadioSubmenu.tsxnew file mode 100644index 000000000000..9b21b80f38c7--- /dev/null+++ b/frontend/src/layout/today/TodayRecentRadioSubmenu.tsx@@ -0,0 +1,37 @@+import { DropdownMenuRadioGroup, DropdownMenuRadioItem } from '@posthog/quill'++import { TodayRecentFilterSubmenu } from './TodayRecentFilterSubmenu'++interface TodayRecentRadioSubmenuProps<T extends string> {+ label: string+ options: { value: T; label: string }[]+ value: T+ defaultValue: T+ onChange: (value: T) => void+ dataAttr: string+}++export function TodayRecentRadioSubmenu<T extends string>({+ label,+ options,+ value,+ defaultValue,+ onChange,+ dataAttr,+}: TodayRecentRadioSubmenuProps<T>): JSX.Element {+ return (+ <TodayRecentFilterSubmenu+ label={label}+ value={options.find((option) => option.value === value)?.label ?? ''}+ narrowed={value !== defaultValue}+ >+ <DropdownMenuRadioGroup value={value} onValueChange={(next) => onChange(next as T)}>+ {options.map((option) => (+ <DropdownMenuRadioItem key={option.value} value={option.value} data-attr={dataAttr}>+ {option.label}+ </DropdownMenuRadioItem>+ ))}+ </DropdownMenuRadioGroup>+ </TodayRecentFilterSubmenu>+ )+}diff --git a/frontend/src/layout/today/TodayRecentSearchField.tsx b/frontend/src/layout/today/TodayRecentSearchField.tsxnew file mode 100644index 000000000000..98593d585dfb--- /dev/null+++ b/frontend/src/layout/today/TodayRecentSearchField.tsx@@ -0,0 +1,70 @@+import { useActions, useValues } from 'kea'+import { ChangeEvent, KeyboardEvent, MouseEvent } from 'react'++import { IconX } from '@posthog/icons'+import {+ InputGroup,+ InputGroupAddon,+ InputGroupButton,+ InputGroupInput,+ InputGroupText,+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@posthog/quill'++import { todaySpacesLogic } from './todaySpacesLogic'++export function TodayRecentSearchField(): JSX.Element {+ const { recentQuery, recentItems } = useValues(todaySpacesLogic)+ const { setRecentQuery, setRecentSearchOpen } = useActions(todaySpacesLogic)+ const hasQuery = recentQuery !== ''+ const label = hasQuery ? 'Clear search' : 'Close search'+ const clearOrClose = (): void => (hasQuery ? setRecentQuery('') : setRecentSearchOpen(false))++ return (+ <InputGroup className="min-w-0 flex-1">+ <InputGroupInput+ autoFocus+ value={recentQuery}+ placeholder="Search recent…"+ aria-label="Search recent"+ data-attr="today-recent-search"+ onChange={(event: ChangeEvent<HTMLInputElement>) => setRecentQuery(event.target.value)}+ onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => {+ if (event.key === 'Escape') {+ event.preventDefault()+ event.stopPropagation()+ clearOrClose()+ }+ }}+ onBlur={() => !hasQuery && setRecentSearchOpen(false)}+ />+ <InputGroupAddon align="inline-end">+ {hasQuery && (+ <InputGroupText className="tabular-nums">+ {recentItems.length === 0 ? 'No results' : recentItems.length}+ </InputGroupText>+ )}+ <Tooltip>+ <TooltipTrigger+ delay={0}+ render={+ <InputGroupButton+ size="icon-xs"+ aria-label={label}+ // Keeps focus in the field, so blur doesn't close it before the click lands.+ onMouseDown={(event: MouseEvent) => event.preventDefault()}+ onClick={clearOrClose}+ data-attr="today-recent-search-clear"+ />+ }+ >+ <IconX />+ </TooltipTrigger>+ <TooltipContent>{label}</TooltipContent>+ </Tooltip>+ </InputGroupAddon>+ </InputGroup>+ )+}diff --git a/frontend/src/layout/today/TodaySpacesSidebar.tsx b/frontend/src/layout/today/TodaySpacesSidebar.tsxindex 31fd657ee1b8..43db4bccc4e2 100644--- a/frontend/src/layout/today/TodaySpacesSidebar.tsx+++ b/frontend/src/layout/today/TodaySpacesSidebar.tsx@@ -2,13 +2,15 @@ import { useActions, useValues } from 'kea'import { router } from 'kea-router'import { Fragment } from 'react'-import { IconChat, IconList, IconLock, IconPlus } from '@posthog/icons'+import { IconChat, IconList, IconLock, IconPlus, IconSearch } from '@posthog/icons'import { Button, Skeleton, Text, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, cn } from '@posthog/quill'import { LinkPrimitive } from 'lib/lemon-ui/Link'import { urls } from 'scenes/urls'import { TodayPaneSection, TodayPaneSectionProps } from './TodayPaneSection'+import { TodayRecentFilterMenu } from './TodayRecentFilterMenu'+import { TodayRecentSearchField } from './TodayRecentSearchField'import { TodaySessionRow } from './TodaySessionRow'import { TodayWorkSectionId, spaceLabel, todaySpacesLogic } from './todaySpacesLogic'import { TodaySpacesRow } from './TodaySpacesRow'@@ -21,13 +23,16 @@ export function TodaySpacesSidebar(): JSX.Element {spacesLoading,spacesUnavailable,pinnedItems,+ allRecentItems,recentItems,recentGroups,+ recentSearchVisible,recentLoading,recentTasksUnavailable,collapsedSections,} = useValues(todaySpacesLogic)- const { loadSpaces, loadRecentTasks, toggleSection } = useActions(todaySpacesLogic)+ const { loadSpaces, loadRecentTasks, toggleSection, setRecentSearchOpen, clearRecentSearchAndFilters } =+ useActions(todaySpacesLogic)const { location, searchParams } = useValues(router)const pinnedIds = new Set(pinnedItems.map((item) => item.id))const browsingSpaces = location.pathname.endsWith(urls.taskSpaces())@@ -82,16 +87,18 @@ export function TodaySpacesSidebar(): JSX.Element {<Skeleton className="h-4 w-2/3" /></div>)- const loadError = (message: string, onRetry: () => void, dataAttr: string): JSX.Element => (+ const notice = (message: string, action: string, onClick: () => void, dataAttr: string): JSX.Element => (<div className="flex flex-col items-start gap-2 px-2 py-1"><Text size="xs" variant="muted">{message}</Text>- <Button variant="outline" size="sm" onClick={onRetry} data-attr={dataAttr}>- Try again+ <Button variant="outline" size="sm" onClick={onClick} data-attr={dataAttr}>+ {action}</Button></div>)+ const loadError = (message: string, onRetry: () => void, dataAttr: string): JSX.Element =>+ notice(message, 'Try again', onRetry, dataAttr)return (<TooltipProvider>@@ -128,28 +135,61 @@ export function TodaySpacesSidebar(): JSX.Element {onToggle={() => toggleSection('recent')}divider={hasPinned}dataAttr="today-section-recent"+ heading={recentSearchVisible ? <TodayRecentSearchField /> : null}+ actions={+ <>+ {!recentSearchVisible && (+ <Tooltip>+ <TooltipTrigger+ delay={0}+ render={+ <Button+ size="icon-sm"+ aria-label="Search recent"+ onClick={() => setRecentSearchOpen(true)}+ data-attr="today-recent-search-open"+ />+ }+ >+ <IconSearch />+ </TooltipTrigger>+ <TooltipContent>Search recent</TooltipContent>+ </Tooltip>+ )}+ <TodayRecentFilterMenu />+ </>+ }>- {recentLoading && !recentItems.length ? (+ {recentLoading && !allRecentItems.length ? (loadingRows- ) : recentTasksUnavailable && !recentItems.length ? (+ ) : recentTasksUnavailable && !allRecentItems.length ? (loadError('Recent sessions didn’t load.', loadRecentTasks, 'today-recent-retry')- ) : !recentItems.length ? (+ ) : !allRecentItems.length ? (<Text size="xs" variant="muted" className="px-2 py-1">Sessions and chats you open show up here.</Text>+ ) : !recentItems.length ? (+ notice(+ 'Nothing here matches.',+ 'Clear filters',+ clearRecentSearchAndFilters,+ 'today-recent-clear-filters'+ )) : (<>{recentTasksUnavailable &&loadError('Some sessions didn’t load.', loadRecentTasks, 'today-recent-retry')}{recentGroups.map((group, index) => (<Fragment key={group.key}>- <Text- size="xs"- variant="muted"- className={cn('block px-2 pb-1', index === 0 ? 'pt-1' : 'pt-3')}- >- {group.label}- </Text>+ {group.label && (+ <Text+ size="xs"+ variant="muted"+ className={cn('block px-2 pb-1', index === 0 ? 'pt-1' : 'pt-3')}+ >+ {group.label}+ </Text>+ )}{group.items.map((item) =>renderItem(item,diff --git a/frontend/src/layout/today/todayRecentFilters.ts b/frontend/src/layout/today/todayRecentFilters.tsnew file mode 100644index 000000000000..b84a2f0d2deb--- /dev/null+++ b/frontend/src/layout/today/todayRecentFilters.ts@@ -0,0 +1,73 @@+import { TodayWorkItem } from './todayWorkItems'++export type TodayRecentCreatedByFilter = 'anyone' | 'me' | 'others'++export interface TodayRecentFilters {+ createdBy: TodayRecentCreatedByFilter+ /** Sources to keep. An empty list keeps every source. */+ sources: string[]+}++export const DEFAULT_RECENT_FILTERS: TodayRecentFilters = { createdBy: 'anyone', sources: [] }++const SOURCE_LABELS: Record<string, string> = {+ user_created: 'Manual',+ posthog_ai: 'PostHog AI',+ slack: 'Slack',+ signal_report: 'Signals',+ signals_scout: 'Signals scout',+ support_queue: 'Support',+ session_summaries: 'Session summary',+ error_tracking: 'Error tracking',+ eval_clusters: 'Evals',+ task_analysis: 'Task analysis',+ hogdesk: 'HogDesk',+ mcp_analytics: 'MCP analytics',+ review_hog: 'ReviewHog',+}++export function recentSourceLabel(source: string): string {+ const words = source.replaceAll('_', ' ')+ return SOURCE_LABELS[source] ?? words.charAt(0).toUpperCase() + words.slice(1)+}++/** The search box is left out: it shows its own query, while a filter in a closed menu shows nothing. */+export function hasActiveRecentFilters(filters: TodayRecentFilters): boolean {+ return filters.createdBy !== DEFAULT_RECENT_FILTERS.createdBy || filters.sources.length > 0+}++/** The sources in the list plus any still selected, so a selection can always be undone. */+export function recentSourceOptions(items: TodayWorkItem[], selected: string[]): string[] {+ const sources = new Set(selected)+ for (const item of items) {+ if (item.source) {+ sources.add(item.source)+ }+ }+ return [...sources].sort()+}++export function filterRecentItems(+ items: TodayWorkItem[],+ query: string,+ filters: TodayRecentFilters,+ userId: number | null+): TodayWorkItem[] {+ const needle = query.trim().toLowerCase()+ return items.filter((item) => {+ if (needle && !(item.title || '').toLowerCase().includes(needle)) {+ return false+ }+ if (filters.createdBy !== 'anyone') {+ // A deleted creator is neither you nor a known other person.+ if (item.createdById === null) {+ return false+ }+ const mine = item.createdById === userId+ if (filters.createdBy === 'me' ? !mine : mine) {+ return false+ }+ }+ return !filters.sources.length || (item.source !== null && filters.sources.includes(item.source))+ })+}diff --git a/frontend/src/layout/today/todayRecentOrder.ts b/frontend/src/layout/today/todayRecentOrder.tsnew file mode 100644index 000000000000..a81391f83c39--- /dev/null+++ b/frontend/src/layout/today/todayRecentOrder.ts@@ -0,0 +1,86 @@+import { Dayjs, dayjs } from 'lib/dayjs'++import { TodayWorkItem, groupByDay } from './todayWorkItems'++export type TodayRecentSort = 'recent' | 'created' | 'alpha'+export type TodayRecentGrouping = 'date' | 'space' | 'repository'++export const DEFAULT_RECENT_SORT: TodayRecentSort = 'recent'+export const DEFAULT_RECENT_GROUPING: TodayRecentGrouping = 'date'++export interface TodayRecentSection {+ key: string+ /** Null for a run with nothing to call it, like an alphabetical list. */+ label: string | null+ items: TodayWorkItem[]+}++function timeOf(timestamp: string | null): number {+ return timestamp ? dayjs(timestamp).valueOf() : 0+}++export function sortRecentItems(items: TodayWorkItem[], sort: TodayRecentSort): TodayWorkItem[] {+ return [...items].sort((first, second) =>+ sort === 'alpha'+ ? first.title.localeCompare(second.title)+ : sort === 'created'+ ? timeOf(second.createdAt) - timeOf(first.createdAt)+ : timeOf(second.timestamp) - timeOf(first.timestamp)+ )+}++/** One section per key, in first-seen order, with the fallback section last. */+function keyedSections(+ items: TodayWorkItem[],+ resolve: (item: TodayWorkItem) => { key: string; label: string } | null,+ fallback: { key: string; label: string }+): TodayRecentSection[] {+ const sections = new Map<string, TodayRecentSection>()+ for (const item of items) {+ const { key, label } = resolve(item) ?? fallback+ const section = sections.get(key)+ if (section) {+ section.items.push(item)+ } else {+ sections.set(key, { key, label, items: [item] })+ }+ }+ const all = [...sections.values()]+ const known = all.filter((section) => section.key !== fallback.key)+ return [...known, ...all.filter((section) => section.key === fallback.key)]+}++/** Cuts a sorted list into sections. Days follow the time the list is sorted by, so each day is one run. */+export function groupRecentItems(+ items: TodayWorkItem[],+ sort: TodayRecentSort,+ grouping: TodayRecentGrouping,+ spaceNames: Record<string, string>,+ now: Dayjs = dayjs()+): TodayRecentSection[] {+ if (!items.length) {+ return []+ }+ if (grouping === 'space') {+ return keyedSections(+ items,+ (item) =>+ item.channel && spaceNames[item.channel]+ ? { key: `space:${item.channel}`, label: spaceNames[item.channel] }+ : null,+ { key: 'space:none', label: 'No space' }+ )+ }+ if (grouping === 'repository') {+ return keyedSections(+ items,+ (item) =>+ item.repository ? { key: `repo:${item.repository.toLowerCase()}`, label: item.repository } : null,+ { key: 'repo:none', label: 'No repository' }+ )+ }+ if (sort === 'alpha') {+ return [{ key: 'all', label: null, items }]+ }+ return groupByDay(items, now, sort === 'created' ? 'createdAt' : 'timestamp')+}diff --git a/frontend/src/layout/today/todaySessionIcon.test.ts b/frontend/src/layout/today/todaySessionIcon.test.tsindex 65b14e8cb766..1b0980ff5084 100644--- a/frontend/src/layout/today/todaySessionIcon.test.ts+++ b/frontend/src/layout/today/todaySessionIcon.test.ts@@ -6,11 +6,14 @@ const item = (kind: TodayWorkItem['kind'], status: string | null): TodayWorkItemid: 'id',title: 'Title',timestamp: null,+ createdAt: null,status,channel: null,createdById: null,latestRunId: null,originProduct: null,+ source: null,+ repository: null,})describe('todaySessionIcon', () => {diff --git a/frontend/src/layout/today/todaySpacesLogic.ts b/frontend/src/layout/today/todaySpacesLogic.tsindex 2866464acd72..8a8ab4b7de01 100644--- a/frontend/src/layout/today/todaySpacesLogic.ts+++ b/frontend/src/layout/today/todaySpacesLogic.ts@@ -10,7 +10,23 @@ import { ConversationDetail, UserType } from '~/types'import { taskChannelsList, tasksList } from 'products/tasks/frontend/generated/api'import { ChannelDTOApi, TaskListItemApi } from 'products/tasks/frontend/generated/api.schemas'-import { TodayWorkGroup, TodayWorkItem, buildRecentItems, groupByDay, sessionItem } from './todayWorkItems'+import {+ DEFAULT_RECENT_FILTERS,+ TodayRecentFilters,+ filterRecentItems,+ hasActiveRecentFilters,+ recentSourceOptions,+} from './todayRecentFilters'+import {+ DEFAULT_RECENT_GROUPING,+ DEFAULT_RECENT_SORT,+ TodayRecentGrouping,+ TodayRecentSection,+ TodayRecentSort,+ groupRecentItems,+ sortRecentItems,+} from './todayRecentOrder'+import { TodayWorkItem, buildRecentItems, sessionItem } from './todayWorkItems'const PINNED_SESSION_LIMIT = 20const RECENT_SESSION_LIMIT = 30@@ -44,18 +60,28 @@ export interface todaySpacesLogicValues {conversationHistoryLoading: boolean // maxGlobalLogiccurrentTeamId: number | null // teamLogicuser: UserType | null // userLogic+ allRecentItems: TodayWorkItem[]collapsedSections: TodayWorkSectionId[]pinnedItems: TodayWorkItem[]pinnedTasks: TaskListItemApi[]pinnedTasksLoading: boolean- recentGroups: TodayWorkGroup[]+ recentFilters: TodayRecentFilters+ recentFiltersActive: boolean+ recentGrouping: TodayRecentGrouping+ recentGroups: TodayRecentSection[]recentItems: TodayWorkItem[]recentLoading: boolean+ recentQuery: string+ recentSearchOpen: boolean+ recentSearchVisible: boolean+ recentSort: TodayRecentSort+ recentSourceOptions: string[]recentTasks: TaskListItemApi[]recentTasksLoading: booleanrecentTasksUnavailable: booleansectionHeights: Partial<Record<TodayWorkSectionId, number>>sortedSpaces: ChannelDTOApi[]+ spaceNames: Record<string, string>spaces: ChannelDTOApi[]spacesLoading: booleanspacesUnavailable: boolean@@ -64,6 +90,12 @@ export interface todaySpacesLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface todaySpacesLogicActions {+ clearRecentFilters: () => {+ value: true+ }+ clearRecentSearchAndFilters: () => {+ value: true+ }loadPinnedTasks: () => anyloadPinnedTasksFailure: (error: string,@@ -116,6 +148,21 @@ export interface todaySpacesLogicActions {lower: TodayWorkSectionIdupper: TodayWorkSectionId}+ setRecentFilters: (filters: TodayRecentFilters) => {+ filters: TodayRecentFilters+ }+ setRecentGrouping: (grouping: TodayRecentGrouping) => {+ grouping: TodayRecentGrouping+ }+ setRecentQuery: (query: string) => {+ query: string+ }+ setRecentSearchOpen: (open: boolean) => {+ open: boolean+ }+ setRecentSort: (sort: TodayRecentSort) => {+ sort: TodayRecentSort+ }setSectionHeights: (heights: Partial<Record<TodayWorkSectionId, number>>) => {heights: Partial<Record<TodayWorkSectionId, number>>}@@ -130,12 +177,28 @@ export interface todaySpacesLogicMeta {sortedSpaces: (spaces: ChannelDTOApi[]) => ChannelDTOApi[]visibleSpaces: (sortedSpaces: ChannelDTOApi[]) => ChannelDTOApi[]pinnedItems: (pinnedTasks: TaskListItemApi[]) => TodayWorkItem[]- recentItems: (+ allRecentItems: (recentTasks: TaskListItemApi[],conversationHistory: ConversationDetail[],pinnedTasks: TaskListItemApi[]) => TodayWorkItem[]- recentGroups: (recentItems: TodayWorkItem[]) => TodayWorkGroup[]+ recentSourceOptions: (allRecentItems: TodayWorkItem[], recentFilters: TodayRecentFilters) => string[]+ recentSearchVisible: (recentSearchOpen: boolean, recentQuery: string) => boolean+ recentFiltersActive: (recentFilters: TodayRecentFilters) => boolean+ recentItems: (+ allRecentItems: TodayWorkItem[],+ recentQuery: string,+ recentFilters: TodayRecentFilters,+ recentSort: TodayRecentSort,+ user: UserType | null+ ) => TodayWorkItem[]+ spaceNames: (spaces: ChannelDTOApi[]) => Record<string, string>+ recentGroups: (+ recentItems: TodayWorkItem[],+ recentSort: TodayRecentSort,+ recentGrouping: TodayRecentGrouping,+ spaceNames: Record<string, string>+ ) => TodayRecentSection[]recentLoading: (recentTasksLoading: boolean, conversationHistoryLoading: boolean) => boolean}}@@ -163,6 +226,13 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([toggleSection: (sectionId: TodayWorkSectionId) => ({ sectionId }),setSectionHeights: (heights: Partial<Record<TodayWorkSectionId, number>>) => ({ heights }),resetSectionPair: (upper: TodayWorkSectionId, lower: TodayWorkSectionId) => ({ upper, lower }),+ setRecentQuery: (query: string) => ({ query }),+ setRecentSearchOpen: (open: boolean) => ({ open }),+ setRecentFilters: (filters: TodayRecentFilters) => ({ filters }),+ clearRecentFilters: true,+ clearRecentSearchAndFilters: true,+ setRecentSort: (sort: TodayRecentSort) => ({ sort }),+ setRecentGrouping: (grouping: TodayRecentGrouping) => ({ grouping }),}),loaders(({ values }) => ({spaces: [@@ -232,6 +302,30 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([},},],+ recentQuery: ['', { setRecentQuery: (_, { query }) => query, clearRecentSearchAndFilters: () => '' }],+ recentSearchOpen: [+ false,+ { setRecentSearchOpen: (_, { open }) => open, clearRecentSearchAndFilters: () => false },+ ],+ recentFilters: [+ DEFAULT_RECENT_FILTERS,+ { persist: true },+ {+ setRecentFilters: (_, { filters }) => filters,+ clearRecentFilters: () => DEFAULT_RECENT_FILTERS,+ clearRecentSearchAndFilters: () => DEFAULT_RECENT_FILTERS,+ },+ ],+ recentSort: [+ DEFAULT_RECENT_SORT as TodayRecentSort,+ { persist: true },+ { setRecentSort: (_, { sort }) => sort },+ ],+ recentGrouping: [+ DEFAULT_RECENT_GROUPING as TodayRecentGrouping,+ { persist: true },+ { setRecentGrouping: (_, { grouping }) => grouping },+ ],spacesUnavailable: [false, { loadSpaces: () => false, loadSpacesFailure: () => true }],recentTasksUnavailable: [false, { loadRecentTasks: () => false, loadRecentTasksFailure: () => true }],}),@@ -246,7 +340,7 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([(pinnedTasks: TaskListItemApi[]): TodayWorkItem[] =>pinnedTasks.filter((task) => !task.archived).map(sessionItem),],- recentItems: [+ allRecentItems: [(s) => [s.recentTasks, s.conversationHistory, s.pinnedTasks],(recentTasks: TaskListItemApi[],@@ -260,9 +354,46 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([RECENT_ITEM_LIMIT),],+ recentSourceOptions: [+ (s) => [s.allRecentItems, s.recentFilters],+ (allRecentItems: TodayWorkItem[], recentFilters: TodayRecentFilters): string[] =>+ recentSourceOptions(allRecentItems, recentFilters.sources),+ ],+ recentSearchVisible: [+ (s) => [s.recentSearchOpen, s.recentQuery],+ (recentSearchOpen: boolean, recentQuery: string): boolean => recentSearchOpen || recentQuery !== '',+ ],+ recentFiltersActive: [+ (s) => [s.recentFilters],+ (recentFilters: TodayRecentFilters): boolean => hasActiveRecentFilters(recentFilters),+ ],+ recentItems: [+ (s) => [s.allRecentItems, s.recentQuery, s.recentFilters, s.recentSort, s.user],+ (+ allRecentItems: TodayWorkItem[],+ recentQuery: string,+ recentFilters: TodayRecentFilters,+ recentSort: TodayRecentSort,+ user: UserType | null+ ): TodayWorkItem[] =>+ sortRecentItems(+ filterRecentItems(allRecentItems, recentQuery, recentFilters, user?.id ?? null),+ recentSort+ ),+ ],+ spaceNames: [+ (s) => [s.spaces],+ (spaces: ChannelDTOApi[]): Record<string, string> =>+ Object.fromEntries(spaces.map((space) => [space.id, spaceLabel(space)])),+ ],recentGroups: [- (s) => [s.recentItems],- (recentItems: TodayWorkItem[]): TodayWorkGroup[] => groupByDay(recentItems),+ (s) => [s.recentItems, s.recentSort, s.recentGrouping, s.spaceNames],+ (+ recentItems: TodayWorkItem[],+ recentSort: TodayRecentSort,+ recentGrouping: TodayRecentGrouping,+ spaceNames: Record<string, string>+ ): TodayRecentSection[] => groupRecentItems(recentItems, recentSort, recentGrouping, spaceNames),],recentLoading: [(s) => [s.recentTasksLoading, s.conversationHistoryLoading],diff --git a/frontend/src/layout/today/todayWorkItems.test.ts b/frontend/src/layout/today/todayWorkItems.test.tsindex 2ddae9855471..859c90462914 100644--- a/frontend/src/layout/today/todayWorkItems.test.ts+++ b/frontend/src/layout/today/todayWorkItems.test.ts@@ -4,7 +4,22 @@ import { ConversationDetail } from '~/types'import { TaskListItemApi } from 'products/tasks/frontend/generated/api.schemas'-import { analysisRunId, buildRecentItems, canHandOff, groupByDay, sessionItem, shortTimeAgo } from './todayWorkItems'+import {+ DEFAULT_RECENT_FILTERS,+ TodayRecentFilters,+ filterRecentItems,+ recentSourceOptions,+} from './todayRecentFilters'+import { TodayRecentGrouping, TodayRecentSort, groupRecentItems, sortRecentItems } from './todayRecentOrder'+import {+ analysisRunId,+ buildRecentItems,+ canHandOff,+ chatItem,+ groupByDay,+ sessionItem,+ shortTimeAgo,+} from './todayWorkItems'const session = (id: string, lastActivityAt: string, archived = false): TaskListItemApi =>({ id, title: `Session ${id}`, last_activity_at: lastActivityAt, archived }) as TaskListItemApi@@ -12,6 +27,50 @@ const session = (id: string, lastActivityAt: string, archived = false): TaskListconst chat = (id: string, updatedAt: string): ConversationDetail =>({ id, title: `Chat ${id}`, updated_at: updatedAt, created_at: updatedAt }) as ConversationDetail+const ME = 7++const mixedItems = [+ sessionItem({+ id: 'mine',+ title: 'Fix Login',+ origin_product: 'user_created',+ created_by: { id: ME },+ } as TaskListItemApi),+ sessionItem({+ id: 'theirs',+ title: 'Triage',+ origin_product: 'error_tracking',+ created_by: { id: 8 },+ } as TaskListItemApi),+ sessionItem({ id: 'orphan', title: 'Old login', origin_product: 'slack', created_by: null } as TaskListItemApi),+ chatItem({ id: 'chat', title: 'Login funnel', user: { id: ME } } as ConversationDetail),+]++const orderedItems = [+ sessionItem({+ id: 'b',+ title: 'Beta',+ created_at: '2026-03-01T09:00:00',+ last_activity_at: '2026-03-10T09:00:00',+ channel: 'space-1',+ repository: 'PostHog/posthog',+ } as TaskListItemApi),+ sessionItem({+ id: 'a',+ title: 'Alpha',+ created_at: '2026-03-09T09:00:00',+ last_activity_at: '2026-03-09T10:00:00',+ channel: 'deleted-space',+ repository: 'posthog/posthog',+ } as TaskListItemApi),+ chatItem({+ id: 'c',+ title: 'Chat',+ created_at: '2026-03-05T09:00:00',+ updated_at: '2026-03-08T09:00:00',+ } as ConversationDetail),+]+describe('todayWorkItems', () => {it('merges sessions and chats by latest activity, without pinned or archived sessions', () => {const items = buildRecentItems(@@ -51,6 +110,49 @@ describe('todayWorkItems', () => {expect(shortTimeAgo(timestamp, dayjs('2026-03-10T12:00:00'))).toEqual(age)})+ it.each<[string, string, Partial<TodayRecentFilters>, string[]]>([+ ['search ignores case', 'LOGIN', {}, ['mine', 'orphan', 'chat']],+ ['created by me keeps your chats', '', { createdBy: 'me' }, ['mine', 'chat']],+ ['created by others skips a deleted creator', '', { createdBy: 'others' }, ['theirs']],+ ['source matches chats as PostHog AI', '', { sources: ['posthog_ai', 'slack'] }, ['orphan', 'chat']],+ ['search and filters combine', 'login', { createdBy: 'me', sources: ['user_created'] }, ['mine']],+ ])('filters recent items: %s', (_name, query, filters, ids) => {+ const items = filterRecentItems(mixedItems, query, { ...DEFAULT_RECENT_FILTERS, ...filters }, ME)++ expect(items.map((item) => item.id)).toEqual(ids)+ })++ it('offers a selected source that is no longer in the list, so it can be cleared', () => {+ expect(recentSourceOptions(mixedItems, ['review_hog'])).toEqual([+ 'error_tracking',+ 'posthog_ai',+ 'review_hog',+ 'slack',+ 'user_created',+ ])+ })++ it.each<[TodayRecentSort, TodayRecentGrouping, string[]]>([+ ['recent', 'date', ['Today: b', 'Yesterday: a', 'Sunday: c']],+ ['created', 'date', ['Yesterday: a', 'Thursday: c', 'Mar 1: b']],+ ['alpha', 'date', ['null: a b c']],+ ['recent', 'space', ['Space one: b', 'No space: a c']],+ ['recent', 'repository', ['PostHog/posthog: b a', 'No repository: c']],+ ])('sorts by %s and groups by %s', (sort, grouping, sections) => {+ const now = dayjs('2026-03-10T12:00:00')+ const groups = groupRecentItems(+ sortRecentItems(orderedItems, sort),+ sort,+ grouping,+ { 'space-1': 'Space one' },+ now+ )++ expect(groups.map((group) => `${group.label}: ${group.items.map((item) => item.id).join(' ')}`)).toEqual(+ sections+ )+ })+it.each([[7, true],[8, false],diff --git a/frontend/src/layout/today/todayWorkItems.ts b/frontend/src/layout/today/todayWorkItems.tsindex 01c9b0215da5..da47ec57ee12 100644--- a/frontend/src/layout/today/todayWorkItems.ts+++ b/frontend/src/layout/today/todayWorkItems.ts@@ -11,11 +11,15 @@ export interface TodayWorkItem {id: stringtitle: stringtimestamp: string | null+ createdAt: string | nullstatus: string | nullchannel: string | nullcreatedById: number | nulllatestRunId: string | nulloriginProduct: string | null+ /** What filed it: a session's origin product, or PostHog AI for a chat. */+ source: string | null+ repository: string | null}export interface TodayWorkGroup {@@ -42,11 +46,14 @@ export function sessionItem(task: TaskListItemApi): TodayWorkItem {id: task.id,title: task.title,timestamp: task.last_activity_at ?? task.updated_at ?? task.created_at ?? null,+ createdAt: task.created_at ?? null,status: task.latest_run?.status ?? null,channel: task.channel ?? null,createdById: task.created_by?.id ?? null,latestRunId: task.latest_run?.id ?? null,originProduct: task.origin_product ?? null,+ source: task.origin_product || null,+ repository: task.repository || null,}}@@ -56,11 +63,14 @@ export function chatItem(conversation: ConversationDetail): TodayWorkItem {id: conversation.id,title: conversation.title ?? '',timestamp: conversation.updated_at ?? conversation.created_at,+ createdAt: conversation.created_at,status: null,channel: null,- createdById: null,+ createdById: conversation.user?.id ?? null,latestRunId: null,originProduct: null,+ source: 'posthog_ai',+ repository: null,}}@@ -79,10 +89,15 @@ export function buildRecentItems(.slice(0, limit)}-export function groupByDay(items: TodayWorkItem[], now: Dayjs = dayjs()): TodayWorkGroup[] {+export function groupByDay(+ items: TodayWorkItem[],+ now: Dayjs = dayjs(),+ timeField: 'timestamp' | 'createdAt' = 'timestamp'+): TodayWorkGroup[] {const groups: TodayWorkGroup[] = []for (const item of items) {- const time = item.timestamp ? earlierOf(dayjs(item.timestamp), now) : null+ const timestamp = item[timeField]+ const time = timestamp ? earlierOf(dayjs(timestamp), now) : nullconst key = time ? time.format('YYYY-MM-DD') : 'undated'const last = groups[groups.length - 1]if (last?.key === key) {