26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
import { LoadPresentation, useCaminoClient } from "@quixos/camino-react";
|
|
import type { Item } from "./protocol.js";
|
|
|
|
export function AgentWidget({ item }: { item: Item }) {
|
|
const client = useCaminoClient();
|
|
const record = (value: unknown): Record<string, unknown> | undefined =>
|
|
value && typeof value === "object" && !Array.isArray(value) ? (value as Record<string, unknown>) : undefined;
|
|
const selected = client.catalog.presentations.map(record).find((value) => value?.id === item.data.presentation);
|
|
const subject = item.subject?._camino.ref,
|
|
mount = item.presentationMount?._camino.ref;
|
|
if (!subject || !mount || typeof selected?.packageRevision !== "string" || typeof selected.component !== "string")
|
|
return (
|
|
<p role="alert">
|
|
This widget is unavailable.{" "}
|
|
{subject && <a href={`/entity/${encodeURIComponent(subject.object)}`}>Open object</a>}
|
|
</p>
|
|
);
|
|
return (
|
|
<LoadPresentation
|
|
subject={subject}
|
|
provider={{ packageRevision: selected.packageRevision, id: selected.component }}
|
|
presentationMount={mount}
|
|
/>
|
|
);
|
|
}
|