Files
baserow/web-frontend/modules/dashboard/components/widget/WidgetOptionsInput.vue
Jérémie Pardouandpeter_baserow 4df2f3dcee feat(dashboard): add choice selector and field option picker (#6915)
* feat(dashboard): add choice selector and field option picker

* refactor(dashboard): import raw option paths separately

* chore(dashboard): remove redundant choice selector changelog

* fix(dashboard): open explorer when switching to formula mode

* fix: show the formula again when a reused formula input leaves raw mode

---------

Co-authored-by: peter_baserow <peter@baserow.io>
2026-11-30 16:27:43 +01:00

65 lines
2.0 KiB
Vue

<template>
<DashboardFormulaInput
:model-value="modelValue"
:data-providers-allowed="['table_context']"
allow-node-selection="array"
allow-raw-values
:raw-value-to-formula="pathToFormula"
@input="$emit('input', $event)"
>
<template #raw-input="{ value, disabled, readOnly, input }">
<Dropdown
:value="value"
:disabled="disabled || readOnly"
:placeholder="$t('textFilterWidget.chooseOptionsField')"
show-search
@input="input"
>
<DropdownItem
v-for="field in fields"
:key="field.path"
:name="field.name"
:value="field.path"
/>
</Dropdown>
</template>
</DashboardFormulaInput>
</template>
<script setup>
import DashboardFormulaInput from '@baserow/modules/dashboard/components/DashboardFormulaInput'
import { toFormulaStringLiteral } from '@baserow/modules/core/formula'
const props = defineProps({
modelValue: { type: Object, default: () => ({}) },
})
defineEmits(['input'])
const app = useNuxtApp()
const context = inject('dashboardFormulaContext', ref({ storePrefix: '' }))
const fields = computed(() => {
const provider = app.$registry.get('dashboardDataProvider', 'table_context')
const schema = provider.getDataSchema(context.value)
return Object.entries(schema.properties || {}).flatMap(([tableId, table]) =>
Object.entries(table.properties || {})
.filter(
([, field]) =>
field.type === 'array' &&
field.items?.properties?.value?.type === 'string'
)
.map(([fieldId, field]) => ({
path: `${provider.type}.${tableId}.${fieldId}`,
name: `${table.title} / ${field.title}`,
}))
)
})
const modelValue = computed(() =>
props.modelValue.mode || props.modelValue.formula
? props.modelValue
: { ...props.modelValue, mode: 'raw' }
)
const pathToFormula = (path) =>
path.startsWith('table_context.')
? `get(${toFormulaStringLiteral(path)})`
: toFormulaStringLiteral(path)
</script>