mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 23:43:55 +01:00
Client streaming working
This commit is contained in:
@@ -48,6 +48,10 @@ export function GrpcConnectionLayout({ style }: Props) {
|
||||
grpc.cancel.mutateAsync().catch(console.error);
|
||||
}, [grpc.cancel]);
|
||||
|
||||
const handleCommit = useCallback(() => {
|
||||
grpc.commit.mutateAsync().catch(console.error);
|
||||
}, [grpc.commit]);
|
||||
|
||||
const handleConnect = useCallback(
|
||||
async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
@@ -62,13 +66,23 @@ export function GrpcConnectionLayout({ style }: Props) {
|
||||
}
|
||||
if (activeMethod.clientStreaming && activeMethod.serverStreaming) {
|
||||
await grpc.streaming.mutateAsync(activeRequest.id);
|
||||
} else if (activeMethod.serverStreaming && !activeMethod.clientStreaming) {
|
||||
} else if (!activeMethod.clientStreaming && activeMethod.serverStreaming) {
|
||||
await grpc.serverStreaming.mutateAsync(activeRequest.id);
|
||||
} else if (activeMethod.clientStreaming && !activeMethod.serverStreaming) {
|
||||
await grpc.clientStreaming.mutateAsync(activeRequest.id);
|
||||
} else {
|
||||
await grpc.unary.mutateAsync(activeRequest.id);
|
||||
}
|
||||
},
|
||||
[activeMethod, activeRequest, alert, grpc.streaming, grpc.serverStreaming, grpc.unary],
|
||||
[
|
||||
activeMethod,
|
||||
activeRequest,
|
||||
alert,
|
||||
grpc.streaming,
|
||||
grpc.serverStreaming,
|
||||
grpc.clientStreaming,
|
||||
grpc.unary,
|
||||
],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -212,6 +226,17 @@ export function GrpcConnectionLayout({ style }: Props) {
|
||||
icon="sendHorizontal"
|
||||
/>
|
||||
)}
|
||||
{activeMethod?.clientStreaming &&
|
||||
!activeMethod.serverStreaming &&
|
||||
grpc.isStreaming && (
|
||||
<IconButton
|
||||
className="border border-highlight"
|
||||
size="sm"
|
||||
title="to-do"
|
||||
onClick={handleCommit}
|
||||
icon="check"
|
||||
/>
|
||||
)}
|
||||
</HStack>
|
||||
</div>
|
||||
<GrpcEditor
|
||||
@@ -288,9 +313,13 @@ export function GrpcConnectionLayout({ style }: Props) {
|
||||
<Separator />
|
||||
</div>
|
||||
<div className="pl-2 overflow-y-auto">
|
||||
<JsonAttributeTree
|
||||
attrValue={JSON.parse(activeMessage?.message ?? '{}')}
|
||||
/>
|
||||
{activeMessage.isInfo ? (
|
||||
<span>{activeMessage.message}</span>
|
||||
) : (
|
||||
<JsonAttributeTree
|
||||
attrValue={JSON.parse(activeMessage?.message ?? '{}')}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -34,6 +34,17 @@ export function useGrpc(url: string | null, requestId: string | null) {
|
||||
},
|
||||
});
|
||||
|
||||
const clientStreaming = useMutation<void, string, string>({
|
||||
mutationKey: ['grpc_client_streaming', url],
|
||||
mutationFn: async (requestId) => {
|
||||
if (url === null) throw new Error('No URL provided');
|
||||
await messages.set([]);
|
||||
const c = (await invoke('cmd_grpc_client_streaming', { requestId })) as GrpcConnection;
|
||||
console.log('GOT CONNECTION', c);
|
||||
setActiveConnectionId(c.id);
|
||||
},
|
||||
});
|
||||
|
||||
const serverStreaming = useMutation<void, string, string>({
|
||||
mutationKey: ['grpc_server_streaming', url],
|
||||
mutationFn: async (requestId) => {
|
||||
@@ -77,6 +88,14 @@ export function useGrpc(url: string | null, requestId: string | null) {
|
||||
},
|
||||
});
|
||||
|
||||
const commit = useMutation({
|
||||
mutationKey: ['grpc_commit', url],
|
||||
mutationFn: async () => {
|
||||
setActiveConnectionId(null);
|
||||
await emit(`grpc_client_msg_${activeConnectionId}`, 'Commit');
|
||||
},
|
||||
});
|
||||
|
||||
const reflect = useQuery<ReflectResponseService[]>({
|
||||
queryKey: ['grpc_reflect', url ?? ''],
|
||||
queryFn: async () => {
|
||||
@@ -87,10 +106,12 @@ export function useGrpc(url: string | null, requestId: string | null) {
|
||||
|
||||
return {
|
||||
unary,
|
||||
clientStreaming,
|
||||
serverStreaming,
|
||||
streaming,
|
||||
services: reflect.data,
|
||||
cancel,
|
||||
commit,
|
||||
isStreaming: activeConnectionId !== null,
|
||||
send,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user