From 740abf844542cd03b29f8d25784cc24e8450f2bc Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 2 Dec 2021 17:53:14 +0000 Subject: [PATCH] Adding radio group of body types. --- packages/bbui/src/Form/RadioGroup.svelte | 2 + packages/builder/src/constants/index.js | 16 +++ .../_components/RestBodyInput.svelte | 13 +++ .../[selectedDatasource]/rest/index.svelte | 19 +++- packages/server/src/integrations/rest.ts | 107 ++++++------------ 5 files changed, 83 insertions(+), 74 deletions(-) create mode 100644 packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/RestBodyInput.svelte diff --git a/packages/bbui/src/Form/RadioGroup.svelte b/packages/bbui/src/Form/RadioGroup.svelte index c661e790b1..528f9f5eba 100644 --- a/packages/bbui/src/Form/RadioGroup.svelte +++ b/packages/bbui/src/Form/RadioGroup.svelte @@ -9,6 +9,7 @@ export let labelPosition = "above" export let error = null export let options = [] + export let direction = "vertical" export let getOptionLabel = option => extractProperty(option, "label") export let getOptionValue = option => extractProperty(option, "value") @@ -31,6 +32,7 @@ {disabled} {value} {options} + {direction} {getOptionLabel} {getOptionValue} on:change={onChange} diff --git a/packages/builder/src/constants/index.js b/packages/builder/src/constants/index.js index c49fd13dc2..ff7ab3baa5 100644 --- a/packages/builder/src/constants/index.js +++ b/packages/builder/src/constants/index.js @@ -66,6 +66,22 @@ export const LAYOUT_NAMES = { }, } +export const RawRestBodyTypes = { + NONE: "none", + FORM: "form", + ENCODED: "encoded", + JSON: "json", + TEXT: "text", +} + +export const RestBodyTypes = [ + { name: "none", value: "none" }, + { name: "form-data", value: "form" }, + { name: "x-www-form-encoded", value: "encoded" }, + { name: "raw (JSON)", value: "json" }, + { name: "raw (Text)", value: "text" }, +] + export const BUDIBASE_INTERNAL_DB = "bb_internal" export const APP_NAME_REGEX = /^[\w\s]+$/ diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/RestBodyInput.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/RestBodyInput.svelte new file mode 100644 index 0000000000..8e5d267fdf --- /dev/null +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/RestBodyInput.svelte @@ -0,0 +1,13 @@ + + +{#if bodyType === RawRestBodyTypes.NONE} + The request does not have a body +{:else if bodyType === RawRestBodyTypes.FORM} + Form +{/if} diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/index.svelte index bff6c9a677..47532ae3b1 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/index.svelte @@ -11,12 +11,15 @@ Divider, Button, Heading, + RadioGroup, } from "@budibase/bbui" import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte" import EditableLabel from "components/common/inputs/EditableLabel.svelte" import CodeMirrorEditor from "components/common/CodeMirrorEditor.svelte" + import RestBodyInput from "../_components/RestBodyInput.svelte" import { capitalise } from "helpers" import { onMount } from "svelte" + import { RestBodyTypes as bodyTypes } from "constants" let query let breakQs = {} @@ -106,6 +109,9 @@ bannerCleared: false, } } + if (query && !query.fields.bodyType) { + query.fields.bodyType = "none" + } }) @@ -134,7 +140,7 @@ - + @@ -146,7 +152,16 @@ activity /> - + + option.name} + getOptionValue={option => option.value} + /> + + {#if !query.flags.bannerCleared} diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index a217bddaa1..c5a5edbed8 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -5,6 +5,36 @@ import { } from "../definitions/datasource" import { IntegrationBase } from "./base/IntegrationBase" +const BodyTypes = { + NONE: "none", + FORM_DATA: "form", + ENCODED: "encoded", + JSON: "json", + TEXT: "text", +} + +const coreFields = { + path: { + type: DatasourceFieldTypes.STRING, + display: "URL", + }, + queryString: { + type: DatasourceFieldTypes.STRING, + }, + headers: { + type: DatasourceFieldTypes.OBJECT, + }, + enabledHeaders: { + type: DatasourceFieldTypes.OBJECT, + }, + requestBody: { + type: DatasourceFieldTypes.JSON, + }, + bodyType: { + type: DatasourceFieldTypes.STRING, + }, +} + module RestModule { const fetch = require("node-fetch") @@ -38,97 +68,30 @@ module RestModule { readable: true, displayName: "POST", type: QueryTypes.FIELDS, - fields: { - path: { - type: DatasourceFieldTypes.STRING, - display: "URL", - }, - queryString: { - type: DatasourceFieldTypes.STRING, - }, - headers: { - type: DatasourceFieldTypes.OBJECT, - }, - requestBody: { - type: DatasourceFieldTypes.JSON, - }, - }, + fields: coreFields, }, read: { displayName: "GET", readable: true, type: QueryTypes.FIELDS, - fields: { - path: { - type: DatasourceFieldTypes.STRING, - display: "URL", - }, - queryString: { - type: DatasourceFieldTypes.STRING, - }, - headers: { - type: DatasourceFieldTypes.OBJECT, - }, - }, + fields: coreFields, }, update: { displayName: "PUT", readable: true, type: QueryTypes.FIELDS, - fields: { - path: { - type: DatasourceFieldTypes.STRING, - display: "URL", - }, - queryString: { - type: DatasourceFieldTypes.STRING, - }, - headers: { - type: DatasourceFieldTypes.OBJECT, - }, - requestBody: { - type: DatasourceFieldTypes.JSON, - }, - }, + fields: coreFields, }, patch: { displayName: "PATCH", readable: true, type: QueryTypes.FIELDS, - fields: { - path: { - type: DatasourceFieldTypes.STRING, - display: "URL", - }, - queryString: { - type: DatasourceFieldTypes.STRING, - }, - headers: { - type: DatasourceFieldTypes.OBJECT, - }, - requestBody: { - type: DatasourceFieldTypes.JSON, - }, - }, + fields: coreFields, }, delete: { displayName: "DELETE", type: QueryTypes.FIELDS, - fields: { - path: { - type: DatasourceFieldTypes.STRING, - display: "URL", - }, - queryString: { - type: DatasourceFieldTypes.STRING, - }, - headers: { - type: DatasourceFieldTypes.OBJECT, - }, - requestBody: { - type: DatasourceFieldTypes.JSON, - }, - }, + fields: coreFields, }, }, }