Extract binding utils
This commit is contained in:
parent
b8d38159d0
commit
5f3aaf458b
|
@ -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",
|
||||||
|
|
|
@ -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} }}`,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue