import { useI18n } from '@solid-primitives/i18n' import { IconSettings } from '@tabler/icons-solidjs' import { ColumnDef, createSolidTable, flexRender, getCoreRowModel, } from '@tanstack/solid-table' import { For, Index, createEffect, createSignal } from 'solid-js' import { twMerge } from 'tailwind-merge' import { Button, LogsSettingsModal } from '~/components' import { LOG_LEVEL, MODAL } from '~/constants' import { logsTableSize, tableSizeClassName, useWsRequest } from '~/signals' import { logLevel, logMaxRows } from '~/signals/config' import { Log } from '~/types' type LogWithSeq = Log & { seq: number } export default () => { const [t] = useI18n() let seq = 1 const [search, setSearch] = createSignal('') const [logs, setLogs] = createSignal([]) const logsData = useWsRequest('logs', { level: logLevel() }) createEffect(() => { const data = logsData() if (!data) { return } setLogs((logs) => [{ ...data, seq }, ...logs].slice(0, logMaxRows())) seq++ }) const columns: ColumnDef[] = [ { header: t('sequence'), accessorFn: (row) => row.seq, }, { header: t('type'), cell: ({ row }) => { const type = row.original.type as LOG_LEVEL let className = '' switch (type) { case LOG_LEVEL.Error: className = 'text-error' break case LOG_LEVEL.Warning: className = 'text-warning' break case LOG_LEVEL.Info: className = 'text-info' break case LOG_LEVEL.Debug: className = 'text-success' break } return {`[${row.original.type}]`} }, }, { header: t('payload'), accessorFn: (row) => row.payload, }, ] const table = createSolidTable({ get data() { return search() ? logs().filter((log) => log.payload.toLowerCase().includes(search().toLowerCase()), ) : logs() }, columns, getCoreRowModel: getCoreRowModel(), }) return (
setSearch(e.target.value)} />
{(keyedHeaderGroup) => { const headerGroup = keyedHeaderGroup() return ( {(keyedHeader) => { const header = keyedHeader() return ( ) }} ) }} {(row) => ( {(cell) => ( )} )}
{header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext(), )}
{flexRender( cell.column.columnDef.cell, cell.getContext(), )}
) }