🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(ui): enable text selection in formatted view value column (#10672)
Michael Fröhlicha041c9ba7b86
diff --git a/web/src/components/table/ValueCell.tsx b/web/src/components/table/ValueCell.tsxindex ec91c28fa7..a5cb6f42d8 100644--- a/web/src/components/table/ValueCell.tsx+++ b/web/src/components/table/ValueCell.tsx@@ -277,7 +277,7 @@ export const ValueCell = memo(return (<div className={`${MONO_TEXT_CLASSES} group relative max-w-full`}>- {content}+ <span className="cursor-text">{content}</span>{needsTruncation && !row.original.hasChildren && (<divclassName="inline cursor-pointer opacity-50"@@ -296,7 +296,7 @@ export const ValueCell = memo(<Buttonvariant="ghost"size="icon"- className="absolute right-0 top-1/2 h-5 w-5 -translate-y-1/2 border bg-background/80 p-0.5 opacity-0 shadow-sm transition-opacity duration-200 hover:bg-background group-hover:opacity-100"+ className="absolute right-0 top-0 h-5 w-5 border bg-background/80 p-0.5 opacity-0 shadow-sm transition-opacity duration-200 hover:bg-background group-hover:opacity-100"onClick={handleCopy}title="Copy value"aria-label="Copy cell value"diff --git a/web/src/components/ui/PrettyJsonView.tsx b/web/src/components/ui/PrettyJsonView.tsxindex 48d15560e5..fddbf31722 100644--- a/web/src/components/ui/PrettyJsonView.tsx+++ b/web/src/components/ui/PrettyJsonView.tsx@@ -1,4 +1,4 @@-import { useMemo, useState, useEffect, useRef, useCallback } from "react";+import { useMemo, useState, useEffect, useRef, useCallback, memo } from "react";import { cn } from "@/src/utils/tailwind";import { deepParseJson } from "@langfuse/shared";import { Skeleton } from "@/src/components/ui/skeleton";@@ -8,6 +8,7 @@ import { MarkdownJsonViewHeader } from "@/src/components/ui/MarkdownJsonView";import { copyTextToClipboard } from "@/src/utils/clipboard";import { JSONView } from "@/src/components/ui/CodeJsonViewer";import { Button } from "@/src/components/ui/button";+import { useClickWithoutSelection } from "@/src/hooks/useClickWithoutSelection";import {ChevronDown,ChevronRight,@@ -337,6 +338,82 @@ function handleRowExpansion(}}+interface JsonTableRowProps {+ row: Row<JsonTableRow>;+ rowIndex: number;+ topLevelRowRef?: React.RefObject<HTMLTableRowElement | null>;+ onLazyLoadChildren?: (rowId: string) => void;+ expandedCells: Set<string>;+ toggleCellExpansion: (cellId: string) => void;+ stickyTopLevelKey: boolean;+ stickyOffsets: { header: number; row: number };+}++const JsonTableRowComponent = memo(+ ({+ row,+ rowIndex,+ topLevelRowRef,+ onLazyLoadChildren,+ expandedCells,+ toggleCellExpansion,+ stickyTopLevelKey,+ stickyOffsets,+ }: JsonTableRowProps) => {+ // Hook is now at top level of this component ✅+ const isExpandable =+ row.original.hasChildren ||+ getValueStringLength(row.original.value) > MAX_CELL_DISPLAY_CHARS;++ const { props: rowClickProps } = useClickWithoutSelection({+ onClick: () => {+ handleRowExpansion(+ row,+ onLazyLoadChildren,+ expandedCells,+ toggleCellExpansion,+ );+ },+ enabled: isExpandable,+ });++ return (+ <TableRow+ ref={+ rowIndex === 0 && row.original.level === 0+ ? topLevelRowRef+ : undefined+ }+ data-observation-id={row.id}+ {...rowClickProps}+ className={cn(+ isExpandable ? "cursor-pointer" : "",+ row.original.level === 0 && stickyTopLevelKey+ ? "sticky z-10 bg-background shadow-sm"+ : "",+ )}+ style={+ row.original.level === 0 && stickyTopLevelKey+ ? { top: `${stickyOffsets.header}px` }+ : undefined+ }+ >+ {row.getVisibleCells().map((cell) => (+ <TableCell+ key={cell.id}+ className="whitespace-normal px-2 py-1 align-top"+ style={{ width: `${cell.column.columnDef.size}%` }}+ >+ {flexRender(cell.column.columnDef.cell, cell.getContext())}+ </TableCell>+ ))}+ </TableRow>+ );+ },+);++JsonTableRowComponent.displayName = "JsonTableRow";+function JsonPrettyTable({data,expandAllRef,@@ -448,7 +525,7 @@ function JsonPrettyTable({)}</div><span- className={`ml-1 ${MONO_TEXT_CLASSES} font-medium`}+ className={`ml-1 ${MONO_TEXT_CLASSES} cursor-text font-medium`}style={{ maxWidth: availableTextWidth }}>{itemBadgeType && (@@ -640,51 +717,21 @@ function JsonPrettyTable({</TableHeader><TableBody>{table.getRowModel().rows.map((row, rowIndex) => (- <TableRow+ <JsonTableRowComponentkey={row.id}- ref={+ row={row}+ rowIndex={rowIndex}+ topLevelRowRef={rowIndex === 0 && row.original.level === 0? topLevelRowRef: undefined}- data-observation-id={row.id}- onClick={() =>- handleRowExpansion(- row,- onLazyLoadChildren,- expandedCells,- toggleCellExpansion,- )- }- className={cn(- row.original.hasChildren ||- (!row.original.hasChildren &&- row.original.type !== "array" &&- row.original.type !== "object" &&- getValueStringLength(row.original.value) >- MAX_CELL_DISPLAY_CHARS)- ? "cursor-pointer"- : "",- row.original.level === 0 && stickyTopLevelKey- ? "sticky z-10 bg-background shadow-sm"- : "",- )}- style={- row.original.level === 0 && stickyTopLevelKey- ? { top: `${stickyOffsets.header}px` }- : undefined- }- >- {row.getVisibleCells().map((cell) => (- <TableCell- key={cell.id}- className="whitespace-normal px-2 py-1 align-top"- style={{ width: `${cell.column.columnDef.size}%` }}- >- {flexRender(cell.column.columnDef.cell, cell.getContext())}- </TableCell>- ))}- </TableRow>+ onLazyLoadChildren={onLazyLoadChildren}+ expandedCells={expandedCells}+ toggleCellExpansion={toggleCellExpansion}+ stickyTopLevelKey={stickyTopLevelKey}+ stickyOffsets={stickyOffsets}+ />))}</TableBody></Table>diff --git a/web/src/hooks/useClickWithoutSelection.ts b/web/src/hooks/useClickWithoutSelection.tsnew file mode 100644index 0000000000..d170805d7b--- /dev/null+++ b/web/src/hooks/useClickWithoutSelection.ts@@ -0,0 +1,119 @@+import { useRef, useCallback, type MouseEvent } from "react";++interface UseClickWithoutSelectionOptions {+ /**+ * Callback to execute when a click is detected (not a text selection drag)+ */+ onClick: (event: MouseEvent) => void;++ /**+ * Distance threshold in pixels to distinguish click from drag+ * @default 5+ */+ dragThreshold?: number;++ /**+ * Whether the hook is enabled+ * @default true+ */+ enabled?: boolean;+}++interface UseClickWithoutSelectionReturn {+ /**+ * Props to spread onto the element+ */+ props: {+ onMouseDown: (e: MouseEvent) => void;+ onClick: (e: MouseEvent) => void;+ };+}++/**+ * Hook to distinguish between clicks and text selection drags.+ * Returns props to spread onto an element that should be clickable+ * but also allow text selection within it.+ *+ * Uses two detection mechanisms:+ * 1. Position-based: Tracks mouse movement between mousedown and click+ * 2. Selection API: Checks if text was selected within the element+ *+ * @example+ * ```tsx+ * const { props } = useClickWithoutSelection({+ * onClick: () => handleExpand(),+ * });+ *+ * return <div {...props}>Clickable content with selectable text</div>+ * ```+ */+export function useClickWithoutSelection({+ onClick,+ dragThreshold = 5,+ enabled = true,+}: UseClickWithoutSelectionOptions): UseClickWithoutSelectionReturn {+ const mouseDownPosRef = useRef<{ x: number; y: number } | null>(null);++ const handleMouseDown = useCallback(+ (e: MouseEvent) => {+ if (!enabled) return;++ // Only track left mouse button+ if (e.button === 0) {+ mouseDownPosRef.current = { x: e.clientX, y: e.clientY };+ }+ },+ [enabled],+ );++ const handleClick = useCallback(+ (e: MouseEvent) => {+ if (!enabled) {+ onClick(e);+ return;+ }++ // Check 1: Position-based drag detection+ let wasDrag = false;+ if (mouseDownPosRef.current) {+ const dx = e.clientX - mouseDownPosRef.current.x;+ const dy = e.clientY - mouseDownPosRef.current.y;+ const distance = Math.sqrt(dx * dx + dy * dy);+ wasDrag = distance > dragThreshold;+ mouseDownPosRef.current = null;+ }++ if (wasDrag) {+ return; // Mouse moved significantly - was a selection drag+ }++ // Check 2: Selection API detection+ const selection = window.getSelection();+ if (selection && selection.toString().length > 0) {+ try {+ const range = selection.getRangeAt(0);+ const targetElement = e.currentTarget as HTMLElement;++ // Only ignore click if selection is within this element+ if (targetElement.contains(range.commonAncestorContainer)) {+ return; // User just selected text in this element+ }+ } catch {+ // getRangeAt can throw if no range exists+ // Fall through to onClick+ }+ }++ // Passed all checks - this was a genuine click+ onClick(e);+ },+ [enabled, onClick, dragThreshold],+ );++ return {+ props: {+ onMouseDown: handleMouseDown,+ onClick: handleClick,+ },+ };+}