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:
parent
6333a3fc07
commit
5ff37195f5
3 changed files with 127 additions and 16 deletions
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ import { useAuth } from "@/lib/auth-client"
|
|||
|
||||
export function MachineBreadcrumbs({ tenantId, machineId }: { tenantId: string; machineId: string }) {
|
||||
const { convexUserId } = useAuth()
|
||||
const list = useQuery(
|
||||
convexUserId ? api.machines.listByTenant : "skip",
|
||||
convexUserId ? { tenantId, includeMetadata: false } : ("skip" as const)
|
||||
) as Array<{ id: Id<"machines">; hostname: string }> | undefined
|
||||
const hostname = useMemo(() => list?.find((m) => m.id === (machineId as unknown as Id<"machines">))?.hostname ?? "Detalhe", [list, machineId])
|
||||
const item = useQuery((api as any).machines.getById, { id: machineId as Id<"machines">, includeMetadata: false }) as
|
||||
| { hostname: string }
|
||||
| null
|
||||
| undefined
|
||||
const hostname = useMemo(() => item?.hostname ?? "Detalhe", [item])
|
||||
|
||||
return (
|
||||
<nav className="mb-4 text-sm text-neutral-600">
|
||||
|
|
@ -27,4 +27,3 @@ export function MachineBreadcrumbs({ tenantId, machineId }: { tenantId: string;
|
|||
</nav>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue