Allow options picker to be used on text columns
This commit is contained in:
parent
2853ae849e
commit
346f1d652b
|
@ -75,6 +75,7 @@
|
|||
{#if canRenderControl(setting)}
|
||||
<PropertyControl
|
||||
type={setting.type}
|
||||
fieldTypes={setting.fieldTypes}
|
||||
control={getComponentForSettingType(setting.type)}
|
||||
label={setting.label}
|
||||
key={setting.key}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
export let componentInstance
|
||||
export let value
|
||||
export let type
|
||||
export let fieldTypes
|
||||
|
||||
$: form = findClosestMatchingComponent(
|
||||
$currentAsset.props,
|
||||
|
@ -18,14 +19,19 @@
|
|||
)
|
||||
$: datasource = getDatasourceForProvider($currentAsset, form)
|
||||
$: schema = getSchemaForDatasource($currentAsset, datasource, true).schema
|
||||
$: options = getOptions(schema, type)
|
||||
$: options = getOptions(schema, type, fieldTypes)
|
||||
|
||||
const getOptions = (schema, fieldType) => {
|
||||
const getOptions = (schema, type, fieldTypes) => {
|
||||
let entries = Object.entries(schema ?? {})
|
||||
if (fieldType) {
|
||||
fieldType = fieldType.split("/")[1]
|
||||
entries = entries.filter(entry => entry[1].type === fieldType)
|
||||
|
||||
// fallback to using only field/options fields
|
||||
if (!fieldTypes) {
|
||||
fieldTypes = [type]
|
||||
}
|
||||
|
||||
const types = fieldTypes.map(fieldType => fieldType.split("/")[1])
|
||||
entries = entries.filter(entry => types.includes(entry[1].type))
|
||||
|
||||
return entries.map(entry => entry[0])
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
export let control = null
|
||||
export let key = ""
|
||||
export let type = ""
|
||||
export let fieldTypes = []
|
||||
export let value = null
|
||||
export let props = {}
|
||||
export let onChange = () => {}
|
||||
|
@ -82,6 +83,7 @@
|
|||
name={key}
|
||||
text={label}
|
||||
{type}
|
||||
{fieldTypes}
|
||||
{...props}
|
||||
/>
|
||||
{#if bindable && !key.startsWith("_") && type === "text"}
|
||||
|
|
|
@ -1950,6 +1950,7 @@
|
|||
"settings": [
|
||||
{
|
||||
"type": "field/options",
|
||||
"fieldTypes": ["field/options", "field/string"],
|
||||
"label": "Field",
|
||||
"key": "field"
|
||||
},
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
<Placeholder
|
||||
text="Add the Field setting to start using your component"
|
||||
/>
|
||||
{:else if fieldSchema?.type && fieldSchema?.type !== type}
|
||||
{:else if fieldSchema?.type && fieldSchema?.type !== type && type !== "options"}
|
||||
<Placeholder
|
||||
text="This Field setting is the wrong data type for this component"
|
||||
/>
|
||||
|
|
Loading…
Reference in New Issue