Browse Source

Nc fix/3616 formula related bugs (#9277)

* fix: handle `@` char in field name while generating identifier token for monaco

* fix: invalid formula validation in UI
pull/9285/head
Pranav C 3 months ago committed by GitHub
parent
commit
6ee2aba938
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      packages/nc-gui/components/monaco/formula.ts
  2. 3
      packages/nc-gui/components/smartsheet/column/FormulaInputHelper.vue
  3. 18
      packages/nocodb-sdk/src/lib/formulaHelpers.ts

4
packages/nc-gui/components/monaco/formula.ts

@ -62,7 +62,7 @@ const generateLanguageDefinition = (identifiers: string[]) => {
],
[/\d+/, 'number'],
[/[-+/*=<>!]+/, 'operator'],
[/[{}()\[\]]/, '@brackets'],
[/[{}()]/, '@brackets'],
[/[ \t\r\n]+/, 'white'],
],
@ -86,12 +86,10 @@ const generateLanguageDefinition = (identifiers: string[]) => {
const languageConfiguration: languages.LanguageConfiguration = {
brackets: [
['{', '}'],
['[', ']'],
['(', ')'],
],
autoClosingPairs: [
{ open: '{', close: '}' },
{ open: '[', close: ']' },
{ open: '(', close: ')' },
{ open: '"', close: '"' },
{ open: "'", close: "'" },

3
packages/nc-gui/components/smartsheet/column/FormulaInputHelper.vue

@ -170,7 +170,8 @@ onMounted(async () => {
languages.setMonarchTokensProvider(
formulaLanguage.name,
formulaLanguage.generateLanguageDefinition(supportedColumns.value.map((c) => c.title!)),
// replace @ with \x01 to avoid conflict with monaco's tokenizer
formulaLanguage.generateLanguageDefinition(supportedColumns.value.map((c) => c.title!.replace(/@/g, '\x01'))),
)
languages.setLanguageConfiguration(formulaLanguage.name, formulaLanguage.languageConfiguration)

18
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -1892,6 +1892,24 @@ export async function validateFormulaAndExtractTreeWithType({
} else {
res.dataType = FormulaDataTypes.NUMERIC;
}
} else if (parsedTree.type === JSEPNode.MEMBER_EXP) {
throw new FormulaError(
FormulaErrorType.NOT_SUPPORTED,
{},
'Bracket notation is not supported'
);
} else if (parsedTree.type === JSEPNode.ARRAY_EXP) {
throw new FormulaError(
FormulaErrorType.NOT_SUPPORTED,
{},
'Array is not supported'
);
} else if (parsedTree.type === JSEPNode.COMPOUND) {
throw new FormulaError(
FormulaErrorType.NOT_SUPPORTED,
{},
'Compound statement is not supported'
);
}
return res;

Loading…
Cancel
Save