Skip to content

Lightweight server monitoring with historical data, docker stats, and alerts.

feat(hub): actions menu with alerts on system detail page (#2803)

Sven van Ginkel53a8b8a9aa4f
diff --git a/internal/site/src/components/alerts/alert-button.tsx b/internal/site/src/components/alerts/alert-button.tsx
index 05d8a1bcb..625202fdb 100644
--- a/internal/site/src/components/alerts/alert-button.tsx
+++ b/internal/site/src/components/alerts/alert-button.tsx
@@ -7,7 +7,7 @@ import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet"
import { $alerts } from "@/lib/stores"
import { cn } from "@/lib/utils"
import type { SystemRecord } from "@/types"
-import { AlertDialogContent } from "./alerts-sheet"
+import { AlertDialogContent, alertsSheetClassName } from "./alerts-sheet"
export default memo(function AlertsButton({ system }: { system: SystemRecord }) {
const [opened, setOpened] = useState(false)
@@ -26,9 +26,7 @@ export default memo(function AlertsButton({ system }: { system: SystemRecord })
/>
</Button>
</SheetTrigger>
- <SheetContent className="max-h-full overflow-auto w-160 !max-w-full p-4 sm:p-6">
- {opened && <AlertDialogContent system={system} />}
- </SheetContent>
+ <SheetContent className={alertsSheetClassName}>{opened && <AlertDialogContent system={system} />}</SheetContent>
</Sheet>
),
[opened, hasSystemAlert]
diff --git a/internal/site/src/components/alerts/alerts-sheet.tsx b/internal/site/src/components/alerts/alerts-sheet.tsx
index bd0ea8975..d97d061fa 100644
--- a/internal/site/src/components/alerts/alerts-sheet.tsx
+++ b/internal/site/src/components/alerts/alerts-sheet.tsx
@@ -26,6 +26,9 @@ const endpoint = "/api/beszel/user-alerts"
const alertDebounce = 400
+/** Class names for the SheetContent that wraps AlertDialogContent */
+export const alertsSheetClassName = "max-h-full overflow-auto w-160 !max-w-full p-4 sm:p-6"
+
const alertKeys = Object.keys(alertInfo) as (keyof typeof alertInfo)[]
/** Round to a multiple of step, trimming float noise like 0.30000000000000004 */
diff --git a/internal/site/src/components/routes/system/info-bar.tsx b/internal/site/src/components/routes/system/info-bar.tsx
index 8367d1e90..2db3a1412 100644
--- a/internal/site/src/components/routes/system/info-bar.tsx
+++ b/internal/site/src/components/routes/system/info-bar.tsx
@@ -23,6 +23,7 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
+import { ActionsButton } from "@/components/system-actions-button"
import { FreeBsdIcon, TuxIcon, WebSocketIcon, WindowsIcon } from "@/components/ui/icons"
import { Separator } from "@/components/ui/separator"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
@@ -210,7 +211,7 @@ export default function InfoBar({
<Settings2Icon className="size-4 opacity-80" />
</Button>
</DropdownMenuTrigger>
- <DropdownMenuContent align="end" className="min-w-44">
+ <DropdownMenuContent className="min-w-38">
<DropdownMenuLabel className="px-3.5">
<Trans context="Layout display options">Display</Trans>
</DropdownMenuLabel>
@@ -246,6 +247,7 @@ export default function InfoBar({
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
+ <ActionsButton system={system} variant="outline" showAlerts />
</div>
</div>
</Card>
diff --git a/internal/site/src/components/system-actions-button.tsx b/internal/site/src/components/system-actions-button.tsx
new file mode 100644
index 000000000..8bc815740
--- /dev/null
+++ b/internal/site/src/components/system-actions-button.tsx
@@ -0,0 +1,193 @@
+import { Trans, useLingui } from "@lingui/react/macro"
+import { useStore } from "@nanostores/react"
+import { getPagePath } from "@nanostores/router"
+import {
+ BellIcon,
+ CopyIcon,
+ MoreHorizontalIcon,
+ PauseCircleIcon,
+ PenBoxIcon,
+ PlayCircleIcon,
+ Trash2Icon,
+} from "lucide-react"
+import { memo, useMemo, useRef, useState } from "react"
+import { SystemDialog } from "@/components/add-system"
+import { AlertDialogContent as AlertsSheetContent, alertsSheetClassName } from "@/components/alerts/alerts-sheet"
+import { $router, navigate } from "@/components/router"
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from "@/components/ui/alert-dialog"
+import { Button, buttonVariants } from "@/components/ui/button"
+import { Dialog } from "@/components/ui/dialog"
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from "@/components/ui/dropdown-menu"
+import { Sheet, SheetContent } from "@/components/ui/sheet"
+import { isReadOnlyUser, pb } from "@/lib/api"
+import { SystemStatus } from "@/lib/enums"
+import { $alerts } from "@/lib/stores"
+import { cn, copyToClipboard } from "@/lib/utils"
+import type { SystemRecord } from "@/types"
+
+/** Menu item that opens the alerts sheet; the bell is filled when the system has alerts configured. */
+const AlertsMenuItem = ({ systemId, onSelect }: { systemId: string; onSelect: () => void }) => {
+ const alerts = useStore($alerts)
+ const hasSystemAlert = alerts[systemId]?.size > 0
+ return (
+ <DropdownMenuItem onSelect={onSelect}>
+ <BellIcon className={cn("me-2.5 size-4", { "fill-primary": hasSystemAlert })} />
+ <Trans>Alerts</Trans>
+ </DropdownMenuItem>
+ )
+}
+
+async function deleteSystem({ id, name }: SystemRecord) {
+ await pb.collection("systems").delete(id)
+ // leave the dashboard of the system that was just deleted (route param may be the id or legacy name slug)
+ const page = $router.get()
+ if (page?.route === "system" && (page.params.id === id || page.params.id === name)) {
+ navigate(getPagePath($router, "home"))
+ }
+}
+
+type ActionsButtonProps = {
+ system: SystemRecord
+ variant?: "ghost" | "outline"
+ /** Include an item that opens the alerts sheet (used where no separate alerts button is shown). */
+ showAlerts?: boolean
+}
+
+export const ActionsButton = memo(({ system, variant = "ghost", showAlerts = false }: ActionsButtonProps) => {
+ const [deleteOpen, setDeleteOpen] = useState(false)
+ const [editOpen, setEditOpen] = useState(false)
+ const editOpened = useRef(false)
+ const [alertsOpen, setAlertsOpen] = useState(false)
+ const alertsOpened = useRef(false)
+ const { t } = useLingui()
+ const { id, status, host, name } = system
+
+ return useMemo(() => {
+ return (
+ <>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button variant={variant} size={"icon"}>
+ <span className="sr-only">
+ <Trans>Open menu</Trans>
+ </span>
+ <MoreHorizontalIcon className="w-5" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end" className="min-w-38">
+ {showAlerts && (
+ <>
+ <AlertsMenuItem
+ systemId={id}
+ onSelect={() => {
+ alertsOpened.current = true
+ setAlertsOpen(true)
+ }}
+ />
+ <DropdownMenuSeparator />
+ </>
+ )}
+ {!isReadOnlyUser() && (
+ <DropdownMenuItem
+ onSelect={() => {
+ editOpened.current = true
+ setEditOpen(true)
+ }}
+ >
+ <PenBoxIcon className="me-2.5 size-4" />
+ <Trans>Edit</Trans>
+ </DropdownMenuItem>
+ )}
+ <DropdownMenuItem
+ className={cn(isReadOnlyUser() && "hidden")}
+ onClick={() => {
+ pb.collection("systems").update(id, {
+ status: status === SystemStatus.Paused ? SystemStatus.Pending : SystemStatus.Paused,
+ })
+ }}
+ >
+ {status === SystemStatus.Paused ? (
+ <>
+ <PlayCircleIcon className="me-2.5 size-4" />
+ <Trans>Resume</Trans>
+ </>
+ ) : (
+ <>
+ <PauseCircleIcon className="me-2.5 size-4" />
+ <Trans>Pause</Trans>
+ </>
+ )}
+ </DropdownMenuItem>
+ <DropdownMenuItem onClick={() => copyToClipboard(name)}>
+ <CopyIcon className="me-2.5 size-4" />
+ <Trans>Copy name</Trans>
+ </DropdownMenuItem>
+ <DropdownMenuItem onClick={() => copyToClipboard(host)}>
+ <CopyIcon className="me-2.5 size-4" />
+ <Trans>Copy host</Trans>
+ </DropdownMenuItem>
+ <DropdownMenuSeparator className={cn(isReadOnlyUser() && "hidden")} />
+ <DropdownMenuItem className={cn(isReadOnlyUser() && "hidden")} onSelect={() => setDeleteOpen(true)}>
+ <Trash2Icon className="me-2.5 size-4" />
+ <Trans>Delete</Trans>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ {/* alerts sheet */}
+ {showAlerts && (
+ <Sheet open={alertsOpen} onOpenChange={setAlertsOpen}>
+ <SheetContent className={alertsSheetClassName}>
+ {alertsOpened.current && <AlertsSheetContent system={system} />}
+ </SheetContent>
+ </Sheet>
+ )}
+ {/* edit dialog */}
+ <Dialog open={editOpen} onOpenChange={setEditOpen}>
+ {editOpened.current && <SystemDialog system={system} setOpen={setEditOpen} />}
+ </Dialog>
+ {/* deletion dialog */}
+ <AlertDialog open={deleteOpen} onOpenChange={(open) => setDeleteOpen(open)}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>
+ <Trans>Are you sure you want to delete {name}?</Trans>
+ </AlertDialogTitle>
+ <AlertDialogDescription>
+ <Trans>
+ This action cannot be undone. This will permanently delete all current records for {name} from the
+ database.
+ </Trans>
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>
+ <Trans>Cancel</Trans>
+ </AlertDialogCancel>
+ <AlertDialogAction
+ className={cn(buttonVariants({ variant: "destructive" }))}
+ onClick={() => deleteSystem(system)}
+ >
+ <Trans>Continue</Trans>
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ </>
+ )
+ }, [id, status, host, name, system, t, deleteOpen, editOpen, alertsOpen, variant, showAlerts])
+})
diff --git a/internal/site/src/components/systems-table/systems-table-columns.tsx b/internal/site/src/components/systems-table/systems-table-columns.tsx
index 890e99fa1..b78430df1 100644
--- a/internal/site/src/components/systems-table/systems-table-columns.tsx
+++ b/internal/site/src/components/systems-table/systems-table-columns.tsx
@@ -1,6 +1,6 @@
/** biome-ignore-all lint/correctness/useHookAtTopLevel: Hooks live inside memoized column definitions */
import { plural, t } from "@lingui/core/macro"
-import { Trans, useLingui } from "@lingui/react/macro"
+import { Trans } from "@lingui/react/macro"
import { useStore } from "@nanostores/react"
import { getPagePath } from "@nanostores/router"
import type { CellContext, ColumnDef, HeaderContext } from "@tanstack/react-table"
@@ -9,59 +9,25 @@ import {
ArrowUpDownIcon,
ChevronRightSquareIcon,
ClockArrowUp,
- CopyIcon,
CpuIcon,
HardDriveIcon,
MemoryStickIcon,
- MoreHorizontalIcon,
PackageIcon,
- PauseCircleIcon,
- PenBoxIcon,
- PlayCircleIcon,
ServerIcon,
TerminalSquareIcon,
- Trash2Icon,
WifiIcon,
} from "lucide-react"
-import { memo, useMemo, useRef, useState } from "react"
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip"
-import { isReadOnlyUser, pb } from "@/lib/api"
import { BatteryState, ConnectionType, connectionTypeLabels, MeterState, SystemStatus } from "@/lib/enums"
import { $userSettings } from "@/lib/stores"
-import {
- cn,
- copyToClipboard,
- decimalString,
- formatBytes,
- formatTemperature,
- parseSemVer,
- secondsToUptimeString,
-} from "@/lib/utils"
+import { cn, decimalString, formatBytes, formatTemperature, parseSemVer, secondsToUptimeString } from "@/lib/utils"
import { batteryStateTranslations } from "@/lib/i18n"
import { connectedWiFi, strongestWiFi, strongestWiFiSignal, wifiSignalState } from "@/lib/wifi"
import type { SystemRecord, WiFi } from "@/types"
-import { SystemDialog } from "../add-system"
import AlertButton from "../alerts/alert-button"
import { $router, Link } from "../router"
-import {
- AlertDialog,
- AlertDialogAction,
- AlertDialogCancel,
- AlertDialogContent,
- AlertDialogDescription,
- AlertDialogFooter,
- AlertDialogHeader,
- AlertDialogTitle,
-} from "../ui/alert-dialog"
-import { Button, buttonVariants } from "../ui/button"
-import { Dialog } from "../ui/dialog"
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuSeparator,
- DropdownMenuTrigger,
-} from "../ui/dropdown-menu"
+import { ActionsButton } from "../system-actions-button"
+import { Button } from "../ui/button"
import {
BatteryMediumIcon,
EthernetIcon,
@@ -723,105 +689,3 @@ export function IndicatorDot({ system, className }: { system: SystemRecord; clas
/>
)
}
-
-export const ActionsButton = memo(({ system }: { system: SystemRecord }) => {
- const [deleteOpen, setDeleteOpen] = useState(false)
- const [editOpen, setEditOpen] = useState(false)
- const editOpened = useRef(false)
- const { t } = useLingui()
- const { id, status, host, name } = system
-
- return useMemo(() => {
- return (
- <>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button variant="ghost" size={"icon"}>
- <span className="sr-only">
- <Trans>Open menu</Trans>
- </span>
- <MoreHorizontalIcon className="w-5" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- {!isReadOnlyUser() && (
- <DropdownMenuItem
- onSelect={() => {
- editOpened.current = true
- setEditOpen(true)
- }}
- >
- <PenBoxIcon className="me-2.5 size-4" />
- <Trans>Edit</Trans>
- </DropdownMenuItem>
- )}
- <DropdownMenuItem
- className={cn(isReadOnlyUser() && "hidden")}
- onClick={() => {
- pb.collection("systems").update(id, {
- status: status === SystemStatus.Paused ? SystemStatus.Pending : SystemStatus.Paused,
- })
- }}
- >
- {status === SystemStatus.Paused ? (
- <>
- <PlayCircleIcon className="me-2.5 size-4" />
- <Trans>Resume</Trans>
- </>
- ) : (
- <>
- <PauseCircleIcon className="me-2.5 size-4" />
- <Trans>Pause</Trans>
- </>
- )}
- </DropdownMenuItem>
- <DropdownMenuItem onClick={() => copyToClipboard(name)}>
- <CopyIcon className="me-2.5 size-4" />
- <Trans>Copy name</Trans>
- </DropdownMenuItem>
- <DropdownMenuItem onClick={() => copyToClipboard(host)}>
- <CopyIcon className="me-2.5 size-4" />
- <Trans>Copy host</Trans>
- </DropdownMenuItem>
- <DropdownMenuSeparator className={cn(isReadOnlyUser() && "hidden")} />
- <DropdownMenuItem className={cn(isReadOnlyUser() && "hidden")} onSelect={() => setDeleteOpen(true)}>
- <Trash2Icon className="me-2.5 size-4" />
- <Trans>Delete</Trans>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- {/* edit dialog */}
- <Dialog open={editOpen} onOpenChange={setEditOpen}>
- {editOpened.current && <SystemDialog system={system} setOpen={setEditOpen} />}
- </Dialog>
- {/* deletion dialog */}
- <AlertDialog open={deleteOpen} onOpenChange={(open) => setDeleteOpen(open)}>
- <AlertDialogContent>
- <AlertDialogHeader>
- <AlertDialogTitle>
- <Trans>Are you sure you want to delete {name}?</Trans>
- </AlertDialogTitle>
- <AlertDialogDescription>
- <Trans>
- This action cannot be undone. This will permanently delete all current records for {name} from the
- database.
- </Trans>
- </AlertDialogDescription>
- </AlertDialogHeader>
- <AlertDialogFooter>
- <AlertDialogCancel>
- <Trans>Cancel</Trans>
- </AlertDialogCancel>
- <AlertDialogAction
- className={cn(buttonVariants({ variant: "destructive" }))}
- onClick={() => pb.collection("systems").delete(id)}
- >
- <Trans>Continue</Trans>
- </AlertDialogAction>
- </AlertDialogFooter>
- </AlertDialogContent>
- </AlertDialog>
- </>
- )
- }, [id, status, host, name, system, t, deleteOpen, editOpen])
-})
diff --git a/internal/site/src/components/systems-table/systems-table.tsx b/internal/site/src/components/systems-table/systems-table.tsx
index 96fc2befa..246ceb396 100644
--- a/internal/site/src/components/systems-table/systems-table.tsx
+++ b/internal/site/src/components/systems-table/systems-table.tsx
@@ -53,7 +53,8 @@ import type { SystemRecord } from "@/types"
import AlertButton from "../alerts/alert-button"
import { $router, Link } from "../router"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui/card"
-import { SystemsTableColumns, ActionsButton, IndicatorDot } from "./systems-table-columns"
+import { ActionsButton } from "../system-actions-button"
+import { SystemsTableColumns, IndicatorDot } from "./systems-table-columns"
type ViewMode = "table" | "grid"
type StatusFilter = "all" | SystemRecord["status"]