From a7743c8481894f8be5e64c5ec158496b1ae2423c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 13 Dec 2021 11:24:13 +0000 Subject: [PATCH] Fixing bug in tabs where double clicks cause tab switching, new headers enabled by default, disabled headers rather than enabled, get requests can have bodies. --- packages/bbui/src/Tabs/Tabs.svelte | 1 + .../components/integration/KeyValueBuilder.svelte | 9 ++------- packages/builder/src/helpers/data/utils.js | 11 +++++++++++ .../[selectedDatasource]/rest/[query]/index.svelte | 12 +++++++----- packages/server/src/integrations/rest.ts | 8 ++++---- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/packages/bbui/src/Tabs/Tabs.svelte b/packages/bbui/src/Tabs/Tabs.svelte index 235e103bb1..c68f715de0 100644 --- a/packages/bbui/src/Tabs/Tabs.svelte +++ b/packages/bbui/src/Tabs/Tabs.svelte @@ -27,6 +27,7 @@ dispatch("select", thisSelected) } else if ($tab.title !== thisSelected) { thisSelected = $tab.title + selected = $tab.title dispatch("select", thisSelected) } if ($tab.title !== thisSelected) { diff --git a/packages/builder/src/components/integration/KeyValueBuilder.svelte b/packages/builder/src/components/integration/KeyValueBuilder.svelte index bde1dc256a..9c438f107d 100644 --- a/packages/builder/src/components/integration/KeyValueBuilder.svelte +++ b/packages/builder/src/components/integration/KeyValueBuilder.svelte @@ -26,13 +26,12 @@ export let tooltip let fields = Object.entries(object).map(([name, value]) => ({ name, value })) - let fieldActivity = [] + let fieldActivity = buildFieldActivity(activity) $: object = fields.reduce( (acc, next) => ({ ...acc, [next.name]: next.value }), {} ) - $: fieldActivity = buildFieldActivity(activity) function buildFieldActivity(obj) { if (!obj || typeof obj !== "object") { @@ -103,11 +102,7 @@ /> {/if} {#if toggle} - + {/if} {#if !readOnly} deleteEntry(idx)} /> diff --git a/packages/builder/src/helpers/data/utils.js b/packages/builder/src/helpers/data/utils.js index 64cb4df5c2..613f533043 100644 --- a/packages/builder/src/helpers/data/utils.js +++ b/packages/builder/src/helpers/data/utils.js @@ -108,3 +108,14 @@ export function customQueryIconColor(datasource, query) { return } } + +export function flipHeaderState(headersActivity) { + if (!headersActivity) { + return {} + } + const enabled = {} + Object.entries(headersActivity).forEach(([key, value]) => { + enabled[key] = !value + }) + return enabled +} diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte index 64572280ca..4169a61dbe 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte @@ -33,6 +33,7 @@ buildQueryString, keyValueToQueryParameters, queryParametersToKeyValue, + flipHeaderState, } from "helpers/data/utils" import { RestBodyTypes as bodyTypes, @@ -48,7 +49,7 @@ bindings = {} let url = "" let saveId - let response, schema, isGet + let response, schema, enabledHeaders let datasourceType, integrationInfo, queryConfig, responseSuccess $: datasource = $datasources.list.find(ds => ds._id === query?.datasourceId) @@ -57,7 +58,6 @@ $: queryConfig = integrationInfo?.query $: url = buildUrl(url, breakQs) $: checkQueryName(url) - $: isGet = query?.queryVerb === "read" $: responseSuccess = response?.info?.code >= 200 && response?.info?.code <= 206 @@ -100,6 +100,7 @@ const queryString = buildQueryString(breakQs) newQuery.fields.path = url.split("?")[0] newQuery.fields.queryString = queryString + newQuery.fields.disabledHeaders = flipHeaderState(enabledHeaders) newQuery.schema = fieldsToSchema(schema) newQuery.parameters = keyValueToQueryParameters(bindings) return newQuery @@ -139,6 +140,7 @@ url = buildUrl(query.fields.path, breakQs) schema = schemaToFields(query.schema) bindings = queryParametersToKeyValue(query.parameters) + enabledHeaders = flipHeaderState(query.fields.disabledHeaders) if (query && !query.transformer) { query.transformer = "return data" } @@ -153,7 +155,7 @@ }) -{#if query} +{#if query && queryConfig}
@@ -201,7 +203,7 @@ option.name} getOptionValue={option => option.value} diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index f568305652..6eb772ec92 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -45,7 +45,7 @@ module RestModule { path: string queryString?: string headers: { [key: string]: any } - enabledHeaders: { [key: string]: any } + disabledHeaders: { [key: string]: any } requestBody: any bodyType: string json: object @@ -161,15 +161,15 @@ module RestModule { } async _req(query: RestQuery) { - const { path = "", queryString = "", headers = {}, method = "GET", enabledHeaders, bodyType, requestBody } = query + const { path = "", queryString = "", headers = {}, method = "GET", disabledHeaders, bodyType, requestBody } = query this.headers = { ...this.config.defaultHeaders, ...headers, } - if (enabledHeaders) { + if (disabledHeaders) { for (let headerKey of Object.keys(this.headers)) { - if (!enabledHeaders[headerKey]) { + if (disabledHeaders[headerKey]) { delete this.headers[headerKey] } }