Files
baserow/web-frontend/modules/automation/components/AutomationBuilderFormulaInput.vue
Peter Evans a0e3591f9f feat: show the values of previous steps in the automation data explorer (#6718)
* feat: show the values of previous steps in the automation data explorer

* fix: hide placeholder sample values and hint untested current node in the data explorer

* fix: shorten the untested step hint and show it inline in the data explorer

* fix: keep the untested step hint visible next to a long node name
2026-11-17 09:18:25 +00:00

119 lines
3.2 KiB
Vue

<template>
<FormulaInputField
v-bind="$attrs"
required
:value="formulaStr"
:nodes-hierarchy="nodesHierarchy"
context-position="left"
:mode="localMode"
:validation-context="{ dataProviderRegistry: dataProviders }"
@update:mode="updateMode"
@input="updatedFormulaStr"
>
<template v-if="$slots['raw-input']" #raw-input="slotProps">
<slot name="raw-input" v-bind="slotProps"></slot>
</template>
</FormulaInputField>
</template>
<script setup>
import FormulaInputField from '@baserow/modules/core/components/formula/FormulaInputField'
import { buildFormulaFunctionNodes } from '@baserow/modules/core/formula'
import {
getDataNodesFromDataProvider,
getSampleValueFromDataProviders,
} from '@baserow/modules/core/utils/dataProviders'
const props = defineProps({
modelValue: { type: [Object, String], required: false, default: () => ({}) },
dataProvidersAllowed: { type: Array, required: false, default: () => [] },
})
const applicationContext = inject('applicationContext')
const emit = defineEmits(['input'])
// Local mode state
const localMode = ref(props.modelValue?.mode || 'simple')
// Watch for external changes to the mode
watch(
() => props.modelValue?.mode,
(newMode) => {
if (newMode !== undefined && newMode !== localMode.value) {
localMode.value = newMode
}
}
)
const app = useNuxtApp()
const dataProviders = computed(() => {
return props.dataProvidersAllowed.map((dataProviderName) =>
app.$registry.get('automationDataProvider', dataProviderName)
)
})
// Shown by the explorer next to each data node: the value from the last test
// of the node it belongs to.
const getDataNodeValue = (path) =>
getSampleValueFromDataProviders(dataProviders.value, applicationContext, path)
const nodesHierarchy = computed(() => {
const hierarchy = []
const filteredDataNodes = getDataNodesFromDataProvider(
dataProviders.value,
applicationContext
)
hierarchy.push({
name: app.$i18n.t('runtimeFormulaTypes.formulaTypeData'),
type: 'data',
icon: 'iconoir-database',
nodes: filteredDataNodes,
getValue: getDataNodeValue,
empty: filteredDataNodes.length === 0,
emptyText: app.$i18n.t('runtimeFormulaTypes.formulaTypeDataEmpty'),
})
// Add functions and operators from the registry
const formulaNodes = buildFormulaFunctionNodes(app)
hierarchy.push(...formulaNodes)
return hierarchy
})
/**
* Extract the formula string from the value object, the FormulaInputField
* component only needs the formula string itself.
* @returns {String} The formula string.
*/
const formulaStr = computed(() => {
// Legacy stored values can contain `formula: null`; `FormulaInputField`
// expects a string.
return props.modelValue?.formula || ''
})
/**
* When `FormulaInputField` emits a new formula string, we need to emit the
* entire value object with the updated formula string.
* @param {String} newFormulaStr The new formula string.
*/
const updatedFormulaStr = (newFormulaStr) => {
emit('input', {
...props.modelValue,
formula: newFormulaStr,
mode: localMode.value,
})
}
/**
* When the mode changes, update the local mode value only
* @param {String} newMode The new mode value
*/
const updateMode = (newMode) => {
localMode.value = newMode
}
</script>