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 2853ae849e
commit 346f1d652b
5 changed files with 16 additions and 6 deletions

View File

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

View File

@ -10,6 +10,7 @@
export let componentInstance export let componentInstance
export let value export let value
export let type export let type
export let fieldTypes
$: form = findClosestMatchingComponent( $: form = findClosestMatchingComponent(
$currentAsset.props, $currentAsset.props,
@ -18,14 +19,19 @@
) )
$: datasource = getDatasourceForProvider($currentAsset, form) $: datasource = getDatasourceForProvider($currentAsset, form)
$: schema = getSchemaForDatasource($currentAsset, datasource, true).schema $: 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 ?? {}) let entries = Object.entries(schema ?? {})
if (fieldType) {
fieldType = fieldType.split("/")[1] // fallback to using only field/options fields
entries = entries.filter(entry => entry[1].type === fieldType) 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]) return entries.map(entry => entry[0])
} }
</script> </script>

View File

@ -13,6 +13,7 @@
export let control = null export let control = null
export let key = "" export let key = ""
export let type = "" export let type = ""
export let fieldTypes = []
export let value = null export let value = null
export let props = {} export let props = {}
export let onChange = () => {} export let onChange = () => {}
@ -82,6 +83,7 @@
name={key} name={key}
text={label} text={label}
{type} {type}
{fieldTypes}
{...props} {...props}
/> />
{#if bindable && !key.startsWith("_") && type === "text"} {#if bindable && !key.startsWith("_") && type === "text"}

View File

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

View File

@ -67,7 +67,7 @@
<Placeholder <Placeholder
text="Add the Field setting to start using your component" 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 <Placeholder
text="This Field setting is the wrong data type for this component" text="This Field setting is the wrong data type for this component"
/> />