diff --git a/packages/nc-gui-v2/components/smartsheet-column/FormulaOptions.vue b/packages/nc-gui-v2/components/smartsheet-column/FormulaOptions.vue index 271e49d2d9..0acfc5732b 100644 --- a/packages/nc-gui-v2/components/smartsheet-column/FormulaOptions.vue +++ b/packages/nc-gui-v2/components/smartsheet-column/FormulaOptions.vue @@ -17,7 +17,6 @@ import { validateDateWithUnknownFormat, } from '@/utils' import MdiFunctionIcon from '~icons/mdi/function' -import MdiColumnIcon from '~icons/mdi/view-column-outline' import MdiOperatorIcon from '~icons/mdi/calculator' enum JSEPNode { @@ -40,7 +39,7 @@ const meta = inject(MetaInj) const columns = computed(() => meta?.value?.columns || []) const validators = { - 'colOptions.formula_raw': [ + formula_raw: [ { validator: (_: any, formula: any) => { return new Promise((resolve, reject) => { @@ -55,8 +54,6 @@ const validators = { ], } -const formula = ref() - const formulaSuggestionDrawer = ref(true) const availableFunctions = formulaList @@ -354,7 +351,7 @@ function validateAgainstType(parsedTree: any, expectedType: string, func: any, t return } if (col.uidt === UITypes.Formula) { - const foundType = getRootDataType(jsep(col?.colOptions?.formula_raw)) + const foundType = getRootDataType(jsep(col?.formula_raw)) if (foundType === 'N/A') { typeErrors.add(`Not supported to reference column ${col.title}`) } else if (expectedType !== foundType) { @@ -442,7 +439,7 @@ function getRootDataType(parsedTree: any): any { } else if (parsedTree.type === JSEPNode.IDENTIFIER) { const col = columns.value.find((c) => c.title === parsedTree.name) as Record if (col?.uidt === UITypes.Formula) { - return getRootDataType(jsep(col?.colOptions?.formula_raw)) + return getRootDataType(jsep(col?.formula_raw)) } else { switch (col?.uidt) { // string @@ -515,11 +512,11 @@ function appendText(item: Record) { const len = wordToComplete.value?.length || 0 if (item.type === 'function') { - formState.value.colOptions.formula_raw = insertAtCursor(formulaRef.value.$el, text, len, 1) + formState.value.formula_raw = insertAtCursor(formulaRef.value.$el, text, len, 1) } else if (item.type === 'column') { - formState.value.colOptions.formula_raw = insertAtCursor(formulaRef.value.$el, `{${text}}`, len + +!isCurlyBracketBalanced()) + formState.value.formula_raw = insertAtCursor(formulaRef.value.$el, `{${text}}`, len + +!isCurlyBracketBalanced()) } else { - formState.value.colOptions.formula_raw = insertAtCursor(formulaRef.value.$el, text, len) + formState.value.formula_raw = insertAtCursor(formulaRef.value.$el, text, len) } autocomplete.value = false if (item.type === 'function' || item.type === 'op') { @@ -597,11 +594,7 @@ function getFormulaTypeName(type: string) { } // set default value -formState.value.colOptions = { - formula: '', - formula_raw: '', - ...column?.colOptions, -} +formState.value.formula_raw = (column?.colOptions as Record)?.formula_raw || '' // set additional validations setAdditionalValidations({ @@ -619,10 +612,10 @@ onMounted(() => {