From c158b1aeebcf3e7ffe91a72b597f34b520f5a9cd Mon Sep 17 00:00:00 2001 From: henrygd Date: Fri, 22 Aug 2025 19:28:00 -0400 Subject: [PATCH] move alerts ui to sheet component --- beszel/site/src/components/add-system.tsx | 289 +++++++++--------- .../src/components/alerts/alert-button.tsx | 41 +-- .../{alerts-dialog.tsx => alerts-sheet.tsx} | 0 beszel/site/src/components/navbar.tsx | 2 +- beszel/site/src/components/router.tsx | 2 +- .../systems-table/systems-table-columns.tsx | 27 +- beszel/site/src/components/ui/sheet.tsx | 101 ++++++ beszel/site/src/components/ui/tabs.tsx | 2 +- 8 files changed, 272 insertions(+), 192 deletions(-) rename beszel/site/src/components/alerts/{alerts-dialog.tsx => alerts-sheet.tsx} (100%) create mode 100644 beszel/site/src/components/ui/sheet.tsx diff --git a/beszel/site/src/components/add-system.tsx b/beszel/site/src/components/add-system.tsx index 07f8555..a5efc68 100644 --- a/beszel/site/src/components/add-system.tsx +++ b/beszel/site/src/components/add-system.tsx @@ -17,7 +17,7 @@ import { $publicKey, pb } from "@/lib/stores" import { cn, generateToken, isReadOnlyUser, tokenMap, useLocalStorage } from "@/lib/utils" import { useStore } from "@nanostores/react" import { ChevronDownIcon, ExternalLinkIcon, PlusIcon } from "lucide-react" -import { memo, useEffect, useRef, useState } from "react" +import { memo, useEffect, useMemo, useRef, useState } from "react" import { $router, basePath, Link, navigate } from "./router" import { SystemRecord } from "@/types" import { AppleIcon, DockerIcon, TuxIcon, WindowsIcon } from "./ui/icons" @@ -122,151 +122,154 @@ export const SystemDialog = ({ setOpen, system }: { setOpen: (open: boolean) => } } - return ( - { - setHostValue(system?.host ?? "") - }} - > - - - - {system ? `${t`Edit`} ${system?.name}` : Add New System} - - - Docker - - Binary - - - - {/* Docker (set tab index to prevent auto focusing content in edit system dialog) */} - - - - Copy the - docker-compose.yml content for the agent - below, or register agents automatically with a{" "} - setOpen(false)} - href={getPagePath($router, "settings", { name: "tokens" })} - className="link" - > - universal token - - . - - - - {/* Binary */} - - - - Copy the installation command for the agent below, or register agents automatically with a{" "} - { - setOpen(false) + return useMemo( + () => ( + { + setHostValue(system?.host ?? "") + }} + > + + + + {system ? `${t`Edit`} ${system?.name}` : Add New System} + + + Docker + + Binary + + + + {/* Docker (set tab index to prevent auto focusing content in edit system dialog) */} + + + + Copy the + docker-compose.yml content for the agent + below, or register agents automatically with a{" "} + setOpen(false)} + href={getPagePath($router, "settings", { name: "tokens" })} + className="link" + > + universal token + + . + + + + {/* Binary */} + + + + Copy the installation command for the agent below, or register agents automatically with a{" "} + setOpen(false)} + href={getPagePath($router, "settings", { name: "tokens" })} + className="link" + > + universal token + + . + + + +
+
+ + + + { + setHostValue(e.target.value) }} - href={getPagePath($router, "settings", { name: "tokens" })} - className="link" - > - universal token - - . - - - - -
- - - - { - setHostValue(e.target.value) - }} - /> - - - - - - -
- - {/* Docker */} - - - copyDockerCompose(isUnixSocket ? hostValue : port.current?.value, publicKey, token) - } - icon={} - dropdownItems={[ - { - text: t({ message: "Copy docker run", context: "Button to copy docker run command" }), - onClick: async () => - copyDockerRun(isUnixSocket ? hostValue : port.current?.value, publicKey, token), - icons: [DockerIcon], - }, - ]} /> - - {/* Binary */} - - } - onClick={async () => copyLinuxCommand(isUnixSocket ? hostValue : port.current?.value, publicKey, token)} - dropdownItems={[ - { - text: t({ message: "Homebrew command", context: "Button to copy install command" }), - onClick: async () => - copyLinuxCommand(isUnixSocket ? hostValue : port.current?.value, publicKey, token, true), - icons: [AppleIcon, TuxIcon], - }, - { - text: t({ message: "Windows command", context: "Button to copy install command" }), - onClick: async () => - copyWindowsCommand(isUnixSocket ? hostValue : port.current?.value, publicKey, token), - icons: [WindowsIcon], - }, - { - text: t`Manual setup instructions`, - url: "https://beszel.dev/guide/agent-installation#binary", - icons: [ExternalLinkIcon], - }, - ]} + + - - {/* Save */} - - - - - + + + + +
+ + {/* Docker */} + + + copyDockerCompose(isUnixSocket ? hostValue : port.current?.value, publicKey, token) + } + icon={} + dropdownItems={[ + { + text: t({ message: "Copy docker run", context: "Button to copy docker run command" }), + onClick: async () => + copyDockerRun(isUnixSocket ? hostValue : port.current?.value, publicKey, token), + icons: [DockerIcon], + }, + ]} + /> + + {/* Binary */} + + } + onClick={async () => + copyLinuxCommand(isUnixSocket ? hostValue : port.current?.value, publicKey, token) + } + dropdownItems={[ + { + text: t({ message: "Homebrew command", context: "Button to copy install command" }), + onClick: async () => + copyLinuxCommand(isUnixSocket ? hostValue : port.current?.value, publicKey, token, true), + icons: [AppleIcon, TuxIcon], + }, + { + text: t({ message: "Windows command", context: "Button to copy install command" }), + onClick: async () => + copyWindowsCommand(isUnixSocket ? hostValue : port.current?.value, publicKey, token), + icons: [WindowsIcon], + }, + { + text: t`Manual setup instructions`, + url: "https://beszel.dev/guide/agent-installation#binary", + icons: [ExternalLinkIcon], + }, + ]} + /> + + {/* Save */} + + + +
+
+ ), + [] ) } diff --git a/beszel/site/src/components/alerts/alert-button.tsx b/beszel/site/src/components/alerts/alert-button.tsx index 16bb8e6..6c3ddfe 100644 --- a/beszel/site/src/components/alerts/alert-button.tsx +++ b/beszel/site/src/components/alerts/alert-button.tsx @@ -2,56 +2,35 @@ import { t } from "@lingui/core/macro" import { memo, useMemo, useState } from "react" import { useStore } from "@nanostores/react" import { $alerts } from "@/lib/stores" -import { Dialog, DialogTrigger, DialogContent } from "@/components/ui/dialog" import { BellIcon } from "lucide-react" import { cn } from "@/lib/utils" import { Button } from "@/components/ui/button" import { SystemRecord } from "@/types" -import { AlertDialogContent } from "./alerts-dialog" +import { AlertDialogContent } from "./alerts-sheet" +import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet" export default memo(function AlertsButton({ system }: { system: SystemRecord }) { const [opened, setOpened] = useState(false) const alerts = useStore($alerts) const hasSystemAlert = alerts[system.id]?.size > 0 - return useMemo( () => ( - - - - - + + {opened && } - - + + ), [opened, hasSystemAlert] ) - - // return useMemo( - // () => ( - // - // - // - // - // - // {opened && } - // - // - // ), - // [opened, hasAlert] - // ) }) diff --git a/beszel/site/src/components/alerts/alerts-dialog.tsx b/beszel/site/src/components/alerts/alerts-sheet.tsx similarity index 100% rename from beszel/site/src/components/alerts/alerts-dialog.tsx rename to beszel/site/src/components/alerts/alerts-sheet.tsx diff --git a/beszel/site/src/components/navbar.tsx b/beszel/site/src/components/navbar.tsx index 747946a..156c25b 100644 --- a/beszel/site/src/components/navbar.tsx +++ b/beszel/site/src/components/navbar.tsx @@ -1,4 +1,4 @@ -import { Trans } from "@lingui/react/macro"; +import { Trans } from "@lingui/react/macro" import { useState, lazy, Suspense } from "react" import { Button, buttonVariants } from "@/components/ui/button" import { diff --git a/beszel/site/src/components/router.tsx b/beszel/site/src/components/router.tsx index 59197af..fcb5b55 100644 --- a/beszel/site/src/components/router.tsx +++ b/beszel/site/src/components/router.tsx @@ -45,7 +45,7 @@ export function Link(props: React.AnchorHTMLAttributes) { if (e.ctrlKey || e.metaKey) { window.open(href, "_blank") } else { - $router.open(href) + navigate(href) props.onClick?.(e) } }} diff --git a/beszel/site/src/components/systems-table/systems-table-columns.tsx b/beszel/site/src/components/systems-table/systems-table-columns.tsx index bb68a32..3dfdb29 100644 --- a/beszel/site/src/components/systems-table/systems-table-columns.tsx +++ b/beszel/site/src/components/systems-table/systems-table-columns.tsx @@ -111,21 +111,18 @@ export default function SystemsTableColumns(viewMode: "table" | "grid"): ColumnD Icon: ServerIcon, cell: (info) => { const { name } = info.row.original - return useMemo( - () => ( - <> - - - {name} - - - - ), - [name] + return ( + <> + + + {name} + + + ) }, header: sortableHeader, diff --git a/beszel/site/src/components/ui/sheet.tsx b/beszel/site/src/components/ui/sheet.tsx new file mode 100644 index 0000000..187fd95 --- /dev/null +++ b/beszel/site/src/components/ui/sheet.tsx @@ -0,0 +1,101 @@ +import * as React from "react" +import * as SheetPrimitive from "@radix-ui/react-dialog" +import { XIcon } from "lucide-react" + +import { cn } from "@/lib/utils" + +function Sheet({ ...props }: React.ComponentProps) { + return +} + +function SheetTrigger({ ...props }: React.ComponentProps) { + return +} + +function SheetClose({ ...props }: React.ComponentProps) { + return +} + +function SheetPortal({ ...props }: React.ComponentProps) { + return +} + +function SheetOverlay({ className, ...props }: React.ComponentProps) { + return ( + + ) +} + +function SheetContent({ + className, + children, + side = "right", + ...props +}: React.ComponentProps & { + side?: "top" | "right" | "bottom" | "left" +}) { + return ( + + + + {children} + + + Close + + + + ) +} + +function SheetHeader({ className, ...props }: React.ComponentProps<"div">) { + return
+} + +function SheetFooter({ className, ...props }: React.ComponentProps<"div">) { + return
+} + +function SheetTitle({ className, ...props }: React.ComponentProps) { + return ( + + ) +} + +function SheetDescription({ className, ...props }: React.ComponentProps) { + return ( + + ) +} + +export { Sheet, SheetTrigger, SheetClose, SheetContent, SheetHeader, SheetFooter, SheetTitle, SheetDescription } diff --git a/beszel/site/src/components/ui/tabs.tsx b/beszel/site/src/components/ui/tabs.tsx index e78b335..842f302 100644 --- a/beszel/site/src/components/ui/tabs.tsx +++ b/beszel/site/src/components/ui/tabs.tsx @@ -27,7 +27,7 @@ const TabsTrigger = React.forwardRef<