Browse Source

Merge pull request #9662 from nocodb/nc-fix/9650-formula-bug

fix: Resolve GUI hang issues in formula creation interface
pull/9665/head
Pranav C 1 month ago committed by GitHub
parent
commit
402bd3db2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 35
      packages/nc-gui/components/smartsheet/column/FormulaOptions.vue

35
packages/nc-gui/components/smartsheet/column/FormulaOptions.vue

@ -85,7 +85,19 @@ if ((column.value?.colOptions as any)?.formula_raw) {
const source = computed(() => activeBase.value?.sources?.find((s) => s.id === meta.value?.source_id)) const source = computed(() => activeBase.value?.sources?.find((s) => s.id === meta.value?.source_id))
const parsedTree = computedAsync(async () => { const parsedTree = ref<any>({
dataType: FormulaDataTypes.UNKNOWN,
})
// Initialize a counter to track watcher invocations
let watcherCounter = 0
// Define the debounced async validation function
const debouncedValidate = useDebounceFn(async () => {
// Increment the counter for each invocation
watcherCounter += 1
const currentCounter = watcherCounter
try { try {
const parsed = await validateFormulaAndExtractTreeWithType({ const parsed = await validateFormulaAndExtractTreeWithType({
formula: vModel.value.formula || vModel.value.formula_raw, formula: vModel.value.formula || vModel.value.formula_raw,
@ -94,13 +106,28 @@ const parsedTree = computedAsync(async () => {
clientOrSqlUi: source.value?.type as any, clientOrSqlUi: source.value?.type as any,
getMeta: async (modelId) => await getMeta(modelId), getMeta: async (modelId) => await getMeta(modelId),
}) })
return parsed
// Update parsedTree only if this is the latest invocation
if (currentCounter === watcherCounter) {
parsedTree.value = parsed
}
} catch (e) { } catch (e) {
return { // Update parsedTree only if this is the latest invocation
if (currentCounter === watcherCounter) {
parsedTree.value = {
dataType: FormulaDataTypes.UNKNOWN, dataType: FormulaDataTypes.UNKNOWN,
} }
} }
}) }
}, 300)
// Watch the formula inputs and call the debounced function
watch(
() => vModel.value.formula || vModel.value.formula_raw,
() => {
debouncedValidate()
},
)
// set additional validations // set additional validations
setAdditionalValidations({ setAdditionalValidations({

Loading…
Cancel
Save