Skip to content

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

Feat/unified logs live filter enums (#36913)

Jonathan Summers-Muir02a6392758b3
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.constants.tsx b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.constants.tsx
index a429b1d02c5..d320ad58872 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.constants.tsx
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.constants.tsx
@@ -58,7 +58,7 @@ export const SEARCH_PARAMS_PARSER = {
'timing.tls': parseAsArrayOf(parseAsInteger, SLIDER_DELIMITER),
'timing.ttfb': parseAsArrayOf(parseAsInteger, SLIDER_DELIMITER),
'timing.transfer': parseAsArrayOf(parseAsInteger, SLIDER_DELIMITER),
- status: parseAsArrayOf(parseAsInteger, SLIDER_DELIMITER),
+ status: parseAsArrayOf(parseAsString, ARRAY_DELIMITER),
regions: parseAsArrayOf(parseAsStringLiteral(REGIONS), ARRAY_DELIMITER),
method: parseAsArrayOf(parseAsStringLiteral(METHODS), ARRAY_DELIMITER),
host: parseAsString,
@@ -78,3 +78,303 @@ export const SEARCH_PARAMS_PARSER = {
uuid: parseAsString,
id: parseAsString,
}
+
+const POSTGRES_STATUS_CODE_LABELS = {
+ '00000': 'Successful Completion',
+ '01000': 'Warning',
+ '0100C': 'Dynamic Result Sets Returned',
+ '01008': 'Implicit Zero Bit Padding',
+ '01003': 'Null Value Eliminated In Set Function',
+ '01007': 'Privilege Not Granted',
+ '01006': 'Privilege Not Revoked',
+ '01004': 'String Data Right Truncation',
+ '01P01': 'Deprecated Feature',
+ '02000': 'No Data',
+ '02001': 'No Additional Dynamic Result Sets Returned',
+ '03000': 'SQL Statement Not Yet Complete',
+ '08000': 'Connection Exception',
+ '08003': 'Connection Does Not Exist',
+ '08006': 'Connection Failure',
+ '08001': 'SQL Client Unable To Establish SQL Connection',
+ '08004': 'SQL Server Rejected Establishment Of SQL Connection',
+ '08007': 'Transaction Resolution Unknown',
+ '08P01': 'Protocol Violation',
+ '09000': 'Triggered Action Exception',
+ '0A000': 'Feature Not Supported',
+ '0B000': 'Invalid Transaction Initiation',
+ '0F000': 'Locator Exception',
+ '0F001': 'Invalid Locator Specification',
+ '0L000': 'Invalid Grantor',
+ '0LP01': 'Invalid Grant Operation',
+ '0P000': 'Invalid Role Specification',
+ '0Z000': 'Diagnostics Exception',
+ '0Z002': 'Stacked Diagnostics Accessed Without Active Handler',
+ '20000': 'Case Not Found',
+ '21000': 'Cardinality Violation',
+ '22000': 'Data Exception',
+ '2202E': 'Array Subscript Error',
+ '22021': 'Character Not In Repertoire',
+ '22008': 'Datetime Field Overflow',
+ '22012': 'Division By Zero',
+ '22005': 'Error In Assignment',
+ '2200B': 'Escape Character Conflict',
+ '22022': 'Indicator Overflow',
+ '22015': 'Interval Field Overflow',
+ '2201E': 'Invalid Argument For Logarithm',
+ '22014': 'Invalid Argument For Ntile Function',
+ '22016': 'Invalid Argument For Nth Value Function',
+ '2201F': 'Invalid Argument For Power Function',
+ '2201G': 'Invalid Argument For Width Bucket Function',
+ '22018': 'Invalid Character Value For Cast',
+ '22007': 'Invalid Datetime Format',
+ '22019': 'Invalid Escape Character',
+ '2200D': 'Invalid Escape Octet',
+ '22025': 'Invalid Escape Sequence',
+ '22P06': 'Nonstandard Use Of Escape Character',
+ '22010': 'Invalid Indicator Parameter Value',
+ '22023': 'Invalid Parameter Value',
+ '2201B': 'Invalid Regular Expression',
+ '2201W': 'Invalid Row Count In Limit Clause',
+ '2201X': 'Invalid Row Count In Result Offset Clause',
+ '22009': 'Invalid Time Zone Displacement Value',
+ '2200C': 'Invalid Use Of Escape Character',
+ '2200G': 'Most Specific Type Mismatch',
+ '22004': 'Null Value Not Allowed',
+ '22002': 'Null Value No Indicator Parameter',
+ '22003': 'Numeric Value Out Of Range',
+ '22026': 'String Data Length Mismatch',
+ '22001': 'String Data Right Truncation',
+ '22011': 'Substring Error',
+ '22027': 'Trim Error',
+ '22024': 'Unterminated C String',
+ '2200F': 'Zero Length Character String',
+ '22P01': 'Floating Point Exception',
+ '22P02': 'Invalid Text Representation',
+ '22P03': 'Invalid Binary Representation',
+ '22P04': 'Bad Copy File Format',
+ '22P05': 'Untranslatable Character',
+ '2200L': 'Not An XML Document',
+ '2200M': 'Invalid XML Document',
+ '2200N': 'Invalid XML Content',
+ '2200S': 'Invalid XML Comment',
+ '2200T': 'Invalid XML Processing Instruction',
+ '23000': 'Integrity Constraint Violation',
+ '23001': 'Restrict Violation',
+ '23502': 'Not Null Violation',
+ '23503': 'Foreign Key Violation',
+ '23505': 'Unique Violation',
+ '23514': 'Check Violation',
+ '23P01': 'Exclusion Violation',
+ '24000': 'Invalid Cursor State',
+ '25000': 'Invalid Transaction State',
+ '25001': 'Active SQL Transaction',
+ '25002': 'Branch Transaction Already Active',
+ '25008': 'Held Cursor Requires Same Isolation Level',
+ '25003': 'Inappropriate Access Mode For Branch Transaction',
+ '25004': 'Inappropriate Isolation Level For Branch Transaction',
+ '25005': 'No Active SQL Transaction For Branch Transaction',
+ '25006': 'Read Only SQL Transaction',
+ '25007': 'Schema And Data Statement Mixing Not Supported',
+ '25P01': 'No Active SQL Transaction',
+ '25P02': 'In Failed SQL Transaction',
+ '25P03': 'Idle In Transaction Session Timeout',
+ '26000': 'Invalid SQL Statement Name',
+ '27000': 'Triggered Data Change Violation',
+ '28000': 'Invalid Authorization Specification',
+ '28P01': 'Invalid Password',
+ '2B000': 'Dependent Privilege Descriptors Still Exist',
+ '2BP01': 'Dependent Objects Still Exist',
+ '2D000': 'Invalid Transaction Termination',
+ '2F000': 'SQL Routine Exception',
+ '2F005': 'Function Executed No Return Statement',
+ '2F002': 'Modifying SQL Data Not Permitted',
+ '2F003': 'Prohibited SQL Statement Attempted',
+ '2F004': 'Reading SQL Data Not Permitted',
+ '34000': 'Invalid Cursor Name',
+ '38000': 'External Routine Exception',
+ '38001': 'Containing SQL Not Permitted',
+ '38002': 'Modifying SQL Data Not Permitted',
+ '38003': 'Prohibited SQL Statement Attempted',
+ '38004': 'Reading SQL Data Not Permitted',
+ '39000': 'External Routine Invocation Exception',
+ '39001': 'Invalid SQLSTATE Returned',
+ '39004': 'Null Value Not Allowed',
+ '39P01': 'Trigger Protocol Violated',
+ '39P02': 'SRF Protocol Violated',
+ '39P03': 'Event Trigger Protocol Violated',
+ '3B000': 'Savepoint Exception',
+ '3B001': 'Invalid Savepoint Specification',
+ '3D000': 'Invalid Catalog Name',
+ '3F000': 'Invalid Schema Name',
+ '40000': 'Transaction Rollback',
+ '40002': 'Transaction Integrity Constraint Violation',
+ '40001': 'Serialization Failure',
+ '40003': 'Statement Completion Unknown',
+ '40P01': 'Deadlock Detected',
+ '42000': 'Syntax Error Or Access Rule Violation',
+ '42601': 'Syntax Error',
+ '42501': 'Insufficient Privilege',
+ '42846': 'Cannot Coerce',
+ '42803': 'Grouping Error',
+ '42P20': 'Windowing Error',
+ '42P19': 'Invalid Recursion',
+ '42830': 'Invalid Foreign Key',
+ '42602': 'Invalid Name',
+ '42622': 'Name Too Long',
+ '42939': 'Reserved Name',
+ '42804': 'Datatype Mismatch',
+ '42P18': 'Indeterminate Datatype',
+ '42809': 'Wrong Object Type',
+ '428C9': 'Generated Always',
+ '42703': 'Undefined Column',
+ '42883': 'Undefined Function',
+ '42P01': 'Undefined Table',
+ '42P02': 'Undefined Parameter',
+ '42704': 'Undefined Object',
+ '42701': 'Duplicate Column',
+ '42P03': 'Duplicate Cursor',
+ '42P04': 'Duplicate Database',
+ '42723': 'Duplicate Function',
+ '42P05': 'Duplicate Prepared Statement',
+ '42P06': 'Duplicate Schema',
+ '42P07': 'Duplicate Table',
+ '42712': 'Duplicate Alias',
+ '42710': 'Duplicate Object',
+ '42702': 'Ambiguous Column',
+ '42725': 'Ambiguous Function',
+ '42P08': 'Ambiguous Parameter',
+ '42P09': 'Ambiguous Alias',
+ '42P10': 'Invalid Column Reference',
+ '42611': 'Invalid Column Definition',
+ '42P11': 'Invalid Cursor Definition',
+ '42P12': 'Invalid Database Definition',
+ '42P13': 'Invalid Function Definition',
+ '42P14': 'Invalid Prepared Statement Definition',
+ '42P15': 'Invalid Schema Definition',
+ '42P16': 'Invalid Table Definition',
+ '42P17': 'Invalid Object Definition',
+ '44000': 'With Check Option Violation',
+ '53000': 'Insufficient Resources',
+ '53100': 'Disk Full',
+ '53200': 'Out Of Memory',
+ '53300': 'Too Many Connections',
+ '53400': 'Configuration Limit Exceeded',
+ '54000': 'Program Limit Exceeded',
+ '54001': 'Statement Too Complex',
+ '54011': 'Too Many Columns',
+ '54023': 'Too Many Arguments',
+ '55000': 'Object Not In Prerequisite State',
+ '55006': 'Object In Use',
+ '55P02': "Can't Change Runtime Param",
+ '55P03': 'Lock Not Available',
+ '55P04': 'Unsafe New Enum Value Usage',
+ '57000': 'Operator Intervention',
+ '57014': 'Query Canceled',
+ '57P01': 'Admin Shutdown',
+ '57P02': 'Crash Shutdown',
+ '57P03': 'Cannot Connect Now',
+ '57P04': 'Database Dropped',
+ '58000': 'System Error',
+ '58030': 'IO Error',
+ '58P01': 'Undefined File',
+ '58P02': 'Duplicate File',
+ F0000: 'Config File Error',
+ F0001: 'Lock File Exists',
+ HV000: 'FDW Error',
+ HV005: 'FDW Column Name Not Found',
+ HV002: 'FDW Dynamic Parameter Value Needed',
+ HV010: 'FDW Function Sequence Error',
+ HV021: 'FDW Inconsistent Data',
+ HV024: 'FDW Invalid Attribute Value',
+ HV007: 'FDW Invalid Column Name',
+ HV008: 'FDW Invalid Column Number',
+ HV004: 'FDW Invalid Data Type',
+ HV006: 'FDW Invalid Data Type Descriptors',
+ HV091: 'FDW Invalid Handle',
+ HV00B: 'FDW Invalid Option Index',
+ HV00C: 'FDW Invalid Option Name',
+ HV00D: 'FDW Invalid String Length Or Buffer Length',
+ HV090: 'FDW Invalid String Format',
+ HV00A: 'FDW Invalid Use Of Null Pointer',
+ HV009: 'FDW Too Many Handles',
+ HV014: 'FDW Out Of Memory',
+ HV001: 'FDW Unsupported Function',
+ P0000: 'PL/pgSQL Error',
+ P0001: 'Raise Exception',
+ P0002: 'No Data Found',
+ P0003: 'Too Many Rows',
+ P0004: 'Assert Failure',
+ XX000: 'Internal Error',
+ XX001: 'Data Corrupted',
+ XX002: 'Index Corrupted',
+}
+
+const HTTP_STATUS_CODE_LABELS = {
+ '100': 'Continue',
+ '101': 'Switching Protocols',
+ '102': 'Processing',
+ '103': 'Early Hints',
+ '200': 'OK',
+ '201': 'Created',
+ '202': 'Accepted',
+ '203': 'Non-Authoritative Information',
+ '204': 'No Content',
+ '205': 'Reset Content',
+ '206': 'Partial Content',
+ '207': 'Multi-Status',
+ '208': 'Already Reported',
+ '226': 'IM Used',
+ '300': 'Multiple Choices',
+ '301': 'Moved Permanently',
+ '302': 'Found',
+ '303': 'See Other',
+ '304': 'Not Modified',
+ '305': 'Use Proxy',
+ '307': 'Temporary Redirect',
+ '308': 'Permanent Redirect',
+ '400': 'Bad Request',
+ '401': 'Unauthorized',
+ '402': 'Payment Required',
+ '403': 'Forbidden',
+ '404': 'Not Found',
+ '405': 'Method Not Allowed',
+ '406': 'Not Acceptable',
+ '407': 'Proxy Authentication Required',
+ '408': 'Request Timeout',
+ '409': 'Conflict',
+ '410': 'Gone',
+ '411': 'Length Required',
+ '412': 'Precondition Failed',
+ '413': 'Payload Too Large',
+ '414': 'URI Too Long',
+ '415': 'Unsupported Media Type',
+ '416': 'Range Not Satisfiable',
+ '417': 'Expectation Failed',
+ '418': "I'm a teapot",
+ '421': 'Misdirected Request',
+ '422': 'Unprocessable Entity',
+ '423': 'Locked',
+ '424': 'Failed Dependency',
+ '425': 'Too Early',
+ '426': 'Upgrade Required',
+ '428': 'Precondition Required',
+ '429': 'Too Many Requests',
+ '431': 'Request Header Fields Too Large',
+ '451': 'Unavailable For Legal Reasons',
+ '500': 'Internal Server Error',
+ '501': 'Not Implemented',
+ '502': 'Bad Gateway',
+ '503': 'Service Unavailable',
+ '504': 'Gateway Timeout',
+ '505': 'HTTP Version Not Supported',
+ '506': 'Variant Also Negotiates',
+ '507': 'Insufficient Storage',
+ '508': 'Loop Detected',
+ '510': 'Not Extended',
+ '511': 'Network Authentication Required',
+}
+
+export const STATUS_CODE_LABELS = {
+ ...HTTP_STATUS_CODE_LABELS,
+ ...POSTGRES_STATUS_CODE_LABELS,
+}
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.fields.tsx b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.fields.tsx
index 686b0ac126a..a2ab7ee4912 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.fields.tsx
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.fields.tsx
@@ -5,7 +5,7 @@ import { LEVELS } from 'components/ui/DataTable/DataTable.constants'
import { DataTableFilterField, Option } from 'components/ui/DataTable/DataTable.types'
import { getLevelColor, getStatusColor } from 'components/ui/DataTable/DataTable.utils'
import { cn } from 'ui'
-import { LOG_TYPES, METHODS } from './UnifiedLogs.constants'
+import { LOG_TYPES, METHODS, STATUS_CODE_LABELS } from './UnifiedLogs.constants'
import { ColumnSchema } from './UnifiedLogs.schema'
import { LogsMeta, SheetField } from './UnifiedLogs.types'
import { getLevelLabel } from './UnifiedLogs.utils'
@@ -28,7 +28,7 @@ export const filterFields = [
options: LOG_TYPES.map((type) => ({ label: type, value: type })),
component: (props: Option) => {
return (
- <div className="flex w-full items-center justify-between gap-2 font-mono">
+ <div className="flex w-full items-center justify-between gap-2">
<span className="capitalize text-foreground/70 group-hover:text-accent-foreground text-xs">
{props.label.replace('_', ' ')}
</span>
@@ -49,9 +49,23 @@ export const filterFields = [
component: (props: Option) => {
if (typeof props.value === 'boolean') return null
if (typeof props.value === 'undefined') return null
- if (typeof props.value === 'string') return null
+
+ const statusValue = String(props.value)
+ const statusLabel = STATUS_CODE_LABELS[statusValue as keyof typeof STATUS_CODE_LABELS]
+
+ // Convert string status codes to numbers for HTTP status styling
+ const statusCode = typeof props.value === 'string' ? parseInt(props.value, 10) : props.value
+ const isHttpStatus = !isNaN(statusCode) && statusCode >= 100 && statusCode < 600
+
return (
- <span className={cn('font-mono', getStatusColor(props.value).text)}>{props.value}</span>
+ <div className="flex items-center gap-2 w-full min-w-0">
+ <span className="flex-shrink-0 text-foreground">{statusValue}</span>
+ {statusLabel && (
+ <span className="text-[0.7rem] text-foreground-lighter truncate" title={statusLabel}>
+ {statusLabel}
+ </span>
+ )}
+ </div>
)
},
},
@@ -65,7 +79,7 @@ export const filterFields = [
// TODO: type `Option` with `options` values via Generics
const value = props.value as (typeof LEVELS)[number]
return (
- <div className="flex w-full max-w-28 items-center justify-between gap-2 font-mono">
+ <div className="flex w-full max-w-28 items-center justify-between gap-2">
<span className="capitalize text-foreground/70 group-hover:text-accent-foreground text-xs">
{props.label}
</span>
@@ -82,25 +96,59 @@ export const filterFields = [
value: 'method',
type: 'checkbox',
defaultOpen: true,
- options: METHODS.map((region) => ({ label: region, value: region })),
+ options: METHODS.map((method) => ({ label: method, value: method })),
component: (props: Option) => {
- return <span className="font-mono">{props.value}</span>
+ return (
+ <span className="truncate block text-[0.75rem]" title={props.value as string}>
+ {props.value}
+ </span>
+ )
},
},
{
label: 'Host',
value: 'host',
- type: 'input',
+ type: 'checkbox',
+ defaultOpen: false,
+ options: [], // Will be populated dynamically from facets
+ component: (props: Option) => {
+ return (
+ <span className="truncate block text-[0.75rem]" title={props.value as string}>
+ {props.value}
+ </span>
+ )
+ },
},
{
label: 'Pathname',
value: 'pathname',
- type: 'input',
+ type: 'checkbox',
+ defaultOpen: true,
+ options: [], // Will be populated dynamically from facets
+ component: (props: Option) => {
+ return (
+ <span className="truncate block w-full text-[0.75rem]" title={props.value as string}>
+ {props.value}
+ </span>
+ )
+ },
},
{
label: 'Auth User',
value: 'auth_user',
- type: 'input',
+ type: 'checkbox',
+ defaultOpen: false,
+ options: [], // Will be populated dynamically from facets
+ component: (props: Option) => {
+ return (
+ <div className="flex items-center gap-2 min-w-0">
+ <User size={14} className="text-foreground-lighter flex-shrink-0" />
+ <span className="truncate text-[0.75rem]" title={props.value as string}>
+ {props.value}
+ </span>
+ </div>
+ )
+ },
},
] satisfies DataTableFilterField<ColumnSchema>[]
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts
index 3c833ad632a..4d9cba79b51 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.queries.ts
@@ -309,7 +309,7 @@ const getPostgresLogsQuery = () => {
id,
pgl.timestamp as timestamp,
'postgres' as log_type,
- pgl_parsed.sql_state_code as status,
+ CAST(pgl_parsed.sql_state_code AS STRING) as status,
CASE
WHEN pgl_parsed.error_severity = 'LOG' THEN 'success'
WHEN pgl_parsed.error_severity = 'WARNING' THEN 'warning'
@@ -508,12 +508,37 @@ ${finalWhere}
/**
* Get a count query for the total logs within the timeframe
- * Also returns facets for all filter dimensions
+ * Uses proper faceted search behavior where facets show "what would I get if I selected ONLY this option"
*/
export const getLogsCountQuery = (search: QuerySearchParamsType): string => {
const { finalWhere } = buildQueryConditions(search)
- const methodWhere =
- finalWhere.length > 0 ? `${finalWhere} AND method is NOT NULL` : 'WHERE method IS NOT NULL'
+
+ // Helper function to build WHERE clause excluding a specific field
+ const buildFacetWhere = (excludeField: string): string => {
+ const conditions: string[] = []
+
+ Object.entries(search).forEach(([key, value]) => {
+ if (key === excludeField) return // Skip the field we're getting facets for
+ if (EXCLUDED_QUERY_PARAMS.includes(key as any)) return // Skip pagination and special params
+
+ // Handle array filters (IN clause)
+ if (Array.isArray(value) && value.length > 0) {
+ conditions.push(`${key} IN (${value.map((v) => `'${v}'`).join(',')})`)
+ return
+ }
+
+ // Handle scalar values
+ if (value !== null && value !== undefined) {
+ if (['host', 'pathname'].includes(key)) {
+ conditions.push(`${key} LIKE '%${value}%'`)
+ } else {
+ conditions.push(`${key} = '${value}'`)
+ }
+ }
+ })
+
+ return conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''
+ }
// Create a count query using the same unified logs CTE
const sql = `
@@ -525,27 +550,66 @@ ${finalWhere}
UNION ALL
--- Get counts by level
+-- Get counts by log_type (exclude log_type filter to avoid self-filtering)
+SELECT 'log_type' as dimension, log_type as value, COUNT(*) as count
+FROM unified_logs
+${buildFacetWhere('log_type') || 'WHERE log_type IS NOT NULL'}
+${buildFacetWhere('log_type') ? ' AND log_type IS NOT NULL' : ''}
+GROUP BY log_type
+
+UNION ALL
+
+-- Get counts by method (exclude method filter to avoid self-filtering)
+SELECT 'method' as dimension, method as value, COUNT(*) as count
+FROM unified_logs
+${buildFacetWhere('method') || 'WHERE method IS NOT NULL'}
+${buildFacetWhere('method') ? ' AND method IS NOT NULL' : ''}
+GROUP BY method
+
+UNION ALL
+
+-- Get counts by level (exclude level filter to avoid self-filtering)
SELECT 'level' as dimension, level as value, COUNT(*) as count
FROM unified_logs
-${finalWhere}
+${buildFacetWhere('level') || 'WHERE level IS NOT NULL'}
+${buildFacetWhere('level') ? ' AND level IS NOT NULL' : ''}
GROUP BY level
UNION ALL
--- Get counts by log_type
-SELECT 'log_type' as dimension, log_type as value, COUNT(*) as count
+-- Get counts by status (exclude status filter to avoid self-filtering)
+SELECT 'status' as dimension, status as value, COUNT(*) as count
FROM unified_logs
-${finalWhere}
-GROUP BY log_type
+${buildFacetWhere('status') || 'WHERE status IS NOT NULL'}
+${buildFacetWhere('status') ? ' AND status IS NOT NULL' : ''}
+GROUP BY status
UNION ALL
--- Get counts by method
-SELECT 'method' as dimension, method as value, COUNT(*) as count
+-- Get counts by host (exclude host filter to avoid self-filtering)
+SELECT 'host' as dimension, host as value, COUNT(*) as count
FROM unified_logs
-${methodWhere}
-GROUP BY method
+${buildFacetWhere('host') || 'WHERE host IS NOT NULL'}
+${buildFacetWhere('host') ? ' AND host IS NOT NULL' : ''}
+GROUP BY host
+
+UNION ALL
+
+-- Get counts by pathname (exclude pathname filter to avoid self-filtering)
+SELECT 'pathname' as dimension, pathname as value, COUNT(*) as count
+FROM unified_logs
+${buildFacetWhere('pathname') || 'WHERE pathname IS NOT NULL'}
+${buildFacetWhere('pathname') ? ' AND pathname IS NOT NULL' : ''}
+GROUP BY pathname
+
+UNION ALL
+
+-- Get counts by auth_user (exclude auth_user filter to avoid self-filtering)
+SELECT 'auth_user' as dimension, auth_user as value, COUNT(*) as count
+FROM unified_logs
+${buildFacetWhere('auth_user') || 'WHERE auth_user IS NOT NULL'}
+${buildFacetWhere('auth_user') ? ' AND auth_user IS NOT NULL' : ''}
+GROUP BY auth_user
`
return sql
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.schema.ts b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.schema.ts
index a6037e1270b..361308dd660 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.schema.ts
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.schema.ts
@@ -41,7 +41,7 @@ export const columnFilterSchema = z.object({
status: z
.string()
.transform((val) => val.split(ARRAY_DELIMITER))
- .pipe(z.coerce.number().array())
+ .pipe(z.string().array())
.optional(),
regions: z
.string()
diff --git a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.tsx b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.tsx
index 2410c0edd38..7010753bfff 100644
--- a/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.tsx
+++ b/apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.tsx
@@ -206,10 +206,17 @@ export const UnifiedLogs = () => {
const filterFields = useMemo(() => {
return defaultFilterFields.map((field) => {
const facetsField = facets?.[field.value]
+
+ // If no facets data available, use the predefined field
if (!facetsField) return field
- if (field.options && field.options.length > 0) return field
- // REMINDER: if no options are set, we need to set them via the API
+ // For hardcoded enum fields, keep the predefined options (facets only used for counts)
+ const isHardcodedField = ['log_type', 'method', 'level'].includes(field.value as string)
+ if (isHardcodedField) {
+ return field // Keep original predefined options
+ }
+
+ // For dynamic fields, use faceted options
const options = facetsField.rows.map(({ value }) => ({ label: `${value}`, value }))
if (field.type === ('slider' as any)) {
diff --git a/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckbox.tsx b/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckbox.tsx
index 94cca02970c..a514895a2b2 100644
--- a/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckbox.tsx
+++ b/apps/studio/components/ui/DataTable/DataTableFilters/DataTableFilterCheckbox.tsx
@@ -25,9 +25,10 @@ export function DataTableFilterCheckbox<TData>({
const Component = component
// filter out the options based on the input value
- const filterOptions = options?.filter(
- (option) => inputValue === '' || option.label.toLowerCase().includes(inputValue.toLowerCase())
- )
+ const filterOptions =
+ options?.filter(
+ (option) => inputValue === '' || option.label.toLowerCase().includes(inputValue.toLowerCase())
+ ) || []
// CHECK: it could be filterValue or searchValue
const filters = filterValue ? (Array.isArray(filterValue) ? filterValue : [filterValue]) : []
@@ -45,75 +46,102 @@ export function DataTableFilterCheckbox<TData>({
</div>
)
- if (!filterOptions?.length) return null
+ // Show empty state when no original options are available (not due to search filtering)
+ if (!options?.length)
+ return (
+ <div className="flex items-center justify-center px-2 py-6 text-center">
+ <div className="flex flex-col items-center gap-2">
+ <div className="h-8 w-8 rounded-full bg-muted flex items-center justify-center">
+ <Search className="h-4 w-4 text-muted-foreground" />
+ </div>
+ <div className="space-y-1">
+ <p className="text-sm text-muted-foreground">No options available</p>
+ <p className="text-xs text-muted-foreground/70">Try adjusting your filters</p>
+ </div>
+ </div>
+ </div>
+ )
return (
<div className="grid gap-2">
{options && options.length > 4 ? (
<InputWithAddons
placeholder="Search"
- leading={<Search className="mt-0.5 h-4 w-4" />}
- containerClassName="h-9 rounded"
+ leading={<Search size={14} className="text-foreground-lighter" />}
+ containerClassName="h-8 rounded"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
/>
) : null}
{/* FIXME: due to the added max-h and overflow-y-auto, the hover state and border is laying on top of the scroll bar */}
<div className="max-h-[200px] overflow-y-auto rounded border border-border empty:border-none">
- {filterOptions
- // TODO: we shoudn't sort the options here, instead filterOptions should be sorted by default
- // .sort((a, b) => a.label.localeCompare(b.label))
- .map((option, index) => {
- const checked = filters.includes(option.value)
+ {filterOptions.length === 0 && inputValue !== '' ? (
+ <div className="flex items-center justify-center px-2 py-4 text-center">
+ <div className="space-y-1">
+ <p className="text-sm text-muted-foreground">No results found</p>
+ <p className="text-xs text-muted-foreground/70">Try a different search term</p>
+ </div>
+ </div>
+ ) : (
+ filterOptions
+ // TODO: we shoudn't sort the options here, instead filterOptions should be sorted by default
+ // .sort((a, b) => a.label.localeCompare(b.label))
+ .map((option, index) => {
+ const checked = filters.includes(option.value)
- return (
- <div
- key={String(option.value)}
- className={cn(
- 'group relative flex items-center space-x-2 px-2 py-2.5 hover:bg-accent/50',
- index !== filterOptions.length - 1 ? 'border-b' : undefined
- )}
- >
- <Checkbox
- 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)
- }}
- />
- <Label
- htmlFor={`${value}-${option.value}`}
- className="flex w-full items-center justify-center gap-1 truncate text-foreground/70 group-hover:text-accent-foreground"
- >
- {Component ? (
- <Component {...option} />
- ) : (
- <span className="truncate font-normal">{option.label}</span>
+ return (
+ <div
+ key={String(option.value)}
+ className={cn(
+ 'group relative flex items-center space-x-2 px-2 py-2 hover:bg-accent/50',
+ index !== filterOptions.length - 1 ? 'border-b' : undefined
)}
- <span className="ml-auto flex items-center justify-center font-mono text-xs">
- {isLoadingCounts ? (
- <Skeleton className="h-4 w-4" />
- ) : facetedValue?.has(option.value) ? (
- formatCompactNumber(facetedValue.get(option.value) || 0)
- ) : null}
- </span>
- <button
- type="button"
- onClick={() => column?.setFilterValue([option.value])}
- className={cn(
- 'absolute inset-y-0 right-0 hidden font-normal text-muted-foreground backdrop-blur-sm hover:text-foreground group-hover:block',
- 'rounded-md ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2'
- )}
+ >
+ <Checkbox
+ 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)
+ }}
+ />
+ <Label
+ htmlFor={`${value}-${option.value}`}
+ className="flex w-full items-center justify-between gap-2 text-foreground/70 group-hover:text-accent-foreground text-[0.8rem] min-w-0"
>
- <span className="px-2">only</span>
- </button>
- </Label>
- </div>
- )
- })}
+ <div className="flex-1 min-w-0 overflow-hidden">
+ {Component ? (
+ <Component {...option} />
+ ) : (
+ <span className="truncate font-normal block">{option.label}</span>
+ )}
+ </div>
+ <span className="flex-shrink-0 flex items-center justify-center font-mono text-xs">
+ {isLoadingCounts ? (
+ <Skeleton className="h-4 w-4" />
+ ) : facetedValue?.has(option.value) ? (
+ formatCompactNumber(facetedValue.get(option.value) || 0)
+ ) : ['log_type', 'method', 'level'].includes(value) ? (
+ '0'
+ ) : null}
+ </span>
+ <button
+ type="button"
+ onClick={() => column?.setFilterValue([option.value])}
+ className={cn(
+ 'absolute inset-y-0 right-0 hidden font-normal text-muted-foreground backdrop-blur-sm hover:text-foreground group-hover:block',
+ 'rounded-md ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2'
+ )}
+ >
+ <span className="px-2">only</span>
+ </button>
+ </Label>
+ </div>
+ )
+ })
+ )}
</div>
</div>
)
diff --git a/apps/studio/components/ui/DataTable/primitives/InputWithAddons.tsx b/apps/studio/components/ui/DataTable/primitives/InputWithAddons.tsx
index bc08b4fe97f..2848c0e3cc3 100644
--- a/apps/studio/components/ui/DataTable/primitives/InputWithAddons.tsx
+++ b/apps/studio/components/ui/DataTable/primitives/InputWithAddons.tsx
@@ -19,14 +19,12 @@ export const InputWithAddons = forwardRef<HTMLInputElement, InputWithAddonsProps
)}
>
{leading ? (
- <div className="border-input bg-muted/50 border-r px-2.5 py-2 flex items-center justify-center">
- {leading}
- </div>
+ <div className="border-input px-2 flex items-center justify-center">{leading}</div>
) : null}
<input
className={cn(
- 'bg-background w-full px-3 py-2 focus:outline-none border-0 placeholder:text-muted-foreground ',
- 'disabled:cursor-not-allowed disabled:opacity-50 text-sm',
+ 'bg-transparent w-full px-0 py-2 focus:outline-none border-0 placeholder:text-foreground-lighter ',
+ 'disabled:cursor-not-allowed disabled:opacity-50 text-[0.75rem]',
className
)}
ref={ref}