forked from tsai/budibase
7 changed files with 156 additions and 12 deletions
@ -1,13 +1,62 @@ |
|||||
<script> |
<script> |
||||
import { Body } from "@budibase/bbui" |
import { Body } from "@budibase/bbui" |
||||
import { RawRestBodyTypes } from "constants" |
import { RawRestBodyTypes } from "constants" |
||||
|
import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte" |
||||
|
import CodeMirrorEditor, { |
||||
|
EditorModes, |
||||
|
} from "components/common/CodeMirrorEditor.svelte" |
||||
|
|
||||
|
const objectTypes = [RawRestBodyTypes.FORM, RawRestBodyTypes.ENCODED] |
||||
|
const textTypes = [RawRestBodyTypes.JSON, RawRestBodyTypes.TEXT] |
||||
|
|
||||
export let query |
export let query |
||||
export let bodyType |
export let bodyType |
||||
|
|
||||
|
$: checkRequestBody(bodyType) |
||||
|
|
||||
|
function checkRequestBody(type) { |
||||
|
if (!bodyType || !query) { |
||||
|
return |
||||
|
} |
||||
|
const currentType = typeof query?.fields.requestBody |
||||
|
if (objectTypes.includes(type) && currentType !== "object") { |
||||
|
query.fields.requestBody = {} |
||||
|
} else if (textTypes.includes(type) && currentType !== "string") { |
||||
|
query.fields.requestBody = "" |
||||
|
} |
||||
|
} |
||||
</script> |
</script> |
||||
|
|
||||
{#if bodyType === RawRestBodyTypes.NONE} |
<div class="margin"> |
||||
<Body>The request does not have a body</Body> |
{#if bodyType === RawRestBodyTypes.NONE} |
||||
{:else if bodyType === RawRestBodyTypes.FORM} |
<div class="none"> |
||||
<Body>Form</Body> |
<Body size="S" weight="800">THE REQUEST DOES NOT HAVE A BODY</Body> |
||||
{/if} |
</div> |
||||
|
{:else if objectTypes.includes(bodyType)} |
||||
|
<KeyValueBuilder |
||||
|
bind:object={query.fields.requestBody} |
||||
|
name="param" |
||||
|
headings |
||||
|
/> |
||||
|
{:else if textTypes.includes(bodyType)} |
||||
|
<CodeMirrorEditor |
||||
|
height={200} |
||||
|
mode={bodyType === RawRestBodyTypes.JSON |
||||
|
? EditorModes.JSON |
||||
|
: EditorModes.Text} |
||||
|
value={query.fields.requestBody} |
||||
|
resize="vertical" |
||||
|
on:change={e => (query.fields.requestBody = e.detail)} |
||||
|
/> |
||||
|
{/if} |
||||
|
</div> |
||||
|
|
||||
|
<style> |
||||
|
.margin { |
||||
|
margin-top: var(--spacing-m); |
||||
|
} |
||||
|
.none { |
||||
|
display: flex; |
||||
|
justify-content: center; |
||||
|
} |
||||
|
</style> |
||||
|
|||||
Loading…
Reference in new issue