Combine grpc handlers, fix duplicate

This commit is contained in:
Gregory Schier
2024-02-10 10:41:45 -08:00
parent bbe62abd20
commit 09c7c2cb91
10 changed files with 135 additions and 551 deletions

View File

@@ -85,8 +85,10 @@ export function GlobalHooks() {
queryClient.setQueryData<Model[]>(queryKey, (values = []) => {
const index = values.findIndex((v) => modelsEq(v, payload)) ?? -1;
if (index >= 0) {
// console.log('UPDATED', payload);
return [...values.slice(0, index), payload, ...values.slice(index + 1)];
} else {
// console.log('CREATED', payload);
return pushToFront ? [payload, ...(values ?? [])] : [...(values ?? []), payload];
}
});

View File

@@ -36,10 +36,18 @@ export function GrpcEditor({
// Find the schema for the selected service and method and update the editor
useEffect(() => {
if (editorViewRef.current == null || services === null) return;
if (
editorViewRef.current == null ||
services === null ||
request.service === null ||
request.method === null
) {
return;
}
const s = services.find((s) => s.name === request.service);
if (request.service != null && s == null) {
if (s == null) {
console.log('Failed to find service', { service: request.service, services });
alert({
id: 'grpc-find-service-error',
title: "Couldn't Find Service",
@@ -52,8 +60,9 @@ export function GrpcEditor({
return;
}
const schema = s?.methods.find((m) => m.name === request.method)?.schema;
const schema = s.methods.find((m) => m.name === request.method)?.schema;
if (request.method != null && schema == null) {
console.log('Failed to find method', { method: request.method, methods: s?.methods });
alert({
id: 'grpc-find-schema-error',
title: "Couldn't Find Method",

View File

@@ -493,7 +493,7 @@ function SidebarItems({
child.item.model === 'http_request' ? (
<HttpMethodTag className="opacity-50">{child.item.method}</HttpMethodTag>
) : child.item.model === 'grpc_request' ? (
<HttpMethodTag className="opacity-50">gRPC</HttpMethodTag>
<HttpMethodTag className="opacity-50">GRPC</HttpMethodTag>
) : null
}
onMove={handleMove}

View File

@@ -13,7 +13,7 @@ const methodMap: Record<string, string> = {
delete: 'DELETE',
options: 'OPTIONS',
head: 'HEAD',
grpc: 'gRPC',
grpc: 'GRPC',
};
export function HttpMethodTag({ children: method, className }: Props) {

View File

@@ -31,6 +31,7 @@ export const JsonAttributeTree = ({ depth = 0, attrKey, attrValue, attrKeyJsonPa
.sort((a, b) => a.localeCompare(b))
.flatMap((k) => (
<JsonAttributeTree
key={k}
depth={depth + 1}
attrValue={attrValue[k]}
attrKey={k}
@@ -48,6 +49,7 @@ export const JsonAttributeTree = ({ depth = 0, attrKey, attrValue, attrKeyJsonPa
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
attrValue.flatMap((v: any, i: number) => (
<JsonAttributeTree
key={i}
depth={depth + 1}
attrValue={v}
attrKey={i}