import { open } from '@tauri-apps/api/dialog'; import { useGrpc } from '../hooks/useGrpc'; import { useGrpcRequest } from '../hooks/useGrpcRequest'; import { useUpdateGrpcRequest } from '../hooks/useUpdateGrpcRequest'; import { count } from '../lib/pluralize'; import { Banner } from './core/Banner'; import { Button } from './core/Button'; import { FormattedError } from './core/FormattedError'; import { IconButton } from './core/IconButton'; import { InlineCode } from './core/InlineCode'; import { Link } from './core/Link'; import { HStack, VStack } from './core/Stacks'; interface Props { requestId: string; onDone: () => void; } export function GrpcProtoSelection({ requestId }: Props) { const request = useGrpcRequest(requestId); const grpc = useGrpc(request, null); const updateRequest = useUpdateGrpcRequest(request?.id ?? null); const services = grpc.reflect.data; const serverReflection = request?.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 */} {!serverReflection && services != null && services.length > 0 && (

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

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

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

)} {request.protoFiles.length > 0 && ( {request.protoFiles.map((f, i) => ( ))}
*.proto Files
{f.split('/').pop()} { await updateRequest.mutateAsync({ protoFiles: request.protoFiles.filter((p) => p !== f), }); grpc.reflect.remove(); }} />
)} {reflectError && {reflectError}} {reflectionUnimplemented && request.protoFiles.length === 0 && ( {request.url} doesn't implement{' '} Server Reflection {' '} . Please manually add the .proto file to get started. )}
); }