: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): select several sidebar sessions like desktop (#109610)
Shy Alter356c7d501b69
diff --git a/frontend/src/layout/today/TodaySessionRow.tsx b/frontend/src/layout/today/TodaySessionRow.tsxindex 197e52c31b3d..90f5f765315c 100644--- a/frontend/src/layout/today/TodaySessionRow.tsx+++ b/frontend/src/layout/today/TodaySessionRow.tsx@@ -24,6 +24,9 @@ interface TodaySessionRowProps {dataAttr: stringsurface: TodaySessionSurfaceunread: boolean+ selected?: boolean+ /** Takes a modifier click over for the sidebar's multi-select. */+ onSelectClick?: (event: React.MouseEvent<HTMLElement>) => void}export function TodaySessionRow({@@ -33,6 +36,8 @@ export function TodaySessionRow({dataAttr,surface,unread,+ selected = false,+ onSelectClick,}: TodaySessionRowProps): JSX.Element {const { renaming } = useValues(todaySessionMenuLogic)const { location, searchParams } = useValues(router)@@ -69,6 +74,8 @@ export function TodaySessionRow({}badgeCount={badgeCount === 2 ? 2 : 1}ticker+ selected={selected}+ onClickCapture={onSelectClick}action={<TodaySessionMenusessionId={item.id}diff --git a/frontend/src/layout/today/TodaySpacesRow.tsx b/frontend/src/layout/today/TodaySpacesRow.tsxindex e5a9c1a09fbe..26f447bcfcb1 100644--- a/frontend/src/layout/today/TodaySpacesRow.tsx+++ b/frontend/src/layout/today/TodaySpacesRow.tsx@@ -36,6 +36,10 @@ interface TodaySpacesRowProps {unreadDot?: boolean/** Fade a long label and scroll it on hover instead of cutting it with an ellipsis. */ticker?: boolean+ /** Part of a multi-session selection, so the row takes Desktop's selected tint. */+ selected?: boolean+ /** Runs before the link navigates, so a modifier click can take the click over. */+ onClickCapture?: (event: React.MouseEvent<HTMLElement>) => void}export function TodaySpacesRow({@@ -51,6 +55,8 @@ export function TodaySpacesRow({unread = false,unreadDot = true,ticker = false,+ selected = false,+ onClickCapture,}: TodaySpacesRowProps): JSX.Element {const [hovered, setHovered] = useState(false)const [keyboardFocused, setKeyboardFocused] = useState(false)@@ -72,6 +78,7 @@ export function TodaySpacesRow({render={<LinkPrimitive to={to} />}aria-current={active ? 'page' : undefined}data-attr={dataAttr}+ onClickCapture={onClickCapture}onFocus={ticker? (e: React.FocusEvent<HTMLElement>) =>@@ -81,7 +88,8 @@ export function TodaySpacesRow({onBlur={ticker ? () => setKeyboardFocused(false) : undefined}className={cn('min-w-0 text-xs font-medium text-foreground',- active && 'bg-fill-selected',+ // Like Desktop, the open row takes a stronger tint than the other selected rows.+ selected ? (active ? 'bg-primary/20' : 'bg-primary/10') : active && 'bg-fill-selected',TRAILING_PADDING[restSlots],HOVER_TRAILING_PADDING[restSlots + actionSlots])}diff --git a/frontend/src/layout/today/TodaySpacesSidebar.tsx b/frontend/src/layout/today/TodaySpacesSidebar.tsxindex 0e9281e07105..7e9452221548 100644--- a/frontend/src/layout/today/TodaySpacesSidebar.tsx+++ b/frontend/src/layout/today/TodaySpacesSidebar.tsx@@ -16,6 +16,8 @@ import { TodayPreviewTrigger } from './TodayPreviewTrigger'import { TodayRecentFilterMenu } from './TodayRecentFilterMenu'import { TodayRecentSearchField } from './TodayRecentSearchField'import { TodaySessionRow } from './TodaySessionRow'+import { selectionClick } from './todaySessionSelection'+import { todaySessionSelectionLogic } from './todaySessionSelectionLogic'import { TodaySpaceActions } from './TodaySpaceActions'import { TodaySpaceGlyph } from './TodaySpaceGlyph'import { TodayWorkSectionId, isLockedSpace, spaceLabel, todaySpacesLogic } from './todaySpacesLogic'@@ -44,9 +46,28 @@ export function TodaySpacesSidebar(): JSX.Element {const { loadSpaces, loadRecentTasks, toggleSection, setRecentSearchOpen, clearRecentSearchAndFilters } =useActions(todaySpacesLogic)const { openNewSpace } = useActions(newSpaceLogic)+ const { selectedSessionIds } = useValues(todaySessionSelectionLogic)+ const { toggleSessionSelection, selectSessionRange, clearSelection } = useActions(todaySessionSelectionLogic)const { location, searchParams } = useValues(router)const pinnedIds = new Set(pinnedItems.map((item) => item.id))const browsingSpaces = location.pathname.endsWith(urls.taskSpaces())+ 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.+ const onSelectClick = (sessionId: string, event: React.MouseEvent<HTMLElement>): void => {+ const click = selectionClick(event)+ if (click === 'open') {+ clearSelection()+ return+ }+ event.preventDefault()+ event.stopPropagation()+ if (click === 'toggle') {+ toggleSessionSelection(sessionId)+ } else {+ selectSessionRange(sessionId)+ }+ }const renderItem = (item: TodayWorkItem, dataAttr: string, inPinnedSection = false): JSX.Element =>item.kind === 'session' ? (@@ -58,6 +79,8 @@ export function TodaySpacesSidebar(): JSX.Element {dataAttr={dataAttr}surface="sidebar"unread={unreadSessionIds.has(item.id)}+ selected={selectedIds.has(item.id)}+ onSelectClick={(event) => onSelectClick(item.id, event)}/>) : (<TodaySpacesRowdiff --git a/frontend/src/layout/today/todaySessionSelection.test.ts b/frontend/src/layout/today/todaySessionSelection.test.tsnew file mode 100644index 000000000000..b91889fc9191--- /dev/null+++ b/frontend/src/layout/today/todaySessionSelection.test.ts@@ -0,0 +1,49 @@+import {+ TodaySessionSelection,+ computeRangeSelection,+ orderedVisibleSessionIds,+ toggleSelection,+} from './todaySessionSelection'+import { TodayWorkSectionId } from './todaySpacesLogic'+import { TodayWorkItem } from './todayWorkItems'++const ORDERED = ['t1', 't2', 't3', 't4', 't5']++function item(id: string, kind: TodayWorkItem['kind'] = 'session'): TodayWorkItem {+ return { id, kind } as TodayWorkItem+}++describe('todaySessionSelection', () => {+ it.each<[string, string | null, string, string[], TodaySessionSelection]>([+ ['selects a forward range', 't2', 't4', [], { ids: ['t2', 't3', 't4'], anchorId: 't4' }],+ ['selects a backward range', 't4', 't2', [], { ids: ['t2', 't3', 't4'], anchorId: 't2' }],+ ['keeps the rest of the selection', 't3', 't5', ['t1'], { ids: ['t1', 't3', 't4', 't5'], anchorId: 't5' }],+ ['selects only the target with no anchor', null, 't3', ['t1'], { ids: ['t3'], anchorId: 't3' }],+ ['selects only the target when the anchor left the list', 't99', 't3', [], { ids: ['t3'], anchorId: 't3' }],+ ])('Shift-click %s', (_, anchor, target, current, expected) => {+ expect(computeRangeSelection(anchor, target, ORDERED, current)).toEqual(expected)+ })++ it.each<[string, TodaySessionSelection, TodaySessionSelection]>([+ [+ 'adds a row and moves the anchor to it',+ { ids: ['t1'], anchorId: 't1' },+ { ids: ['t1', 't3'], anchorId: 't3' },+ ],+ [+ 'removes a row and still anchors there',+ { ids: ['t1', 't3'], anchorId: 't1' },+ { ids: ['t1'], anchorId: 't3' },+ ],+ ])('Cmd-click %s', (_, before, after) => {+ expect(toggleSelection(before, 't3')).toEqual(after)+ })++ it.each<[string, TodayWorkSectionId[], string[]]>([+ ['runs Pinned then Recent and skips chats', [], ['p1', 'r1', 'r2']],+ ['skips a collapsed section', ['pinned'], ['r1', 'r2']],+ ])('visible order %s', (_, collapsed, expected) => {+ const recent = [item('r1'), item('chat', 'chat'), item('r2')]+ expect(orderedVisibleSessionIds([item('p1')], recent, collapsed)).toEqual(expected)+ })+})diff --git a/frontend/src/layout/today/todaySessionSelection.ts b/frontend/src/layout/today/todaySessionSelection.tsnew file mode 100644index 000000000000..79d095f68460--- /dev/null+++ b/frontend/src/layout/today/todaySessionSelection.ts@@ -0,0 +1,58 @@+import type { TodayWorkSectionId } from './todaySpacesLogic'+import type { TodayWorkItem } from './todayWorkItems'++/** The ids picked for a bulk action, and the row a Shift-click range starts from. */+export interface TodaySessionSelection {+ ids: string[]+ anchorId: string | null+}++export type TodaySelectionClick = 'toggle' | 'range' | 'open'++export const EMPTY_SELECTION: TodaySessionSelection = { ids: [], anchorId: null }++export function selectionClick(event: Pick<MouseEvent, 'shiftKey' | 'metaKey' | 'ctrlKey'>): TodaySelectionClick {+ return event.shiftKey ? 'range' : event.metaKey || event.ctrlKey ? 'toggle' : 'open'+}++/** Pinned first, then Recent, skipping chats and any collapsed section, like the rows on screen. */+export function orderedVisibleSessionIds(+ pinned: TodayWorkItem[],+ recent: TodayWorkItem[],+ collapsedSections: TodayWorkSectionId[]+): string[] {+ return [+ ...(collapsedSections.includes('pinned') ? [] : pinned),+ ...(collapsedSections.includes('recent') ? [] : recent),+ ]+ .filter((item) => item.kind === 'session')+ .map((item) => item.id)+}++export function toggleSelection(selection: TodaySessionSelection, id: string): TodaySessionSelection {+ return {+ ids: selection.ids.includes(id) ? selection.ids.filter((selected) => selected !== id) : [...selection.ids, id],+ anchorId: id,+ }+}++/** Adds the rows from the anchor to `toId` and keeps the rest of the selection, like Shift-click in Desktop. */+export function computeRangeSelection(+ anchorId: string | null,+ toId: string,+ orderedIds: string[],+ current: string[]+): TodaySessionSelection {+ const anchorIndex = anchorId ? orderedIds.indexOf(anchorId) : -1+ const toIndex = orderedIds.indexOf(toId)+ if (anchorIndex === -1 || toIndex === -1) {+ return { ids: [toId], anchorId: toId }+ }+ const range = orderedIds.slice(Math.min(anchorIndex, toIndex), Math.max(anchorIndex, toIndex) + 1)+ return { ids: Array.from(new Set([...current, ...range])), anchorId: toId }+}++export function pruneToVisible(ids: string[], visibleIds: string[]): string[] {+ const visible = new Set(visibleIds)+ return ids.filter((id) => visible.has(id))+}diff --git a/frontend/src/layout/today/todaySessionSelectionLogic.test.ts b/frontend/src/layout/today/todaySessionSelectionLogic.test.tsnew file mode 100644index 000000000000..fcee4a1c52ed--- /dev/null+++ b/frontend/src/layout/today/todaySessionSelectionLogic.test.ts@@ -0,0 +1,60 @@+import { router } from 'kea-router'+import { expectLogic } from 'kea-test-utils'++import { urls } from 'scenes/urls'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { todaySessionSelectionLogic } from './todaySessionSelectionLogic'+import { todaySpacesLogic } from './todaySpacesLogic'++const session = (id: string, lastActivityAt: string): object => ({+ id,+ title: id,+ archived: false,+ channel: null,+ last_activity_at: lastActivityAt,+ latest_run: null,+})++const PINNED = [session('task-p', '2026-09-28T12:00:00Z')]+const RECENT = [session('task-a', '2026-09-28T11:00:00Z'), session('task-b', '2026-09-28T10:00:00Z')]++describe('todaySessionSelectionLogic', () => {+ let logic: ReturnType<typeof todaySessionSelectionLogic.build>++ beforeEach(async () => {+ useMocks({+ get: {+ '/api/projects/:team_id/task_channels/': [],+ '/api/projects/:team_id/task_activity/': { results: [] },+ '/api/projects/:team_id/tasks/': ({ request }) => {+ const pinned = new URL(request.url).searchParams.get('pinned')+ return [200, { results: pinned ? PINNED : [...PINNED, ...RECENT], count: 3 }]+ },+ },+ })+ initKeaTests()+ logic = todaySessionSelectionLogic()+ logic.mount()+ await expectLogic(todaySpacesLogic).toDispatchActions(['loadPinnedTasksSuccess', 'loadRecentTasksSuccess'])+ })++ it('starts a Shift-click range at the open session when nothing was clicked yet, across Pinned and Recent', async () => {+ router.actions.push(urls.aiTask('task-p'))+ logic.actions.selectSessionRange('task-b')++ expect(logic.values.selectedSessionIds).toEqual(['task-p', 'task-a', 'task-b'])+ })++ it.each([+ ['a route change', () => router.actions.push(urls.ai())],+ ['Escape', () => window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))],+ ])('clears the selection on %s', async (_, clear) => {+ logic.actions.setSelection({ ids: ['task-a', 'task-b'], anchorId: 'task-b' })+ clear()++ expect(logic.values.selectedSessionIds).toEqual([])+ })+})diff --git a/frontend/src/layout/today/todaySessionSelectionLogic.ts b/frontend/src/layout/today/todaySessionSelectionLogic.tsnew file mode 100644index 000000000000..d6da3fd7c8d5--- /dev/null+++ b/frontend/src/layout/today/todaySessionSelectionLogic.ts@@ -0,0 +1,161 @@+import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'+import { router } from 'kea-router'+import type { LocationChangedPayload } from 'kea-router/lib/types'++import { TodayRecentSection } from './todayRecentOrder'+import {+ EMPTY_SELECTION,+ TodaySessionSelection,+ computeRangeSelection,+ orderedVisibleSessionIds,+ pruneToVisible,+ toggleSelection,+} from './todaySessionSelection'+import { TodayWorkSectionId, todaySpacesLogic } from './todaySpacesLogic'+import { TodayWorkItem } from './todayWorkItems'++function isEditableTarget(target: EventTarget | null): boolean {+ return (+ target instanceof HTMLElement &&+ (target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName))+ )+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface todaySessionSelectionLogicValues {+ collapsedSections: TodayWorkSectionId[] // todaySpacesLogic+ pinnedItems: TodayWorkItem[] // todaySpacesLogic+ recentGroups: TodayRecentSection[] // todaySpacesLogic+ orderedSessionIds: string[]+ selectedSessionIds: string[]+ selection: TodaySessionSelection+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface todaySessionSelectionLogicActions {+ locationChanged: ({+ method,+ pathname,+ search,+ searchParams,+ hash,+ hashParams,+ initial,+ url,+ routerState,+ }: LocationChangedPayload) => {+ hash: string+ hashParams: Record<string, any>+ initial: boolean+ method: 'POP' | 'PUSH' | 'REPLACE'+ pathname: string+ routerState: Record<string, any>+ search: string+ searchParams: Record<string, any>+ url: string+ } // router+ clearSelection: () => {+ value: true+ }+ selectSessionRange: (sessionId: string) => {+ sessionId: string+ }+ setSelection: (selection: TodaySessionSelection) => {+ selection: TodaySessionSelection+ }+ toggleSessionSelection: (sessionId: string) => {+ sessionId: string+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface todaySessionSelectionLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ orderedSessionIds: (+ pinnedItems: TodayWorkItem[],+ recentGroups: TodayRecentSection[],+ collapsedSections: TodayWorkSectionId[]+ ) => string[]+ selectedSessionIds: (selection: TodaySessionSelection, orderedSessionIds: string[]) => string[]+ }+}++export type todaySessionSelectionLogicType = MakeLogicType<+ todaySessionSelectionLogicValues,+ todaySessionSelectionLogicActions,+ Record<string, any>,+ todaySessionSelectionLogicMeta+>++export const todaySessionSelectionLogic = kea<todaySessionSelectionLogicType>([+ path(['layout', 'today', 'todaySessionSelectionLogic']),+ connect(() => ({+ values: [todaySpacesLogic, ['collapsedSections', 'pinnedItems', 'recentGroups']],+ actions: [router, ['locationChanged']],+ })),+ actions({+ setSelection: (selection: TodaySessionSelection) => ({ selection }),+ toggleSessionSelection: (sessionId: string) => ({ sessionId }),+ selectSessionRange: (sessionId: string) => ({ sessionId }),+ clearSelection: true,+ }),+ reducers({+ selection: [+ EMPTY_SELECTION,+ {+ setSelection: (_, { selection }) => selection,+ toggleSessionSelection: (state, { sessionId }) => toggleSelection(state, sessionId),+ clearSelection: () => EMPTY_SELECTION,+ locationChanged: () => EMPTY_SELECTION,+ },+ ],+ }),+ selectors({+ orderedSessionIds: [+ (s) => [s.pinnedItems, s.recentGroups, s.collapsedSections],+ (+ pinnedItems: TodayWorkItem[],+ recentGroups: TodayRecentSection[],+ collapsedSections: TodayWorkSectionId[]+ ): string[] =>+ orderedVisibleSessionIds(+ pinnedItems,+ recentGroups.flatMap((group) => group.items),+ collapsedSections+ ),+ ],+ // Rows that leave the list, like archived ones or those behind a filter, drop out of the selection.+ selectedSessionIds: [+ (s) => [s.selection, s.orderedSessionIds],+ (selection: TodaySessionSelection, orderedSessionIds: string[]): string[] =>+ pruneToVisible(selection.ids, orderedSessionIds),+ ],+ }),+ listeners(({ actions, values }) => ({+ selectSessionRange: ({ sessionId }) => {+ // With no anchor yet, the range starts at the open session, as it does in Desktop.+ const { location, searchParams } = router.values+ const openId =+ location.pathname.endsWith('/ai') && typeof searchParams.task === 'string' ? searchParams.task : null+ actions.setSelection(+ computeRangeSelection(+ values.selection.anchorId ?? openId,+ sessionId,+ values.orderedSessionIds,+ values.selectedSessionIds+ )+ )+ },+ })),+ afterMount(({ actions, values, cache }) => {+ cache.disposables.add(() => {+ const onKeyDown = (event: KeyboardEvent): void => {+ if (event.key === 'Escape' && !isEditableTarget(event.target) && values.selection.ids.length) {+ actions.clearSelection()+ }+ }+ window.addEventListener('keydown', onKeyDown)+ return () => window.removeEventListener('keydown', onKeyDown)+ }, 'clearSelectionOnEscape')+ }),+])diff --git a/frontend/src/scenes/project-homepage/today/Today.stories.tsx b/frontend/src/scenes/project-homepage/today/Today.stories.tsxindex 2c11e019fa58..288da828259c 100644--- a/frontend/src/scenes/project-homepage/today/Today.stories.tsx+++ b/frontend/src/scenes/project-homepage/today/Today.stories.tsx@@ -11,6 +11,7 @@ import { urls } from 'scenes/urls'import { sessionPreview, spacePreview } from '~/layout/today/todayPreviewCards'import { TodaySessionHoverCard } from '~/layout/today/TodaySessionHoverCard'+import { todaySessionSelectionLogic } from '~/layout/today/todaySessionSelectionLogic'import { TodaySpaceHoverCard } from '~/layout/today/TodaySpaceHoverCard'import { sessionItem } from '~/layout/today/todayWorkItems'import { mswDecorator } from '~/mocks/browser'@@ -368,6 +369,15 @@ export const SpacePage: Story = {parameters: { pageUrl: urls.taskSpace('space-checkout') },}+// 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 = {+ parameters: { pageUrl: urls.taskSpace('space-checkout') },+ play: async ({ canvasElement }) => {+ await within(canvasElement).findAllByText('Add a retry to the billing webhook')+ todaySessionSelectionLogic.actions.setSelection({ ids: ['task-pinned', 'task-1'], anchorId: 'task-1' })+ },+}+export const SpacesBrowse: Story = {parameters: { pageUrl: urls.taskSpaces() },}