import { useMemo, useState } from 'react' import { Link, Outlet, useLocation } from 'react-router-dom' import { getLastRequestIds } from '../api/client' import { Button, Code, TextInput } from '../components/primitives' type NavItem = { label: string to: string } const navItems: NavItem[] = [ { label: 'Overview', to: '/' }, { label: 'Tenants', to: '/tenants' }, { label: 'Users', to: '/users' }, { label: 'Sessions', to: '/sessions' }, { label: 'Roles & Permissions', to: '/roles-permissions' }, { label: 'Config', to: '/config' }, { label: 'Definitions', to: '/definitions' }, { label: 'Scale & Placement', to: '/scale-placement' }, { label: 'Deployments', to: '/deployments' }, { label: 'Observability', to: '/observability' }, { label: 'Audit Log', to: '/audit-log' }, { label: 'Settings', to: '/settings' }, ] function normalizePath(pathname: string) { if (pathname === '') return '/' if (pathname === '/') return '/' return pathname.endsWith('/') ? pathname.slice(0, -1) : pathname } export function Layout() { const location = useLocation() const active = normalizePath(location.pathname) const [query, setQuery] = useState('') const lastIds = getLastRequestIds() const grafana = useMemo(() => { const base = (import.meta.env.VITE_GRAFANA_URL as string | undefined) ?? '' const loki = (import.meta.env.VITE_GRAFANA_LOKI_DATASOURCE as string | undefined) ?? 'Loki' const tempo = (import.meta.env.VITE_GRAFANA_TEMPO_DATASOURCE as string | undefined) ?? 'Tempo' return { base, loki, tempo } }, []) function openGrafanaLogs(id: string) { if (!grafana.base) return const left = encodeURIComponent( JSON.stringify({ datasource: grafana.loki, queries: [{ refId: 'A', expr: `{correlation_id="${id}"}` }], }), ) window.open(`${grafana.base.replace(/\/$/, '')}/explore?left=${left}`, '_blank', 'noreferrer') } function openGrafanaTrace(id: string) { if (!grafana.base) return const left = encodeURIComponent( JSON.stringify({ datasource: grafana.tempo, queries: [{ refId: 'A', queryType: 'traceId', traceId: id }], }), ) window.open(`${grafana.base.replace(/\/$/, '')}/explore?left=${left}`, '_blank', 'noreferrer') } async function copy(text: string) { try { await navigator.clipboard.writeText(text) } catch { return } } return (
{lastIds.requestId}
{lastIds.correlationId}