import { useI18n } from '@solid-primitives/i18n' import { ColumnDef, createSolidTable, flexRender, getCoreRowModel, } from '@tanstack/solid-table' import { For, createEffect, createSignal } from 'solid-js' import { twMerge } from 'tailwind-merge' import { tableSize, tableSizeClassName, useWsRequest } from '~/signals' import { Log } from '~/types' type LogWithSeq = Log & { seq: number } export default () => { const [t] = useI18n() let seq = 0 const [search, setSearch] = createSignal('') const [logs, setLogs] = createSignal([]) const logsData = useWsRequest('logs') createEffect(() => { const data = logsData() if (!data) { return } setLogs((logs) => [{ ...data, seq }, ...logs].slice(0, 100)) seq++ }) const columns: ColumnDef[] = [ { header: t('sequence'), accessorFn: (row) => row.seq, }, { header: t('type'), cell: ({ row }) => { const type = row.original.type let className = '' switch (type) { case 'error': className = 'text-error' break case 'warning': className = 'text-warning' break case 'info': className = 'text-info' 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)} />
{(headerGroup) => ( {(header) => ( )} )} {(row) => ( {(cell) => ( )} )}
{header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext(), )}
{flexRender( cell.column.columnDef.cell, cell.getContext(), )}
) }