mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 16:31:18 +02:00
Tiny fixes
This commit is contained in:
@@ -54,11 +54,11 @@ export function GrpcConnectionLayout({ style }: Props) {
|
|||||||
const grpc = useGrpc(url.value ?? null, activeRequestId);
|
const grpc = useGrpc(url.value ?? null, activeRequestId);
|
||||||
|
|
||||||
const activeMethod = useMemo(() => {
|
const activeMethod = useMemo(() => {
|
||||||
if (grpc.schema == null) return null;
|
if (grpc.services == null) return null;
|
||||||
const s = grpc.schema.find((s) => s.name === service.value);
|
const s = grpc.services.find((s) => s.name === service.value);
|
||||||
if (s == null) return null;
|
if (s == null) return null;
|
||||||
return s.methods.find((m) => m.name === method.value);
|
return s.methods.find((m) => m.name === method.value);
|
||||||
}, [grpc.schema, method.value, service.value]);
|
}, [grpc.services, method.value, service.value]);
|
||||||
|
|
||||||
const handleCancel = useCallback(() => {
|
const handleCancel = useCallback(() => {
|
||||||
grpc.cancel.mutateAsync().catch(console.error);
|
grpc.cancel.mutateAsync().catch(console.error);
|
||||||
@@ -111,12 +111,11 @@ export function GrpcConnectionLayout({ style }: Props) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('GrpcConnectionLayout');
|
if (grpc.services == null) return;
|
||||||
if (grpc.schema == null) return;
|
const s = grpc.services.find((s) => s.name === service.value);
|
||||||
const s = grpc.schema.find((s) => s.name === service.value);
|
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
service.set(grpc.schema[0]?.name ?? null);
|
service.set(grpc.services[0]?.name ?? null);
|
||||||
method.set(grpc.schema[0]?.methods[0]?.name ?? null);
|
method.set(grpc.services[0]?.methods[0]?.name ?? null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +124,7 @@ export function GrpcConnectionLayout({ style }: Props) {
|
|||||||
method.set(s.methods[0]?.name ?? null);
|
method.set(s.methods[0]?.name ?? null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, [grpc.schema, method, service]);
|
}, [grpc.services, method, service]);
|
||||||
|
|
||||||
const handleChangeService = useCallback(
|
const handleChangeService = useCallback(
|
||||||
(v: string) => {
|
(v: string) => {
|
||||||
@@ -139,7 +138,7 @@ export function GrpcConnectionLayout({ style }: Props) {
|
|||||||
|
|
||||||
const select = useMemo(() => {
|
const select = useMemo(() => {
|
||||||
const options =
|
const options =
|
||||||
grpc.schema?.flatMap((s) =>
|
grpc.services?.flatMap((s) =>
|
||||||
s.methods.map((m) => ({
|
s.methods.map((m) => ({
|
||||||
label: `${s.name.split('.', 2).pop() ?? s.name}/${m.name}`,
|
label: `${s.name.split('.', 2).pop() ?? s.name}/${m.name}`,
|
||||||
value: `${s.name}/${m.name}`,
|
value: `${s.name}/${m.name}`,
|
||||||
@@ -147,7 +146,7 @@ export function GrpcConnectionLayout({ style }: Props) {
|
|||||||
) ?? [];
|
) ?? [];
|
||||||
const value = `${service.value ?? ''}/${method.value ?? ''}`;
|
const value = `${service.value ?? ''}/${method.value ?? ''}`;
|
||||||
return { value, options };
|
return { value, options };
|
||||||
}, [grpc.schema, method.value, service.value]);
|
}, [grpc.services, method.value, service.value]);
|
||||||
|
|
||||||
const [paneSize, setPaneSize] = useState(99999);
|
const [paneSize, setPaneSize] = useState(99999);
|
||||||
const urlContainerEl = useRef<HTMLDivElement>(null);
|
const urlContainerEl = useRef<HTMLDivElement>(null);
|
||||||
@@ -162,14 +161,14 @@ export function GrpcConnectionLayout({ style }: Props) {
|
|||||||
return (
|
return (
|
||||||
<SplitLayout
|
<SplitLayout
|
||||||
name="grpc_layout"
|
name="grpc_layout"
|
||||||
className="p-3"
|
className="p-3 gap-1.5"
|
||||||
style={style}
|
style={style}
|
||||||
leftSlot={() => (
|
leftSlot={() => (
|
||||||
<VStack space={2}>
|
<VStack space={2}>
|
||||||
<div
|
<div
|
||||||
ref={urlContainerEl}
|
ref={urlContainerEl}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
'grid grid-cols-[minmax(0,1fr)_auto_auto] gap-1.5',
|
'grid grid-cols-[minmax(0,1fr)_auto] gap-1.5',
|
||||||
paneSize < 400 && '!grid-cols-1',
|
paneSize < 400 && '!grid-cols-1',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { EditorView } from 'codemirror';
|
import type { EditorView } from 'codemirror';
|
||||||
import { updateSchema } from 'codemirror-json-schema';
|
import { updateSchema } from 'codemirror-json-schema';
|
||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
|
import { useActiveRequestId } from '../hooks/useActiveRequestId';
|
||||||
import { useAlert } from '../hooks/useAlert';
|
import { useAlert } from '../hooks/useAlert';
|
||||||
import { useGrpc } from '../hooks/useGrpc';
|
import { useGrpc } from '../hooks/useGrpc';
|
||||||
import { tryFormatJson } from '../lib/formatters';
|
import { tryFormatJson } from '../lib/formatters';
|
||||||
@@ -21,12 +22,13 @@ type Props = Pick<
|
|||||||
|
|
||||||
export function GrpcEditor({ url, service, method, defaultValue, ...extraEditorProps }: Props) {
|
export function GrpcEditor({ url, service, method, defaultValue, ...extraEditorProps }: Props) {
|
||||||
const editorViewRef = useRef<EditorView>(null);
|
const editorViewRef = useRef<EditorView>(null);
|
||||||
const grpc = useGrpc(url);
|
const activeRequestId = useActiveRequestId();
|
||||||
|
const grpc = useGrpc(url, activeRequestId);
|
||||||
const alert = useAlert();
|
const alert = useAlert();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (editorViewRef.current == null || grpc.schema == null) return;
|
if (editorViewRef.current == null || grpc.services == null) return;
|
||||||
const s = grpc.schema?.find((s) => s.name === service);
|
const s = grpc.services?.find((s) => s.name === service);
|
||||||
if (service != null && s == null) {
|
if (service != null && s == null) {
|
||||||
alert({
|
alert({
|
||||||
id: 'grpc-find-service-error',
|
id: 'grpc-find-service-error',
|
||||||
@@ -77,7 +79,7 @@ export function GrpcEditor({ url, service, method, defaultValue, ...extraEditorP
|
|||||||
});
|
});
|
||||||
console.log('Failed to parse method schema', method, schema);
|
console.log('Failed to parse method schema', method, schema);
|
||||||
}
|
}
|
||||||
}, [alert, grpc.schema, method, service]);
|
}, [alert, grpc.services, method, service]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full w-full grid grid-cols-1 grid-rows-[minmax(0,100%)_auto_auto_minmax(0,auto)]">
|
<div className="h-full w-full grid grid-cols-1 grid-rows-[minmax(0,100%)_auto_auto_minmax(0,auto)]">
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export function HttpRequestLayout({ style }: Props) {
|
|||||||
return (
|
return (
|
||||||
<SplitLayout
|
<SplitLayout
|
||||||
name="http_layout"
|
name="http_layout"
|
||||||
className="p-3"
|
className="p-3 gap-1.5"
|
||||||
style={style}
|
style={style}
|
||||||
leftSlot={({ orientation, style }) => (
|
leftSlot={({ orientation, style }) => (
|
||||||
<RequestPane style={style} fullHeight={orientation === 'horizontal'} />
|
<RequestPane style={style} fullHeight={orientation === 'horizontal'} />
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { useMutation, useQuery } from '@tanstack/react-query';
|
|||||||
import { invoke } from '@tauri-apps/api';
|
import { invoke } from '@tauri-apps/api';
|
||||||
import type { UnlistenFn } from '@tauri-apps/api/event';
|
import type { UnlistenFn } from '@tauri-apps/api/event';
|
||||||
import { emit, listen } from '@tauri-apps/api/event';
|
import { emit, listen } from '@tauri-apps/api/event';
|
||||||
import { type } from '@tauri-apps/api/os';
|
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { tryFormatJson } from '../lib/formatters';
|
import { tryFormatJson } from '../lib/formatters';
|
||||||
import { useKeyValue } from './useKeyValue';
|
import { useKeyValue } from './useKeyValue';
|
||||||
@@ -147,7 +146,7 @@ export function useGrpc(url: string | null, requestId: string | null) {
|
|||||||
unary,
|
unary,
|
||||||
serverStreaming,
|
serverStreaming,
|
||||||
bidiStreaming,
|
bidiStreaming,
|
||||||
schema: reflect.data,
|
services: reflect.data,
|
||||||
cancel,
|
cancel,
|
||||||
messages,
|
messages,
|
||||||
isStreaming: activeConnectionId !== null,
|
isStreaming: activeConnectionId !== null,
|
||||||
|
|||||||
Reference in New Issue
Block a user