import type { GrpcRequest } from "@yaakapp-internal/models"; import { Banner, InlineCode, VStack } from "@yaakapp-internal/ui"; import { useActiveRequest } from "../hooks/useActiveRequest"; import { useGrpc } from "../hooks/useGrpc"; import { useGrpcProtoFiles } from "../hooks/useGrpcProtoFiles"; import { DialogFooter } from "./core/Dialog"; import { PathList } from "./core/PathList"; import { Link } from "./core/Link"; import { platform } from "@yaakapp-internal/platform"; import { pluralizeCount } from "@yaakapp-internal/lib/pluralize"; interface Props { onDone: () => void; } export function GrpcProtoSelectionDialog(props: Props) { const request = useActiveRequest(); if (request?.model !== "grpc_request") return null; return ; } function GrpcProtoSelectionDialogWithRequest({ request, onDone, }: Props & { request: GrpcRequest }) { const protoFilesKv = useGrpcProtoFiles(request.id); const protoFiles = protoFilesKv.value ?? []; const grpc = useGrpc(request, null, protoFiles); const services = grpc.reflect.data; const serverReflection = protoFiles.length === 0 && services != null; let reflectError = grpc.reflect.error ?? null; const reflectionUnimplemented = String(reflectError).match(/unimplemented/i); if (reflectionUnimplemented) { reflectError = null; } if (request == null) { return null; } return ( <> {reflectError && (

Reflection failed on URL {request.url || "n/a"}

{reflectError.trim()}

)} {!serverReflection && services != null && services.length > 0 && (

Found services{" "} {services?.slice(0, 5).map((s, i) => { return ( m.name).join(",")}> {s.name} {i === services.length - 1 ? "" : i === services.length - 2 ? " and " : ", "} ); })} {services?.length > 5 && pluralizeCount("other", services?.length - 5)}

)} {serverReflection && services != null && services.length > 0 && (

Server reflection found services {services?.map((s, i) => { return ( m.name).join(",")}> {s.name} {i === services.length - 1 ? "" : i === services.length - 2 ? " and " : ", "} ); })} . You can override this schema by manually selecting *.proto{" "} files.

)} ({ path, icon: path.endsWith(".proto") ? "file_code" : "folder_code", }))} onRemove={async (path) => { await protoFilesKv.set(protoFiles.filter((p) => p !== path)); await grpc.reflect.refetch(); }} addLabel="Add proto files or an import folder" addItems={[ { label: "Proto files", icon: "file_code", onSelect: async () => { const selected = await platform.dialog.open({ title: "Select Proto Files", multiple: true, filters: [{ name: "Proto Files", extensions: ["proto"] }], }); if (selected == null) return; const newFiles = selected.filter((p) => !protoFiles.includes(p)); await protoFilesKv.set([...protoFiles, ...newFiles]); await grpc.reflect.refetch(); }, }, { label: "Import folder", icon: "folder_code", onSelect: async () => { const selected = await platform.dialog.open({ title: "Select Proto Directory", directory: true, }); if (selected == null) return; await protoFilesKv.set([...protoFiles.filter((f) => f !== selected), selected]); await grpc.reflect.refetch(); }, }, ]} /> {reflectionUnimplemented && protoFiles.length === 0 && ( {request.url} doesn't implement{" "} Server Reflection {" "} . Please manually add the .proto file to get started. )}
grpc.reflect.refetch(), }, { label: "Done", color: "primary", onClick: onDone }, ]} /> ); }