Extract binding utils

This commit is contained in:
Adria Navarro 2025-01-24 14:50:06 +01:00
parent b8d38159d0
commit 5f3aaf458b
3 changed files with 32 additions and 22 deletions

View File

@ -31,7 +31,11 @@
import IntegrationQueryEditor from "@/components/integration/index.svelte" import IntegrationQueryEditor from "@/components/integration/index.svelte"
import { makePropSafe as safe } from "@budibase/string-templates" import { makePropSafe as safe } from "@budibase/string-templates"
import { findAllComponents } from "@/helpers/components" import { findAllComponents } from "@/helpers/components"
import { extractFields, extractRelationships } from "@/helpers/bindings" import {
extractFields,
extractJSONArrayFields,
extractRelationships,
} from "@/helpers/bindings"
import ClientBindingPanel from "@/components/common/bindings/ClientBindingPanel.svelte" import ClientBindingPanel from "@/components/common/bindings/ClientBindingPanel.svelte"
import DataSourceCategory from "@/components/design/settings/controls/DataSourceSelect/DataSourceCategory.svelte" import DataSourceCategory from "@/components/design/settings/controls/DataSourceSelect/DataSourceCategory.svelte"
import { API } from "@/api" import { API } from "@/api"
@ -84,27 +88,7 @@
})) }))
$: links = extractRelationships(bindings) $: links = extractRelationships(bindings)
$: fields = extractFields(bindings) $: fields = extractFields(bindings)
$: jsonArrays = bindings $: jsonArrays = extractJSONArrayFields(bindings)
.filter(
x =>
x.fieldSchema?.type === "jsonarray" ||
(x.fieldSchema?.type === "json" && x.fieldSchema?.subtype === "array")
)
.map(binding => {
const { providerId, readableBinding, runtimeBinding, tableId } = binding
const { name, type, prefixKeys, subtype } = binding.fieldSchema
return {
providerId,
label: readableBinding,
fieldName: name,
fieldType: type,
tableId,
prefixKeys,
type: type === "jsonarray" ? "jsonarray" : "queryarray",
subtype,
value: `{{ literal ${runtimeBinding} }}`,
}
})
$: custom = { $: custom = {
type: "custom", type: "custom",
label: "JSON / CSV", label: "JSON / CSV",

View File

@ -48,3 +48,27 @@ export function extractFields(bindings: UIBinding[]) {
} }
}) })
} }
export function extractJSONArrayFields(bindings: UIBinding[]) {
return bindings
.filter(
x =>
x.fieldSchema?.type === "jsonarray" ||
(x.fieldSchema?.type === "json" && x.fieldSchema?.subtype === "array")
)
.map(binding => {
const { providerId, readableBinding, runtimeBinding, tableId } = binding
const { name, type, prefixKeys, subtype } = binding.fieldSchema!
return {
providerId,
label: readableBinding,
fieldName: name,
fieldType: type,
tableId,
prefixKeys,
type: type === "jsonarray" ? "jsonarray" : "queryarray",
subtype,
value: `{{ literal ${runtimeBinding} }}`,
}
})
}

View File

@ -31,6 +31,8 @@ export interface UIBinding {
name: string name: string
tableId: string tableId: string
type: string type: string
subtype?: string
prefixKeys?: string
} }
component?: string component?: string
providerId: string providerId: string