From c12b27afb55b32076cdfb7c781749ebc57e904a8 Mon Sep 17 00:00:00 2001 From: henrygd Date: Wed, 19 Feb 2025 20:28:45 -0500 Subject: [PATCH] refactor: update system table and improve add-system dialog --- beszel/site/src/components/add-system.tsx | 62 +++++++++++------ .../systems-table/systems-table.tsx | 68 +++++++++++-------- 2 files changed, 78 insertions(+), 52 deletions(-) diff --git a/beszel/site/src/components/add-system.tsx b/beszel/site/src/components/add-system.tsx index fc154e0..1f1cc8b 100644 --- a/beszel/site/src/components/add-system.tsx +++ b/beszel/site/src/components/add-system.tsx @@ -19,7 +19,7 @@ import { i18n } from "@lingui/core" import { t, Trans } from "@lingui/macro" import { useStore } from "@nanostores/react" import { ChevronDownIcon, Copy, PlusIcon } from "lucide-react" -import { memo, MutableRefObject, useRef, useState } from "react" +import { memo, useRef, useState } from "react" import { basePath, navigate } from "./router" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "./ui/dropdown-menu" import { SystemRecord } from "@/types" @@ -49,19 +49,8 @@ export function AddSystemButton({ className }: { className?: string }) { ) } -/** - * SystemDialog component for adding or editing a system. - * @param {Object} props - The component props. - * @param {function} props.setOpen - Function to set the open state of the dialog. - * @param {SystemRecord} [props.system] - Optional system record for editing an existing system. - */ -export const SystemDialog = memo(({ setOpen, system }: { setOpen: (open: boolean) => void; system?: SystemRecord }) => { - const port = useRef() as MutableRefObject - const publicKey = useStore($publicKey) - - function copyDockerCompose(port: string) { + function copyDockerCompose(port = "45876", publicKey: string) { copyToClipboard(`services: - version: "3" beszel-agent: image: "henrygd/beszel-agent" container_name: "beszel-agent" @@ -76,13 +65,13 @@ export const SystemDialog = memo(({ setOpen, system }: { setOpen: (open: boolean KEY: "${publicKey}"`) } - function copyDockerRun(port: string) { + function copyDockerRun(port = "45876", publicKey: string) { copyToClipboard( `docker run -d --name beszel-agent --network host --restart unless-stopped -v /var/run/docker.sock:/var/run/docker.sock:ro -e KEY="${publicKey}" -e PORT=${port} henrygd/beszel-agent:latest` ) } - function copyInstallCommand(port: string) { + function copyInstallCommand(port = "45876", publicKey: string) { let cmd = `curl -sL https://raw.githubusercontent.com/henrygd/beszel/main/supplemental/scripts/install-agent.sh -o install-agent.sh && chmod +x install-agent.sh && ./install-agent.sh -p ${port} -k "${publicKey}"` // add china mirrors flag if zh-CN if ((i18n.locale + navigator.language).includes("zh-CN")) { @@ -91,6 +80,18 @@ export const SystemDialog = memo(({ setOpen, system }: { setOpen: (open: boolean copyToClipboard(cmd) } +/** + * SystemDialog component for adding or editing a system. + * @param {Object} props - The component props. + * @param {function} props.setOpen - Function to set the open state of the dialog. + * @param {SystemRecord} [props.system] - Optional system record for editing an existing system. + */ +export const SystemDialog = memo(({ setOpen, system }: { setOpen: (open: boolean) => void; system?: SystemRecord }) => { + const publicKey = useStore($publicKey) + const port = useRef(null) + const [hostValue, setHostValue] = useState(system?.host ?? "") + const isUnixSocket = hostValue.startsWith("/") + async function handleSubmit(e: SubmitEvent) { e.preventDefault() const formData = new FormData(e.target as HTMLFormElement) @@ -111,7 +112,9 @@ export const SystemDialog = memo(({ setOpen, system }: { setOpen: (open: boolean } return ( - + { + setHostValue(system?.host ?? "") + }}> @@ -150,11 +153,26 @@ export const SystemDialog = memo(({ setOpen, system }: { setOpen: (open: boolean - -