admin(machines): fix machine detail not loading by switching to server-side fetch by ID

- Add Convex query machines.getById with full payload (metrics/inventory)
- Update AdminMachineDetailsClient to use getById instead of listByTenant+find
- Update MachineBreadcrumbs to fetch hostname by ID

This prevents the empty state when the list query hasn’t loaded or filtered out the machine.
This commit is contained in:
codex-bot 2025-10-22 08:25:12 -03:00
parent 6333a3fc07
commit 5ff37195f5
3 changed files with 127 additions and 16 deletions

View file

@ -10,18 +10,18 @@ import {
} from "@/components/admin/machines/admin-machines-overview"
import { Card, CardContent } from "@/components/ui/card"
import { Skeleton } from "@/components/ui/skeleton"
import type { Id } from "@/convex/_generated/dataModel"
export function AdminMachineDetailsClient({ tenantId, machineId }: { tenantId: string; machineId: string }) {
const rawResult = useQuery(api.machines.listByTenant, { tenantId, includeMetadata: true }) as Array<Record<string, unknown>> | undefined
const machines: MachinesQueryItem[] | undefined = useMemo(() => {
if (!rawResult) return undefined
return rawResult.map((item) => normalizeMachineItem(item))
}, [rawResult])
const isLoading = rawResult === undefined
const machine = useMemo(() => {
if (!machines) return null
return machines.find((m) => m.id === machineId) ?? null
}, [machines, machineId])
const single = useQuery((api as any).machines.getById, { id: machineId as Id<"machines">, includeMetadata: true }) as
| Record<string, unknown>
| null
| undefined
const machine: MachinesQueryItem | null = useMemo(() => {
if (single === undefined || single === null) return single as null
return normalizeMachineItem(single)
}, [single])
const isLoading = single === undefined
if (isLoading) {
return (