mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 09:49:28 +08:00
updates
This commit is contained in:
@@ -6,32 +6,39 @@ import { DataTable } from '../server-table/data-table'
|
|||||||
export function Home() {
|
export function Home() {
|
||||||
const [systems, setSystems] = useState([] as SystemRecord[])
|
const [systems, setSystems] = useState([] as SystemRecord[])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
document.title = 'Home'
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
pb.collection<SystemRecord>('systems')
|
pb.collection<SystemRecord>('systems')
|
||||||
.getList(1, 20)
|
.getFullList({
|
||||||
.then(({ items }) => {
|
sort: 'name',
|
||||||
|
})
|
||||||
|
.then((items) => {
|
||||||
setSystems(items)
|
setSystems(items)
|
||||||
})
|
})
|
||||||
|
|
||||||
pb.collection<SystemRecord>('systems').subscribe('*', (e) => {
|
// pb.collection<SystemRecord>('systems').subscribe('*', (e) => {
|
||||||
setSystems((curSystems) => {
|
// setSystems((curSystems) => {
|
||||||
const i = curSystems.findIndex((s) => s.id === e.record.id)
|
// const i = curSystems.findIndex((s) => s.id === e.record.id)
|
||||||
if (i > -1) {
|
// if (i > -1) {
|
||||||
const newSystems = [...curSystems]
|
// const newSystems = [...curSystems]
|
||||||
newSystems[i] = e.record
|
// newSystems[i] = e.record
|
||||||
return newSystems
|
// return newSystems
|
||||||
} else {
|
// } else {
|
||||||
return [...curSystems, e.record]
|
// return [...curSystems, e.record]
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
})
|
// })
|
||||||
return () => pb.collection('systems').unsubscribe('*')
|
// return () => pb.collection('systems').unsubscribe('*')
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
// if (!systems.length) return <>Loading...</>
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 class="my-5">Dashboard</h1>
|
<DataTable data={systems} />
|
||||||
{systems.length && <DataTable data={systems} />}
|
|
||||||
{/* <pre>{JSON.stringify(systems, null, 2)}</pre> */}
|
{/* <pre>{JSON.stringify(systems, null, 2)}</pre> */}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
@@ -1,12 +1,28 @@
|
|||||||
import { useEffect } from 'preact/hooks'
|
import { pb } from '@/lib/stores'
|
||||||
|
import { SystemRecord } from '@/types'
|
||||||
|
import { useEffect, useState } from 'preact/hooks'
|
||||||
import { useRoute } from 'wouter-preact'
|
import { useRoute } from 'wouter-preact'
|
||||||
|
|
||||||
export function ServerDetail() {
|
export function ServerDetail() {
|
||||||
const [_, params] = useRoute('/server/:name')
|
const [_, params] = useRoute('/server/:name')
|
||||||
|
const [node, setNode] = useState({} as SystemRecord)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.title = `Server: ${params!.name}`
|
document.title = params!.name
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return <>Info for {params!.name}</>
|
useEffect(() => {
|
||||||
|
pb.collection<SystemRecord>('systems')
|
||||||
|
.getFirstListItem(`name="${params!.name}"`)
|
||||||
|
.then((record) => {
|
||||||
|
setNode(record)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h1>{node.name}</h1>
|
||||||
|
<pre>{JSON.stringify(node, null, 2)}</pre>
|
||||||
|
</>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@@ -33,34 +33,40 @@ import {
|
|||||||
} from '@/components/ui/dropdown-menu'
|
} from '@/components/ui/dropdown-menu'
|
||||||
|
|
||||||
import { SystemRecord } from '@/types'
|
import { SystemRecord } from '@/types'
|
||||||
import { MoreHorizontal, ArrowUpDown } from 'lucide-react'
|
import { MoreHorizontal, ArrowUpDown, Copy, RefreshCcw } from 'lucide-react'
|
||||||
import { Link } from 'wouter-preact'
|
import { Link } from 'wouter-preact'
|
||||||
import { useState } from 'preact/hooks'
|
import { useState } from 'preact/hooks'
|
||||||
|
|
||||||
function CellFormatter(info: CellContext<SystemRecord, unknown>) {
|
function CellFormatter(info: CellContext<SystemRecord, unknown>) {
|
||||||
const val = info.getValue() as number
|
const val = info.getValue() as number
|
||||||
let background = '#42b768'
|
let background = '#42b768'
|
||||||
if (val > 25) {
|
if (val > 80) {
|
||||||
|
// red
|
||||||
background = '#da2a49'
|
background = '#da2a49'
|
||||||
} else if (val > 10) {
|
} else if (val > 50) {
|
||||||
|
// yellow
|
||||||
background = '#daa42a'
|
background = '#daa42a'
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div class="flex gap-2 items-center">
|
<div class="flex gap-2 items-center">
|
||||||
<span class="grow block bg-secondary h-4 relative rounded-sm overflow-hidden">
|
<span class="grow block bg-secondary h-4 relative rounded-sm overflow-hidden">
|
||||||
<span
|
<span
|
||||||
className="absolute inset-0 w-full h-full origin-left transition-all duration-500 ease-in-out"
|
className="absolute inset-0 w-full h-full origin-left"
|
||||||
style={{ transform: `scalex(${val}%)`, background }}
|
style={{ transform: `scalex(${val}%)`, background }}
|
||||||
></span>
|
></span>
|
||||||
</span>
|
</span>
|
||||||
<span class="w-14">{val.toFixed(2)}%</span>
|
<span class="w-16">{val.toFixed(2)}%</span>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortableHeader(column: Column<SystemRecord, unknown>, name: string) {
|
function sortableHeader(column: Column<SystemRecord, unknown>, name: string) {
|
||||||
return (
|
return (
|
||||||
<Button variant="ghost" onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}>
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
className="h-9 px-3"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||||
|
>
|
||||||
{name}
|
{name}
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -72,7 +78,19 @@ export function DataTable({ data }: { data: SystemRecord[] }) {
|
|||||||
{
|
{
|
||||||
size: 40,
|
size: 40,
|
||||||
accessorKey: 'name',
|
accessorKey: 'name',
|
||||||
cell: (info) => <strong>{info.getValue() as string}</strong>,
|
cell: (info) => (
|
||||||
|
<span className="flex gap-2 items-center text-base">
|
||||||
|
{info.getValue() as string}{' '}
|
||||||
|
<button
|
||||||
|
title={`Copy "${info.getValue() as string}" to clipboard`}
|
||||||
|
class="opacity-50 hover:opacity-70 active:opacity-100 duration-75"
|
||||||
|
onClick={() => navigator.clipboard.writeText(info.getValue() as string)}
|
||||||
|
>
|
||||||
|
<Copy className="h-3.5 w-3.5 " />
|
||||||
|
</button>
|
||||||
|
{/* </Button> */}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
header: ({ column }) => sortableHeader(column, 'Node'),
|
header: ({ column }) => sortableHeader(column, 'Node'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -145,7 +163,7 @@ export function DataTable({ data }: { data: SystemRecord[] }) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="w-full my-6">
|
||||||
<div className="flex items-center py-4">
|
<div className="flex items-center py-4">
|
||||||
<Input
|
<Input
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -154,10 +172,20 @@ export function DataTable({ data }: { data: SystemRecord[] }) {
|
|||||||
onChange={(event: Event) => table.getColumn('name')?.setFilterValue(event.target.value)}
|
onChange={(event: Event) => table.getColumn('name')?.setFilterValue(event.target.value)}
|
||||||
className="max-w-sm"
|
className="max-w-sm"
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
alert('todo: refresh')
|
||||||
|
}}
|
||||||
|
className="ml-auto flex gap-2"
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
<RefreshCcw className="h-4 w-4" />
|
||||||
|
Refresh
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div className="rounded-md border tabular-nums">
|
<div className="rounded-md border">
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader className="bg-muted/60">
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
<TableRow key={headerGroup.id}>
|
<TableRow key={headerGroup.id}>
|
||||||
{headerGroup.headers.map((header) => {
|
{headerGroup.headers.map((header) => {
|
||||||
@@ -193,6 +221,6 @@ export function DataTable({ data }: { data: SystemRecord[] }) {
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user