import { open } from "@tauri-apps/plugin-dialog"; import type { GrpcRequest } from "@yaakapp-internal/models"; import { useActiveRequest } from "../hooks/useActiveRequest"; import { useGrpc } from "../hooks/useGrpc"; import { useGrpcProtoFiles } from "../hooks/useGrpcProtoFiles"; import { pluralizeCount } from "../lib/pluralize"; import { Banner } from "./core/Banner"; import { Button } from "./core/Button"; import { Icon } from "./core/Icon"; import { IconButton } from "./core/IconButton"; import { InlineCode } from "./core/InlineCode"; import { Link } from "./core/Link"; import { HStack, VStack } from "./core/Stacks"; interface Props { onDone: () => void; } export function GrpcProtoSelectionDialog(props: Props) { const request = useActiveRequest(); if (request?.model !== "grpc_request") return null; return ; } function GrpcProtoSelectionDialogWithRequest({ request }: 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 = `${reflectError}`.match(/unimplemented/i); if (reflectionUnimplemented) { reflectError = null; } if (request == null) { return null; } return ( {/* Buttons on top so they get focus first */} {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.

)} {protoFiles.length > 0 && ( {protoFiles.map((f, i) => { const parts = f.split("/"); return ( // oxlint-disable-next-line react/no-array-index-key ); })}
Added File Paths
{parts.length > 3 && ".../"} {parts.slice(-3).join("/")} { await protoFilesKv.set(protoFiles.filter((p) => p !== f)); }} />
)} {reflectionUnimplemented && protoFiles.length === 0 && ( {request.url} doesn't implement{" "} Server Reflection {" "} . Please manually add the .proto file to get started. )}
); }