From 36b2e203b566134d32e80964ece21cfd161b7297 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Fri, 17 May 2024 20:40:59 +0000 Subject: [PATCH] refactor: show unsupported formula functions as disabled --- .../smartsheet/column/FormulaOptions.vue | 66 +++++++++++-------- packages/nc-gui/lang/en.json | 1 + packages/nocodb-sdk/src/lib/formulaHelpers.ts | 11 ++-- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue index dd541072a5..5a6e1db3da 100644 --- a/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue +++ b/packages/nc-gui/components/smartsheet/column/FormulaOptions.vue @@ -102,36 +102,47 @@ const sortOrder: Record = { const suggestionsList = computed(() => { const unsupportedFnList = sqlUi.value.getUnsupportedFnList() - return [ - ...availableFunctions - .filter((fn: string) => !unsupportedFnList.includes(fn)) - .map((fn: string) => ({ + return ( + [ + ...availableFunctions.map((fn: string) => ({ text: `${fn}()`, type: 'function', description: formulas[fn].description, syntax: formulas[fn].syntax, examples: formulas[fn].examples, docsUrl: formulas[fn].docsUrl, + unsupported: unsupportedFnList.includes(fn), })), - ...supportedColumns.value - .filter((c) => { - // skip system LTAR columns - if (c.uidt === UITypes.LinkToAnotherRecord && c.system) return false - // v1 logic? skip the current column - if (!column) return true - return column.value?.id !== c.id - }) - .map((c: any) => ({ - text: c.title, - type: 'column', - icon: getUIDTIcon(c.uidt), - uidt: c.uidt, + ...supportedColumns.value + .filter((c) => { + // skip system LTAR columns + if (c.uidt === UITypes.LinkToAnotherRecord && c.system) return false + // v1 logic? skip the current column + if (!column) return true + return column.value?.id !== c.id + }) + .map((c: any) => ({ + text: c.title, + type: 'column', + icon: getUIDTIcon(c.uidt), + uidt: c.uidt, + })), + ...availableBinOps.map((op: string) => ({ + text: op, + type: 'op', })), - ...availableBinOps.map((op: string) => ({ - text: op, - type: 'op', - })), - ] + ] + // move unsupported functions to the end + .sort((a: Record, b: Record) => { + if (a.unsupported && !b.unsupported) { + return 1 + } + if (!a.unsupported && b.unsupported) { + return -1 + } + return 0 + }) + ) }) // set default suggestion list @@ -214,6 +225,7 @@ function handleInput() { function selectText() { if (suggestion.value && selected.value > -1 && selected.value < suggestionsList.value.length) { if (selected.value < suggestedFormulas.value.length) { + if (suggestedFormulas.value[selected.value].unsupported) return appendText(suggestedFormulas.value[selected.value]) } else { appendText(variableList.value[selected.value + suggestedFormulas.value.length]) @@ -276,7 +288,7 @@ onMounted(() => {