import { format } from 'date-fns'
import { User } from 'lucide-react'
import { LEVELS } from 'components/ui/DataTable/DataTable.constants'
import { DataTableFilterField, Option } from 'components/ui/DataTable/DataTable.types'
import { getLevelColor } from 'components/ui/DataTable/DataTable.utils'
import { cn } from 'ui'
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'
// instead of filterFields, maybe just 'fields' with a filterDisabled prop?
// that way, we could have 'message' or 'headers' field with label and value as well as type!
export const filterFields = [
{
label: 'Time Range',
value: 'date',
type: 'timerange',
defaultOpen: true,
commandDisabled: true,
},
{
label: 'Log Type',
value: 'log_type',
type: 'checkbox',
defaultOpen: true,
options: LOG_TYPES.map((type) => ({ label: type, value: type })),
component: (props: Option) => {
return (
{props.label.replace('_', ' ')}
)
},
},
{
label: 'Status',
value: 'status',
type: 'checkbox',
defaultOpen: true,
options: [],
hasDynamicOptions: true,
component: (props: Option) => {
if (typeof props.value === 'boolean') return null
if (typeof props.value === 'undefined') return null
const statusValue = String(props.value)
const statusLabel = STATUS_CODE_LABELS[statusValue as keyof typeof STATUS_CODE_LABELS]
return (
{statusValue}
{statusLabel && (
{statusLabel}
)}
)
},
},
{
label: 'Level',
value: 'level',
type: 'checkbox',
defaultOpen: true,
options: LEVELS.map((level) => ({ label: level, value: level })),
component: (props: Option) => {
// TODO: type `Option` with `options` values via Generics
const value = props.value as (typeof LEVELS)[number]
return (
)
},
},
{
label: 'Method',
value: 'method',
type: 'checkbox',
defaultOpen: true,
options: METHODS.map((method) => ({ label: method, value: method })),
component: (props: Option) => {
return (
{props.value}
)
},
},
{
label: 'Pathname',
value: 'pathname',
type: 'checkbox',
defaultOpen: false,
options: [],
hasDynamicOptions: true,
hasAsyncSearch: false,
component: (props: Option) => {
return (
{props.value}
)
},
},
] satisfies DataTableFilterField[]
export const sheetFields = [
{
id: 'id',
label: 'Request ID',
type: 'readonly',
skeletonClassName: 'w-64',
},
{
id: 'date',
label: 'Date',
type: 'timerange',
component: (props) => {
const date = new Date(props.date)
const month = format(date, 'LLL')
const day = format(date, 'dd')
const year = format(date, 'y')
const time = format(date, 'HH:mm:ss')
return (
{month}
·
{day}
·
{year}
·
{time}
)
},
skeletonClassName: 'w-36',
},
{
id: 'auth_user',
label: 'Auth User',
type: 'readonly',
condition: (props) => Boolean(props.auth_user),
component: (props) => (
{props.auth_user}
),
skeletonClassName: 'w-56',
},
{
id: 'pathname',
label: 'Pathname',
type: 'input',
skeletonClassName: 'w-56',
},
] satisfies SheetField[]