Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Fix sync between filter bar and filter controls in unified logs (#50383)

Joshen Lim4b245483459e
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.filters.test.ts b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.filters.test.ts
index d78b2f75b86..178dee0a3f7 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.filters.test.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.filters.test.ts
@@ -10,7 +10,7 @@ import {
} from './UnifiedLogs.filters'
describe('columnFiltersToLogsFilters', () => {
- it('serializes a bare string[] (sidebar checkbox) using the default `=` operator', () => {
+ it('serializes a bare string[] (defensive fallback for un-wrapped input) using the default `=` operator', () => {
const filters = columnFiltersToLogsFilters([
{ id: 'log_type', value: ['postgres', 'postgrest'] },
])
@@ -58,12 +58,14 @@ describe('columnFiltersToLogsFilters', () => {
})
describe('logsFiltersToColumnFilters', () => {
- it('seeds an `=` group as a bare string[] so sidebar checkboxes render ticked', () => {
+ it('seeds an `=` group as { operator, values }, the shape every column filter uses', () => {
const columnFilters = logsFiltersToColumnFilters([
{ column: 'log_type', operator: '=', value: 'postgres' },
{ column: 'log_type', operator: '=', value: 'postgrest' },
])
- expect(columnFilters).toEqual([{ id: 'log_type', value: ['postgres', 'postgrest'] }])
+ expect(columnFilters).toEqual([
+ { id: 'log_type', value: { operator: '=', values: ['postgres', 'postgrest'] } },
+ ])
})
it('keeps non-eq groups wrapped so the operator survives a round-trip', () => {
@@ -95,7 +97,7 @@ describe('buildFilterSearchUpdate', () => {
{ value: 'method', type: 'checkbox' },
]
- it('serializes a bare sidebar checkbox into the `filter` param (the regression)', () => {
+ it('serializes a bare string[] into the `filter` param (defensive fallback for un-wrapped input)', () => {
const update = buildFilterSearchUpdate([{ id: 'log_type', value: ['postgres'] }], fields)
expect(update.filter).toEqual(['log_type:eq:postgres'])
})
@@ -137,7 +139,7 @@ describe('buildDefaultColumnFilters', () => {
date: range,
})
expect(columnFilters).toEqual([
- { id: 'log_type', value: ['postgres'] },
+ { id: 'log_type', value: { operator: '=', values: ['postgres'] } },
{ id: 'date', value: range },
])
@@ -148,7 +150,7 @@ describe('buildDefaultColumnFilters', () => {
it('omits `date` when no range is present, matching the pre-existing no-filter case', () => {
expect(buildDefaultColumnFilters({ filter: ['log_type:eq:postgres'], date: null })).toEqual([
- { id: 'log_type', value: ['postgres'] },
+ { id: 'log_type', value: { operator: '=', values: ['postgres'] } },
])
})
@@ -157,7 +159,9 @@ describe('buildDefaultColumnFilters', () => {
filter: ['log_type:eq:postgres'],
date: [new Date('2026-05-08T00:00:00Z')],
})
- expect(columnFilters).toEqual([{ id: 'log_type', value: ['postgres'] }])
+ expect(columnFilters).toEqual([
+ { id: 'log_type', value: { operator: '=', values: ['postgres'] } },
+ ])
})
it('does not duplicate the `date` id when a hand-crafted `filter` param also targets it', () => {
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.filters.ts b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.filters.ts
index 92a4549d208..4c808bc6536 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.filters.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.filters.ts
@@ -16,13 +16,6 @@ export interface LogsColumnFilterValue {
values: string[]
}
-export const LOGS_FILTER_OPERATORS = [
- '=',
- '<>',
- '~~*',
- '!~~*',
-] as const satisfies readonly LogsFilterOperator[]
-
const OPERATOR_TO_ABBREV: Record<LogsFilterOperator, string> = {
'=': 'eq',
'<>': 'neq',
@@ -83,10 +76,11 @@ export const groupLogsFiltersByColumn = (
export const logsFiltersToColumnFilters = (
filters: LogsFilter[]
-): { id: string; value: string[] | LogsColumnFilterValue }[] => {
- return Object.entries(groupLogsFiltersByColumn(filters)).map(([id, group]) =>
- group.operator === '=' ? { id, value: group.values } : { id, value: group }
- )
+): { id: string; value: LogsColumnFilterValue }[] => {
+ return Object.entries(groupLogsFiltersByColumn(filters)).map(([id, group]) => ({
+ id,
+ value: group,
+ }))
}
// Seeds `date` too, so `logsFiltersToColumnFilters` (which only covers the `filter`
diff --git a/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.tsx b/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.tsx
index 723adb10cd8..1c2be221958 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.tsx
+++ b/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.tsx
@@ -9,12 +9,13 @@ import {
type FilterGroup,
} from 'ui-patterns/FilterBar'
+import { isLogsFilterColumnValue } from '../UnifiedLogs.filters'
import {
- isLogsFilterColumnValue,
- type LogsColumnFilterValue,
- type LogsFilterOperator,
-} from '../UnifiedLogs.filters'
-import { buildFilterProperties, getUserFilterValue, USER_PROPERTY } from './LogsFilterBar.utils'
+ buildColumnFilterValues,
+ buildFilterProperties,
+ getUserFilterValue,
+ USER_PROPERTY,
+} from './LogsFilterBar.utils'
import { searchAuthUsers } from '@/components/interfaces/UserJourneys/UserJourneys.queries'
import { useDataTable } from '@/components/ui/DataTable/providers/DataTableProvider'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
@@ -28,17 +29,15 @@ const buildFilterGroup = (
): FilterGroup => {
const conditions: FilterCondition[] = []
for (const { id, value } of columnFilters) {
- if (!filterableNames.has(id) || value === null || value === undefined) continue
- // Equality filters carry their operator inside a wrapped value; range/slider
- // filters arrive as plain arrays and default to `=`.
- const { operator, values } = isLogsFilterColumnValue(value)
- ? value
- : { operator: '=' as LogsFilterOperator, values: Array.isArray(value) ? value : [value] }
- for (const v of values) {
+ // Non-timerange column filter values are always the wrapped `{ operator, values }`
+ // shape; skip anything else (e.g. the `date` timerange brush, which isn't in
+ // filterableNames, or an unexpected shape).
+ if (!filterableNames.has(id) || !isLogsFilterColumnValue(value)) continue
+ for (const v of value.values) {
conditions.push({
propertyName: id,
value: v as FilterCondition['value'],
- operator,
+ operator: value.operator,
})
}
}
@@ -119,26 +118,14 @@ export const LogsFilterBar = () => {
applyUser(getUserFilterValue(next.conditions as FilterCondition[]))
- const wrappedByColumn = new Map<string, LogsColumnFilterValue>()
- for (const cond of next.conditions as FilterCondition[]) {
- if (cond.propertyName === USER_PROPERTY) continue
- const operator = cond.operator as LogsFilterOperator
- const existing = wrappedByColumn.get(cond.propertyName)
- if (!existing) {
- wrappedByColumn.set(cond.propertyName, { operator, values: [String(cond.value)] })
- } else {
- existing.values.push(String(cond.value))
- if (existing.operator !== operator) existing.operator = operator
- }
- }
-
- for (const [name, wrapped] of wrappedByColumn) {
- table.getColumn(name)?.setFilterValue(wrapped)
+ const columnFilterValues = buildColumnFilterValues(next.conditions as FilterCondition[])
+ for (const [name, value] of columnFilterValues) {
+ table.getColumn(name)?.setFilterValue(value)
}
// Only clear filters owned by this bar — leaves externally-set filters
// (e.g. the timeline date range) untouched.
- const nextNames = new Set(wrappedByColumn.keys())
+ const nextNames = new Set(columnFilterValues.keys())
const filtersToRemove = table
.getState()
.columnFilters.filter((x) => columnBackedNames.has(x.id) && !nextNames.has(x.id))
diff --git a/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.utils.test.ts b/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.utils.test.ts
index 96af8707399..5a9828e42f6 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.utils.test.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.utils.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'
import { z } from 'zod'
import {
+ buildColumnFilterValues,
buildFilterProperties,
filterPropertySchema,
getUserFilterValue,
@@ -115,3 +116,54 @@ describe('getUserFilterValue', () => {
expect(result).toBe('first')
})
})
+
+describe('buildColumnFilterValues', () => {
+ it.each(['=', '<>', '~~*', '!~~*'] as const)(
+ 'wraps a `%s` condition as { operator, values }, the one shape every column filter uses',
+ (operator) => {
+ const result = buildColumnFilterValues([
+ { propertyName: 'log_type', value: 'postgres', operator },
+ ])
+ expect(result.get('log_type')).toEqual({ operator, values: ['postgres'] })
+ }
+ )
+
+ it('accumulates multiple `=` conditions on the same column into one group', () => {
+ const result = buildColumnFilterValues([
+ { propertyName: 'log_type', value: 'postgres', operator: '=' },
+ { propertyName: 'log_type', value: 'auth', operator: '=' },
+ ])
+ expect(result.get('log_type')).toEqual({ operator: '=', values: ['postgres', 'auth'] })
+ })
+
+ it('coerces non-string condition values to strings', () => {
+ const result = buildColumnFilterValues([
+ { propertyName: 'status_code', value: 500, operator: '=' },
+ ])
+ expect(result.get('status_code')).toEqual({ operator: '=', values: ['500'] })
+ })
+
+ it('keeps separate columns independent', () => {
+ const result = buildColumnFilterValues([
+ { propertyName: 'log_type', value: 'postgres', operator: '=' },
+ { propertyName: 'event_message', value: 'error', operator: '~~*' },
+ ])
+ expect(result.get('log_type')).toEqual({ operator: '=', values: ['postgres'] })
+ expect(result.get('event_message')).toEqual({ operator: '~~*', values: ['error'] })
+ })
+
+ it('lets the last operator win when a column mixes operators', () => {
+ const result = buildColumnFilterValues([
+ { propertyName: 'log_type', value: 'postgres', operator: '=' },
+ { propertyName: 'log_type', value: 'auth', operator: '<>' },
+ ])
+ expect(result.get('log_type')).toEqual({ operator: '<>', values: ['postgres', 'auth'] })
+ })
+
+ it('excludes the synthetic user condition', () => {
+ const result = buildColumnFilterValues([
+ { propertyName: USER_PROPERTY, value: '[email protected]', operator: '=' },
+ ])
+ expect(result.has(USER_PROPERTY)).toBe(false)
+ })
+})
diff --git a/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.utils.ts b/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.utils.ts
index 6dac6208a45..302d1e424f2 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.utils.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/components/LogsFilterBar.utils.ts
@@ -5,6 +5,7 @@ import {
} from 'ui-patterns/FilterBar'
import { z } from 'zod'
+import type { LogsColumnFilterValue, LogsFilterOperator } from '../UnifiedLogs.filters'
import type { Option } from '@/components/ui/DataTable/DataTable.types'
export const USER_PROPERTY = 'user'
@@ -72,3 +73,25 @@ export const getUserFilterValue = (conditions: FilterCondition[]): string | unde
const userCondition = conditions.find((condition) => condition.propertyName === USER_PROPERTY)
return userCondition ? String(userCondition.value) : undefined
}
+
+// Groups filter bar conditions by column into the wrapped `{ operator, values }` shape —
+// the one shape every column filter value uses, matching logsFiltersToColumnFilters.
+export const buildColumnFilterValues = (
+ conditions: FilterCondition[]
+): Map<string, LogsColumnFilterValue> => {
+ const wrappedByColumn = new Map<string, LogsColumnFilterValue>()
+ for (const condition of conditions) {
+ if (condition.propertyName === USER_PROPERTY) continue
+ const operator = condition.operator as LogsFilterOperator
+ const existing = wrappedByColumn.get(condition.propertyName)
+ if (!existing) {
+ wrappedByColumn.set(condition.propertyName, { operator, values: [String(condition.value)] })
+ } else {
+ existing.values.push(String(condition.value))
+ // Mixed operators on the same column aren't expressible in the column-filter
+ // shape (one operator per column). Last write wins.
+ if (existing.operator !== operator) existing.operator = operator
+ }
+ }
+ return wrappedByColumn
+}
diff --git a/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckbox.tsx b/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckbox.tsx
index 2ce56bf564b..8d7260e748e 100644
--- a/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckbox.tsx
+++ b/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckbox.tsx
@@ -9,6 +9,7 @@ import { InputWithAddons } from '../primitives/InputWithAddons'
import { useDataTable } from '../providers/DataTableProvider'
import { DataTableFilterCheckboxLoader } from './DataTableFilterCheckboxLoader'
import { SEARCH_PARAMS_PARSER } from '@/components/interfaces/UnifiedLogs/UnifiedLogs.constants'
+import { isLogsFilterColumnValue } from '@/components/interfaces/UnifiedLogs/UnifiedLogs.filters'
export function DataTableFilterCheckbox<TData>({
value: _value,
@@ -49,8 +50,8 @@ export function DataTableFilterCheckbox<TData>({
(option) => inputValue === '' || option.label.toLowerCase().includes(inputValue.toLowerCase())
) || []
- // CHECK: it could be filterValue or searchValue
- const filters = filterValue ? (Array.isArray(filterValue) ? filterValue : [filterValue]) : []
+ // Column filter values are always the wrapped `{ operator, values }` shape.
+ const filters = isLogsFilterColumnValue(filterValue) ? filterValue.values : []
// REMINDER: if no options are defined, while fetching data, we should show a skeleton
if (isLoading && !filterOptions?.length) return <DataTableFilterCheckboxLoader />
@@ -103,10 +104,12 @@ export function DataTableFilterCheckbox<TData>({
id={`${value}-${option.value}`}
checked={checked}
onCheckedChange={(checked) => {
- const newValue = checked
- ? [...(filters || []), option.value]
- : filters?.filter((value) => option.value !== value)
- column?.setFilterValue(newValue?.length ? newValue : undefined)
+ const newValues = checked
+ ? [...filters, option.value]
+ : filters.filter((value) => option.value !== value)
+ column?.setFilterValue(
+ newValues.length ? { operator: '=', values: newValues } : undefined
+ )
}}
/>
<Label
@@ -149,7 +152,9 @@ export function DataTableFilterCheckbox<TData>({
<button
type="button"
tabIndex={0}
- onClick={() => column?.setFilterValue([option.value])}
+ onClick={() =>
+ column?.setFilterValue({ operator: '=', values: [option.value] })
+ }
className={cn(
'text-xs text-muted-foreground hover:text-foreground',
'absolute inset-y-0 right-0 hidden bg-surface-100 group-hover:flex group-focus-within:flex items-center cursor-pointer',
diff --git a/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckboxAsync.tsx b/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckboxAsync.tsx
index 6b44f955cdf..2037c283bed 100644
--- a/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckboxAsync.tsx
+++ b/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckboxAsync.tsx
@@ -9,6 +9,7 @@ import type { DataTableCheckboxFilterField } from '../DataTable.types'
import { formatCompactNumber } from '../DataTable.utils'
import { InputWithAddons } from '../primitives/InputWithAddons'
import { useDataTable } from '../providers/DataTableProvider'
+import { isLogsFilterColumnValue } from '@/components/interfaces/UnifiedLogs/UnifiedLogs.filters'
import { useUnifiedLogsFacetCountQuery } from '@/data/logs/unified-logs-facet-count-query'
export function DataTableFilterCheckboxAsync<TData>({
@@ -46,7 +47,8 @@ export function DataTableFilterCheckboxAsync<TData>({
const column = table.getColumn(value)
const filterValue = columnFilters.find((i) => i.id === value)?.value
const facetedValue = getFacetedUniqueValues?.(table, value) || column?.getFacetedUniqueValues()
- const filters = filterValue ? (Array.isArray(filterValue) ? filterValue : [filterValue]) : []
+ // Column filter values are always the wrapped `{ operator, values }` shape.
+ const filters = isLogsFilterColumnValue(filterValue) ? filterValue.values : []
if (!options?.length)
return (
@@ -90,10 +92,12 @@ export function DataTableFilterCheckboxAsync<TData>({
id={`${value}-${option.value}`}
checked={checked}
onCheckedChange={(checked) => {
- const newValue = checked
- ? [...(filters || []), option.value]
- : filters?.filter((value) => option.value !== value)
- column?.setFilterValue(newValue?.length ? newValue : undefined)
+ const newValues = checked
+ ? [...filters, option.value]
+ : filters.filter((value) => option.value !== value)
+ column?.setFilterValue(
+ newValues.length ? { operator: '=', values: newValues } : undefined
+ )
}}
/>
<Label
@@ -119,7 +123,9 @@ export function DataTableFilterCheckboxAsync<TData>({
<button
type="button"
tabIndex={0}
- onClick={() => column?.setFilterValue([option.value])}
+ onClick={() =>
+ column?.setFilterValue({ operator: '=', values: [option.value] })
+ }
className={cn(
'text-xs text-muted-foreground hover:text-foreground',
'absolute inset-y-0 right-0 hidden bg-surface-100 group-hover:flex group-focus-within:flex items-center cursor-pointer',