add net column to systems table

This commit is contained in:
Henry Dollman
2024-10-12 16:37:09 -04:00
parent c0a3bbeefc
commit b464fa5b3f
3 changed files with 36 additions and 3 deletions

View File

@@ -59,15 +59,16 @@ import {
import { useEffect, useMemo, useState } from 'react' import { useEffect, useMemo, useState } from 'react'
import { $hubVersion, $systems, pb } from '@/lib/stores' import { $hubVersion, $systems, pb } from '@/lib/stores'
import { useStore } from '@nanostores/react' import { useStore } from '@nanostores/react'
import { cn, copyToClipboard, isReadOnlyUser } from '@/lib/utils' import { cn, copyToClipboard, decimalString, isReadOnlyUser } from '@/lib/utils'
import AlertsButton from '../table-alerts' import AlertsButton from '../table-alerts'
import { navigate } from '../router' import { navigate } from '../router'
import { EthernetIcon } from '../ui/icons'
function CellFormatter(info: CellContext<SystemRecord, unknown>) { function CellFormatter(info: CellContext<SystemRecord, unknown>) {
const val = info.getValue() as number const val = info.getValue() as number
return ( return (
<div className="flex gap-1 items-center tabular-nums tracking-tight"> <div className="flex gap-1 items-center tabular-nums tracking-tight">
<span className="min-w-[3.5em]">{val.toFixed(1)}%</span> <span className="min-w-[3.5em]">{decimalString(val, 1)}%</span>
<span className="grow min-w-10 block bg-muted h-[1em] relative rounded-sm overflow-hidden"> <span className="grow min-w-10 block bg-muted h-[1em] relative rounded-sm overflow-hidden">
<span <span
className={cn( className={cn(
@@ -161,9 +162,22 @@ export default function SystemsTable({ filter }: { filter?: string }) {
cell: CellFormatter, cell: CellFormatter,
header: ({ column }) => sortableHeader(column, 'Disk', HardDrive), header: ({ column }) => sortableHeader(column, 'Disk', HardDrive),
}, },
{
accessorKey: 'info.b',
size: 80,
header: ({ column }) => sortableHeader(column, 'Net', EthernetIcon),
cell: (info) => {
return (
<span className="tabular-nums whitespace-nowrap pl-1">
{decimalString((info.getValue() as number) || 0, 2)} MB/s
</span>
)
},
},
{ {
accessorKey: 'info.v', accessorKey: 'info.v',
size: 50, size: 50,
header: ({ column }) => sortableHeader(column, 'Agent', WifiIcon, true),
cell: (info) => { cell: (info) => {
const version = info.getValue() as string const version = info.getValue() as string
if (!version || !hubVersion) { if (!version || !hubVersion) {
@@ -182,7 +196,6 @@ export default function SystemsTable({ filter }: { filter?: string }) {
</span> </span>
) )
}, },
header: ({ column }) => sortableHeader(column, 'Agent', WifiIcon, true),
}, },
{ {
id: 'actions', id: 'actions',

View File

@@ -45,3 +45,19 @@ export function ChartMax(props: SVGProps<SVGSVGElement>) {
</svg> </svg>
) )
} }
// Lucide https://github.com/lucide-icons/lucide (not in package for some reason)
export function EthernetIcon(props: SVGProps<SVGSVGElement>) {
return (
<svg
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeWidth="2"
viewBox="0 0 24 24"
{...props}
>
<path d="m15 20 3-3h2a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h2l3 3zM6 8v1m4-1v1m4-1v1m4-1v1" />
</svg>
)
}

View File

@@ -30,6 +30,10 @@ export interface SystemInfo {
mp: number mp: number
/** disk percent */ /** disk percent */
dp: number dp: number
/** bandwidth (mb) */
b: number
/** agent version */
v: string
} }
export interface SystemStats { export interface SystemStats {