Handle "no body" case

This commit is contained in:
Gregory Schier
2023-03-20 13:49:21 -07:00
parent bb139744a1
commit a938dc45f0
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");
let builder = client.request(m, url_string.to_string()).headers(headers);
let sendable_req_result = match req.body {
Some(b) => builder.body(b).build(),
None => builder.build(),
let sendable_req_result = match (req.body, req.body_type) {
(Some(b), Some(_)) => builder.body(b).build(),
_ => builder.build(),
};
let sendable_req = match sendable_req_result {

View File

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

View File

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

View File

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