Merge pull request #7809 from Budibase/fix/missing-rest-binding-category-names

Fix/missing rest binding category names
This commit is contained in:
Martin McKeaveney 2022-09-21 15:33:59 +01:00 committed by GitHub
commit f1d5f37e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 24 deletions

View File

@ -9,14 +9,14 @@ import {
import { store } from "builderStore" import { store } from "builderStore"
import { import {
queries as queriesStores, queries as queriesStores,
roles as rolesStore,
tables as tablesStore, tables as tablesStore,
roles as rolesStore,
} from "stores/backend" } from "stores/backend"
import { import {
makePropSafe,
isJSBinding,
decodeJSBinding, decodeJSBinding,
encodeJSBinding, encodeJSBinding,
isJSBinding,
makePropSafe,
} from "@budibase/string-templates" } from "@budibase/string-templates"
import { TableNames } from "../constants" import { TableNames } from "../constants"
import { JSONUtils } from "@budibase/frontend-core" import { JSONUtils } from "@budibase/frontend-core"
@ -71,17 +71,19 @@ export const getAuthBindings = () => {
runtime: `${safeUser}.${safeOAuth2}.${safeAccessToken}`, runtime: `${safeUser}.${safeOAuth2}.${safeAccessToken}`,
readable: `Current User.OAuthToken`, readable: `Current User.OAuthToken`,
key: "accessToken", key: "accessToken",
display: { name: "OAuthToken" },
}, },
] ]
bindings = Object.keys(authBindings).map(key => { bindings = authBindings.map(fieldBinding => {
const fieldBinding = authBindings[key]
return { return {
type: "context", type: "context",
runtimeBinding: fieldBinding.runtime, runtimeBinding: fieldBinding.runtime,
readableBinding: fieldBinding.readable, readableBinding: fieldBinding.readable,
fieldSchema: { type: "string", name: fieldBinding.key }, fieldSchema: { type: "string", name: fieldBinding.key },
providerId: "user", providerId: "user",
category: "Current User",
display: fieldBinding.display,
} }
}) })
return bindings return bindings
@ -93,7 +95,7 @@ export const getAuthBindings = () => {
* @param {string} prefix A contextual string prefix/path for a user readable binding * @param {string} prefix A contextual string prefix/path for a user readable binding
* @return {object[]} An array containing readable/runtime binding objects * @return {object[]} An array containing readable/runtime binding objects
*/ */
export const toBindingsArray = (valueMap, prefix) => { export const toBindingsArray = (valueMap, prefix, category) => {
if (!valueMap) { if (!valueMap) {
return [] return []
} }
@ -101,11 +103,20 @@ export const toBindingsArray = (valueMap, prefix) => {
if (!binding || !valueMap[binding]) { if (!binding || !valueMap[binding]) {
return acc return acc
} }
acc.push({
let config = {
type: "context", type: "context",
runtimeBinding: binding, runtimeBinding: binding,
readableBinding: `${prefix}.${binding}`, readableBinding: `${prefix}.${binding}`,
}) icon: "Brackets",
}
if (category) {
config.category = category
}
acc.push(config)
return acc return acc
}, []) }, [])
} }
@ -382,9 +393,11 @@ export const getUserBindings = () => {
const { schema } = getSchemaForTable(TableNames.USERS) const { schema } = getSchemaForTable(TableNames.USERS)
const keys = Object.keys(schema).sort() const keys = Object.keys(schema).sort()
const safeUser = makePropSafe("user") const safeUser = makePropSafe("user")
keys.forEach(key => {
bindings = keys.reduce((acc, key) => {
const fieldSchema = schema[key] const fieldSchema = schema[key]
bindings.push({ if (fieldSchema.type !== "link") {
acc.push({
type: "context", type: "context",
runtimeBinding: `${safeUser}.${makePropSafe(key)}`, runtimeBinding: `${safeUser}.${makePropSafe(key)}`,
readableBinding: `Current User.${key}`, readableBinding: `Current User.${key}`,
@ -394,9 +407,11 @@ export const getUserBindings = () => {
providerId: "user", providerId: "user",
category: "Current User", category: "Current User",
icon: "User", icon: "User",
display: fieldSchema,
})
}) })
}
return acc
}, [])
return bindings return bindings
} }

View File

@ -60,14 +60,20 @@
$: staticVariables = datasource?.config?.staticVariables || {} $: staticVariables = datasource?.config?.staticVariables || {}
$: customRequestBindings = toBindingsArray(requestBindings, "Binding") $: customRequestBindings = toBindingsArray(
requestBindings,
"Binding",
"Bindings"
)
$: globalDynamicRequestBindings = toBindingsArray( $: globalDynamicRequestBindings = toBindingsArray(
globalDynamicBindings, globalDynamicBindings,
"Dynamic",
"Dynamic" "Dynamic"
) )
$: dataSourceStaticBindings = toBindingsArray( $: dataSourceStaticBindings = toBindingsArray(
staticVariables, staticVariables,
"Datasource.Static" "Datasource.Static",
"Datasource Static"
) )
$: mergedBindings = [ $: mergedBindings = [