Skip to content

Commit dd8d3d4

Browse files
committed
feat(webapp): only leaf values are selectable in the sample tree
Object and array rows in the smart-column sample now only expand and collapse; only leaf values fill the path when clicked, since a column renders a single value. Drill into a container to pick a leaf inside it (e.g. an array element, or a key within an array element).
1 parent 8604a03 commit dd8d3d4

2 files changed

Lines changed: 27 additions & 42 deletions

File tree

apps/webapp/app/components/runs/v3/AddSmartColumnDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ export function AddSmartColumnDialog({
222222
onSelectPath={setPath}
223223
/>
224224
<Paragraph variant="extra-small" className="text-text-dimmed">
225-
Click a key to use its path.
225+
Click a value to use its path. Expand objects and arrays to reach the value you
226+
want.
226227
</Paragraph>
227228
</>
228229
)}

apps/webapp/app/components/runs/v3/SmartColumnSample.tsx

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ const AUTO_OPEN_DEPTH = 2;
88
const MAX_STRING = 80;
99

1010
/**
11-
* A clickable, syntax-colored JSON tree for the smart-column sample. Clicking a
12-
* key (or array index) fills the JSON path field via `onSelectPath`; the value
13-
* currently at `activePath` is highlighted.
11+
* A clickable, syntax-colored JSON tree for the smart-column sample. Only leaf
12+
* values are selectable: clicking one fills the JSON path field via
13+
* `onSelectPath` and highlights it. Object/array rows only expand and collapse,
14+
* so you drill into a container and pick a leaf inside it.
1415
*/
1516
export function SmartColumnSample({
1617
value,
@@ -59,39 +60,23 @@ function JsonNode({
5960
const [open, setOpen] = useState(depth < AUTO_OPEN_DEPTH);
6061
const isObject = value !== null && typeof value === "object";
6162
const selected = path === activePath;
63+
const keyLabel = name === undefined ? null : typeof name === "number" ? name : `"${name}"`;
6264

63-
const keyButton =
64-
name !== undefined ? (
65-
<button
66-
type="button"
67-
onClick={() => onSelectPath(path)}
68-
className={cn(
69-
"rounded px-0.5 text-sky-300 hover:bg-blue-500/20",
70-
selected && "bg-blue-500/30 text-sky-200"
71-
)}
72-
>
73-
{typeof name === "number" ? name : `"${name}"`}
74-
</button>
75-
) : depth === 0 && !isObject ? (
65+
if (!isObject) {
66+
const target = name === undefined ? "$" : path;
67+
return (
7668
<button
7769
type="button"
78-
onClick={() => onSelectPath("$")}
70+
onClick={() => onSelectPath(target)}
7971
className={cn(
80-
"rounded px-0.5 text-text-dimmed hover:bg-blue-500/20",
81-
selected && "bg-blue-500/30"
72+
"flex w-full items-baseline whitespace-pre rounded px-0.5 text-left hover:bg-blue-500/15",
73+
selected && "bg-blue-500/25"
8274
)}
8375
>
84-
$
85-
</button>
86-
) : null;
87-
88-
if (!isObject) {
89-
return (
90-
<div className="whitespace-pre">
91-
{keyButton}
92-
{keyButton && <span className="text-text-dimmed">: </span>}
76+
{keyLabel !== null && <span className="text-sky-300">{keyLabel}</span>}
77+
{keyLabel !== null && <span className="text-text-dimmed">: </span>}
9378
<PrimitiveValue value={value} />
94-
</div>
79+
</button>
9580
);
9681
}
9782

@@ -105,25 +90,24 @@ function JsonNode({
10590

10691
return (
10792
<div>
108-
<div className="flex items-start whitespace-pre">
109-
<button
110-
type="button"
111-
onClick={() => setOpen((o) => !o)}
112-
aria-label={open ? "Collapse" : "Expand"}
113-
className="mr-1 w-3 shrink-0 text-text-dimmed hover:text-text-bright"
114-
>
115-
{open ? "▾" : "▸"}
116-
</button>
117-
{keyButton}
118-
{keyButton && <span className="text-text-dimmed">: </span>}
93+
<button
94+
type="button"
95+
onClick={() => setOpen((o) => !o)}
96+
aria-label={open ? "Collapse" : "Expand"}
97+
aria-expanded={open}
98+
className="flex w-full items-start whitespace-pre rounded px-0.5 text-left hover:bg-charcoal-750"
99+
>
100+
<span className="mr-1 w-3 shrink-0 text-text-dimmed">{open ? "▾" : "▸"}</span>
101+
{keyLabel !== null && <span className="text-sky-300">{keyLabel}</span>}
102+
{keyLabel !== null && <span className="text-text-dimmed">: </span>}
119103
<span className="text-text-dimmed">
120104
{openBrace}
121105
{!open && `… ${closeBrace}`}
122106
{!open && entries.length > 0 && (
123107
<span className="ml-1 text-faint">{`${entries.length} ${isArray ? "items" : "keys"}`}</span>
124108
)}
125109
</span>
126-
</div>
110+
</button>
127111
{open && (
128112
<div className="ml-[0.4rem] border-l border-grid-dimmed/50 pl-3">
129113
{shown.map(([key, childValue]) => (

0 commit comments

Comments
 (0)