Allow options picker to be used on text columns

This commit is contained in:
Rory Powell 2021-10-14 16:36:45 +01:00
parent c33689182a
commit 88cdc7c1bd
5 changed files with 16 additions and 6 deletions

View File

@ -75,6 +75,7 @@
{#if canRenderControl(setting)}
<PropertyControl
type={setting.type}
fieldTypes={setting.fieldTypes}
control={getComponentForSettingType(setting.type)}
label={setting.label}
key={setting.key}

View File

@ -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>

View File

@ -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"}

View File

@ -1950,6 +1950,7 @@
"settings": [
{
"type": "field/options",
"fieldTypes": ["field/options", "field/string"],
"label": "Field",
"key": "field"
},

View File

@ -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"
/>