Skip to content

: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.

feat(today): canvas card previews and a quieter feed selection (#110428)

Shy Alterd0c6494808d3
diff --git a/packages/quill/packages/primitives/AGENTS.md b/packages/quill/packages/primitives/AGENTS.md
index efdc51357faa..0b5f8693b2e8 100644
--- a/packages/quill/packages/primitives/AGENTS.md
+++ b/packages/quill/packages/primitives/AGENTS.md
@@ -330,6 +330,8 @@ Grouped fields with fieldset:
</div>
```
+For a select-all over a partly selected list, pass `indeterminate`: the box fills like a checked one and shows a minus instead of a check.
+
Switch has sizes: `<Switch size="sm" />` or `<Switch size="default" />`
### Select
diff --git a/packages/quill/packages/primitives/src/checkbox.css b/packages/quill/packages/primitives/src/checkbox.css
index 1fb22b56bffe..54a47617b3af 100644
--- a/packages/quill/packages/primitives/src/checkbox.css
+++ b/packages/quill/packages/primitives/src/checkbox.css
@@ -58,13 +58,15 @@
border-color: var(--primary);
}
- .quill-checkbox[data-checked] {
+ .quill-checkbox[data-checked],
+ .quill-checkbox[data-indeterminate] {
color: var(--primary-foreground);
background-color: var(--primary);
border-color: var(--primary);
}
- :is(.dark, [theme='dark']) .quill-checkbox[data-checked] {
+ :is(.dark, [theme='dark']) .quill-checkbox[data-checked],
+ :is(.dark, [theme='dark']) .quill-checkbox[data-indeterminate] {
background-color: var(--primary);
}
diff --git a/packages/quill/packages/primitives/src/checkbox.stories.tsx b/packages/quill/packages/primitives/src/checkbox.stories.tsx
index 5852e61bc2c6..472f3662a31d 100644
--- a/packages/quill/packages/primitives/src/checkbox.stories.tsx
+++ b/packages/quill/packages/primitives/src/checkbox.stories.tsx
@@ -19,6 +19,17 @@ export const Default: Story = {
),
} satisfies Story
+export const States: Story = {
+ render: () => (
+ <div className="flex items-center gap-3">
+ <Checkbox aria-label="Unchecked" />
+ <Checkbox aria-label="Checked" defaultChecked />
+ <Checkbox aria-label="Some checked" indeterminate />
+ <Checkbox aria-label="Small, some checked" size="sm" indeterminate />
+ </div>
+ ),
+} satisfies Story
+
export const WithFieldGroup: Story = {
render: () => (
<FieldGroup className="max-w-sm">
diff --git a/packages/quill/packages/primitives/src/checkbox.tsx b/packages/quill/packages/primitives/src/checkbox.tsx
index 822cc4dd6875..8796def05e69 100644
--- a/packages/quill/packages/primitives/src/checkbox.tsx
+++ b/packages/quill/packages/primitives/src/checkbox.tsx
@@ -1,9 +1,10 @@
+import './checkbox.css'
+
import { Checkbox as CheckboxPrimitive } from '@base-ui/react/checkbox'
import { cva, type VariantProps } from 'class-variance-authority'
-import { CheckIcon } from 'lucide-react'
+import { CheckIcon, MinusIcon } from 'lucide-react'
import * as React from 'react'
-import './checkbox.css'
import { cn } from './lib/utils'
const checkboxIndicatorVariants = cva('quill-checkbox-indicator flex shrink-0 items-center justify-center', {
@@ -77,7 +78,11 @@ function Checkbox({
data-slot="checkbox-primitive-indicator"
className="grid place-content-center text-current transition-none"
>
- <CheckboxIndicator checked size={size ?? 'default'} className="border-none bg-transparent" />
+ {props.indeterminate ? (
+ <MinusIcon className={checkIconVariants({ size })} />
+ ) : (
+ <CheckboxIndicator checked size={size ?? 'default'} className="border-none bg-transparent" />
+ )}
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
)
diff --git a/products/tasks/frontend/spaces/SpaceCanvasCard.tsx b/products/tasks/frontend/spaces/SpaceCanvasCard.tsx
index 1ae0db303fe1..470da89c7d52 100644
--- a/products/tasks/frontend/spaces/SpaceCanvasCard.tsx
+++ b/products/tasks/frontend/spaces/SpaceCanvasCard.tsx
@@ -9,38 +9,40 @@ import { shortTimeAgo } from '~/layout/today/todayWorkItems'
import type { CanvasApi } from 'products/canvas/frontend/generated/api.schemas'
import { SpaceCanvasActions } from './SpaceCanvasActions'
-import { spaceCanvasAuthor, spaceCanvasTemplateIcon } from './spaceCanvasDisplay'
+import { spaceCanvasAuthor } from './spaceCanvasDisplay'
import { SpaceCanvasMenu } from './SpaceCanvasMenu'
+import { SpaceCanvasPreview } from './SpaceCanvasPreview'
import { TaskUserAvatar, taskUserName } from './TaskUserAvatar'
export function SpaceCanvasCard({ spaceId, canvas }: { spaceId: string; canvas: CanvasApi }): JSX.Element {
const author = spaceCanvasAuthor(canvas)
const authorName = taskUserName(author)
- const TemplateIcon = spaceCanvasTemplateIcon(canvas.template_id)
return (
<ContextMenu>
<ContextMenuTrigger render={<div className="min-w-0" />}>
<Card
size="sm"
- className="group relative gap-1 rounded-xl px-4 py-3 transition-colors hover:bg-fill-hover"
+ className="group relative gap-0 rounded-xl py-0 transition-colors hover:bg-fill-hover has-focus-visible:ring-2 has-focus-visible:ring-ring"
>
- <div className="flex min-w-0 items-center gap-2">
- <TemplateIcon className="size-3.5 shrink-0 text-muted-foreground" />
- <LinkPrimitive
- to={urls.canvasDetail(canvas.id)}
- className="min-w-0 flex-1 truncate text-sm font-medium text-foreground after:absolute after:inset-0"
- data-attr="today-space-canvases-card"
- >
- {canvas.name || 'Untitled canvas'}
- </LinkPrimitive>
- <SpaceCanvasMenu spaceId={spaceId} canvas={canvas} />
- <span aria-hidden className="relative flex shrink-0">
- <TaskUserAvatar user={author} />
- </span>
+ <SpaceCanvasPreview spaceId={spaceId} canvas={canvas} />
+ <div className="flex min-w-0 flex-col gap-1 px-4 py-3">
+ <div className="flex min-w-0 items-center gap-2">
+ <LinkPrimitive
+ to={urls.canvasDetail(canvas.id)}
+ className="min-w-0 flex-1 truncate text-sm font-medium text-foreground after:absolute after:inset-0"
+ data-attr="today-space-canvases-card"
+ >
+ {canvas.name || 'Untitled canvas'}
+ </LinkPrimitive>
+ <SpaceCanvasMenu spaceId={spaceId} canvas={canvas} />
+ <span aria-hidden className="relative flex shrink-0">
+ <TaskUserAvatar user={author} />
+ </span>
+ </div>
+ <Text size="xs" variant="muted" className="truncate">
+ {`Updated ${shortTimeAgo(canvas.updated_at)} · ${authorName}`}
+ </Text>
</div>
- <Text size="xs" variant="muted" className="truncate">
- {`Updated ${shortTimeAgo(canvas.updated_at)} · ${authorName}`}
- </Text>
</Card>
</ContextMenuTrigger>
<ContextMenuContent className="w-48">
diff --git a/products/tasks/frontend/spaces/SpaceCanvasDeleteDialog.tsx b/products/tasks/frontend/spaces/SpaceCanvasDeleteDialog.tsx
index 72a73831051c..6f1056024516 100644
--- a/products/tasks/frontend/spaces/SpaceCanvasDeleteDialog.tsx
+++ b/products/tasks/frontend/spaces/SpaceCanvasDeleteDialog.tsx
@@ -36,7 +36,6 @@ export function SpaceCanvasDeleteDialog({ spaceId }: { spaceId: string }): JSX.E
<AlertDialogFooter>
<Button
variant="outline"
- size="sm"
onClick={() => setCanvasDeleteTarget(null)}
disabled={canvasDeleting}
data-attr="today-space-canvases-delete-cancel"
@@ -44,8 +43,7 @@ export function SpaceCanvasDeleteDialog({ spaceId }: { spaceId: string }): JSX.E
Cancel
</Button>
<Button
- variant="destructive"
- size="sm"
+ variant="destructive-outline"
loading={canvasDeleting}
disabled={canvasDeleting}
onClick={() => confirmCanvasDelete()}
diff --git a/products/tasks/frontend/spaces/SpaceCanvasMenu.tsx b/products/tasks/frontend/spaces/SpaceCanvasMenu.tsx
index 5a60de300a3f..ae5c63d5da00 100644
--- a/products/tasks/frontend/spaces/SpaceCanvasMenu.tsx
+++ b/products/tasks/frontend/spaces/SpaceCanvasMenu.tsx
@@ -1,7 +1,16 @@
import { useState } from 'react'
import { IconEllipsis } from '@posthog/icons'
-import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, cn } from '@posthog/quill'
+import {
+ Button,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuTrigger,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ cn,
+} from '@posthog/quill'
import { DROPDOWN_PARTS } from '~/layout/today/todayMenuParts'
@@ -13,21 +22,31 @@ export function SpaceCanvasMenu({ spaceId, canvas }: { spaceId: string; canvas:
const [open, setOpen] = useState(false)
return (
<DropdownMenu open={open} onOpenChange={setOpen}>
- <DropdownMenuTrigger
- render={
- <Button
- size="icon-xs"
- aria-label={`Options for ${canvas.name || 'Untitled canvas'}`}
- className={cn(
- 'relative shrink-0 transition-opacity motion-reduce:transition-none',
- open ? 'opacity-100' : 'opacity-0 group-hover:opacity-100 focus-visible:opacity-100'
- )}
- data-attr="today-space-canvases-card-menu"
- />
- }
- >
- <IconEllipsis />
- </DropdownMenuTrigger>
+ <Tooltip>
+ <TooltipTrigger
+ delay={0}
+ render={
+ <DropdownMenuTrigger
+ render={
+ <Button
+ size="icon-xs"
+ aria-label={`More actions for ${canvas.name || 'Untitled canvas'}`}
+ className={cn(
+ 'relative shrink-0 transition-opacity motion-reduce:transition-none',
+ open
+ ? 'opacity-100'
+ : 'opacity-0 group-hover:opacity-100 focus-visible:opacity-100'
+ )}
+ data-attr="today-space-canvases-card-menu"
+ />
+ }
+ />
+ }
+ >
+ <IconEllipsis />
+ </TooltipTrigger>
+ <TooltipContent>More actions</TooltipContent>
+ </Tooltip>
<DropdownMenuContent align="end" className="w-48">
<SpaceCanvasActions
parts={DROPDOWN_PARTS}
diff --git a/products/tasks/frontend/spaces/SpaceCanvasPreview.tsx b/products/tasks/frontend/spaces/SpaceCanvasPreview.tsx
new file mode 100644
index 000000000000..9e2c56c655d0
--- /dev/null
+++ b/products/tasks/frontend/spaces/SpaceCanvasPreview.tsx
@@ -0,0 +1,76 @@
+import { useActions, useValues } from 'kea'
+import { useEffect, useRef } from 'react'
+
+import { Skeleton } from '@posthog/quill'
+
+import { themeLogic } from 'lib/logic/themeLogic'
+
+import type { CanvasApi } from 'products/canvas/frontend/generated/api.schemas'
+import { BuiltCanvas } from 'products/canvas/frontend/host/BuiltCanvas'
+
+import { spaceCanvasTemplateIcon } from './spaceCanvasDisplay'
+import { spaceCanvasPreviewKey, spaceCanvasPreviewsLogic } from './spaceCanvasPreviewsLogic'
+
+const NO_HIGHLIGHTS: never[] = []
+const denyDataRequest = (): Promise<never> => Promise.reject(new Error('A canvas preview has no data access'))
+const noUserActivation = (): boolean => false
+const ignoreExternalOpen = (): void => {}
+
+export function SpaceCanvasPreview({ spaceId, canvas }: { spaceId: string; canvas: CanvasApi }): JSX.Element {
+ const previewKey = spaceCanvasPreviewKey(canvas)
+ const logic = spaceCanvasPreviewsLogic({ spaceId })
+ const { previews } = useValues(logic)
+ const { requestPreview } = useActions(logic)
+ const { isDarkModeOn } = useValues(themeLogic)
+ const ref = useRef<HTMLDivElement>(null)
+
+ useEffect(() => {
+ const element = ref.current
+ if (!element || !previewKey) {
+ return
+ }
+ const observer = new IntersectionObserver(
+ (entries) => {
+ if (entries.some((entry) => entry.isIntersecting)) {
+ requestPreview(previewKey, canvas.id)
+ observer.disconnect()
+ }
+ },
+ { rootMargin: '400px 0px' }
+ )
+ observer.observe(element)
+ return () => observer.disconnect()
+ }, [previewKey, canvas.id, requestPreview])
+
+ const preview = previewKey ? previews[previewKey] : null
+ const TemplateIcon = spaceCanvasTemplateIcon(canvas.template_id)
+
+ return (
+ <div ref={ref} aria-hidden className="relative h-36 shrink-0 overflow-hidden border-b border-border bg-muted">
+ {preview?.status === 'ready' && preview.artifactUrl ? (
+ // Renders the canvas at four times the card's width, then scales it down to fit.
+ <div
+ className="pointer-events-none absolute top-0 left-0 h-[400%] w-[400%] origin-top-left scale-25"
+ {...{ inert: '' }}
+ >
+ <BuiltCanvas
+ artifactUrl={preview.artifactUrl}
+ capabilities={null}
+ theme={isDarkModeOn ? 'dark' : 'light'}
+ onDataRequest={denyDataRequest}
+ hasUserActivation={noUserActivation}
+ onOpenExternal={ignoreExternalOpen}
+ commentHighlights={NO_HIGHLIGHTS}
+ clearTextSelectionKey={0}
+ />
+ </div>
+ ) : previewKey && preview?.status !== 'unavailable' ? (
+ <Skeleton className="size-full rounded-none" />
+ ) : (
+ <div className="flex size-full items-center justify-center">
+ <TemplateIcon className="size-6 text-muted-foreground" />
+ </div>
+ )}
+ </div>
+ )
+}
diff --git a/products/tasks/frontend/spaces/SpaceCanvases.tsx b/products/tasks/frontend/spaces/SpaceCanvases.tsx
index b94ee0069173..d58f2a435c88 100644
--- a/products/tasks/frontend/spaces/SpaceCanvases.tsx
+++ b/products/tasks/frontend/spaces/SpaceCanvases.tsx
@@ -87,7 +87,7 @@ export function SpaceCanvases({ id }: { id: string }): JSX.Element {
</div>
<div className={GRID_CLASS}>
{Array.from({ length: 6 }, (_, index) => (
- <Skeleton key={index} className="h-16 w-full rounded-xl" />
+ <Skeleton key={index} className="h-52 w-full rounded-xl" />
))}
</div>
</div>
diff --git a/products/tasks/frontend/spaces/SpaceFeedCanvasRow.tsx b/products/tasks/frontend/spaces/SpaceFeedCanvasRow.tsx
index 14ccaa805d1f..d9d9ab132e8b 100644
--- a/products/tasks/frontend/spaces/SpaceFeedCanvasRow.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeedCanvasRow.tsx
@@ -38,10 +38,9 @@ export function SpaceFeedCanvasRow({ canvas, listRow }: SpaceFeedCanvasRowProps)
if (listRow) {
return (
- <div className="relative flex h-8 w-full items-center gap-2 rounded-md px-2 transition-colors hover:bg-fill-selected">
- <span aria-hidden className="size-3.5 shrink-0" />
+ <div className="relative flex h-8 w-full items-center gap-2 rounded-md px-2 transition-colors hover:bg-fill-selected has-focus-visible:ring-2 has-focus-visible:ring-ring">
{icon}
- {name('flex-1 text-sm font-medium')}
+ {name('flex-1 text-(length:--text-ui) leading-(--text-ui--line-height) font-medium')}
{avatar}
<Text render={<span />} size="xs" variant="muted" className="w-8 shrink-0 text-right" translate="no">
{age}
@@ -52,10 +51,9 @@ export function SpaceFeedCanvasRow({ canvas, listRow }: SpaceFeedCanvasRowProps)
return (
<Card
size="sm"
- className="relative my-1.5 gap-0 rounded-xl px-4 pt-3.5 pb-3 transition-colors hover:bg-fill-hover"
+ className="relative my-1.5 gap-0 rounded-xl px-4 pt-3.5 pb-3 transition-colors hover:bg-fill-hover has-focus-visible:ring-2 has-focus-visible:ring-ring"
>
<div className="flex min-w-0 items-center gap-3">
- <span aria-hidden className="size-3.5 shrink-0" />
<div className="flex min-w-0 flex-1 items-baseline gap-1.5">
<span className="flex translate-y-0.5">{icon}</span>
{name('text-sm leading-snug font-semibold')}
diff --git a/products/tasks/frontend/spaces/SpaceFeedCard.tsx b/products/tasks/frontend/spaces/SpaceFeedCard.tsx
index d7a4ffd526a6..ee6911d69923 100644
--- a/products/tasks/frontend/spaces/SpaceFeedCard.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeedCard.tsx
@@ -83,18 +83,17 @@ export function SpaceFeedCard({ spaceId, task, pinned, unread, repository }: Spa
const authorName = author ? taskUserName(author) : null
const source = getOriginProductMeta(item.originProduct ?? undefined)
const selection = useSpaceFeedBulkSelection(spaceId)
+ const selected = selection.selectedSessionIds.includes(task.id)
const card = (
<Card
size="sm"
- className="group/card relative my-1.5 gap-0 rounded-xl px-4 pt-3.5 pb-3 transition hover:bg-fill-hover hover:ring-1 hover:ring-input"
+ className={cn(
+ 'group/card relative my-1.5 gap-0 rounded-xl px-4 pt-3.5 pb-3 transition-colors hover:bg-fill-hover has-focus-visible:ring-2 has-focus-visible:ring-ring',
+ selected && 'bg-primary/10 hover:bg-primary/15'
+ )}
>
<div className="flex min-w-0 items-center gap-3">
- <SpaceFeedSelectCheckbox
- spaceId={spaceId}
- sessionId={task.id}
- title={item.title || 'Untitled session'}
- />
{renaming?.sessionId === task.id && renaming.surface === 'feed' ? (
<div className="flex min-w-0 flex-1 items-center gap-1.5">
<SpaceFeedStatusIcon item={item} />
@@ -105,7 +104,14 @@ export function SpaceFeedCard({ spaceId, task, pinned, unread, repository }: Spa
) : (
<div className="flex min-w-0 flex-1 items-baseline gap-1.5">
{/* Nudged down so the icon sits on the title's baseline, like PostHog Desktop's feed cards. */}
- <SpaceFeedStatusIcon item={item} className="translate-y-0.5" />
+ <SpaceFeedSelectCheckbox
+ spaceId={spaceId}
+ sessionId={task.id}
+ title={item.title || 'Untitled session'}
+ className="translate-y-0.5"
+ >
+ <SpaceFeedStatusIcon item={item} />
+ </SpaceFeedSelectCheckbox>
<LinkPrimitive
to={urls.aiTask(task.id)}
className="min-w-0 truncate text-sm leading-snug font-semibold text-foreground after:absolute after:inset-0"
diff --git a/products/tasks/frontend/spaces/SpaceFeedListRow.tsx b/products/tasks/frontend/spaces/SpaceFeedListRow.tsx
index 2f77844f1838..233c5fef5b5f 100644
--- a/products/tasks/frontend/spaces/SpaceFeedListRow.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeedListRow.tsx
@@ -1,7 +1,7 @@
import { useValues } from 'kea'
import { useId } from 'react'
-import { Badge, Spinner, Text, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'
+import { Badge, Spinner, Text, Tooltip, TooltipContent, TooltipTrigger, cn } from '@posthog/quill'
import { LinkPrimitive } from 'lib/lemon-ui/Link'
import { urls } from 'scenes/urls'
@@ -44,11 +44,11 @@ export function SpaceFeedListRow({ spaceId, task, pinned, unread }: SpaceFeedLis
const author = task.created_by
const source = getOriginProductMeta(item.originProduct ?? undefined)
const selection = useSpaceFeedBulkSelection(spaceId)
+ const selected = selection.selectedSessionIds.includes(task.id)
if (renaming?.sessionId === task.id && renaming.surface === 'feed') {
return (
<div className="flex h-8 items-center gap-2 px-2">
- <span aria-hidden className="size-3.5 shrink-0" />
<SpaceFeedStatusIcon item={item} />
<div className="min-w-0 flex-1">
<TodaySessionRenameInput sessionId={task.id} title={task.title} />
@@ -59,16 +59,22 @@ export function SpaceFeedListRow({ spaceId, task, pinned, unread }: SpaceFeedLis
return (
<>
<TodaySessionContextMenu target={menu} surface="feed" selection={selection}>
- <div className="group/row relative flex h-8 w-full items-center gap-2 rounded-md px-2 transition-colors hover:bg-fill-selected">
+ <div
+ className={cn(
+ 'group/row relative flex h-8 w-full items-center gap-2 rounded-md px-2 transition-colors hover:bg-fill-selected has-focus-visible:ring-2 has-focus-visible:ring-ring',
+ selected && 'bg-primary/10 hover:bg-primary/15'
+ )}
+ >
<SpaceFeedSelectCheckbox
spaceId={spaceId}
sessionId={task.id}
title={item.title || 'Untitled session'}
- />
- <SpaceFeedStatusIcon item={item} />
+ >
+ <SpaceFeedStatusIcon item={item} />
+ </SpaceFeedSelectCheckbox>
<LinkPrimitive
to={urls.aiTask(task.id)}
- className="min-w-0 flex-1 truncate text-sm font-medium text-foreground after:absolute after:inset-0"
+ className="min-w-0 flex-1 truncate text-(length:--text-ui) leading-(--text-ui--line-height) font-medium text-foreground after:absolute after:inset-0"
data-attr="today-space-feed-row"
>
{item.title || 'Untitled session'}
diff --git a/products/tasks/frontend/spaces/SpaceFeedPullRequestRow.tsx b/products/tasks/frontend/spaces/SpaceFeedPullRequestRow.tsx
index 02c206a026db..9ebb8ec3c70c 100644
--- a/products/tasks/frontend/spaces/SpaceFeedPullRequestRow.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeedPullRequestRow.tsx
@@ -69,11 +69,10 @@ export function SpaceFeedPullRequestRow({
if (listRow) {
return (
- <div className="relative flex h-8 w-full items-center gap-2 rounded-md px-2 transition-colors hover:bg-fill-selected">
- <span aria-hidden className="size-3.5 shrink-0" />
+ <div className="relative flex h-8 w-full items-center gap-2 rounded-md px-2 transition-colors hover:bg-fill-selected has-focus-visible:ring-2 has-focus-visible:ring-ring">
{icon}
{number}
- {link('flex-1 text-sm font-medium')}
+ {link('flex-1 text-(length:--text-ui) leading-(--text-ui--line-height) font-medium')}
{avatar}
{age && (
<Text
@@ -92,10 +91,9 @@ export function SpaceFeedPullRequestRow({
return (
<Card
size="sm"
- className="relative my-1.5 gap-0 rounded-xl px-4 pt-3.5 pb-3 transition-colors hover:bg-fill-hover"
+ className="relative my-1.5 gap-0 rounded-xl px-4 pt-3.5 pb-3 transition-colors hover:bg-fill-hover has-focus-visible:ring-2 has-focus-visible:ring-ring"
>
<div className="flex min-w-0 items-center gap-3">
- <span aria-hidden className="size-3.5 shrink-0" />
<div className="flex min-w-0 flex-1 items-baseline gap-1.5">
<span className="flex translate-y-0.5">{icon}</span>
{number}
diff --git a/products/tasks/frontend/spaces/SpaceFeedSelectCheckbox.tsx b/products/tasks/frontend/spaces/SpaceFeedSelectCheckbox.tsx
index 37b5401aeeeb..4216484831bc 100644
--- a/products/tasks/frontend/spaces/SpaceFeedSelectCheckbox.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeedSelectCheckbox.tsx
@@ -1,4 +1,5 @@
import { useActions, useValues } from 'kea'
+import { ReactNode } from 'react'
import { Checkbox, cn } from '@posthog/quill'
@@ -8,34 +9,59 @@ interface SpaceFeedSelectCheckboxProps {
spaceId: string
sessionId: string
title: string
+ /** The row's status icon, which the checkbox takes the place of. */
+ children: ReactNode
+ className?: string
}
-/** Picks a session for the feed's bulk actions, like a row checkbox in Gmail. Shift-click picks a range. */
-export function SpaceFeedSelectCheckbox({ spaceId, sessionId, title }: SpaceFeedSelectCheckboxProps): JSX.Element {
+/**
+ * The row's status icon, which turns into a checkbox on hover or focus, and on every row while anything is
+ * selected. Shift-click picks a range.
+ */
+export function SpaceFeedSelectCheckbox({
+ spaceId,
+ sessionId,
+ title,
+ children,
+ className,
+}: SpaceFeedSelectCheckboxProps): JSX.Element {
const { selectedSessionIds } = useValues(spaceFeedSelectionLogic({ id: spaceId }))
const { toggleSessionSelection, selectSessionRange } = useActions(spaceFeedSelectionLogic({ id: spaceId }))
const selecting = selectedSessionIds.length > 0
+ const revealed =
+ 'group-focus-within/card:opacity-100 group-focus-within/row:opacity-100 group-hover/card:opacity-100 group-hover/row:opacity-100'
+ const concealed =
+ 'group-focus-within/card:opacity-0 group-focus-within/row:opacity-0 group-hover/card:opacity-0 group-hover/row:opacity-0'
return (
- <Checkbox
- size="sm"
- checked={selectedSessionIds.includes(sessionId)}
- onCheckedChange={(_, { event }) => {
- if (event instanceof MouseEvent && event.shiftKey) {
- selectSessionRange(sessionId)
- } else {
- toggleSessionSelection(sessionId)
- }
- }}
- onClick={(event) => event.stopPropagation()}
- aria-label={`Select ${title}`}
- // Above the row link's overlay, so a click picks the session instead of opening it.
- className={cn(
- 'z-1 transition-opacity',
- !selecting &&
- 'opacity-0 group-focus-within/card:opacity-100 group-focus-within/row:opacity-100 group-hover/card:opacity-100 group-hover/row:opacity-100'
- )}
- data-attr="today-space-feed-select"
- />
+ <span className={cn('relative flex size-3.5 shrink-0 items-center justify-center', className)}>
+ <span
+ className={cn(
+ 'flex transition-opacity motion-reduce:transition-none',
+ selecting ? 'opacity-0' : concealed
+ )}
+ >
+ {children}
+ </span>
+ <Checkbox
+ size="sm"
+ checked={selectedSessionIds.includes(sessionId)}
+ onCheckedChange={(_, { event }) => {
+ if (event instanceof MouseEvent && event.shiftKey) {
+ selectSessionRange(sessionId)
+ } else {
+ toggleSessionSelection(sessionId)
+ }
+ }}
+ onClick={(event) => event.stopPropagation()}
+ aria-label={`Select ${title}`}
+ // Above the row link's overlay, so a click picks the session instead of opening it.
+ className={cn(
+ 'absolute z-1 transition-opacity motion-reduce:transition-none',
+ !selecting && cn('opacity-0', revealed)
+ )}
+ data-attr="today-space-feed-select"
+ />
+ </span>
)
}
diff --git a/products/tasks/frontend/spaces/SpaceFeedSelectionBar.tsx b/products/tasks/frontend/spaces/SpaceFeedSelectionBar.tsx
index 0cfd467ae093..7950d3749433 100644
--- a/products/tasks/frontend/spaces/SpaceFeedSelectionBar.tsx
+++ b/products/tasks/frontend/spaces/SpaceFeedSelectionBar.tsx
@@ -76,8 +76,9 @@ export function SpaceFeedSelectionBar({ spaceId }: { spaceId: string }): JSX.Ele
{count > 0 ? `${sessionsLabel(count)} selected` : ''}
</span>
{count > 0 && (
+ // Early in the tab order, so the bulk actions are a few Tabs away; shown at the bottom of the feed.
<div
- className="mb-1 flex flex-wrap items-center gap-x-3 gap-y-1 rounded-md bg-fill-selected px-2 py-1"
+ className="sticky bottom-3 z-20 order-last mt-3 flex flex-wrap items-center gap-x-3 gap-y-1 max-w-full self-center rounded-lg border border-border bg-popover px-2 py-1.5 text-popover-foreground shadow-md"
data-attr="today-space-feed-bulk-bar"
>
<div className="flex min-w-0 items-center gap-2">
diff --git a/products/tasks/frontend/spaces/spaceCanvasPreviewsLogic.test.ts b/products/tasks/frontend/spaces/spaceCanvasPreviewsLogic.test.ts
new file mode 100644
index 000000000000..3d1409b7a484
--- /dev/null
+++ b/products/tasks/frontend/spaces/spaceCanvasPreviewsLogic.test.ts
@@ -0,0 +1,99 @@
+import { expectLogic } from 'kea-test-utils'
+
+import { useMocks } from '~/mocks/jest'
+import { initKeaTests } from '~/test/init'
+
+import type { CanvasApi } from 'products/canvas/frontend/generated/api.schemas'
+
+import {
+ SPACE_CANVAS_PREVIEWS_MAX_LOADING,
+ spaceCanvasPreviewKey,
+ spaceCanvasPreviewsLogic,
+} from './spaceCanvasPreviewsLogic'
+
+type ViewMock = [number, Record<string, unknown>]
+
+const readyView = (id: string): ViewMock => [
+ 200,
+ { published_build: { build_status: 'ready', artifact_url: `https://artifacts.example.com/${id}/index.html` } },
+]
+
+describe('spaceCanvasPreviewsLogic', () => {
+ let logic: ReturnType<typeof spaceCanvasPreviewsLogic.build>
+ let viewRequests: string[]
+ let respond: (id: string) => ViewMock
+ let release: () => void
+ let gate: Promise<void>
+
+ beforeEach(() => {
+ viewRequests = []
+ respond = readyView
+ gate = Promise.resolve()
+ useMocks({
+ get: {
+ '/api/projects/:team_id/canvases/:id/view/': async ({ params }) => {
+ const id = String(params.id)
+ viewRequests.push(id)
+ await gate
+ return respond(id)
+ },
+ },
+ })
+ initKeaTests()
+ logic = spaceCanvasPreviewsLogic({ spaceId: 'space-a' })
+ logic.mount()
+ })
+
+ afterEach(() => {
+ logic.unmount()
+ })
+
+ it('loads at most a few previews at once and starts queued ones as others settle', async () => {
+ gate = new Promise((resolve) => {
+ release = resolve
+ })
+ const ids = ['c1', 'c2', 'c3', 'c4', 'c5']
+ for (const id of ids) {
+ logic.actions.requestPreview(`${id}:build`, id)
+ }
+
+ await expectLogic(logic).delay(0)
+ expect(viewRequests).toHaveLength(SPACE_CANVAS_PREVIEWS_MAX_LOADING)
+ expect(logic.values.previews['c5:build'].status).toEqual('queued')
+
+ release()
+ await expectLogic(logic).toFinishAllListeners()
+ expect(viewRequests.sort()).toEqual(ids)
+ expect(logic.values.previews['c5:build']).toEqual({
+ canvasId: 'c5',
+ status: 'ready',
+ artifactUrl: 'https://artifacts.example.com/c5/index.html',
+ })
+ })
+
+ it.each([
+ [
+ 'the build is not ready',
+ (): ViewMock => [200, { published_build: { build_status: 'building', artifact_url: null } }],
+ ],
+ [
+ 'artifact delivery is unavailable',
+ (): ViewMock => [200, { published_build: { build_status: 'ready', artifact_url: null } }],
+ ],
+ ['the view request fails', (): ViewMock => [500, { detail: 'error' }]],
+ ])('falls back to no preview when %s', async (_, response) => {
+ respond = response
+ logic.actions.requestPreview('c1:build', 'c1')
+
+ await expectLogic(logic).toDispatchActions(['previewSettled'])
+ expect(logic.values.previews['c1:build']).toEqual({ canvasId: 'c1', status: 'unavailable', artifactUrl: null })
+ })
+
+ it.each([
+ ['a canvas with no published build', { kind: 'freeform', published_build_id: null }, null],
+ ['a grid canvas', { kind: 'grid', published_build_id: 'b1' }, null],
+ ['a built freeform canvas', { kind: 'freeform', published_build_id: 'b1' }, 'c1:b1'],
+ ])('keys %s for preview', (_, fields, expected) => {
+ expect(spaceCanvasPreviewKey({ id: 'c1', ...fields } as CanvasApi)).toEqual(expected)
+ })
+})
diff --git a/products/tasks/frontend/spaces/spaceCanvasPreviewsLogic.ts b/products/tasks/frontend/spaces/spaceCanvasPreviewsLogic.ts
new file mode 100644
index 000000000000..34bebd2f92bc
--- /dev/null
+++ b/products/tasks/frontend/spaces/spaceCanvasPreviewsLogic.ts
@@ -0,0 +1,149 @@
+import { MakeLogicType, LogicWrapper, actions, connect, kea, key, listeners, path, props, reducers } from 'kea'
+
+import { teamLogic } from 'scenes/teamLogic'
+
+import { canvasesViewRetrieve } from 'products/canvas/frontend/generated/api'
+import type { CanvasApi, CanvasViewResponseApi } from 'products/canvas/frontend/generated/api.schemas'
+
+export const SPACE_CANVAS_PREVIEWS_MAX_LOADING = 3
+
+export type SpaceCanvasPreviewStatus = 'queued' | 'loading' | 'ready' | 'unavailable'
+
+export interface SpaceCanvasPreview {
+ canvasId: string
+ status: SpaceCanvasPreviewStatus
+ artifactUrl: string | null
+}
+
+export interface SpaceCanvasPreviewsLogicProps {
+ spaceId: string
+}
+
+/** Null when the canvas has nothing a preview can render, so the card never asks for one. */
+export function spaceCanvasPreviewKey(canvas: CanvasApi): string | null {
+ if (canvas.kind === 'grid' || !canvas.published_build_id) {
+ return null
+ }
+ return `${canvas.id}:${canvas.published_build_id}`
+}
+
+export function spaceCanvasPreviewUrl(view: CanvasViewResponseApi): string | null {
+ const build = view.published_build
+ return build?.build_status === 'ready' ? (build.artifact_url ?? null) : null
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface spaceCanvasPreviewsLogicValues {
+ currentTeamId: number | null // teamLogic
+ previews: Record<string, SpaceCanvasPreview>
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface spaceCanvasPreviewsLogicActions {
+ previewSettled: (
+ previewKey: string,
+ artifactUrl: string | null
+ ) => {
+ artifactUrl: string | null
+ previewKey: string
+ }
+ previewStarted: (
+ previewKey: string,
+ canvasId: string
+ ) => {
+ canvasId: string
+ previewKey: string
+ }
+ requestPreview: (
+ previewKey: string,
+ canvasId: string
+ ) => {
+ canvasId: string
+ previewKey: string
+ }
+ startQueuedPreviews: () => {
+ value: true
+ }
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface spaceCanvasPreviewsLogicMeta {
+ key: string
+}
+
+export type spaceCanvasPreviewsLogicType = MakeLogicType<
+ spaceCanvasPreviewsLogicValues,
+ spaceCanvasPreviewsLogicActions,
+ SpaceCanvasPreviewsLogicProps,
+ spaceCanvasPreviewsLogicMeta
+>
+
+export const spaceCanvasPreviewsLogic: LogicWrapper<spaceCanvasPreviewsLogicType> = kea<spaceCanvasPreviewsLogicType>([
+ props({} as SpaceCanvasPreviewsLogicProps),
+ key((props) => props.spaceId),
+ path((spaceId) => ['products', 'tasks', 'spaces', 'spaceCanvasPreviewsLogic', spaceId]),
+ connect(() => ({ values: [teamLogic, ['currentTeamId']] })),
+ actions({
+ requestPreview: (previewKey: string, canvasId: string) => ({ previewKey, canvasId }),
+ previewStarted: (previewKey: string, canvasId: string) => ({ previewKey, canvasId }),
+ previewSettled: (previewKey: string, artifactUrl: string | null) => ({ previewKey, artifactUrl }),
+ startQueuedPreviews: true,
+ }),
+ reducers({
+ previews: [
+ {} as Record<string, SpaceCanvasPreview>,
+ {
+ requestPreview: (state, { previewKey, canvasId }) =>
+ state[previewKey]
+ ? state
+ : { ...state, [previewKey]: { canvasId, status: 'queued', artifactUrl: null } },
+ previewStarted: (state, { previewKey, canvasId }) => ({
+ ...state,
+ [previewKey]: { canvasId, status: 'loading', artifactUrl: null },
+ }),
+ previewSettled: (state, { previewKey, artifactUrl }) =>
+ state[previewKey]
+ ? {
+ ...state,
+ [previewKey]: {
+ ...state[previewKey],
+ status: artifactUrl ? 'ready' : 'unavailable',
+ artifactUrl,
+ },
+ }
+ : state,
+ },
+ ],
+ }),
+ listeners(({ actions, values }) => ({
+ requestPreview: () => actions.startQueuedPreviews(),
+ previewSettled: () => actions.startQueuedPreviews(),
+ startQueuedPreviews: () => {
+ const entries = Object.entries(values.previews)
+ let free =
+ SPACE_CANVAS_PREVIEWS_MAX_LOADING - entries.filter(([, preview]) => preview.status === 'loading').length
+ for (const [previewKey, preview] of entries) {
+ if (free <= 0) {
+ return
+ }
+ if (preview.status === 'queued') {
+ free -= 1
+ actions.previewStarted(previewKey, preview.canvasId)
+ }
+ }
+ },
+ previewStarted: async ({ previewKey, canvasId }) => {
+ let artifactUrl: string | null = null
+ try {
+ if (values.currentTeamId) {
+ artifactUrl = spaceCanvasPreviewUrl(
+ await canvasesViewRetrieve(String(values.currentTeamId), canvasId)
+ )
+ }
+ } catch {
+ artifactUrl = null
+ }
+ actions.previewSettled(previewKey, artifactUrl)
+ },
+ })),
+])