use anchor tag for system table links

This commit is contained in:
henrygd
2025-08-21 18:44:38 -04:00
parent 7ba1f366ba
commit 9d25181d1d
4 changed files with 39 additions and 33 deletions

View File

@@ -19,9 +19,9 @@ export default memo(function AlertsButton({ system }: { system: SystemRecord })
() => ( () => (
<Dialog> <Dialog>
<DialogTrigger asChild> <DialogTrigger asChild>
<Button variant="ghost" size="icon" aria-label={t`Alerts`} data-nolink onClick={() => setOpened(true)}> <Button variant="ghost" size="icon" aria-label={t`Alerts`} onClick={() => setOpened(true)}>
<BellIcon <BellIcon
className={cn("h-[1.2em] w-[1.2em] pointer-events-none", { className={cn("h-[1.2em] w-[1.2em]", {
"fill-primary": hasSystemAlert, "fill-primary": hasSystemAlert,
})} })}
/> />

View File

@@ -35,18 +35,15 @@ export const navigate = (urlString: string) => {
$router.open(urlString) $router.open(urlString)
} }
function onClick(e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) { export function Link(props: React.AnchorHTMLAttributes<HTMLAnchorElement>) {
return (
<a
{...props}
onClick={(e) => {
e.preventDefault() e.preventDefault()
$router.open(new URL((e.currentTarget as HTMLAnchorElement).href).pathname) $router.open(new URL((e.currentTarget as HTMLAnchorElement).href).pathname)
}
export const Link = (props: React.AnchorHTMLAttributes<HTMLAnchorElement>) => {
let clickFn = onClick
if (props.onClick) {
clickFn = (e) => {
onClick(e)
props.onClick?.(e) props.onClick?.(e)
} }}
} ></a>
return <a {...props} onClick={clickFn}></a> )
} }

View File

@@ -55,6 +55,8 @@ import {
import { buttonVariants } from "../ui/button" import { buttonVariants } from "../ui/button"
import { t } from "@lingui/core/macro" import { t } from "@lingui/core/macro"
import { MeterState } from "@/lib/enums" import { MeterState } from "@/lib/enums"
import { $router, Link } from "../router"
import { getPagePath } from "@nanostores/router"
const STATUS_COLORS = { const STATUS_COLORS = {
up: "bg-green-500", up: "bg-green-500",
@@ -107,12 +109,25 @@ export default function SystemsTableColumns(viewMode: "table" | "grid"): ColumnD
enableHiding: false, enableHiding: false,
invertSorting: false, invertSorting: false,
Icon: ServerIcon, Icon: ServerIcon,
cell: (info) => ( cell: (info) => {
const { name } = info.row.original
return useMemo(
() => (
<>
<span className="flex gap-2 items-center font-medium text-sm text-nowrap md:ps-1 md:pe-5"> <span className="flex gap-2 items-center font-medium text-sm text-nowrap md:ps-1 md:pe-5">
<IndicatorDot system={info.row.original} /> <IndicatorDot system={info.row.original} />
{info.getValue() as string} {name}
</span> </span>
<Link
href={getPagePath($router, "system", { name })}
className="inset-0 absolute size-full"
aria-label={name}
></Link>
</>
), ),
[name]
)
},
header: sortableHeader, header: sortableHeader,
}, },
{ {
@@ -277,7 +292,7 @@ export default function SystemsTableColumns(viewMode: "table" | "grid"): ColumnD
name: () => t({ message: "Actions", comment: "Table column" }), name: () => t({ message: "Actions", comment: "Table column" }),
size: 50, size: 50,
cell: ({ row }) => ( cell: ({ row }) => (
<div className="flex justify-end items-center gap-1 -ms-3"> <div className="relative z-10 flex justify-end items-center gap-1 -ms-3">
<AlertButton system={row.original} /> <AlertButton system={row.original} />
<ActionsButton system={row.original} /> <ActionsButton system={row.original} />
</div> </div>
@@ -349,7 +364,7 @@ export const ActionsButton = memo(({ system }: { system: SystemRecord }) => {
<> <>
<DropdownMenu> <DropdownMenu>
<DropdownMenuTrigger asChild> <DropdownMenuTrigger asChild>
<Button variant="ghost" size={"icon"} data-nolink> <Button variant="ghost" size={"icon"}>
<span className="sr-only"> <span className="sr-only">
<Trans>Open menu</Trans> <Trans>Open menu</Trans>
</span> </span>

View File

@@ -41,7 +41,7 @@ import { memo, useEffect, useMemo, useState } from "react"
import { $systems } from "@/lib/stores" import { $systems } from "@/lib/stores"
import { useStore } from "@nanostores/react" import { useStore } from "@nanostores/react"
import { cn, useLocalStorage } from "@/lib/utils" import { cn, useLocalStorage } from "@/lib/utils"
import { $router, Link, navigate } from "../router" import { $router, Link } from "../router"
import { useLingui, Trans } from "@lingui/react/macro" import { useLingui, Trans } from "@lingui/react/macro"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui/card" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui/card"
import { Input } from "../ui/input" import { Input } from "../ui/input"
@@ -291,15 +291,9 @@ const SystemTableRow = memo(
return ( return (
<TableRow <TableRow
// data-state={row.getIsSelected() && "selected"} // data-state={row.getIsSelected() && "selected"}
className={cn("cursor-pointer transition-opacity", { className={cn("cursor-pointer transition-opacity relative", {
"opacity-50": system.status === "paused", "opacity-50": system.status === "paused",
})} })}
onClick={(e) => {
const target = e.target as HTMLElement
if (!target.closest("[data-nolink]") && e.currentTarget.contains(target)) {
navigate(getPagePath($router, "system", { name: system.name }))
}
}}
> >
{row.getVisibleCells().map((cell) => ( {row.getVisibleCells().map((cell) => (
<TableCell <TableCell
@@ -307,7 +301,7 @@ const SystemTableRow = memo(
style={{ style={{
width: cell.column.getSize(), width: cell.column.getSize(),
}} }}
className={cn("overflow-hidden relative", length > 10 ? "py-2" : "py-2.5")} className={length > 10 ? "py-2" : "py-2.5"}
> >
{flexRender(cell.column.columnDef.cell, cell.getContext())} {flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell> </TableCell>