From 5347a8339cba411dc65fcf41de37f1b7f15eb40b Mon Sep 17 00:00:00 2001 From: Dean Date: Fri, 16 Sep 2022 17:32:50 +0100 Subject: [PATCH 1/4] Minor fix to add categories for rest bindings --- packages/builder/src/builderStore/dataBinding.js | 16 +++++++++++++--- .../rest/[query]/index.svelte | 10 ++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index d961a3a1cd..562e4fdcbc 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -82,6 +82,7 @@ export const getAuthBindings = () => { readableBinding: fieldBinding.readable, fieldSchema: { type: "string", name: fieldBinding.key }, providerId: "user", + category: "Current User", } }) return bindings @@ -93,7 +94,7 @@ export const getAuthBindings = () => { * @param {string} prefix A contextual string prefix/path for a user readable binding * @return {object[]} An array containing readable/runtime binding objects */ -export const toBindingsArray = (valueMap, prefix) => { +export const toBindingsArray = (valueMap, prefix, category) => { if (!valueMap) { return [] } @@ -101,11 +102,20 @@ export const toBindingsArray = (valueMap, prefix) => { if (!binding || !valueMap[binding]) { return acc } - acc.push({ + + let config = { type: "context", runtimeBinding: binding, readableBinding: `${prefix}.${binding}`, - }) + icon: "Brackets", + } + + if (category) { + config.category = category + } + + acc.push(config) + return acc }, []) } 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 d2c1630416..fc13310ed9 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 @@ -60,14 +60,20 @@ $: staticVariables = datasource?.config?.staticVariables || {} - $: customRequestBindings = toBindingsArray(requestBindings, "Binding") + $: customRequestBindings = toBindingsArray( + requestBindings, + "Binding", + "Bindings" + ) $: globalDynamicRequestBindings = toBindingsArray( globalDynamicBindings, + "Dynamic", "Dynamic" ) $: dataSourceStaticBindings = toBindingsArray( staticVariables, - "Datasource.Static" + "Datasource.Static", + "Datasource Static" ) $: mergedBindings = [ From 58d96d3a6b64c8735eda32114ae2581330707b9f Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 20 Sep 2022 10:07:07 +0100 Subject: [PATCH 2/4] Minor change to ensure correct labelling for OAuthToken binding --- packages/builder/src/builderStore/dataBinding.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index fc16ceec18..41476fd9ec 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -9,14 +9,14 @@ import { import { store } from "builderStore" import { queries as queriesStores, - roles as rolesStore, tables as tablesStore, + roles as rolesStore, } from "stores/backend" import { + makePropSafe, + isJSBinding, decodeJSBinding, encodeJSBinding, - isJSBinding, - makePropSafe, } from "@budibase/string-templates" import { TableNames } from "../constants" import { JSONUtils } from "@budibase/frontend-core" @@ -71,11 +71,11 @@ export const getAuthBindings = () => { runtime: `${safeUser}.${safeOAuth2}.${safeAccessToken}`, readable: `Current User.OAuthToken`, key: "accessToken", + display: { name: "OAuthToken" }, }, ] - bindings = Object.keys(authBindings).map(key => { - const fieldBinding = authBindings[key] + bindings = authBindings.map(fieldBinding => { return { type: "context", runtimeBinding: fieldBinding.runtime, @@ -83,6 +83,7 @@ export const getAuthBindings = () => { fieldSchema: { type: "string", name: fieldBinding.key }, providerId: "user", category: "Current User", + display: fieldBinding.display, } }) return bindings @@ -404,7 +405,7 @@ export const getUserBindings = () => { providerId: "user", category: "Current User", icon: "User", - display: fieldSchema, + display: fieldSchema.fieldName, }) }) return bindings From d0d63f14b089e4aa9aeed1e7b3209c4c92a8890a Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 20 Sep 2022 10:15:23 +0100 Subject: [PATCH 3/4] Removed redundant display variable from user bindings --- packages/builder/src/builderStore/dataBinding.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index 41476fd9ec..bf589ad4a9 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -405,7 +405,6 @@ export const getUserBindings = () => { providerId: "user", category: "Current User", icon: "User", - display: fieldSchema.fieldName, }) }) return bindings From a6cee098123cded782f4a3d7e4f81b5a9d67aae9 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 20 Sep 2022 11:09:58 +0100 Subject: [PATCH 4/4] Filter 'link' fields from the Current User bindings --- .../builder/src/builderStore/dataBinding.js | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/builder/src/builderStore/dataBinding.js b/packages/builder/src/builderStore/dataBinding.js index bf589ad4a9..ca36380077 100644 --- a/packages/builder/src/builderStore/dataBinding.js +++ b/packages/builder/src/builderStore/dataBinding.js @@ -393,20 +393,25 @@ export const getUserBindings = () => { const { schema } = getSchemaForTable(TableNames.USERS) const keys = Object.keys(schema).sort() const safeUser = makePropSafe("user") - keys.forEach(key => { + + bindings = keys.reduce((acc, key) => { const fieldSchema = schema[key] - bindings.push({ - type: "context", - runtimeBinding: `${safeUser}.${makePropSafe(key)}`, - readableBinding: `Current User.${key}`, - // Field schema and provider are required to construct relationship - // datasource options, based on bindable properties - fieldSchema, - providerId: "user", - category: "Current User", - icon: "User", - }) - }) + if (fieldSchema.type !== "link") { + acc.push({ + type: "context", + runtimeBinding: `${safeUser}.${makePropSafe(key)}`, + readableBinding: `Current User.${key}`, + // Field schema and provider are required to construct relationship + // datasource options, based on bindable properties + fieldSchema, + providerId: "user", + category: "Current User", + icon: "User", + }) + } + return acc + }, []) + return bindings }