: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): rename the spaces pane to chats (#112561)
Shy Alter53b7fb496a1b
diff --git a/frontend/src/layout/today/TodayNewChatButton.tsx b/frontend/src/layout/today/TodayNewChatButton.tsxnew file mode 100644index 000000000000..9cbdcf11775b--- /dev/null+++ b/frontend/src/layout/today/TodayNewChatButton.tsx@@ -0,0 +1,37 @@+import { useValues } from 'kea'+import { router } from 'kea-router'++import { IconPlus } from '@posthog/icons'+import { Button, Tooltip, TooltipContent, TooltipTrigger, cn } from '@posthog/quill'++import { LinkPrimitive } from 'lib/lemon-ui/Link'+import { urls } from 'scenes/urls'++import { todayShellLogic } from './todayShellLogic'++export function TodayNewChatButton(): JSX.Element {+ const { location } = useValues(router)+ const { phoneLayout } = useValues(todayShellLogic)+ const starting = location.pathname.endsWith(urls.taskNewSession())++ return (+ <Tooltip>+ <TooltipTrigger+ delay={0}+ render={+ <Button+ size={phoneLayout ? 'icon-lg' : 'icon'}+ render={<LinkPrimitive to={urls.taskNewSession()} />}+ aria-current={starting ? 'page' : undefined}+ className={cn('-me-2 text-muted-foreground', starting && 'bg-fill-selected text-foreground')}+ aria-label="New chat"+ data-attr="today-new-chat-header"+ />+ }+ >+ <IconPlus />+ </TooltipTrigger>+ <TooltipContent>New chat</TooltipContent>+ </Tooltip>+ )+}diff --git a/frontend/src/layout/today/TodayShell.tsx b/frontend/src/layout/today/TodayShell.tsxindex d6635bb98001..bb766cad432b 100644--- a/frontend/src/layout/today/TodayShell.tsx+++ b/frontend/src/layout/today/TodayShell.tsx@@ -16,6 +16,7 @@ import { TodayHomeSidebar } from 'scenes/project-homepage/today/TodayHomeSidebarimport { QuillSceneHeader } from '~/layout/scenes/components/QuillSceneHeader'+import { TodayNewChatButton } from './TodayNewChatButton'import { TodayPhoneHeader } from './TodayPhoneHeader'import { TodayPreviewCardProvider } from './TodayPreviewCardProvider'import { TodayRail } from './TodayRail'@@ -37,7 +38,7 @@ const NewSpaceDialog = lazyWithRetry(() =>const PANE_LABELS = {home: 'Today',- spaces: 'Spaces',+ spaces: 'Chats',views: 'Views',products: 'Products',}@@ -118,6 +119,7 @@ export function TodayShell({ className }: { className?: string }): JSX.Element {{PANE_LABELS[activePane]}</h2>}+ actions={activePane === 'spaces' ? <TodayNewChatButton /> : undefined}/>{paneContent}</div>@@ -144,9 +146,10 @@ export function TodayShell({ className }: { className?: string }): JSX.Element {{...(sidebarVisible ? {} : { inert: '' })}><div className="flex min-h-14 shrink-0 items-end gap-1 px-4 pt-3">- <Heading render={<h1 />} size="2xl" className="m-0 truncate leading-10">+ <Heading render={<h1 />} size="2xl" className="m-0 flex-1 truncate leading-10">{PANE_LABELS[activePane]}</Heading>+ {activePane === 'spaces' && <TodayNewChatButton />}</div><div className="TodayShell__pane">{paneContent}</div><TodaySidebarFooter />diff --git a/frontend/src/layout/today/TodaySpacesSectionTabs.tsx b/frontend/src/layout/today/TodaySpacesSectionTabs.tsxindex 82ec52a52dce..106e89c6564a 100644--- a/frontend/src/layout/today/TodaySpacesSectionTabs.tsx+++ b/frontend/src/layout/today/TodaySpacesSectionTabs.tsx@@ -7,7 +7,6 @@ import { TodayWorkSectionId } from './todaySpacesLogic'const SECTIONS: { id: TodayWorkSectionId; label: string }[] = [{ id: 'pinned', label: 'Pinned' },{ id: 'recent', label: 'Recent' },- { id: 'spaces', label: 'Spaces' },]interface TodaySpacesSectionTabsProps {diff --git a/frontend/src/layout/today/TodaySpacesSidebar.tsx b/frontend/src/layout/today/TodaySpacesSidebar.tsxindex 82be9623ca86..5c03fcdd3209 100644--- a/frontend/src/layout/today/TodaySpacesSidebar.tsx+++ b/frontend/src/layout/today/TodaySpacesSidebar.tsx@@ -1,22 +1,13 @@import { useActions, useValues } from 'kea'-import { router } from 'kea-router'import { Fragment } from 'react'-import { IconPlus, IconTableOfContents } 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 { newSpaceLogic } from 'products/tasks/frontend/spaces/newSpaceLogic'-import { SpacePresenceAvatars } from 'products/tasks/frontend/spaces/SpacePresenceAvatars'+import { Button, Skeleton, Text, TooltipProvider, cn } from '@posthog/quill'import { TodayChatRow } from './TodayChatRow'import { TodayListAppearanceDialog } from './TodayListAppearanceDialog'import { TodayPaneGroupLabel } from './TodayPaneGroupLabel'import { TodayPaneSearchList } from './TodayPaneSearchList'import { TodayPaneSection, TodayPaneSectionProps } from './TodayPaneSection'-import { TodayPreviewTrigger } from './TodayPreviewTrigger'import { TodayRecentFilterMenu } from './TodayRecentFilterMenu'import { TodaySessionBulkBar } from './TodaySessionBulkBar'import { TodaySessionRow } from './TodaySessionRow'@@ -24,10 +15,7 @@ import { selectionClick } from './todaySessionSelection'import { todaySessionSelectionLogic } from './todaySessionSelectionLogic'import { todayShellLogic } from './todayShellLogic'import { todayRecentClearLabel, todaySidebarSectionState } from './todaySidebarSectionState'-import { TodaySpaceContextMenu } from './TodaySpaceContextMenu'-import { TodaySpaceGlyph } from './TodaySpaceGlyph'-import { TodayWorkSectionId, isLockedSpace, spaceLabel, todaySpacesLogic } from './todaySpacesLogic'-import { TodaySpacesRow } from './TodaySpacesRow'+import { TodayWorkSectionId, todaySpacesLogic } from './todaySpacesLogic'import { TodaySpacesSectionTabs } from './TodaySpacesSectionTabs'import { TodayWorkItem } from './todayWorkItems'import { useTodaySectionLayout } from './useTodaySectionLayout'@@ -36,12 +24,8 @@ const SKELETON_ROW_WIDTHS = ['w-3/5', 'w-4/5', 'w-2/5'] as constexport function TodaySpacesSidebar(): JSX.Element {const {- visibleSpaces,- spacesLoading,- spacesUnavailable,pinnedItems,shownPinnedItems,- shownSpaces,allRecentItems,recentItems,recentGroups,@@ -51,21 +35,16 @@ export function TodaySpacesSidebar(): JSX.Element {recentTasksUnavailable,collapsedSections,unreadSessionIds,- unreadSpaceIds,- spacePresence,- spacePreviews,phoneSection,pinnedTasksLoading,} = useValues(todaySpacesLogic)- const { loadSpaces, loadRecentTasks, toggleSection, setRecentQuery, clearRecentSearchAndFilters, setPhoneSection } =+ const { loadRecentTasks, toggleSection, setRecentQuery, clearRecentSearchAndFilters, setPhoneSection } =useActions(todaySpacesLogic)const { phoneLayout } = useValues(todayShellLogic)- const { openNewSpace } = useActions(newSpaceLogic)const { selectedSessionIds } = useValues(todaySessionSelectionLogic)const { toggleSessionSelection, selectSessionRange, clearSelection } = useActions(todaySessionSelectionLogic)- const { location } = useValues(router)const pinnedIds = new Set(pinnedItems.map((item) => item.id))- const browsingSpaces = location.pathname.endsWith(urls.taskSpaces())+ const shownSection: TodayWorkSectionId = phoneSection === 'pinned' ? 'pinned' : 'recent'const selectedIds = new Set(selectedSessionIds)// Like Desktop, Cmd/Ctrl-click and Shift-click pick rows instead of opening them, and a plain click clears the pick.@@ -119,7 +98,6 @@ export function TodaySpacesSidebar(): JSX.Element {const layoutSections: { id: TodayWorkSectionId; open: boolean }[] = [...(hasPinned ? [{ id: 'pinned' as const, open: !collapsedSections.includes('pinned') }] : []),{ id: 'recent', open: !collapsedSections.includes('recent') },- { id: 'spaces', open: !collapsedSections.includes('spaces') },]const layout = useTodaySectionLayout(layoutSections)const sectionLayout = (@@ -144,12 +122,6 @@ export function TodaySpacesSidebar(): JSX.Element {total: allRecentItems.length,shown: recentItems.length,})- const spacesState = todaySidebarSectionState({- loading: spacesLoading,- failed: spacesUnavailable,- total: visibleSpaces.length,- shown: visibleSpaces.length,- })const loadingRows = (label: string): JSX.Element => (<div role="status" aria-label={label} className="flex flex-col gap-px">@@ -177,60 +149,16 @@ export function TodaySpacesSidebar(): JSX.Element {</Button>)- const actionSize = phoneLayout ? 'icon-lg' : 'icon-xs'- const spacesActions = (- <>- <Tooltip>- <TooltipTrigger- delay={0}- render={- <Button- size={actionSize}- className="text-muted-foreground"- aria-label="New space"- onClick={openNewSpace}- data-attr="today-new-space-open-sidebar"- />- }- >- <IconPlus />- </TooltipTrigger>- <TooltipContent>New space</TooltipContent>- </Tooltip>- <Tooltip>- <TooltipTrigger- delay={0}- render={- <Button- size={actionSize}- render={<LinkPrimitive to={urls.taskSpaces()} />}- aria-current={browsingSpaces ? 'page' : undefined}- className={cn(- 'text-muted-foreground',- browsingSpaces && 'bg-fill-selected text-foreground'- )}- aria-label="Browse spaces"- data-attr="today-spaces-browse"- />- }- >- <IconTableOfContents />- </TooltipTrigger>- <TooltipContent>Browse spaces</TooltipContent>- </Tooltip>- </>- )-const pinnedRows = shownPinnedItems.map((item) => renderItem(item, 'pinned', 'today-pinned-session', true))const recentBody =recentState === 'loading' ? (loadingRows('Loading recent')) : recentState === 'error' ? (- loadError('Recent sessions didn’t load.', loadRecentTasks, 'today-recent-retry')+ loadError('Recent chats didn’t load.', loadRecentTasks, 'today-recent-retry')) : recentState === 'empty' ? (<Text size="xs" variant="muted" className="px-2 py-1">- Sessions and chats you open show up here. Start one with New chat.+ Chats you start show up here. Start one with New chat.</Text>) : recentState === 'no-matches' ? (notice(@@ -246,8 +174,7 @@ export function TodaySpacesSidebar(): JSX.Element {)) : (<>- {recentTasksUnavailable &&- loadError('Some sessions didn’t load.', loadRecentTasks, 'today-recent-retry')}+ {recentTasksUnavailable && loadError('Some chats didn’t load.', loadRecentTasks, 'today-recent-retry')}{recentGroups.map((group, index) => (<Fragment key={group.key}>{group.label && <TodayPaneGroupLabel first={index === 0}>{group.label}</TodayPaneGroupLabel>}@@ -263,83 +190,17 @@ export function TodaySpacesSidebar(): JSX.Element {</>)- const spacesBody =- spacesState === 'loading' ? (- loadingRows('Loading spaces')- ) : spacesState === 'error' ? (- loadError('Spaces didn’t load.', loadSpaces, 'today-spaces-retry')- ) : spacesState === 'empty' ? (- notice(- 'Spaces you star show up here.',- <>- <Button variant="outline" size="sm" onClick={openNewSpace} data-attr="today-spaces-empty-new-space">- <IconPlus />- New space…- </Button>- <Button- variant="outline"- size="sm"- render={<LinkPrimitive to={urls.taskSpaces()} />}- data-attr="today-spaces-add"- >- Browse spaces- </Button>- </>- )- ) : (- <>- {spacesUnavailable && loadError('Spaces didn’t refresh.', loadSpaces, 'today-spaces-retry')}- {shownSpaces.map((space) => {- const presence = spacePresence[space.id]- return (- <TodaySpaceContextMenu key={space.id} space={space}>- <TodayPreviewTrigger payload={spacePreviews[space.id]}>- <TodaySpacesRow- label={spaceLabel(space)}- icon={- <TodaySpaceGlyph- locked={isLockedSpace(space)}- className="text-muted-foreground"- />- }- to={urls.taskSpace(space.id)}- active={location.pathname.includes(urls.taskSpace(space.id))}- dataAttr="today-space-row"- optionValue={`space:${space.id}`}- badge={presence ? <SpacePresenceAvatars presence={presence} /> : null}- badgeCount={Math.min(presence?.people.length ?? 1, 3) as 1 | 2 | 3}- unread={unreadSpaceIds.has(space.id)}- />- </TodayPreviewTrigger>- </TodaySpaceContextMenu>- )- })}- {visibleSpaces.length === 1 && (- <Button- variant="outline"- size="sm"- className="mt-1 self-start"- data-attr="today-spaces-add"- render={<LinkPrimitive to={urls.taskSpaces()} />}- >- <IconPlus />- Add the spaces you work in- </Button>- )}- </>- )-if (phoneLayout) {const pinnedBody =pinnedTasksLoading && pinnedItems.length === 0 ? (loadingRows('Loading pinned')) : pinnedItems.length === 0 ? (<Text size="sm" variant="muted" className="px-2 py-2">- Pinned sessions show up here. To pin a session, press and hold it, then pick Pin.+ Pinned chats show up here. To pin a chat, press and hold it, then pick Pin.</Text>) : shownPinnedItems.length === 0 ? (<Text size="sm" variant="muted" className="px-2 py-2">- No pinned sessions match your search.+ No pinned chats match your search.</Text>) : (pinnedRows@@ -350,28 +211,18 @@ export function TodaySpacesSidebar(): JSX.Element {<TodayPaneSearchListquery={recentQuery}onQueryChange={setRecentQuery}- searchLabel="Search sessions and spaces"+ searchLabel="Search chats"dataAttr="today-recent-search"listClassName="mt-1 flex flex-col pb-4"><TodaySpacesSectionTabs- value={phoneSection}+ value={shownSection}onChange={setPhoneSection}- counts={{ pinned: pinnedItems.length, spaces: visibleSpaces.length }}- actions={- phoneSection === 'recent' ? (- <TodayRecentFilterMenu />- ) : phoneSection === 'spaces' ? (- spacesActions- ) : null- }+ counts={{ pinned: pinnedItems.length }}+ actions={shownSection === 'recent' ? <TodayRecentFilterMenu /> : null}/>- <div className="flex flex-col gap-px" data-attr={`today-spaces-tab-panel-${phoneSection}`}>- {phoneSection === 'pinned'- ? pinnedBody- : phoneSection === 'recent'- ? recentBody- : spacesBody}+ <div className="flex flex-col gap-px" data-attr={`today-spaces-tab-panel-${shownSection}`}>+ {shownSection === 'pinned' ? pinnedBody : recentBody}</div></TodayPaneSearchList><TodaySessionBulkBar />@@ -387,7 +238,7 @@ export function TodaySpacesSidebar(): JSX.Element {<TodayPaneSearchListquery={recentQuery}onQueryChange={setRecentQuery}- searchLabel="Search sessions and spaces"+ searchLabel="Search chats"dataAttr="today-recent-search"searchActions={<TodayRecentFilterMenu />}listClassName="flex flex-col overflow-hidden pb-0"@@ -414,17 +265,6 @@ export function TodaySpacesSidebar(): JSX.Element {>{recentBody}</TodayPaneSection>- <TodayPaneSection- label="Spaces"- {...sectionLayout('spaces')}- count={visibleSpaces.length}- onToggle={() => toggleSection('spaces')}- divider- dataAttr="today-section-spaces"- actions={spacesActions}- >- {spacesBody}- </TodayPaneSection></div></TodayPaneSearchList><TodaySessionBulkBar />diff --git a/frontend/src/layout/today/todayRailItems.tsx b/frontend/src/layout/today/todayRailItems.tsxindex 591c1d57d3b1..e0c489ab7f07 100644--- a/frontend/src/layout/today/todayRailItems.tsx+++ b/frontend/src/layout/today/todayRailItems.tsx@@ -10,7 +10,7 @@ export interface TodayRailItem {export const TODAY_RAIL_ITEMS: TodayRailItem[] = [{ pane: 'home', label: 'Home', icon: <IconHome /> },- { pane: 'spaces', label: 'Spaces', icon: <IconChat /> },+ { pane: 'spaces', label: 'Chats', icon: <IconChat /> },{ pane: 'views', label: 'Views', icon: <IconGridMasonry /> },{ pane: 'products', label: 'Products', icon: <IconApps /> },]diff --git a/frontend/src/layout/today/todaySectionLayout.test.ts b/frontend/src/layout/today/todaySectionLayout.test.tsindex 194f4e10af8c..b2a814175c57 100644--- a/frontend/src/layout/today/todaySectionLayout.test.ts+++ b/frontend/src/layout/today/todaySectionLayout.test.ts@@ -15,61 +15,61 @@ const section = (id: TodaySectionInput['id'], contentHeight: number, open = truedescribe('todaySectionLayout', () => {test.each<[string, TodaySectionInput[], number, PreferredTodaySectionHeights, TodaySectionHeights]>([[- 'recent absorbs the height the short sections leave',- [section('pinned', 100), section('recent', 50), section('spaces', 80)],+ 'recent absorbs the height a short pinned section leaves',+ [section('pinned', 100), section('recent', 50)],600,{},- { pinned: 100, recent: 420, spaces: 80 },+ { pinned: 100, recent: 500 },],[- 'long sections stop at the share cap',- [section('recent', 1000), section('spaces', 1000)],+ 'a long pinned section stops at the share cap',+ [section('pinned', 1000), section('recent', 1000)],500,{},- { pinned: 0, recent: 300, spaces: 200 },+ { pinned: 200, recent: 300 },],['a dragged height wins over the share cap',- [section('recent', 1000), section('spaces', 1000)],+ [section('pinned', 1000), section('recent', 1000)],500,- { spaces: 120 },- { pinned: 0, recent: 380, spaces: 120 },+ { pinned: 120 },+ { pinned: 120, recent: 380 },],[- 'a collapsed section gets no height and spaces fill in its place',- [section('pinned', 100), section('recent', 1000, false), section('spaces', 1000)],+ 'a collapsed recent gets no height and pinned fills in its place',+ [section('pinned', 1000), section('recent', 1000, false)],600,{},- { pinned: 100, recent: 0, spaces: 500 },+ { pinned: 600, recent: 0 },],[- 'short sections do not grow past their content when recent is collapsed',- [section('pinned', 50), section('recent', 1000, false), section('spaces', 80)],+ 'pinned does not grow past its content when recent is collapsed',+ [section('pinned', 50), section('recent', 1000, false)],600,{},- { pinned: 50, recent: 0, spaces: 80 },+ { pinned: 50, recent: 0 },],[- 'other sections shrink so recent keeps its minimum height',+ 'pinned shrinks so recent keeps its minimum height',[section('pinned', 500), section('recent', 500)],100,{ pinned: 90 },- { pinned: 44, recent: 56, spaces: 0 },+ { pinned: 44, recent: 56 },],])('%s', (_, sections, available, preferred, expected) => {expect(layoutTodaySections(sections, available, preferred)).toEqual(expected)})- test('a drag clamps the lower section at its minimum and never stores the filling section', () => {+ test('a drag clamps the upper section at its minimum and never stores the filling section', () => {expect(resizeTodaySections({- sections: [section('recent', 1000), section('spaces', 1000)],- heights: { pinned: 0, recent: 300, spaces: 200 },- upper: 'recent',- lower: 'spaces',- delta: 500,+ sections: [section('pinned', 1000), section('recent', 1000)],+ heights: { pinned: 200, recent: 300 },+ upper: 'pinned',+ lower: 'recent',+ delta: -500,preferred: {},})- ).toEqual({ spaces: 40 })+ ).toEqual({ pinned: 40 })})})diff --git a/frontend/src/layout/today/todaySectionLayout.ts b/frontend/src/layout/today/todaySectionLayout.tsindex 1579c43c924b..e5703053c223 100644--- a/frontend/src/layout/today/todaySectionLayout.ts+++ b/frontend/src/layout/today/todaySectionLayout.ts@@ -10,7 +10,7 @@ export interface TodaySectionInput {contentHeight: number}-const FILL_ORDER: readonly TodayWorkSectionId[] = ['recent', 'spaces', 'pinned']+const FILL_ORDER: readonly TodayWorkSectionId[] = ['recent', 'pinned']export const TODAY_SECTION_HEADER_HEIGHT = 28const SHARE_CAP = 0.4@@ -27,7 +27,7 @@ export function layoutTodaySections(available: number,preferred: PreferredTodaySectionHeights = {}): TodaySectionHeights {- const heights: TodaySectionHeights = { pinned: 0, recent: 0, spaces: 0 }+ const heights: TodaySectionHeights = { pinned: 0, recent: 0 }const fill = fillingSection(sections)if (fill === null || available <= 0) {return heightsdiff --git a/frontend/src/layout/today/todayShellLogic.test.ts b/frontend/src/layout/today/todayShellLogic.test.tsindex 46a23519077e..323e874d1dc4 100644--- a/frontend/src/layout/today/todayShellLogic.test.ts+++ b/frontend/src/layout/today/todayShellLogic.test.ts@@ -79,7 +79,7 @@ describe('todayShellLogic', () => {test.each([['home', '/home'],- ['spaces', '/ai'],+ ['spaces', '/spaces/new'],['views', '/views'],['products', '/tools'],] as const)('opens the %s section when its rail item is picked', (pane, pathname) => {diff --git a/frontend/src/layout/today/todayShellLogic.ts b/frontend/src/layout/today/todayShellLogic.tsindex 990391c1fe59..e03655a8bd2b 100644--- a/frontend/src/layout/today/todayShellLogic.ts+++ b/frontend/src/layout/today/todayShellLogic.ts@@ -37,7 +37,7 @@ function isUnder(path: string, root: string): boolean {const RAIL_PANE_HOME: Record<TodayRailPane, () => string> = {home: () => urls.projectHomepage(),- spaces: () => urls.ai(),+ spaces: () => urls.taskNewSession(),views: () => urls.views(),products: () => urls.tools(),}diff --git a/frontend/src/layout/today/todaySpacesLogic.ts b/frontend/src/layout/today/todaySpacesLogic.tsindex 4732f1a683a3..ecbd2029136e 100644--- a/frontend/src/layout/today/todaySpacesLogic.ts+++ b/frontend/src/layout/today/todaySpacesLogic.ts@@ -30,16 +30,9 @@ import {TaskActivityReadMarkerApi,TaskListItemApi,} from 'products/tasks/frontend/generated/api.schemas'-import {- SpaceActivity,- SpacePresence,- lastActivityBySpace,- presenceBySpace,-} from 'products/tasks/frontend/spaces/spacePresence'import { pullRequestStates, sessionIdsWithPullRequests } from 'products/tasks/frontend/spaces/taskPullRequests'import { matchesPaneQuery } from './todayPaneSearch'-import { TodaySpacePreview, spacePreview } from './todayPreviewCards'import {DEFAULT_RECENT_FILTERS,TodayRecentFilters,@@ -63,9 +56,7 @@ import {sessionItem,sessionReadRequest,setActivityUnread,- unreadSessionCountsBySpace,unreadSessionIds,- unreadSpaceIds,} from './todayWorkItems'const PINNED_SESSION_LIMIT = 20@@ -75,16 +66,12 @@ const RECENT_ITEM_LIMIT = 30const UNREAD_ACTIVITY_LIMIT = 200// The sidebar and a space scene both refresh on mount, so collapse their requests into one.const UNREAD_ACTIVITY_DEBOUNCE_MS = 100-// Like PostHog Desktop: one page of the team's newest activity across all spaces, polled slowly.-// A space whose latest activity sits below this page shows no faces.-const SPACE_PRESENCE_FETCH_LIMIT = 100-const SPACE_PRESENCE_POLL_INTERVAL_MS = 90_000// Other clients start sessions this tab never hears about, so Recent reloads on a timer and on each return to// the tab, and the cooldown holds a flick between tabs to one request.const RECENT_REFRESH_INTERVAL_MS = 60_000const RECENT_REFRESH_COOLDOWN_MS = 15_000-export type TodayWorkSectionId = 'pinned' | 'recent' | 'spaces'+export type TodayWorkSectionId = 'pinned' | 'recent'export type TodayTouchMenu = 'session' | 'space' | 'bulk' | 'filter' | 'chat'@@ -166,23 +153,15 @@ export interface todaySpacesLogicValues {recentTasksUnavailable: booleansectionHeights: Partial<Record<TodayWorkSectionId, number>>shownPinnedItems: TodayWorkItem[]- shownSpaces: ChannelDTOApi[]sortedSpaces: ChannelDTOApi[]- spaceActivity: SpaceActivity- spaceActivityLoading: booleanspaceNames: Record<string, string>- spacePresence: Record<string, SpacePresence>- spacePreviews: Record<string, TodaySpacePreview>spaces: ChannelDTOApi[]spacesLoading: booleanspacesUnavailable: booleanstoredRecentFilters: Partial<TodayRecentFilters>taskActivity: TaskActivityDTOApi[]taskActivityLoading: boolean- unreadSessionCounts: Record<string, number>unreadSessionIds: Set<string>- unreadSpaceIds: Set<string>- visibleSpaces: ChannelDTOApi[]}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -250,27 +229,6 @@ export interface todaySpacesLogicActions {recentTasks: TaskListItemApi[]payload?: void}- loadSpaceActivity: () => any- loadSpaceActivityFailure: (- error: string,- errorObject?: any- ) => {- error: string- errorObject?: any- }- loadSpaceActivitySuccess: (- spaceActivity: {- lastActivityAt: Record<string, string>- presence: Record<string, SpacePresence>- },- payload?: any- ) => {- spaceActivity: {- lastActivityAt: Record<string, string>- presence: Record<string, SpacePresence>- }- payload?: any- }loadSpaces: () => anyloadSpacesFailure: (error: string,@@ -364,7 +322,6 @@ export interface todaySpacesLogicActions {export interface todaySpacesLogicMeta {__keaTypeGenInternalSelectorTypes: {sortedSpaces: (spaces: ChannelDTOApi[]) => ChannelDTOApi[]- visibleSpaces: (sortedSpaces: ChannelDTOApi[]) => ChannelDTOApi[]pinnedItems: (pinnedTasks: TaskListItemApi[]) => TodayWorkItem[]allRecentItems: (recentTasks: TaskListItemApi[],@@ -374,7 +331,6 @@ export interface todaySpacesLogicMeta {recentFilters: (storedRecentFilters: Partial<TodayRecentFilters>) => TodayRecentFiltersrecentSourceOptions: (allRecentItems: TodayWorkItem[], recentFilters: TodayRecentFilters) => string[]shownPinnedItems: (pinnedItems: TodayWorkItem[], recentQuery: string) => TodayWorkItem[]- shownSpaces: (visibleSpaces: ChannelDTOApi[], recentQuery: string) => ChannelDTOApi[]recentFiltersActive: (recentFilters: TodayRecentFilters) => booleanunreadSessionIds: (taskActivity: TaskActivityDTOApi[]) => Set<string>recentItems: (@@ -394,14 +350,6 @@ export interface todaySpacesLogicMeta {spaceNames: Record<string, string>) => TodayRecentSection[]recentLoading: (recentTasksLoading: boolean, conversationHistoryLoading: boolean) => boolean- unreadSpaceIds: (taskActivity: TaskActivityDTOApi[]) => Set<string>- unreadSessionCounts: (taskActivity: TaskActivityDTOApi[]) => Record<string, number>- spacePresence: (spaceActivity: SpaceActivity) => Record<string, SpacePresence>- spacePreviews: (- visibleSpaces: ChannelDTOApi[],- spaceActivity: SpaceActivity,- unreadSessionCounts: Record<string, number>- ) => Record<string, TodaySpacePreview>}}@@ -495,25 +443,6 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([},},],- spaceActivity: [- { presence: {}, lastActivityAt: {} } as SpaceActivity,- {- loadSpaceActivity: async () => {- if (!values.currentTeamId) {- return { presence: {}, lastActivityAt: {} }- }- const response = await tasksList(String(values.currentTeamId), {- ordering: '-last_activity_at',- basic: true,- limit: SPACE_PRESENCE_FETCH_LIMIT,- })- return {- presence: presenceBySpace(response.results, Date.now()),- lastActivityAt: lastActivityBySpace(response.results),- }- },- },- ],taskActivity: [[] as TaskActivityDTOApi[],{@@ -600,10 +529,6 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([}),selectors({sortedSpaces: [(s) => [s.spaces], (spaces: ChannelDTOApi[]): ChannelDTOApi[] => sortSpaces(spaces)],- visibleSpaces: [- (s) => [s.sortedSpaces],- (sortedSpaces: ChannelDTOApi[]): ChannelDTOApi[] => starredSpaces(sortedSpaces),- ],pinnedItems: [(s) => [s.pinnedTasks],(pinnedTasks: TaskListItemApi[]): TodayWorkItem[] =>@@ -639,11 +564,6 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([(pinnedItems: TodayWorkItem[], recentQuery: string): TodayWorkItem[] =>pinnedItems.filter((item) => matchesPaneQuery(item.title || '', recentQuery)),],- shownSpaces: [- (s) => [s.visibleSpaces, s.recentQuery],- (visibleSpaces: ChannelDTOApi[], recentQuery: string): ChannelDTOApi[] =>- visibleSpaces.filter((space) => matchesPaneQuery(spaceLabel(space), recentQuery)),- ],recentFiltersActive: [(s) => [s.recentFilters],(recentFilters: TodayRecentFilters): boolean => hasActiveRecentFilters(recentFilters),@@ -699,39 +619,6 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([(recentTasksLoading: boolean, conversationHistoryLoading: boolean): boolean =>recentTasksLoading || conversationHistoryLoading,],- unreadSpaceIds: [- (s) => [s.taskActivity],- (taskActivity: TaskActivityDTOApi[]): Set<string> => unreadSpaceIds(taskActivity),- ],- unreadSessionCounts: [- (s) => [s.taskActivity],- (taskActivity: TaskActivityDTOApi[]): Record<string, number> => unreadSessionCountsBySpace(taskActivity),- ],- spacePresence: [- (s) => [s.spaceActivity],- (spaceActivity: SpaceActivity): Record<string, SpacePresence> => spaceActivity.presence,- ],- // One object per space that changes only when its inputs do, so the hover card's payload stays stable.- spacePreviews: [- (s) => [s.visibleSpaces, s.spaceActivity, s.unreadSessionCounts],- (- visibleSpaces: ChannelDTOApi[],- spaceActivity: SpaceActivity,- unreadSessionCounts: Record<string, number>- ): Record<string, TodaySpacePreview> =>- Object.fromEntries(- visibleSpaces.map((space) => [- space.id,- spacePreview(- space,- spaceLabel(space),- spaceActivity.presence[space.id],- spaceActivity.lastActivityAt[space.id],- unreadSessionCounts[space.id] ?? 0- ),- ])- ),- ],}),listeners(({ actions, values, cache }) => {// Reading a session anywhere in the app clears it, so the rail follows the open session rather than clicks.@@ -814,12 +701,6 @@ export const todaySpacesLogic = kea<todaySpacesLogicType>([}actions.loadSpaces()actions.loadPinnedTasks()- // Setup runs now and again whenever the tab comes back, so the faces refresh on return.- cache.disposables.add(() => {- actions.loadSpaceActivity()- const pollTimer = window.setInterval(() => actions.loadSpaceActivity(), SPACE_PRESENCE_POLL_INTERVAL_MS)- return () => clearInterval(pollTimer)- }, 'spacePresencePoll')// A disposable rather than a plain afterMount load, so setup runs again on each return to the tab.cache.disposables.add(() => {if (recentRefreshIsDue(cache.recentTasksLoadedAt)) {diff --git a/frontend/src/layout/today/useTodaySectionLayout.ts b/frontend/src/layout/today/useTodaySectionLayout.tsindex 93682fcb95b9..47e521fd1f65 100644--- a/frontend/src/layout/today/useTodaySectionLayout.ts+++ b/frontend/src/layout/today/useTodaySectionLayout.ts@@ -80,7 +80,7 @@ function useMeasuredHeights(): {measure()}}- return { area: ref('area'), pinned: ref('pinned'), recent: ref('recent'), spaces: ref('spaces') }+ return { area: ref('area'), pinned: ref('pinned'), recent: ref('recent') }}, [measure])return { measuredHeights, measureRefs }diff --git a/frontend/src/scenes/project-homepage/today/Today.stories.tsx b/frontend/src/scenes/project-homepage/today/Today.stories.tsxindex db75c576fbbd..586f71f502b0 100644--- a/frontend/src/scenes/project-homepage/today/Today.stories.tsx+++ b/frontend/src/scenes/project-homepage/today/Today.stories.tsx@@ -859,25 +859,9 @@ export const ReportInANarrowWindow: Story = {parameters: { pageUrl: urls.todayReport('report-1'), testOptions: { viewport: { width: 800, height: 900 } } },}-export const SpacesPane: Story = {+export const ChatsPane: Story = {play: async ({ canvasElement }) => {- await userEvent.click(await within(canvasElement).findByLabelText('Spaces'))- },-}--// A hovered space row shows no buttons, so the faces keep their place.-// Its actions, New session first, are in the hover card that opens beside it.-export const SpacesPaneHoveringSpaceRow: Story = {- play: async ({ canvasElement }) => {- const canvas = within(canvasElement)- await userEvent.click(await canvas.findByLabelText('Spaces'))- const labels = await canvas.findAllByText('checkout')- const row = labels.find((label) => label.closest('[data-attr="today-space-row"]'))- if (row) {- await userEvent.hover(row)- // The card opens in a portal outside the story's canvas.- await within(document.body).findByText('New session')- }+ await userEvent.click(await within(canvasElement).findByLabelText('Chats'))},}@@ -891,7 +875,7 @@ export const NewSessionPage: Story = {}// A Cmd-click pick can't be held in a static story, so the play step selects a pinned and a recent row through the logic.-export const SpacesPaneWithSelectedSessions: Story = {+export const ChatsPaneWithSelectedSessions: Story = {parameters: { pageUrl: urls.taskSpace('space-checkout') },play: async ({ canvasElement }) => {await within(canvasElement).findAllByText('Add a retry to the billing webhook')@@ -900,7 +884,7 @@ export const SpacesPaneWithSelectedSessions: Story = {}// The narrowed filters show their values in the primary color, and Clear filters shows at the end.-export const SpacesPaneWithRecentFilterMenu: Story = {+export const ChatsPaneWithRecentFilterMenu: Story = {parameters: { pageUrl: urls.taskSpace('space-checkout') },play: async ({ canvasElement }) => {await within(canvasElement).findAllByText('Add a retry to the billing webhook')@@ -952,27 +936,17 @@ async function sidebarRow(canvasElement: HTMLElement, label: string, rowAttr: st}// Right-clicking a session row opens the same actions as its hover card.-export const SpacesPaneSessionContextMenu: Story = {+export const ChatsPaneChatContextMenu: Story = {play: async ({ canvasElement }) => {- await userEvent.click(await within(canvasElement).findByLabelText('Spaces'))+ await userEvent.click(await within(canvasElement).findByLabelText('Chats'))const row = await sidebarRow(canvasElement, 'Add a retry to the billing webhook', 'today-recent-session')rightClick(row)await within(document.body).findByText('Open in new tab')},}-// Right-clicking a space row opens its actions, New session first, like its hover card.-export const SpacesPaneSpaceContextMenu: Story = {- play: async ({ canvasElement }) => {- await userEvent.click(await within(canvasElement).findByLabelText('Spaces'))- const row = await sidebarRow(canvasElement, 'checkout', 'today-space-row')- rightClick(row)- await within(document.body).findByText('New session')- },-}-// With two sessions picked, right-clicking one of them offers the selection's actions instead of the row's.-export const SpacesPaneSelectedSessionsContextMenu: Story = {+export const ChatsPaneSelectedSessionsContextMenu: Story = {parameters: { pageUrl: urls.taskSpace('space-checkout') },play: async ({ canvasElement }) => {await within(canvasElement).findAllByText('Add a retry to the billing webhook')@@ -1136,9 +1110,9 @@ export const ReportHoverCardResolved: Story = {}// The details are picked through the logic, where the dialog saves them, so each session row shows a second line.-export const SpacesPaneWithListItemDetails: Story = {+export const ChatsPaneWithListItemDetails: Story = {play: async ({ canvasElement }) => {- await userEvent.click(await within(canvasElement).findByLabelText('Spaces'))+ await userEvent.click(await within(canvasElement).findByLabelText('Chats'))await within(canvasElement).findAllByText('Add a retry to the billing webhook')todayListAppearanceLogic.actions.setFields(['repository', 'activity'])},@@ -1146,7 +1120,7 @@ export const SpacesPaneWithListItemDetails: Story = {export const ListItemAppearanceDialog: Story = {play: async ({ canvasElement }) => {- await userEvent.click(await within(canvasElement).findByLabelText('Spaces'))+ await userEvent.click(await within(canvasElement).findByLabelText('Chats'))await within(canvasElement).findAllByText('Add a retry to the billing webhook')todayListAppearanceLogic.actions.setFields(['space', 'branch'])todayListAppearanceLogic.actions.openAppearanceDialog()diff --git a/frontend/src/scenes/project-homepage/today/TodayHomeSidebar.tsx b/frontend/src/scenes/project-homepage/today/TodayHomeSidebar.tsxindex 98d51d79164c..3ab75702c34c 100644--- a/frontend/src/scenes/project-homepage/today/TodayHomeSidebar.tsx+++ b/frontend/src/scenes/project-homepage/today/TodayHomeSidebar.tsx@@ -96,7 +96,7 @@ export function TodayHomeSidebar(): JSX.Element {data-attr="today-new-chat"><IconPlus />- New session+ New chat</Button><div className="TodayPane__scroll"><div className="TodaySidebar__list">diff --git a/products/tasks/frontend/spaces/spaceSceneLogic.test.ts b/products/tasks/frontend/spaces/spaceSceneLogic.test.tsindex b912f0b7bfea..32c4dde7a598 100644--- a/products/tasks/frontend/spaces/spaceSceneLogic.test.ts+++ b/products/tasks/frontend/spaces/spaceSceneLogic.test.ts@@ -534,14 +534,12 @@ describe('spaceSceneLogic', () => {logic.mount()await expectLogic(todaySpacesLogic).toDispatchActions(['loadTaskActivitySuccess'])expect([...todaySpacesLogic.values.unreadSessionIds]).toEqual(['task-1'])- expect([...todaySpacesLogic.values.unreadSpaceIds]).toEqual(['space-a'])router.actions.push(urls.aiTask('task-1'))await expectLogic(todaySpacesLogic).toFinishAllListeners()expect(markReadBodies).toEqual([{ activities: [{ task_id: 'task-1', seen_before: seenBefore }] }])expect([...todaySpacesLogic.values.unreadSessionIds]).toEqual(unreadAfter)- expect([...todaySpacesLogic.values.unreadSpaceIds]).toEqual(unreadAfter.length ? ['space-a'] : [])} finally {jest.useRealTimers()}diff --git a/products/tasks/frontend/spaces/spacesSceneLogic.test.ts b/products/tasks/frontend/spaces/spacesSceneLogic.test.tsindex 06096c0476d4..ac50ce3f5826 100644--- a/products/tasks/frontend/spaces/spacesSceneLogic.test.ts+++ b/products/tasks/frontend/spaces/spacesSceneLogic.test.ts@@ -1,7 +1,11 @@+import { expectLogic } from 'kea-test-utils'+import { isLockedSpace, spaceLabel } from '~/layout/today/todaySpacesLogic'+import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'import { ChannelDTOApi } from '../generated/api.schemas'-import { spacesIndexLists } from './spacesSceneLogic'+import { spacesIndexLists, spacesSceneLogic } from './spacesSceneLogic'const space = (id: string, name: string, starred: boolean, system_role: string | null = null): ChannelDTOApi =>({ id, name, starred, system_role }) as ChannelDTOApi@@ -42,4 +46,31 @@ describe('spacesSceneLogic', () => {])('labels %s', (_, channel, label) => {expect(spaceLabel(channel)).toBe(label)})++ it('shows a person whose only recent task is past the first page of tasks', async () => {+ const recent = new Date(Date.now() - 60_000).toISOString()+ const task = (channel: string, uuid: string): Record<string, unknown> => ({+ channel,+ archived: false,+ last_activity_at: recent,+ created_by: { id: 1, uuid, first_name: uuid, email: `${uuid}@example.com` },+ })+ useMocks({+ get: {+ '/api/projects/:team_id/tasks/': ({ request }) => {+ const offset = Number(new URL(request.url).searchParams.get('offset') ?? 0)+ return offset === 0+ ? [200, { next: 'next-page', results: [task('checkout', 'ada')] }]+ : [200, { next: null, results: [task('billing', 'grace')] }]+ },+ },+ })+ initKeaTests()+ const logic = spacesSceneLogic()+ logic.mount()+ logic.actions.loadSpacePresence()+ await expectLogic(logic).toDispatchActions(['loadSpacePresenceSuccess'])++ expect(logic.values.spacePresence['billing']?.people.map((person) => person.uuid)).toEqual(['grace'])+ })})diff --git a/products/tasks/frontend/spaces/spacesSceneLogic.ts b/products/tasks/frontend/spaces/spacesSceneLogic.tsindex 909abe45424a..a171c6c00e2d 100644--- a/products/tasks/frontend/spaces/spacesSceneLogic.ts+++ b/products/tasks/frontend/spaces/spacesSceneLogic.ts@@ -8,9 +8,13 @@ import { urls } from 'scenes/urls'import { starredSpaces, todaySpacesLogic } from '~/layout/today/todaySpacesLogic'import { Breadcrumb } from '~/types'-import { taskChannelsContributorsRetrieve } from '../generated/api'-import { ChannelDTOApi, TaskUserBasicInfoApi } from '../generated/api.schemas'-import { SpacePresence } from './spacePresence'+import { taskChannelsContributorsRetrieve, tasksList } from '../generated/api'+import { ChannelDTOApi, TaskListItemApi, TaskUserBasicInfoApi } from '../generated/api.schemas'+import { PRESENCE_RECENT_WINDOW_MS, SpacePresence, presenceBySpace } from './spacePresence'++const SPACE_PRESENCE_FETCH_LIMIT = 100+const SPACE_PRESENCE_MAX_PAGES = 10+const SPACE_PRESENCE_POLL_INTERVAL_MS = 90_000export interface SpacesIndexLists {starred: ChannelDTOApi[]@@ -30,7 +34,6 @@ export interface spacesSceneLogicValues {currentTeamId: number | null // teamLogicpendingSpaceIds: string[] // todaySpacesLogicsortedSpaces: ChannelDTOApi[] // todaySpacesLogic- spacePresence: Record<string, SpacePresence> // todaySpacesLogicspacesLoading: boolean // todaySpacesLogicspacesUnavailable: boolean // todaySpacesLogicbreadcrumbs: Breadcrumb[]@@ -38,6 +41,8 @@ export interface spacesSceneLogicValues {contributorsLoading: booleanlists: SpacesIndexListssearch: string+ spacePresence: Record<string, SpacePresence>+ spacePresenceLoading: boolean}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -69,6 +74,21 @@ export interface spacesSceneLogicActions {} | nullpayload?: any}+ loadSpacePresence: () => any+ loadSpacePresenceFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadSpacePresenceSuccess: (+ spacePresence: Record<string, SpacePresence>,+ payload?: any+ ) => {+ spacePresence: Record<string, SpacePresence>+ payload?: any+ }setSearch: (search: string) => {search: string}@@ -93,7 +113,7 @@ export const spacesSceneLogic = kea<spacesSceneLogicType>([connect(() => ({values: [todaySpacesLogic,- ['sortedSpaces', 'spacesLoading', 'spacesUnavailable', 'pendingSpaceIds', 'spacePresence'],+ ['sortedSpaces', 'spacesLoading', 'spacesUnavailable', 'pendingSpaceIds'],teamLogic,['currentTeamId'],],@@ -106,6 +126,33 @@ export const spacesSceneLogic = kea<spacesSceneLogicType>([search: ['', { setSearch: (_, { search }) => search }],}),loaders(({ values }) => ({+ spacePresence: [+ {} as Record<string, SpacePresence>,+ {+ loadSpacePresence: async () => {+ if (!values.currentTeamId) {+ return {}+ }+ const now = Date.now()+ const tasks: TaskListItemApi[] = []+ for (let page = 0; page < SPACE_PRESENCE_MAX_PAGES; page++) {+ const response = await tasksList(String(values.currentTeamId), {+ ordering: '-last_activity_at',+ basic: true,+ limit: SPACE_PRESENCE_FETCH_LIMIT,+ offset: page * SPACE_PRESENCE_FETCH_LIMIT,+ })+ tasks.push(...response.results)+ const oldest = response.results[response.results.length - 1]?.last_activity_at+ // The list is newest first, so a page that reaches past the window holds the last faces.+ if (!response.next || !oldest || now - Date.parse(oldest) >= PRESENCE_RECENT_WINDOW_MS) {+ break+ }+ }+ return presenceBySpace(tasks, now)+ },+ },+ ],contributors: [null as Record<string, TaskUserBasicInfoApi[]> | null,{@@ -129,7 +176,12 @@ export const spacesSceneLogic = kea<spacesSceneLogicType>([(): Breadcrumb[] => [{ key: Scene.TaskSpaces, name: 'Spaces', path: urls.taskSpaces(), iconType: 'task' }],],}),- afterMount(({ actions }) => {+ afterMount(({ actions, cache }) => {actions.loadContributors()+ cache.disposables.add(() => {+ actions.loadSpacePresence()+ const pollTimer = window.setInterval(() => actions.loadSpacePresence(), SPACE_PRESENCE_POLL_INTERVAL_MS)+ return () => clearInterval(pollTimer)+ }, 'spacePresencePoll')}),])