Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(filters): surface selected options at the top of the filter sidebar (#14529)

Nikita Kabardin216d422635f5
diff --git a/web/src/components/table/data-table-controls.clienttest.tsx b/web/src/components/table/data-table-controls.clienttest.tsx
index f6cf17603d..81a532e3c3 100644
--- a/web/src/components/table/data-table-controls.clienttest.tsx
+++ b/web/src/components/table/data-table-controls.clienttest.tsx
@@ -47,4 +47,130 @@ describe("CategoricalFacet", () => {
expect(screen.getByLabelText("Clear Type filter")).toBeInTheDocument();
});
+
+ it("pins a selected option to the top of a long list so it is visible without 'Show more'", () => {
+ // 20 options, one selected near the bottom. Without pinning the selected
+ // value sits below the 12-item cap and is hidden behind "Show more".
+ const options = Array.from({ length: 20 }, (_, i) => `opt-${i}`);
+ render(
+ <Accordion type="multiple" value={["c"]}>
+ <CategoricalFacet
+ label="C"
+ filterKey="c"
+ expanded
+ loading={false}
+ options={options}
+ counts={new Map()}
+ value={["opt-18"]}
+ onChange={() => {}}
+ isActive
+ isDisabled={false}
+ onReset={() => {}}
+ />
+ </Accordion>,
+ );
+
+ // The list is long enough to be capped...
+ expect(
+ screen.getByRole("button", { name: "Show more values" }),
+ ).toBeInTheDocument();
+
+ // ...yet the selected value is shown despite sitting at position 19,
+ // and it precedes the first unselected option in DOM order (pinned to top).
+ const selected = screen.getByText("opt-18");
+ const firstUnselected = screen.getByText("opt-0");
+ expect(selected).toBeInTheDocument();
+ expect(
+ selected.compareDocumentPosition(firstUnselected) &
+ Node.DOCUMENT_POSITION_FOLLOWING,
+ ).toBeTruthy();
+ });
+
+ it("keeps the 'Show more' cap when every option is reported selected (no-filter default)", () => {
+ // useSidebarFilterState returns value === options when no filter is applied
+ // (computeSelectedValues). That all-selected default must NOT be treated as
+ // a pinned selection — doing so would render the entire list with no cap.
+ const options = Array.from({ length: 20 }, (_, i) => `opt-${i}`);
+ render(
+ <Accordion type="multiple" value={["c"]}>
+ <CategoricalFacet
+ label="C"
+ filterKey="c"
+ expanded
+ loading={false}
+ options={options}
+ counts={new Map()}
+ value={options}
+ onChange={() => {}}
+ isActive={false}
+ isDisabled={false}
+ onReset={() => {}}
+ />
+ </Accordion>,
+ );
+
+ // The cap is preserved: "Show more" still renders and a deep value stays hidden.
+ expect(
+ screen.getByRole("button", { name: "Show more values" }),
+ ).toBeInTheDocument();
+ expect(screen.queryByText("opt-19")).not.toBeInTheDocument();
+ });
+
+ it("never bypasses the cap, even for a large selection", () => {
+ // A large selection (e.g. a "none of" include-set) must still respect the
+ // visible-count cap rather than dumping every value into the DOM.
+ const options = Array.from({ length: 20 }, (_, i) => `opt-${i}`);
+ const selected = options.slice(0, 18); // 18 of 20 selected
+ render(
+ <Accordion type="multiple" value={["c"]}>
+ <CategoricalFacet
+ label="C"
+ filterKey="c"
+ expanded
+ loading={false}
+ options={options}
+ counts={new Map()}
+ value={selected}
+ onChange={() => {}}
+ isActive
+ isDisabled={false}
+ onReset={() => {}}
+ />
+ </Accordion>,
+ );
+
+ expect(
+ screen.getByRole("button", { name: "Show more values" }),
+ ).toBeInTheDocument();
+ // Only the capped number of rows render, not all 18 selected.
+ expect(screen.getAllByRole("checkbox").length).toBeLessThanOrEqual(12);
+ });
+
+ it("does not reorder short, fully-visible lists", () => {
+ render(
+ <Accordion type="multiple" value={["c"]}>
+ <CategoricalFacet
+ label="C"
+ filterKey="c"
+ expanded
+ loading={false}
+ options={["a", "b", "c"]}
+ counts={new Map()}
+ value={["c"]}
+ onChange={() => {}}
+ isActive
+ isDisabled={false}
+ onReset={() => {}}
+ />
+ </Accordion>,
+ );
+
+ // No cap, no "Show more": the natural order is preserved (a, b, c) — the
+ // selected "c" is NOT pulled above "a".
+ const a = screen.getByText("a");
+ const c = screen.getByText("c");
+ expect(
+ a.compareDocumentPosition(c) & Node.DOCUMENT_POSITION_FOLLOWING,
+ ).toBeTruthy();
+ });
});
diff --git a/web/src/components/table/data-table-controls.tsx b/web/src/components/table/data-table-controls.tsx
index ea1cc61e8e..737340e4af 100644
--- a/web/src/components/table/data-table-controls.tsx
+++ b/web/src/components/table/data-table-controls.tsx
@@ -650,10 +650,67 @@ export function CategoricalFacet({
})
: visibleOptionValues;
- const hasMoreFilteredOptions = filteredOptions.length > MAX_VISIBLE_OPTIONS;
+ // Order a genuine selection to the top of the list so an applied filter is
+ // immediately visible — without scrolling or expanding "Show more" — even
+ // when the selected value sits far down a long list (LFE-10494).
+ //
+ // Two guards keep this honest:
+ // 1. Only reorder long lists (more options than the cap) that carry a real,
+ // strict-subset selection. `value` mirrors the hook's
+ // `computeSelectedValues`, which reports EVERY option as "selected" when
+ // no filter is applied (and the inverted set for `none of`). Requiring a
+ // strict subset skips that all-selected default — otherwise the whole
+ // list would be treated as pinned — and leaves short lists untouched.
+ // 2. The visible-count cap is applied to the COMBINED ordered list, so even
+ // a large selection (many values, or a `none of` include-set) can never
+ // render the entire list; "Show more" still gates the overflow.
+ const selectedSet = new Set(value);
+ const pinSelected =
+ hasMoreOptions &&
+ value.length > 0 &&
+ value.length < visibleOptionValues.length;
+ const orderedOptions = pinSelected
+ ? [
+ ...filteredOptions.filter((option) => selectedSet.has(option)),
+ ...filteredOptions.filter((option) => !selectedSet.has(option)),
+ ]
+ : filteredOptions;
+
+ const hasMoreFilteredOptions = orderedOptions.length > MAX_VISIBLE_OPTIONS;
const visibleOptions = showAll
- ? filteredOptions
- : filteredOptions.slice(0, MAX_VISIBLE_OPTIONS);
+ ? orderedOptions
+ : orderedOptions.slice(0, MAX_VISIBLE_OPTIONS);
+
+ // Split the visible slice so a separator can mark where the pinned selection
+ // ends. When not pinning, everything renders in natural order (no divider).
+ const visibleSelectedOptions = pinSelected
+ ? visibleOptions.filter((option) => selectedSet.has(option))
+ : [];
+ const visibleRemainingOptions = pinSelected
+ ? visibleOptions.filter((option) => !selectedSet.has(option))
+ : visibleOptions;
+
+ const renderOption = (option: string) => {
+ const displayLabel = displayByValue?.get(option) ?? option;
+ return (
+ <FilterValueCheckbox
+ key={option}
+ id={`${filterKey}-${option}`}
+ label={displayLabel}
+ icon={renderIcon?.(option)}
+ count={counts.get(option) || 0}
+ checked={value.includes(option)}
+ onCheckedChange={(checked) => {
+ const newValues = checked
+ ? [...value, option]
+ : value.filter((v: string) => v !== option);
+ onChange(newValues);
+ }}
+ onLabelClick={onOnlyChange ? () => onOnlyChange(option) : undefined}
+ totalSelected={value.length}
+ />
+ );
+ };
return (
<FilterAccordionItem
@@ -818,32 +875,20 @@ export function CategoricalFacet({
</div>
) : (
<>
- {visibleOptions.map((option: string) => {
- const displayLabel =
- displayByValue?.get(option) ?? option;
- return (
- <FilterValueCheckbox
- key={option}
- id={`${filterKey}-${option}`}
- label={displayLabel}
- icon={renderIcon?.(option)}
- count={counts.get(option) || 0}
- checked={value.includes(option)}
- onCheckedChange={(checked) => {
- const newValues = checked
- ? [...value, option]
- : value.filter((v: string) => v !== option);
- onChange(newValues);
- }}
- onLabelClick={
- onOnlyChange
- ? () => onOnlyChange(option)
- : undefined
- }
- totalSelected={value.length}
+ {/* Selected options, pinned to the top (long lists only) */}
+ {visibleSelectedOptions.map(renderOption)}
+
+ {/* Separator between the pinned selection and the rest */}
+ {visibleSelectedOptions.length > 0 &&
+ visibleRemainingOptions.length > 0 && (
+ <div
+ className="border-border/60 mx-3 my-1 border-t"
+ aria-hidden
/>
- );
- })}
+ )}
+
+ {/* Remaining (unselected) options, capped */}
+ {visibleRemainingOptions.map(renderOption)}
{hasMoreFilteredOptions && !showAll && (
<div className="px-2">
<Button
diff --git a/web/src/features/events/config/filter-config.ts b/web/src/features/events/config/filter-config.ts
index 9b97241efc..2dd84ec0ad 100644
--- a/web/src/features/events/config/filter-config.ts
+++ b/web/src/features/events/config/filter-config.ts
@@ -120,6 +120,13 @@ export const observationEventsFilterConfig: FilterConfig = {
column: "name",
label: getEventsColumnName("name"),
},
+ {
+ // Tags are a primary, user-defined filter — keep them near the identity
+ // facets at the top of the sidebar rather than buried mid-list (LFE-10494).
+ type: "categorical" as const,
+ column: "traceTags",
+ label: getEventsColumnName("traceTags"),
+ },
{
type: "categorical" as const,
column: "level",
@@ -140,11 +147,6 @@ export const observationEventsFilterConfig: FilterConfig = {
column: "promptName",
label: getEventsColumnName("promptName"),
},
- {
- type: "categorical" as const,
- column: "traceTags",
- label: getEventsColumnName("traceTags"),
- },
{
type: "stringKeyValue" as const,
column: "metadata",
diff --git a/web/src/features/filters/config/observations-config.ts b/web/src/features/filters/config/observations-config.ts
index 5f967b8630..e7c8fd0426 100644
--- a/web/src/features/filters/config/observations-config.ts
+++ b/web/src/features/filters/config/observations-config.ts
@@ -45,6 +45,13 @@ export const observationFilterConfig: FilterConfig = {
column: "traceName",
label: "Trace Name",
},
+ {
+ // Tags are a primary, user-defined filter — keep them near the identity
+ // facets at the top of the sidebar rather than buried mid-list (LFE-10494).
+ type: "categorical" as const,
+ column: "tags",
+ label: "Trace Tags",
+ },
{
type: "categorical" as const,
column: "level",
@@ -65,11 +72,6 @@ export const observationFilterConfig: FilterConfig = {
column: "promptName",
label: "Prompt Name",
},
- {
- type: "categorical" as const,
- column: "tags",
- label: "Trace Tags",
- },
{
type: "stringKeyValue" as const,
column: "metadata",
diff --git a/web/src/features/filters/config/traces-config.ts b/web/src/features/filters/config/traces-config.ts
index 276cf52fb1..914cc7e872 100644
--- a/web/src/features/filters/config/traces-config.ts
+++ b/web/src/features/filters/config/traces-config.ts
@@ -39,6 +39,13 @@ export const traceFilterConfig: FilterConfig = {
column: "sessionId",
label: "Session ID",
},
+ {
+ // Tags are a primary, user-defined filter — keep them near the identity
+ // facets at the top of the sidebar rather than buried mid-list (LFE-10494).
+ type: "categorical" as const,
+ column: "traceTags",
+ label: "Tags",
+ },
{
type: "stringKeyValue" as const,
column: "metadata",
@@ -73,11 +80,6 @@ export const traceFilterConfig: FilterConfig = {
column: "commentContent",
label: "Comment Content",
},
- {
- type: "categorical" as const,
- column: "traceTags",
- label: "Tags",
- },
{
type: "categorical" as const,
column: "level",