: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(conversations): add hover preview of ticket thread in tickets list (#72519)
Luke Beltond464b36e6faa
diff --git a/products/conversations/frontend/components/TicketPreview/TicketPreviewPopover.tsx b/products/conversations/frontend/components/TicketPreview/TicketPreviewPopover.tsxnew file mode 100644index 000000000000..5afdd024c907--- /dev/null+++ b/products/conversations/frontend/components/TicketPreview/TicketPreviewPopover.tsx@@ -0,0 +1,115 @@+import { useValues } from 'kea'+import { useEffect, useRef, useState } from 'react'++import { IconLock } from '@posthog/icons'+import { Spinner } from '@posthog/lemon-ui'++import { TZLabel } from 'lib/components/TZLabel'+import { Popover } from 'lib/lemon-ui/Popover'+import { stripMarkdown } from 'lib/utils/markdown'++import type { TicketMessageApi } from '../../generated/api.schemas'+import { ticketPreviewLogic } from './ticketPreviewLogic'++function TicketPreviewMessage({ message }: { message: TicketMessageApi }): JSX.Element {+ return (+ <div className="flex flex-col gap-0.5">+ <div className="flex items-center gap-1.5">+ <span className="font-semibold text-xs">{message.author_name}</span>+ {message.is_private && (+ <span className="inline-flex items-center gap-0.5 text-xs text-warning-dark bg-warning-highlight px-1.5 py-0.5 rounded">+ <IconLock className="text-xs" />+ Private note+ </span>+ )}+ <span className="text-xs text-muted-alt">+ <TZLabel time={message.created_at} showPopover={false} />+ </span>+ </div>+ <p className="text-xs whitespace-pre-line line-clamp-4 mb-0">{stripMarkdown(message.content)}</p>+ </div>+ )+}++export function TicketPreviewContent({ ticketId }: { ticketId: string }): JSX.Element {+ const { preview, previewLoading } = useValues(ticketPreviewLogic({ ticketId }))++ if (previewLoading && !preview) {+ return (+ <div className="flex items-center gap-2 p-3">+ <Spinner />+ <span className="text-xs">Loading messages…</span>+ </div>+ )+ }++ if (preview?.error) {+ return <span className="text-xs text-muted-alt block p-3">Couldn't load messages</span>+ }++ if (!preview || preview.firstMessages.length === 0) {+ return <span className="text-xs text-muted-alt block p-3">No messages in this ticket yet</span>+ }++ return (+ <div className="flex flex-col gap-2 p-3 max-w-100">+ {preview.firstMessages.map((message) => (+ <TicketPreviewMessage key={message.id} message={message} />+ ))}+ {preview.lastMessage && (+ <>+ {preview.hiddenCount > 0 && (+ <div className="flex items-center gap-2 text-xs text-muted-alt">+ <div className="flex-1 border-t border-primary" />+ <span className="shrink-0">+ {preview.hiddenCount} more {preview.hiddenCount === 1 ? 'message' : 'messages'}+ </span>+ <div className="flex-1 border-t border-primary" />+ </div>+ )}+ <TicketPreviewMessage message={preview.lastMessage} />+ </>+ )}+ </div>+ )+}++/**+ * Wraps table cell content with a hover card previewing the ticket's thread,+ * starting from its first message. Built on Popover so the card renders on the+ * normal app-theme surface (readable in both light and dark mode). Messages are+ * fetched lazily on first hover — Popover only mounts its overlay once visible.+ */+export function TicketPreviewPopover({ ticketId, children }: { ticketId: string; children: JSX.Element }): JSX.Element {+ const [visible, setVisible] = useState(false)+ const hoverTimerRef = useRef<ReturnType<typeof setTimeout>>()++ useEffect(() => () => clearTimeout(hoverTimerRef.current), [])++ const showPreview = (): void => {+ clearTimeout(hoverTimerRef.current)+ // Hover-intent delay avoids popover spam while sweeping across table rows.+ hoverTimerRef.current = setTimeout(() => setVisible(true), 300)+ }++ const hidePreview = (): void => {+ clearTimeout(hoverTimerRef.current)+ // Grace period so the mouse can travel from the cell into the card.+ hoverTimerRef.current = setTimeout(() => setVisible(false), 300)+ }++ return (+ <Popover+ visible={visible}+ placement="bottom-start"+ showArrow+ onMouseEnterInside={showPreview}+ onMouseLeaveInside={hidePreview}+ overlay={<TicketPreviewContent ticketId={ticketId} />}+ >+ <span onMouseEnter={showPreview} onMouseLeave={hidePreview}>+ {children}+ </span>+ </Popover>+ )+}diff --git a/products/conversations/frontend/components/TicketPreview/ticketPreviewLogic.ts b/products/conversations/frontend/components/TicketPreview/ticketPreviewLogic.tsnew file mode 100644index 000000000000..13df14b4f659--- /dev/null+++ b/products/conversations/frontend/components/TicketPreview/ticketPreviewLogic.ts@@ -0,0 +1,113 @@+import { MakeLogicType, afterMount, kea, key, path, props } from 'kea'+import { loaders } from 'kea-loaders'+import posthog from 'posthog-js'++import { getCurrentTeamId } from 'lib/utils/getAppContext'++import { conversationsTicketsMessagesList } from '../../generated/api'+import type { TicketMessageApi } from '../../generated/api.schemas'++export interface TicketPreviewLogicProps {+ ticketId: string+}++export interface TicketPreview {+ firstMessages: TicketMessageApi[]+ // The newest message in the thread, shown after the truncation divider. Null when the+ // whole thread already fits in firstMessages.+ lastMessage: TicketMessageApi | null+ // How many messages sit between firstMessages and lastMessage (the "+N more" count).+ hiddenCount: number+ // True when the fetch failed, so the card can distinguish an error from an empty thread.+ error: boolean+}++/** How many of the ticket's first messages the hover preview shows. */+export const TICKET_PREVIEW_MESSAGE_COUNT = 3++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface ticketPreviewLogicValues {+ preview: TicketPreview | null+ previewLoading: boolean+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface ticketPreviewLogicActions {+ loadPreview: () => any+ loadPreviewFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadPreviewSuccess: (+ preview: TicketPreview,+ payload?: any+ ) => {+ preview: TicketPreview+ payload?: any+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface ticketPreviewLogicMeta {+ key: string+}++export type ticketPreviewLogicType = MakeLogicType<+ ticketPreviewLogicValues,+ ticketPreviewLogicActions,+ TicketPreviewLogicProps,+ ticketPreviewLogicMeta+>++export const ticketPreviewLogic = kea<ticketPreviewLogicType>([+ props({} as TicketPreviewLogicProps),+ key((props) => props.ticketId),+ path((key) => ['products', 'conversations', 'frontend', 'components', 'TicketPreview', 'ticketPreviewLogic', key]),++ loaders(({ props }) => ({+ preview: [+ null as TicketPreview | null,+ {+ loadPreview: async (): Promise<TicketPreview> => {+ try {+ const teamId = String(getCurrentTeamId())+ const first = await conversationsTicketsMessagesList(teamId, props.ticketId, {+ limit: TICKET_PREVIEW_MESSAGE_COUNT,+ })++ // Short threads fit entirely in the first batch, so there's no tail to fetch.+ if (first.count <= TICKET_PREVIEW_MESSAGE_COUNT) {+ return { firstMessages: first.results, lastMessage: null, hiddenCount: 0, error: false }+ }++ // The thread is oldest-first with no reverse ordering, so the newest message is+ // the last page. Fetch a short window at the tail and take its last item: if a+ // reply lands between the two requests, the stale offset lands one short and the+ // window still includes the real newest message. Truncation uses the tail+ // response's own (fresher) count, not the first request's.+ const tail = await conversationsTicketsMessagesList(teamId, props.ticketId, {+ limit: 2,+ offset: first.count - 1,+ })+ const lastMessage = tail.results[tail.results.length - 1] ?? null+ const hiddenCount = Math.max(0, tail.count - first.results.length - (lastMessage ? 1 : 0))++ return { firstMessages: first.results, lastMessage, hiddenCount, error: false }+ } catch (e) {+ posthog.captureException(e)+ return { firstMessages: [], lastMessage: null, hiddenCount: 0, error: true }+ }+ },+ },+ ],+ })),++ afterMount(({ actions, values }) => {+ if (!values.preview && !values.previewLoading) {+ actions.loadPreview()+ }+ }),+])diff --git a/products/conversations/frontend/scenes/tickets/ticketColumns.tsx b/products/conversations/frontend/scenes/tickets/ticketColumns.tsxindex a0c276d0273d..76b43ae244f7 100644--- a/products/conversations/frontend/scenes/tickets/ticketColumns.tsx+++ b/products/conversations/frontend/scenes/tickets/ticketColumns.tsx@@ -12,6 +12,7 @@ import { AssigneeDisplay, AssigneeResolver } from '../../components/Assignee'import { ChannelsTag } from '../../components/Channels/ChannelsTag'import { IdentityBadge } from '../../components/IdentityBadge/IdentityBadge'import { SlaDisplay } from '../../components/SlaDisplay'+import { TicketPreviewPopover } from '../../components/TicketPreview/TicketPreviewPopover'import {type Ticket,aiTriageProcessingLabel,@@ -98,14 +99,16 @@ const TICKET_COLUMNS: Record<TicketColumnKey, TicketColumnDefinition> = {render: (_, ticket) => (<div className="flex items-center gap-2">{ticket.last_message_text ? (- <span- className={clsx('text-xs truncate max-w-md', {- 'text-muted-alt': ticket.unread_team_count === 0,- 'font-medium': ticket.unread_team_count > 0,- })}- >- {stripMarkdown(ticket.last_message_text)}- </span>+ <TicketPreviewPopover ticketId={ticket.id}>+ <span+ className={clsx('text-xs truncate max-w-md', {+ 'text-muted-alt': ticket.unread_team_count === 0,+ 'font-medium': ticket.unread_team_count > 0,+ })}+ >+ {stripMarkdown(ticket.last_message_text)}+ </span>+ </TicketPreviewPopover>) : (<span className="text-muted-alt text-xs">—</span>)}