|
|
@ -2,19 +2,24 @@ |
|
|
|
import jsep from 'jsep' |
|
|
|
import jsep from 'jsep' |
|
|
|
import { UITypes, jsepCurlyHook } from 'nocodb-sdk' |
|
|
|
import { UITypes, jsepCurlyHook } from 'nocodb-sdk' |
|
|
|
import { useColumnCreateStoreOrThrow, useDebounceFn } from '#imports' |
|
|
|
import { useColumnCreateStoreOrThrow, useDebounceFn } from '#imports' |
|
|
|
import { NcAutocompleteTree, formulaList, formulaTypes, formulas, getWordUntilCaret, insertAtCursor } from '@/utils' |
|
|
|
import { MetaInj } from '~/context' |
|
|
|
|
|
|
|
import { NcAutocompleteTree, formulaList, formulaTypes, formulas, getUIDTIcon, getWordUntilCaret, insertAtCursor } from '@/utils' |
|
|
|
|
|
|
|
|
|
|
|
const { formState, validateInfos, setAdditionalValidations, sqlUi, onDataTypeChange, onAlter, column } = |
|
|
|
const { formState, validateInfos, setAdditionalValidations, sqlUi, onDataTypeChange, onAlter, column } = |
|
|
|
useColumnCreateStoreOrThrow() |
|
|
|
useColumnCreateStoreOrThrow() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const meta = inject(MetaInj) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const columns = computed(() => meta?.value?.columns || []) |
|
|
|
|
|
|
|
|
|
|
|
const validators = { |
|
|
|
const validators = { |
|
|
|
'colOptions.formula': [ |
|
|
|
'colOptions.formula_raw': [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
validator: (_: any, formual: any) => { |
|
|
|
validator: (_: any, formula: any) => { |
|
|
|
return new Promise<void>((resolve, reject) => { |
|
|
|
return new Promise<void>((resolve, reject) => { |
|
|
|
// if (!parseAndValidateFormula(formual)) { |
|
|
|
if (!parseAndValidateFormula(formula)) { |
|
|
|
// return reject(new Error('Invalid formual')) |
|
|
|
return reject(new Error('Invalid formula')) |
|
|
|
// } |
|
|
|
} |
|
|
|
resolve() |
|
|
|
resolve() |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
@ -51,34 +56,33 @@ const sortOrder: Record<string, number> = { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const suggestionsList = computed(() => { |
|
|
|
const suggestionsList = computed(() => { |
|
|
|
return [] |
|
|
|
const unsupportedFnList = sqlUi.value.getUnsupportedFnList() |
|
|
|
// const unsupportedFnList = sqlUi.getUnsupportedFnList(); |
|
|
|
return [ |
|
|
|
// return [ |
|
|
|
...availableFunctions |
|
|
|
// ...availableFunctions |
|
|
|
.filter((fn) => !unsupportedFnList.includes(fn)) |
|
|
|
// .filter(fn => !unsupportedFnList.includes(fn)) |
|
|
|
.map((fn) => ({ |
|
|
|
// .map(fn => ({ |
|
|
|
text: `${fn}()`, |
|
|
|
// text: fn + '()', |
|
|
|
type: 'function', |
|
|
|
// type: 'function', |
|
|
|
description: formulas[fn].description, |
|
|
|
// description: formulas[fn].description, |
|
|
|
syntax: formulas[fn].syntax, |
|
|
|
// syntax: formulas[fn].syntax, |
|
|
|
examples: formulas[fn].examples, |
|
|
|
// examples: formulas[fn].examples, |
|
|
|
})), |
|
|
|
// })), |
|
|
|
...columns.value |
|
|
|
// ...meta.columns |
|
|
|
.filter( |
|
|
|
// .filter( |
|
|
|
(c: Record<string, any>) => |
|
|
|
// (c: Record<string, any>) => |
|
|
|
!column || (column.id !== c.id && !(c.uidt === UITypes.LinkToAnotherRecord && c.system === 1)), |
|
|
|
// !column || (column.id !== c.id && !(c.uidt === UITypes.LinkToAnotherRecord && c.system === 1)) |
|
|
|
) |
|
|
|
// ) |
|
|
|
.map((c: any) => ({ |
|
|
|
// .map(c => ({ |
|
|
|
text: c.title, |
|
|
|
// text: c.title, |
|
|
|
type: 'column', |
|
|
|
// type: 'column', |
|
|
|
icon: getUIDTIcon(c.uidt), |
|
|
|
// icon: getUIDTIcon(c.uidt), |
|
|
|
c, |
|
|
|
// c, |
|
|
|
})), |
|
|
|
// })), |
|
|
|
...availableBinOps.map((op: string) => ({ |
|
|
|
// ...availableBinOps.map((op: string) => ({ |
|
|
|
text: op, |
|
|
|
// text: op, |
|
|
|
type: 'op', |
|
|
|
// type: 'op', |
|
|
|
})), |
|
|
|
// })), |
|
|
|
] |
|
|
|
// ]; |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const acTree = computed(() => { |
|
|
|
const acTree = computed(() => { |
|
|
@ -384,8 +388,8 @@ formState.value.colOptions = { |
|
|
|
|
|
|
|
|
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<div class="formula-wrapper"> |
|
|
|
<div class="formula-wrapper"> |
|
|
|
{{ formState }} |
|
|
|
{{ formState.colOptions }} |
|
|
|
<a-form-item v-bind="validateInfos['meta.formula']" label="Formula"> |
|
|
|
<a-form-item v-bind="validateInfos['colOptions.formula_raw']" label="Formula"> |
|
|
|
<a-input ref="formulaRef" v-model:value="formState.colOptions.formula_raw" @keydown.down.prevent="suggestionListDown" /> |
|
|
|
<a-input ref="formulaRef" v-model:value="formState.colOptions.formula_raw" @keydown.down.prevent="suggestionListDown" /> |
|
|
|
</a-form-item> |
|
|
|
</a-form-item> |
|
|
|
<!-- <a-text-field --> |
|
|
|
<!-- <a-text-field --> |
|
|
@ -407,7 +411,7 @@ formState.value.colOptions = { |
|
|
|
Hint: Use {} to reference columns, e.g: {column_name}. For more, please check out |
|
|
|
Hint: Use {} to reference columns, e.g: {column_name}. For more, please check out |
|
|
|
<a href="https://docs.nocodb.com/setup-and-usages/formulas#available-formula-features" target="_blank">Formulas</a>. |
|
|
|
<a href="https://docs.nocodb.com/setup-and-usages/formulas#available-formula-features" target="_blank">Formulas</a>. |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<v-card v-if="suggestion && suggestion.length" class="formula-suggestion"> |
|
|
|
<a-card v-if="suggestion && suggestion.length" class="formula-suggestion"> |
|
|
|
<v-card-text>Suggestions</v-card-text> |
|
|
|
<v-card-text>Suggestions</v-card-text> |
|
|
|
<v-divider /> |
|
|
|
<v-divider /> |
|
|
|
<v-list ref="sugList" dense max-height="50vh" style="overflow: auto"> |
|
|
|
<v-list ref="sugList" dense max-height="50vh" style="overflow: auto"> |
|
|
@ -477,6 +481,6 @@ formState.value.colOptions = { |
|
|
|
</v-list-item> |
|
|
|
</v-list-item> |
|
|
|
</v-list-item-group> |
|
|
|
</v-list-item-group> |
|
|
|
</v-list> |
|
|
|
</v-list> |
|
|
|
</v-card> |
|
|
|
</a-card> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|