SPB Git

spb/akos

Public
2.3 KB · 24 lines tsx
1import { Link, useParams } from "react-router";2import type { Endpoint, ExecutionRow, Project, Variable } from "../api";3import { useFetch, fmtDate } from "../hooks";4import { Badge, ErrorBox, KV, Loading, Td } from "../components/ui";5import { EndpointRow } from "../components/shared";67type E = Endpoint & { api_version_id: string; version: string; api_id: string; api_name: string; base_url: string | null; variables: Variable[]; executions: ExecutionRow[] };89export default function EndpointDetail() {10  const { id } = useParams();11  const { data, error, loading } = useFetch<E>(`endpoints/${id}`);12  const projects = useFetch<{ projects: Project[] }>("projects");13  if (loading) return <Loading />; if (error) return <ErrorBox error={error} />; if (!data) return null;14  return (15    <div>16      <h1><code>{data.method}</code> {data.path}</h1>17      <div className="card"><KV items={[["API", <Link to={`/apis/${data.api_id}`}>{data.api_name}</Link>], ["Version", <Link to={`/versions/${data.api_version_id}`}>{data.version}</Link>], ["Operation", data.operation_id], ["Base URL", <code>{data.base_url}</code>], ["Summary", data.summary ?? "—"], ["Description", data.description ?? "—"], ["Evidence", data.inferred ? <Badge v="warn" label="schema inferred from probe" /> : <Badge v="good" label="documented" />]]} /></div>18      <EndpointRow e={data} apiId={data.api_id} projects={projects.data?.projects.map((p) => ({ slug: p.slug, name: `${p.name} (${p.policy_mode})` })) ?? [{ slug: "default", name: "default" }]} />19      <div className="card"><h3>Variables</h3>{data.variables.length ? <table className="tbl"><thead><tr><th>Name</th><th>Path</th><th>Type</th><th>Unit</th></tr></thead><tbody>{data.variables.map((v) => <tr key={v.id}><Td l="name"><code>{v.name}</code></Td><Td l="path"><code>{v.json_path}</code></Td><Td l="type">{v.data_type}</Td><Td l="unit">{v.unit ?? "—"}</Td></tr>)}</tbody></table> : <span className="hint">none</span>}</div>20      <div className="card"><h3>Recent executions</h3>{data.executions.length ? data.executions.map((e) => <div key={e.id} className="row between" style={{ fontSize: 13 }}><Link to={`/executions/${e.id}`}>{fmtDate(e.created_at)}</Link><span><Badge v={e.state} /> {e.status_code ?? "—"} · {e.duration_ms ?? "—"} ms</span></div>) : <span className="hint">none</span>}</div>21    </div>22  );23}24
Files · main
Menu

Theme