import { useQueries } from "@tanstack/react-query" import { Link, type LinkProps } from "@tanstack/react-router" import { ICONS } from "@/components/Dashboard/icons" import { dashboardQueryOptions } from "@/components/Dashboard/queries" import { Button } from "@/components/ui/button" import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip" import { cn } from "@/lib/utils" /** How much room the rail takes, canvas insets included. Mirrors the side * panel's `27rem`: the button plus the gutters either side of it. */ export const RAIL_INSET = "4.5rem" /** Two letters off the title, so a rail of four reads as four different things. */ function initials(label: string): string { const words = label.split(/[\s_-]+/).filter(Boolean) if (words.length === 0) return "?" if (words.length === 1) return words[0].slice(0, 2).toUpperCase() return (words[0][0] + words[1][0]).toUpperCase() } /** * Switching between the dashboards one panel was assigned. * * Permanent rather than a menu behind a button: a wall panel is glanced at, * and something you have to open first is something nobody opens. It costs * about a fortieth of the canvas, which `CanvasSurface` absorbs by scaling — * the grid itself never changes, so an arrangement made without the rail still * fits with it. * * Reading the dashboards it links to is also what fills the labels, and it * warms the cache for the neighbours so a switch draws immediately. */ export function PanelRail({ dashboards, current, linkFor, className, }: { dashboards: string[] current: string linkFor: (name: string) => LinkProps className?: string }) { const entries = useQueries({ queries: dashboards.map((name) => dashboardQueryOptions(name)), combine: (results) => results.map((result, index) => ({ label: result.data?.title || dashboards[index], icon: result.data?.icon ?? "", })), }) return ( ) }