mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 17:28:29 +02:00
Actually fix GraphQLEditor.tsx properly
This commit is contained in:
@@ -174,7 +174,6 @@ export function GrpcEditor({
|
|||||||
language="json"
|
language="json"
|
||||||
autocompleteFunctions
|
autocompleteFunctions
|
||||||
autocompleteVariables
|
autocompleteVariables
|
||||||
forceUpdateKey={request.id}
|
|
||||||
defaultValue={request.message}
|
defaultValue={request.message}
|
||||||
heightMode="auto"
|
heightMode="auto"
|
||||||
placeholder="..."
|
placeholder="..."
|
||||||
|
|||||||
@@ -409,7 +409,6 @@ export function HttpRequestPane({ style, fullHeight, className, activeRequest }:
|
|||||||
) : activeRequest.bodyType === BODY_TYPE_GRAPHQL ? (
|
) : activeRequest.bodyType === BODY_TYPE_GRAPHQL ? (
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<GraphQLEditor
|
<GraphQLEditor
|
||||||
key={forceUpdateKey}
|
|
||||||
forceUpdateKey={forceUpdateKey}
|
forceUpdateKey={forceUpdateKey}
|
||||||
baseRequest={activeRequest}
|
baseRequest={activeRequest}
|
||||||
request={activeRequest}
|
request={activeRequest}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { HttpRequest } from '@yaakapp-internal/models';
|
|||||||
|
|
||||||
import { formatSdl } from 'format-graphql';
|
import { formatSdl } from 'format-graphql';
|
||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import { useLocalStorage } from 'react-use';
|
import { useLocalStorage } from 'react-use';
|
||||||
import { useIntrospectGraphQL } from '../../hooks/useIntrospectGraphQL';
|
import { useIntrospectGraphQL } from '../../hooks/useIntrospectGraphQL';
|
||||||
import { useStateWithDeps } from '../../hooks/useStateWithDeps';
|
import { useStateWithDeps } from '../../hooks/useStateWithDeps';
|
||||||
@@ -45,20 +45,31 @@ export function GraphQLEditor({ request, onChange, baseRequest, ...extraEditorPr
|
|||||||
|
|
||||||
return { query: request.body.query ?? '', variables: request.body.variables ?? '' };
|
return { query: request.body.query ?? '', variables: request.body.variables ?? '' };
|
||||||
}, [extraEditorProps.forceUpdateKey]);
|
}, [extraEditorProps.forceUpdateKey]);
|
||||||
|
|
||||||
const [isDocOpenRecord, setGraphqlDocStateAtomValue] = useAtom(showGraphQLDocExplorerAtom);
|
const [isDocOpenRecord, setGraphqlDocStateAtomValue] = useAtom(showGraphQLDocExplorerAtom);
|
||||||
const isDocOpen = isDocOpenRecord[request.id] !== undefined;
|
const isDocOpen = isDocOpenRecord[request.id] !== undefined;
|
||||||
|
|
||||||
const handleChangeQuery = (query: string) => {
|
const handleChangeQuery = useCallback(
|
||||||
const newBody = { query, variables: currentBody.variables || undefined };
|
(query: string) => {
|
||||||
setCurrentBody(newBody);
|
setCurrentBody(({ variables }) => {
|
||||||
onChange(newBody);
|
const newBody = { query, variables };
|
||||||
};
|
onChange(newBody);
|
||||||
|
return newBody;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[onChange, setCurrentBody],
|
||||||
|
);
|
||||||
|
|
||||||
const handleChangeVariables = (variables: string) => {
|
const handleChangeVariables = useCallback(
|
||||||
const newBody = { query: currentBody.query, variables: variables || undefined };
|
(variables: string) => {
|
||||||
setCurrentBody(newBody);
|
setCurrentBody(({ query }) => {
|
||||||
onChange(newBody);
|
const newBody = { query, variables: variables || undefined };
|
||||||
};
|
onChange(newBody);
|
||||||
|
return newBody;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[onChange, setCurrentBody],
|
||||||
|
);
|
||||||
|
|
||||||
const actions = useMemo<EditorProps['actions']>(
|
const actions = useMemo<EditorProps['actions']>(
|
||||||
() => [
|
() => [
|
||||||
|
|||||||
Reference in New Issue
Block a user