response parsing
This commit is contained in:
parent
a834f17a80
commit
f53463ec0c
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { Input } from "@budibase/bbui"
|
import { Button, Input } from "@budibase/bbui"
|
||||||
|
|
||||||
export let object = {}
|
export let object = {}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
<i class="ri-close-circle-fill" on:click={() => deleteEntry(idx)} />
|
<i class="ri-close-circle-fill" on:click={() => deleteEntry(idx)} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
<i class="ri-add-circle-fill" on:click={addEntry} />
|
<Button secondary thin outline on:click={addEntry}>Add</Button>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.container {
|
.container {
|
||||||
|
@ -39,8 +39,7 @@
|
||||||
margin-bottom: var(--spacing-m);
|
margin-bottom: var(--spacing-m);
|
||||||
}
|
}
|
||||||
|
|
||||||
.ri-close-circle-fill,
|
.ri-close-circle-fill {
|
||||||
.ri-add-circle-fill {
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
Input,
|
Input,
|
||||||
Heading,
|
Heading,
|
||||||
Select,
|
Select,
|
||||||
|
Spacer
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import Editor from "./QueryEditor.svelte"
|
import Editor from "./QueryEditor.svelte"
|
||||||
import KeyValueBuilder from "./KeyValueBuilder.svelte"
|
import KeyValueBuilder from "./KeyValueBuilder.svelte"
|
||||||
|
@ -30,6 +31,7 @@
|
||||||
{#if schema.fields[field]?.type === 'object'}
|
{#if schema.fields[field]?.type === 'object'}
|
||||||
<div>
|
<div>
|
||||||
<Label small>{field}</Label>
|
<Label small>{field}</Label>
|
||||||
|
<Spacer small />
|
||||||
<KeyValueBuilder bind:object={fields[field]} />
|
<KeyValueBuilder bind:object={fields[field]} />
|
||||||
</div>
|
</div>
|
||||||
{:else if schema.fields[field]?.type === 'json'}
|
{:else if schema.fields[field]?.type === 'json'}
|
||||||
|
@ -57,6 +59,8 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{#if schema.customisable}
|
{#if schema.customisable}
|
||||||
|
<Label small>Query</Label>
|
||||||
|
<Spacer small />
|
||||||
<Editor
|
<Editor
|
||||||
label="Query"
|
label="Query"
|
||||||
mode="json"
|
mode="json"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { params } from "@sveltech/routify"
|
import { params } from "@sveltech/routify"
|
||||||
import { Switcher, Modal } from "@budibase/bbui"
|
import { Button, Switcher, Modal } from "@budibase/bbui"
|
||||||
import TableNavigator from "components/backend/TableNavigator/TableNavigator.svelte"
|
import TableNavigator from "components/backend/TableNavigator/TableNavigator.svelte"
|
||||||
import DatasourceNavigator from "components/backend/DatasourceNavigator/DatasourceNavigator.svelte"
|
import DatasourceNavigator from "components/backend/DatasourceNavigator/DatasourceNavigator.svelte"
|
||||||
import CreateDatasourceModal from "components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte"
|
import CreateDatasourceModal from "components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte"
|
||||||
|
@ -27,10 +27,9 @@
|
||||||
<div class="nav">
|
<div class="nav">
|
||||||
<Switcher headings={tabs} bind:value={tab}>
|
<Switcher headings={tabs} bind:value={tab}>
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<i
|
<Button blue data-cy={`new-${tab}`} on:click={modal.show}>
|
||||||
data-cy={`new-${tab}`}
|
<i class="ri-add-fill" />
|
||||||
class="ri-add-circle-fill"
|
</Button>
|
||||||
on:click={modal.show} />
|
|
||||||
</div>
|
</div>
|
||||||
{#if tab === 'table'}
|
{#if tab === 'table'}
|
||||||
<TableNavigator />
|
<TableNavigator />
|
||||||
|
@ -82,7 +81,7 @@
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
i {
|
.title {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: var(--spacing-l);
|
top: var(--spacing-l);
|
||||||
|
|
|
@ -98,53 +98,72 @@ class RestIntegration {
|
||||||
this.config = config
|
this.config = config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async parseResponse(response) {
|
||||||
|
switch (this.headers.Accept) {
|
||||||
|
case "application/json":
|
||||||
|
return await response.json()
|
||||||
|
case "text/html":
|
||||||
|
return await response.text()
|
||||||
|
default:
|
||||||
|
return await response.json()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async create({ path, queryString, headers = {}, json }) {
|
async create({ path, queryString, headers = {}, json }) {
|
||||||
const response = await fetch(this.config.url + path + queryString, {
|
this.headers = {
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
...this.config.defaultHeaders,
|
...this.config.defaultHeaders,
|
||||||
...headers,
|
...headers,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
const response = await fetch(this.config.url + path + queryString, {
|
||||||
|
method: "POST",
|
||||||
|
headers: this.headers,
|
||||||
body: JSON.stringify(json),
|
body: JSON.stringify(json),
|
||||||
})
|
})
|
||||||
|
|
||||||
return await response.json()
|
return await this.parseResponse(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
async read({ path, queryString, headers = {} }) {
|
async read({ path, queryString, headers = {} }) {
|
||||||
const response = await fetch(this.config.url + path + queryString, {
|
this.headers = {
|
||||||
headers: {
|
|
||||||
...this.config.defaultHeaders,
|
...this.config.defaultHeaders,
|
||||||
...headers,
|
...headers,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
const response = await fetch(this.config.url + path + queryString, {
|
||||||
|
headers: this.headers,
|
||||||
})
|
})
|
||||||
|
|
||||||
return await response.json()
|
return await this.parseResponse(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
async update({ path, queryString, headers = {}, json }) {
|
async update({ path, queryString, headers = {}, json }) {
|
||||||
const response = await fetch(this.config.url + path + queryString, {
|
this.headers = {
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
...this.config.defaultHeaders,
|
...this.config.defaultHeaders,
|
||||||
...headers,
|
...headers,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
const response = await fetch(this.config.url + path + queryString, {
|
||||||
|
method: "POST",
|
||||||
|
headers: this.headers,
|
||||||
body: JSON.stringify(json),
|
body: JSON.stringify(json),
|
||||||
})
|
})
|
||||||
|
|
||||||
return await response.json()
|
return await this.parseResponse(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete({ path, queryString, headers = {} }) {
|
async delete({ path, queryString, headers = {} }) {
|
||||||
const response = await fetch(this.config.url + path + queryString, {
|
this.headers = {
|
||||||
method: "DELETE",
|
|
||||||
headers: {
|
|
||||||
...this.config.defaultHeaders,
|
...this.config.defaultHeaders,
|
||||||
...headers,
|
...headers,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
const response = await fetch(this.config.url + path + queryString, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: this.headers,
|
||||||
})
|
})
|
||||||
|
|
||||||
return await response.json()
|
return await this.parseResponse(response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue