🪢 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(filter-sidebar): use positive matching for arrayOptions checkbox filter (#12206)
Hunmin Kim0bb69f3cab28
diff --git a/web/src/features/filters/filter-integration.clienttest.ts b/web/src/features/filters/filter-integration.clienttest.tsindex 1bad454c82..03ce82ad1d 100644--- a/web/src/features/filters/filter-integration.clienttest.ts+++ b/web/src/features/filters/filter-integration.clienttest.ts@@ -18,7 +18,10 @@ import { traceFilterConfig } from "./config/traces-config";import { observationFilterConfig } from "./config/observations-config";import { transformFiltersForBackend } from "./lib/filter-transform";import { sessionFilterConfig } from "./config/sessions-config";-import { decodeAndNormalizeFilters } from "./hooks/useSidebarFilterState";+import {+ decodeAndNormalizeFilters,+ resolveCheckboxOperator,+} from "./hooks/useSidebarFilterState";// Helper to simulate complete URL flowfunction simulateUrlFlow(filters: FilterState): FilterState {@@ -565,3 +568,136 @@ describe("Filter Flow: URL → Decode → Normalize → Transform", () => {expect(result[0]?.column).toBe("traceTags");});});++describe("resolveCheckboxOperator (arrayOptions vs stringOptions)", () => {+ const availableValues = ["tag-1", "tag-2", "tag-3", "tag-4", "tag-5"];++ describe("arrayOptions (e.g., tags)", () => {+ it('should use "any of" with selected values when no existing filter', () => {+ const result = resolveCheckboxOperator({+ colType: "arrayOptions",+ existingFilter: undefined,+ values: ["tag-1", "tag-2"],+ availableValues,+ });++ expect(result).toEqual({+ finalOperator: "any of",+ finalValues: ["tag-1", "tag-2"],+ });+ });++ it('should switch from "none of" to "any of" for arrayOptions', () => {+ const result = resolveCheckboxOperator({+ colType: "arrayOptions",+ existingFilter: {+ column: "tags",+ type: "arrayOptions",+ operator: "none of",+ value: ["tag-3", "tag-4", "tag-5"],+ },+ values: ["tag-1", "tag-2"],+ availableValues,+ });++ // Must NOT keep "none of" — it gives wrong results for multi-valued arrays+ expect(result).toEqual({+ finalOperator: "any of",+ finalValues: ["tag-1", "tag-2"],+ });+ });++ it('should preserve "all of" operator for arrayOptions', () => {+ const result = resolveCheckboxOperator({+ colType: "arrayOptions",+ existingFilter: {+ column: "tags",+ type: "arrayOptions",+ operator: "all of",+ value: ["tag-1"],+ },+ values: ["tag-1", "tag-2"],+ availableValues,+ });++ expect(result).toEqual({+ finalOperator: "all of",+ finalValues: ["tag-1", "tag-2"],+ });+ });++ it('should use "any of" when existing filter is "any of"', () => {+ const result = resolveCheckboxOperator({+ colType: "arrayOptions",+ existingFilter: {+ column: "tags",+ type: "arrayOptions",+ operator: "any of",+ value: ["tag-1"],+ },+ values: ["tag-1", "tag-2", "tag-3"],+ availableValues,+ });++ expect(result).toEqual({+ finalOperator: "any of",+ finalValues: ["tag-1", "tag-2", "tag-3"],+ });+ });+ });++ describe("stringOptions (e.g., environment) — regression tests", () => {+ it('should use "none of" with deselected values when no existing filter', () => {+ const result = resolveCheckboxOperator({+ colType: "stringOptions",+ existingFilter: undefined,+ values: ["tag-1", "tag-2"],+ availableValues,+ });++ // "none of" inversion is safe for single-valued columns+ expect(result).toEqual({+ finalOperator: "none of",+ finalValues: ["tag-3", "tag-4", "tag-5"],+ });+ });++ it('should keep "none of" with updated deselected values for stringOptions', () => {+ const result = resolveCheckboxOperator({+ colType: "stringOptions",+ existingFilter: {+ column: "environment",+ type: "stringOptions",+ operator: "none of",+ value: ["tag-3", "tag-4", "tag-5"],+ },+ values: ["tag-1", "tag-2", "tag-3"],+ availableValues,+ });++ expect(result).toEqual({+ finalOperator: "none of",+ finalValues: ["tag-4", "tag-5"],+ });+ });++ it('should use "any of" when existing filter is "any of" for stringOptions', () => {+ const result = resolveCheckboxOperator({+ colType: "stringOptions",+ existingFilter: {+ column: "environment",+ type: "stringOptions",+ operator: "any of",+ value: ["tag-1"],+ },+ values: ["tag-1", "tag-2"],+ availableValues,+ });++ expect(result).toEqual({+ finalOperator: "any of",+ finalValues: ["tag-1", "tag-2"],+ });+ });+ });+});diff --git a/web/src/features/filters/hooks/useSidebarFilterState.tsx b/web/src/features/filters/hooks/useSidebarFilterState.tsxindex e3d0f57fa2..3584d6f1de 100644--- a/web/src/features/filters/hooks/useSidebarFilterState.tsx+++ b/web/src/features/filters/hooks/useSidebarFilterState.tsx@@ -310,6 +310,56 @@ type UpdateFilter = (operator?: "any of" | "none of" | "all of",) => void;+/**+ * Pure function that determines the operator and values for checkbox-based+ * filter interactions. Extracted for testability.+ *+ * For arrayOptions (e.g., tags), "none of" inversion is NOT semantically+ * equivalent because a single trace can have multiple tags. For example,+ * a trace with tags [tag-1, tag-3] matches "any of [tag-1, tag-2]" but does NOT match+ * "none of [tag-3, tag-4, tag-5]" (because it contains tag-3). So we always use positive+ * matching ("any of" / "all of") for array columns.+ *+ * For stringOptions (e.g., environment), each row has a single value,+ * so "none of [deselected]" is semantically equivalent to "any of [selected]".+ *+ * @param params - Filter context including column type, existing filter, selected and available values+ * @returns Object with finalOperator and finalValues to apply+ */+export function resolveCheckboxOperator(params: {+ colType: string | undefined;+ existingFilter: FilterState[number] | undefined;+ values: string[];+ availableValues: string[];+}): { finalOperator: "any of" | "none of" | "all of"; finalValues: string[] } {+ const { colType, existingFilter, values, availableValues } = params;++ if (colType === "arrayOptions") {+ // For array columns, always use positive matching.+ if (+ existingFilter?.operator === "all of" &&+ existingFilter.type === "arrayOptions"+ ) {+ return { finalOperator: "all of", finalValues: values };+ }+ return { finalOperator: "any of", finalValues: values };+ }++ // For single-valued columns (stringOptions), "none of" inversion is safe+ if (!existingFilter) {+ const deselected = availableValues.filter((v) => !values.includes(v));+ return { finalOperator: "none of", finalValues: deselected };+ }+ if (+ existingFilter.operator === "none of" &&+ existingFilter.type === "stringOptions"+ ) {+ const deselected = availableValues.filter((v) => !values.includes(v));+ return { finalOperator: "none of", finalValues: deselected };+ }+ return { finalOperator: "any of", finalValues: values };+}+export function useSidebarFilterState(config: FilterConfig,options: Record<@@ -601,34 +651,12 @@ export function useSidebarFilterState(}// Checkbox interaction - smart operator selectionconst existingFilter = current.find((f) => f.column === column);-- if (!existingFilter) {- // No existing filter - user is deselecting from "all selected" state- // Use "none of" with deselected items- const deselected = availableValues.filter((v) => !values.includes(v));- finalOperator = "none of";- finalValues = deselected;- } else if (- existingFilter.operator === "none of" &&- (existingFilter.type === "stringOptions" ||- existingFilter.type === "arrayOptions")- ) {- // Existing "none of" filter - keep "none of", update to deselected items- const deselected = availableValues.filter((v) => !values.includes(v));- finalOperator = "none of";- finalValues = deselected;- } else if (- existingFilter.operator === "all of" &&- existingFilter.type === "arrayOptions"- ) {- // Existing "all of" filter - keep "all of" with selected items- finalOperator = "all of";- finalValues = values;- } else {- // Existing "any of" filter or other - keep "any of" with selected items- finalOperator = "any of";- finalValues = values;- }+ ({ finalOperator, finalValues } = resolveCheckboxOperator({+ colType,+ existingFilter,+ values,+ availableValues,+ }));}const filterType: "arrayOptions" | "stringOptions" =