import classnames from 'classnames'; import { useCallback, useMemo } from 'react'; import { act } from 'react-dom/test-utils'; import { useActiveRequest } from '../hooks/useActiveRequest'; import { useKeyValue } from '../hooks/useKeyValue'; import { useUpdateRequest } from '../hooks/useUpdateRequest'; import { tryFormatJson } from '../lib/formatters'; import type { HttpHeader } from '../lib/models'; import { Editor } from './core/Editor'; import { PairEditor } from './core/PairEditor'; import type { TabItem } from './core/Tabs/Tabs'; import { TabContent, Tabs } from './core/Tabs/Tabs'; import { GraphQLEditor } from './GraphQLEditor'; import { HeaderEditor } from './HeaderEditor'; import { ParametersEditor } from './ParameterEditor'; import { UrlBar } from './UrlBar'; interface Props { fullHeight: boolean; className?: string; } export function RequestPane({ fullHeight, className }: Props) { const activeRequest = useActiveRequest(); const activeRequestId = activeRequest?.id ?? null; const updateRequest = useUpdateRequest(activeRequestId); const activeTab = useKeyValue({ key: ['active_request_body_tab', activeRequestId ?? 'n/a'], initialValue: 'body', }); const tabs: TabItem[] = useMemo( () => [ { value: 'body', label: activeRequest?.bodyType ?? 'NoBody', options: { onValueChange: (t) => updateRequest.mutate({ bodyType: t.value }), value: activeRequest?.bodyType ?? 'nobody', items: [ { label: 'No Body', value: 'nobody' }, { label: 'JSON', value: 'json' }, { label: 'GraphQL', value: 'graphql' }, ], }, }, { value: 'params', label: 'Params' }, { value: 'headers', label: 'Headers' }, { value: 'auth', label: 'Auth' }, ], [activeRequest?.bodyType], ); const handleBodyChange = useCallback((body: string) => updateRequest.mutate({ body }), []); const handleHeadersChange = useCallback( (headers: HttpHeader[]) => updateRequest.mutate({ headers }), [], ); if (activeRequest === null) return null; return (
null} /> {activeRequest.bodyType === 'json' ? ( tryFormatJson(v) : undefined} /> ) : activeRequest.bodyType === 'graphql' ? ( ) : (
No Body
)}
); }