🪢 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(filters): hide non-matching facets during a sidebar search, active ones included (#16154)
Nikita Kabardinab58010c8133
diff --git a/web/src/components/table/data-table-controls.clienttest.tsx b/web/src/components/table/data-table-controls.clienttest.tsxindex a8a4411dd7..ee1e987f2f 100644--- a/web/src/components/table/data-table-controls.clienttest.tsx+++ b/web/src/components/table/data-table-controls.clienttest.tsx@@ -868,6 +868,8 @@ describe("DataTableControls facet-name search", () => {searchFor("token");expect(screen.getByText("Total Tokens")).toBeVisible();expect(screen.getByText("Environment")).not.toBeVisible();+ // The query hides a facet whose name misses it even while it is filtering.+ expect(screen.getByText("User ID")).not.toBeVisible();// The column key matches too: the label's space would defeat "userid".searchFor("userid");expect(screen.getByText("User ID")).toBeVisible();@@ -881,20 +883,42 @@ describe("DataTableControls facet-name search", () => {expect(screen.getByText("x")).toBeInTheDocument();});- it("keeps a selected facet visible when it does not match, and says so", () => {- const { rerender } = render(controls(catalog(["userId"])));+ it("reaches the no-match state with a filter active, without touching it", () => {+ // A query hides every facet it misses, so the dead end is reachable while a+ // filter is in force. Hiding is presentation ONLY: nothing here may reset,+ // clear or re-apply anything, or a keystroke in the search box would change+ // the rows on screen.+ const mutations: string[] = [];+ const filters = catalog(["userId"]).map((filter) => ({+ ...filter,+ onChange: () => mutations.push(`change:${filter.column}`),+ onReset: () => mutations.push(`reset:${filter.column}`),+ }));+ const qf: QueryFilter = {+ ...queryFilter(filters),+ clearAll: () => mutations.push("clearAll"),+ setFilterState: () => mutations.push("setFilterState"),+ onExpandedChange: () => mutations.push("expand"),+ };+ render(+ <TooltipProvider>+ <DataTableControls queryFilter={qf} />+ </TooltipProvider>,+ );searchFor("zzz");- // Pinned by its selection, not by the query.- expect(screen.getByText("User ID")).toBeVisible();+ expect(screen.getByText("User ID")).not.toBeVisible();expect(screen.getByText("Environment")).not.toBeVisible();- expect(- screen.getByText('No other filters match "zzz"'),- ).toBeInTheDocument();-- // With nothing pinned above it, the same dead end drops the "other".- rerender(controls(catalog()));expect(screen.getByText('No filters match "zzz"')).toBeInTheDocument();+ expect(mutations).toEqual([]);++ fireEvent.click(+ screen.getByRole("button", { name: "Clear filter search" }),+ );+ // Back in full, selection intact — its header summary still reads it.+ expect(screen.getByText("User ID")).toBeVisible();+ expect(screen.getByText("x")).toBeInTheDocument();+ expect(mutations).toEqual([]);});it("hides a non-matching facet rather than unmounting it, so an open draft survives", () => {diff --git a/web/src/components/table/data-table-controls.tsx b/web/src/components/table/data-table-controls.tsxindex 145dc05331..8e80e86072 100644--- a/web/src/components/table/data-table-controls.tsx+++ b/web/src/components/table/data-table-controls.tsx@@ -284,28 +284,21 @@ export function DataTableControls({// must never narrow the list behind the user's back.const facetSearchQuery = showFacetSearch ? facetSearch.trim() : "";- // Matching facet columns, or null when not searching. Selected/added facets- // stay visible whether or not they match — a query must never hide what is- // currently filtering — so the match set is also what tells "nothing matched"- // apart from "only the pinned ones are left".- const facetSearchMatches = facetSearchQuery- ? new Set(- displayedFilters- .filter((filter) => facetNameRank(filter, facetSearchQuery) !== null)- .map((filter) => filter.column),- )- : null;- // Search FILTERS, it does not reorder: the settled promoted block and config- // order still own every position.+ // The name search FILTERS, it does not reorder: the settled promoted block+ // and config order still own every position. A facet whose name misses the+ // query goes whether or not it is filtering — what is in force stays on show+ // above the list (the header's active count, plus the search bar's tokens+ // where there is one), so the sidebar need not repeat it mid-search.//// Non-matching facets are HIDDEN, never unmounted. Every facet holds// uncommitted local state — a typed-but-not-added text filter, a metadata// condition mid-build, a "show more" expansion, a debounced numeric draft —- // and unmounting throws all of it away with nothing said. Typing in a box- // above the list must not be able to do that.- const visibleFilters = facetSearchMatches+ // and unmounting throws all of it away with nothing said. Now that an ACTIVE+ // facet can be hidden too, that matters more, not less: hiding is+ // presentation only and must never touch the filter state.+ const visibleFilters = facetSearchQuery? displayedFilters.filter(- (filter) => facetSearchMatches.has(filter.column) || isPromoted(filter),+ (filter) => facetNameRank(filter, facetSearchQuery) !== null,): displayedFilters;const visibleColumns = new Set(visibleFilters.map((filter) => filter.column));@@ -411,6 +404,8 @@ export function DataTableControls({const changed = [...became, ...ceased];if (changed.length !== 1) return;+ // A name search may be hiding the target; display:none has no box, so this+ // simply does nothing rather than scrolling to an invisible row.const facetElement = scrollRootRef.current?.querySelector(`[data-facet-column="${CSS.escape(changed[0])}"]`,);@@ -756,14 +751,11 @@ export function DataTableControls({})}</Accordion>- {/* Nothing in the catalog matched. Says "other" when pinned- selections are still listed above, so the message never- contradicts the facets on screen. */}- {facetSearchMatches?.size === 0 && (+ {/* Nothing matched — including any facet currently filtering, which the+ query hides like the rest. */}+ {facetSearchQuery !== "" && visibleFilters.length === 0 && (<p className="text-muted-foreground px-3 pt-6 text-center text-xs break-words">- {visibleFilters.length > 0- ? `No other filters match "${facetSearchQuery}"`- : `No filters match "${facetSearchQuery}"`}+ {`No filters match "${facetSearchQuery}"`}</p>)}