import { useMutation, useQuery } from "@tanstack/react-query"; import { useParams } from "react-router-dom"; import { exportOperationYaml, generateDraft, getOperation, getOperationVersion, importOperationYaml, listAuthProfiles, } from "../../entities/operation/api"; import type { OperationTarget } from "../../entities/operation/types"; import { GrpcDescriptorPanel } from "../../features/grpc-descriptor/panel"; import { PublishOperationPanel } from "../../features/publish-operation/panel"; import { SampleUploadPanel } from "../../features/sample-upload/panel"; import { SchemaViewerPanel } from "../../features/schema-viewer/panel"; import { TestRunPanel } from "../../features/test-run/panel"; import { PageSection } from "../../shared/ui/page-section"; function describeTarget(target: OperationTarget) { switch (target.kind) { case "rest": return [ ["Base URL", target.base_url], ["Method", target.method], ["Path", target.path_template], ] as const; case "graphql": return [ ["Endpoint", target.endpoint], ["Operation", `${target.operation_type} ${target.operation_name}`], ["Response path", target.response_path], ] as const; case "grpc": return [ ["Server", target.server_addr], ["Service", `${target.package}.${target.service}/${target.method}`], ["Descriptor ref", target.descriptor_ref], ] as const; } } function readObjectRecord(value: unknown) { if (value === null || typeof value !== "object" || Array.isArray(value)) { return {}; } return value as Record; } function readExecutionHeaders(value: unknown) { const config = readObjectRecord(value); const headers = config.headers; if (headers === null || typeof headers !== "object" || Array.isArray(headers)) { return {}; } return headers as Record; } function draftSubtitle(target: OperationTarget) { switch (target.kind) { case "rest": return "Upload request and response JSON samples, then infer schema and mapping drafts."; case "graphql": return "Upload stable request and response samples for the fixed GraphQL operation contract."; case "grpc": return "Upload JSON samples or inspect descriptor-driven schemas before refining mappings."; } } export function OperationDetailPage() { const { operationId = "" } = useParams(); const summaryQuery = useQuery({ queryKey: ["operation-summary", operationId], queryFn: () => getOperation(operationId), enabled: operationId.length > 0, }); const currentVersion = summaryQuery.data?.current_draft_version ?? 0; const versionQuery = useQuery({ queryKey: ["operation-version", operationId, currentVersion], queryFn: () => getOperationVersion(operationId, currentVersion), enabled: operationId.length > 0 && currentVersion > 0, }); const authProfilesQuery = useQuery({ queryKey: ["auth-profiles"], queryFn: listAuthProfiles, }); const draftMutation = useMutation({ mutationFn: async () => generateDraft(operationId), }); const exportMutation = useMutation({ mutationFn: async () => exportOperationYaml(operationId, currentVersion), }); const importMutation = useMutation({ mutationFn: async (yamlText: string) => importOperationYaml(yamlText, "upsert"), }); const snapshot = versionQuery.data?.snapshot; const exportedYaml = exportMutation.data; const targetRows = snapshot ? describeTarget(snapshot.target) : []; return (
{summaryQuery.data ? (
Status {summaryQuery.data.status}
Published version {summaryQuery.data.latest_published_version ?? "none"}
Updated {new Date(summaryQuery.data.updated_at).toLocaleString()}
{snapshot ? (
{targetRows.map(([label, value]) => (
{label} {value}
))}
) : null}
) : null}
{snapshot ? (

Tool description

Title
{snapshot.tool_description.title}
Tags
{snapshot.tool_description.tags.join(", ") || "none"}

{snapshot.tool_description.description}

Execution config

{JSON.stringify(snapshot.execution_config, null, 2)}

Transport headers

{JSON.stringify(readExecutionHeaders(snapshot.execution_config), null, 2)}
{snapshot.target.kind === "rest" ? (

REST static headers

{JSON.stringify(snapshot.target.static_headers ?? {}, null, 2)}
) : null}
) : null} {snapshot?.target.kind === "grpc" ? ( ) : null} draftMutation.mutate()} type="button" > {draftMutation.isPending ? "Generating..." : "Generate draft"} } >
exportMutation.mutate()} > {exportMutation.isPending ? "Exporting..." : "Export YAML"} } >
{exportedYaml ? ( <>
{exportedYaml}
) : (

Export YAML to inspect the current operation snapshot and transport contract.

)} {importMutation.data ? (
Imported version {String(importMutation.data.version)} in{" "} {String(importMutation.data.import_mode)} mode.
) : null}
{(authProfilesQuery.data?.items ?? []).map((profile) => (
{profile.kind}

{profile.name}

{profile.id}

{JSON.stringify(profile.config, null, 2)}
))}
); }