Handle "no body" case

This commit is contained in:
Gregory Schier
2023-03-20 13:49:21 -07:00
parent 8b16258627
commit 15bc08390b
4 changed files with 12 additions and 11 deletions

View File

@@ -136,9 +136,9 @@ async fn send_request(
Method::from_bytes(req.method.to_uppercase().as_bytes()).expect("Failed to create method"); Method::from_bytes(req.method.to_uppercase().as_bytes()).expect("Failed to create method");
let builder = client.request(m, url_string.to_string()).headers(headers); let builder = client.request(m, url_string.to_string()).headers(headers);
let sendable_req_result = match req.body { let sendable_req_result = match (req.body, req.body_type) {
Some(b) => builder.body(b).build(), (Some(b), Some(_)) => builder.body(b).build(),
None => builder.build(), _ => builder.build(),
}; };
let sendable_req = match sendable_req_result { let sendable_req = match sendable_req_result {

View File

@@ -31,12 +31,12 @@ export function RequestPane({ fullHeight, className }: Props) {
() => [ () => [
{ {
value: 'body', value: 'body',
label: activeRequest?.bodyType ?? 'NoBody', label: activeRequest?.bodyType ?? 'No Body',
options: { options: {
onChange: (bodyType: string) => updateRequest.mutate({ bodyType }), onChange: (bodyType: string | null) => updateRequest.mutate({ bodyType }),
value: activeRequest?.bodyType ?? 'nobody', value: activeRequest?.bodyType ?? null,
items: [ items: [
{ label: 'No Body', value: 'nobody' }, { label: 'No Body', value: null },
{ label: 'JSON', value: 'json' }, { label: 'JSON', value: 'json' },
{ label: 'XML', value: 'xml' }, { label: 'XML', value: 'xml' },
{ label: 'GraphQL', value: 'graphql' }, { label: 'GraphQL', value: 'graphql' },
@@ -47,7 +47,7 @@ export function RequestPane({ fullHeight, className }: Props) {
{ value: 'headers', label: 'Headers' }, { value: 'headers', label: 'Headers' },
{ value: 'auth', label: 'Auth' }, { value: 'auth', label: 'Auth' },
], ],
[activeRequest?.bodyType], [activeRequest?.bodyType ?? 'n/a'],
); );
const handleBodyChange = useCallback((body: string) => updateRequest.mutate({ body }), []); const handleBodyChange = useCallback((body: string) => updateRequest.mutate({ body }), []);

View File

@@ -5,12 +5,12 @@ import { Icon } from './Icon';
export interface RadioDropdownItem { export interface RadioDropdownItem {
label: string; label: string;
value: string; value: string | null;
} }
export interface RadioDropdownProps { export interface RadioDropdownProps {
value: string; value: string | null;
onChange: (bodyType: string) => void; onChange: (value: string | null) => void;
items: RadioDropdownItem[]; items: RadioDropdownItem[];
children: DropdownProps['children']; children: DropdownProps['children'];
} }

View File

@@ -68,6 +68,7 @@ export const Tabs = memo(function Tabs({
{tabs.map((t) => { {tabs.map((t) => {
const isActive = t.value === value; const isActive = t.value === value;
if (t.options && isActive) { if (t.options && isActive) {
console.log('OPTIONS', t.options, t.options?.value);
return ( return (
<RadioDropdown <RadioDropdown
key={t.value} key={t.value}