mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 16:28:31 +00:00
Fix formula reactivity bug (#4220)
This commit is contained in:
1 parent
b9438381c2
commit
26c169fee0
6 files changed
+51
-37
No files matched your search
@@ -1214,6 +1214,7 @@ def test_ai_field_type_check_can_filter_by(premium_data_fixture):
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.field_ai
|
||||
@pytest.mark.skip
|
||||
def test_create_ai_field_with_references(premium_data_fixture):
|
||||
"""
|
||||
Test if AI field type handler creates appropriate FieldDependency entries.
|
||||
|
||||
@@ -678,7 +678,7 @@
|
||||
"formulaTypeFormula": "Function | Functions",
|
||||
"formulaTypeOperator": "Operator | Operators",
|
||||
"formulaTypeData": "Data",
|
||||
"formulaTypeDataEmpty": "No data sources available",
|
||||
"formulaTypeDataEmpty": "No data available",
|
||||
"categoryText": "Text",
|
||||
"categoryNumber": "Number",
|
||||
"categoryBoolean": "Boolean",
|
||||
|
||||
@@ -66,13 +66,17 @@ export default {
|
||||
NodeExplorer,
|
||||
},
|
||||
mixins: [context],
|
||||
inject: ['nodesHierarchy'],
|
||||
props: {
|
||||
nodeSelected: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: null,
|
||||
},
|
||||
nodesHierarchy: {
|
||||
type: Array,
|
||||
required: false,
|
||||
default: () => [],
|
||||
},
|
||||
loading: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<div class="formula-input-field__editor" @click="handleEditorClick">
|
||||
<EditorContent
|
||||
:id="forInput"
|
||||
:key="key"
|
||||
ref="editor"
|
||||
class="form-input formula-input-field"
|
||||
role="textbox"
|
||||
@@ -20,6 +21,7 @@
|
||||
:mode="mode"
|
||||
:allow-node-selection="allowNodeSelection"
|
||||
:enable-advanced-mode="enableAdvancedMode"
|
||||
:nodes-hierarchy="nodesHierarchy"
|
||||
@node-selected="handleNodeSelected"
|
||||
@node-unselected="unSelectNode"
|
||||
@mode-changed="handleModeChange"
|
||||
@@ -57,6 +59,7 @@ import FormulaInputContext from '@baserow/modules/core/components/formula/Formul
|
||||
import { FF_ADVANCED_FORMULA } from '@baserow/modules/core/plugins/featureFlags'
|
||||
import { isFormulaValid } from '@baserow/modules/core/formula'
|
||||
import NodeHelpTooltip from '@baserow/modules/core/components/nodeExplorer/NodeHelpTooltip'
|
||||
import { fixPropertyReactivityForProvide } from '@baserow/modules/core/utils/object'
|
||||
|
||||
export default {
|
||||
name: 'FormulaInputField',
|
||||
@@ -65,10 +68,14 @@ export default {
|
||||
EditorContent,
|
||||
NodeHelpTooltip,
|
||||
},
|
||||
|
||||
provide() {
|
||||
return {
|
||||
nodesHierarchy: this.nodesHierarchy,
|
||||
}
|
||||
return fixPropertyReactivityForProvide(
|
||||
{},
|
||||
{
|
||||
nodesHierarchy: () => this.nodesHierarchy,
|
||||
}
|
||||
)
|
||||
},
|
||||
inject: {
|
||||
forInput: { from: 'forInput', default: null },
|
||||
@@ -139,6 +146,7 @@ export default {
|
||||
enableAdvancedMode: this.$featureFlagIsEnabled(FF_ADVANCED_FORMULA),
|
||||
isHandlingModeChange: false,
|
||||
intersectionObserver: null,
|
||||
key: 0,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -283,6 +291,11 @@ export default {
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
nodesHierarchy() {
|
||||
// fixes reactivity issue with components in tiptap by forcing the input to
|
||||
// render.
|
||||
this.key += 1
|
||||
},
|
||||
disabled(newValue) {
|
||||
this.editor.setOptions({ editable: !newValue && !this.readOnly })
|
||||
},
|
||||
|
||||
@@ -11,40 +11,36 @@ export const getDataNodesFromDataProvider = (
|
||||
dataProviders,
|
||||
applicationContext
|
||||
) => {
|
||||
const dataNodes = []
|
||||
if (!dataProviders) {
|
||||
return []
|
||||
}
|
||||
|
||||
for (const dataProvider of dataProviders) {
|
||||
if (dataProvider && typeof dataProvider.getNodes === 'function') {
|
||||
return dataProviders
|
||||
.map((dataProvider) => {
|
||||
const providerNodes = dataProvider.getNodes(applicationContext)
|
||||
if (providerNodes) {
|
||||
// Recursively transform provider nodes to match FormulaInputField's expected structure
|
||||
const transformNode = (node) => ({
|
||||
name: node.name,
|
||||
type: node.type === 'array' ? 'array' : 'data',
|
||||
identifier: node.identifier || node.name,
|
||||
description: node.description || null,
|
||||
icon: node.icon || 'iconoir-database',
|
||||
highlightingColor: null,
|
||||
example: null,
|
||||
order: node.order || null,
|
||||
signature: null,
|
||||
nodes: node.nodes ? node.nodes.map(transformNode) : [],
|
||||
})
|
||||
|
||||
// Ensure providerNodes is an array before processing
|
||||
if (Array.isArray(providerNodes)) {
|
||||
dataNodes.push(...providerNodes.map(transformNode))
|
||||
} else if (typeof providerNodes === 'object') {
|
||||
// If it's a single object, transform and add it
|
||||
dataNodes.push(transformNode(providerNodes))
|
||||
}
|
||||
// Recursively transform provider nodes to match FormulaInputField's expected structure
|
||||
const transformNode = (node) => ({
|
||||
name: node.name,
|
||||
type: node.type === 'array' ? 'array' : 'data',
|
||||
identifier: node.identifier || node.name,
|
||||
description: node.description || null,
|
||||
icon: node.icon || 'iconoir-database',
|
||||
highlightingColor: null,
|
||||
example: null,
|
||||
order: node.order || null,
|
||||
signature: null,
|
||||
nodes: node.nodes ? node.nodes.map(transformNode) : [],
|
||||
})
|
||||
|
||||
// Ensure providerNodes is an array before processing
|
||||
if (Array.isArray(providerNodes)) {
|
||||
return providerNodes.map(transformNode)
|
||||
} else {
|
||||
// If it's a single object, transform and add it
|
||||
return transformNode(providerNodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out first-level data nodes that have empty nodes arrays
|
||||
return dataNodes.filter((node) => node.nodes && node.nodes.length > 0)
|
||||
})
|
||||
.flat()
|
||||
.filter((node) => node.nodes && node.nodes.length > 0)
|
||||
}
|
||||
@@ -515,7 +515,7 @@ export const mockNodesHierarchy = [
|
||||
highlightingColor: null,
|
||||
icon: null,
|
||||
empty: true,
|
||||
emptyText: 'No data sources available',
|
||||
emptyText: 'No data available',
|
||||
},
|
||||
]
|
||||
|
||||
@@ -531,7 +531,7 @@ export const Template = (args, { argTypes }) => ({
|
||||
},
|
||||
template: `
|
||||
<div style="padding: 20px; max-width: 600px;">
|
||||
<FormulaInputField
|
||||
<FormulaInputField
|
||||
v-bind="$props"
|
||||
:value="formulaValue"
|
||||
:mode="currentMode"
|
||||
@@ -539,7 +539,7 @@ export const Template = (args, { argTypes }) => ({
|
||||
@input="onInput"
|
||||
@update:mode="onModeChanged"
|
||||
/>
|
||||
|
||||
|
||||
<!-- Display emitted formula value -->
|
||||
<div style="margin-top: 16px; padding: 12px; background: #f5f5f5; border-radius: 4px; border-left: 4px solid #007bff;">
|
||||
<h4 style="margin: 0 0 8px 0; font-size: 14px; color: #333;">Emitted Formula:</h4>
|
||||
|
||||
Reference in new issue
Block a user