From 1499f1cab3eaf0851f8fe012248cbd5ae61dd900 Mon Sep 17 00:00:00 2001 From: Vehbi Sinan Tunalioglu Date: Sat, 23 Mar 2024 19:13:56 +0800 Subject: [PATCH] feat(website): improve host details --- website/src/components/app/-app.tsx | 153 ++++++++++++++++----------- website/src/components/app/-data.tsx | 4 +- website/src/components/app/-ui.tsx | 26 +++++ 3 files changed, 120 insertions(+), 63 deletions(-) diff --git a/website/src/components/app/-app.tsx b/website/src/components/app/-app.tsx index 6dd1529..be237fe 100644 --- a/website/src/components/app/-app.tsx +++ b/website/src/components/app/-app.tsx @@ -7,6 +7,7 @@ import Link from 'next/link'; import { Just, Maybe, Nothing } from 'purify-ts/Maybe'; import { useState } from 'react'; import { LhpData } from './-data'; +import { KVBox } from './-ui'; export function App({ data, onFlushRequest }: { data: LhpData[]; onFlushRequest: () => void }) { const [host, setHost] = useState>(Nothing); @@ -185,73 +186,105 @@ export function TabulateHosts({ hosts, onHostSelect }: { hosts: LhpData[]; onHos } export function HostDetails({ host }: { host: LhpData }) { - const kvs = [ - { key: 'Hostname', value: host.host.name }, - { key: 'Kernel Name', value: host.kernel.name }, - { key: 'Kernel Architecture', value: host.kernel.machine }, - { key: 'Kernel Release', value: host.kernel.release }, - { key: 'Operating System', value: host.kernel.os }, - { key: 'Distribution ID', value: host.distribution.id }, - { key: 'Distribution Name', value: host.distribution.name }, - { key: 'Distribution Version ID', value: host.distribution.id }, - { key: 'Distribution Version', value: host.distribution.version }, - { key: 'Distribution Version Code', value: host.distribution.codename }, - { key: 'Distribution Full Name', value: host.distribution.description }, - { key: 'Cloud', value: host.cloud.name }, - { key: 'Type', value: host.cloud.hostType }, - { key: 'Region', value: host.cloud.hostRegion }, - { key: 'CPU', value: `${host.hardware.cpuCount} cores` }, - { key: 'RAM', value: `${host.hardware.ramTotal} GB` }, - { key: 'DISK', value: `${host.hardware.diskRoot} GB` }, - ]; - return (
-

{host.host.name}

+

+
+ {host.host.name} + {host.host.url && ( + + 🔗 + + )} +
+ +
+ {(host.host.tags || []).map((x) => ( + + {x} + + ))} +
+

+ +
+ +
+ +
+ -
-
- - Host Information + +
- - - {({ key, value }) => ( - - {key} +
+ + Docker Containers + + + {host.dockerContainers ? ( + (a.running ? 0 : 1) - (b.running ? 0 : 1) || a.name.localeCompare(b.name) + ), + ]} + emptyContent={Docker service has no containers.} + > + {({ id, image, name, running, created }) => ( + 🟢 : <>🔴} + endContent={ + + {created} + + } + > + {name} )} - - -
- -
- - Docker Containers - - - {host.dockerContainers ? ( - (a.running ? 0 : 1) - (b.running ? 0 : 1) || a.name.localeCompare(b.name) - ), - ]} - emptyContent={Docker service has no containers.} - > - {({ id, image, name, running }) => ( - 🟢 : <>🔴}> - {name} - - )} - - ) : ( - Docker service is not found. - )} - - -
+ ) : ( + Docker service is not found. + )} +
+
); diff --git a/website/src/components/app/-data.tsx b/website/src/components/app/-data.tsx index d83dc6b..7404f90 100644 --- a/website/src/components/app/-data.tsx +++ b/website/src/components/app/-data.tsx @@ -52,9 +52,7 @@ export interface LhpData { dockerContainers: | null | { - created: { - [k: string]: unknown; - }; + created: string; id: string; image: string; name: string; diff --git a/website/src/components/app/-ui.tsx b/website/src/components/app/-ui.tsx index 23c0130..638e77e 100644 --- a/website/src/components/app/-ui.tsx +++ b/website/src/components/app/-ui.tsx @@ -1,3 +1,5 @@ +import { Card, CardBody, CardHeader } from '@nextui-org/card'; +import { Listbox, ListboxItem } from '@nextui-org/listbox'; import { Spinner } from '@nextui-org/react'; export function Centered({ children }: { children: React.ReactNode }) { @@ -11,3 +13,27 @@ export function BigSpinner({ label }: { label?: string }) { ); } + +export function KVBox({ + title, + kvs, +}: { + title: string; + kvs: { key: string; value: React.ReactNode | string | number | null | undefined }[]; +}) { + return ( + + {title} + + + + {({ key, value }) => ( + + {key} + + )} + + + + ); +}