Browse Source

refactor: add formula description

pull/7019/head
Pranav C 1 year ago
parent
commit
2d1837f200
  1. 54
      packages/nc-gui/utils/formulaUtils.ts
  2. 2
      tests/playwright/tests/db/columns/columnFormula.spec.ts

54
packages/nc-gui/utils/formulaUtils.ts

@ -448,7 +448,7 @@ const formulas: Record<string, any> = {
rqd: 2, rqd: 2,
}, },
}, },
description: 'Returns whether the input text matches a regular expression.', description: 'Returns 1 if the input text matches a regular expression or 0 if it does not.',
syntax: 'REGEX_MATCH(string, regex)', syntax: 'REGEX_MATCH(string, regex)',
examples: ['REGEX_MATCH({title}, "abc.*")'], examples: ['REGEX_MATCH({title}, "abc.*")'],
}, },
@ -460,7 +460,7 @@ const formulas: Record<string, any> = {
rqd: 2, rqd: 2,
}, },
}, },
description: 'Returns the first substring that matches a regular expression.', description: 'Returns the first match of a regular expression in a string.',
syntax: 'REGEX_MATCH(string, regex)', syntax: 'REGEX_MATCH(string, regex)',
examples: ['REGEX_EXTRACT({title}, "abc.*")'], examples: ['REGEX_EXTRACT({title}, "abc.*")'],
}, },
@ -471,7 +471,7 @@ const formulas: Record<string, any> = {
rqd: 3, rqd: 3,
}, },
}, },
description: 'Substitutes all matching substrings with a replacement string value.', description: 'Replaces all matches of a regular expression in a string with a replacement string',
syntax: 'REGEX_MATCH(string, regex, replacement)', syntax: 'REGEX_MATCH(string, regex, replacement)',
examples: ['REGEX_EXTRACT({title}, "abc.*", "abcd")'], examples: ['REGEX_EXTRACT({title}, "abc.*", "abcd")'],
}, },
@ -482,7 +482,7 @@ const formulas: Record<string, any> = {
rqd: 0, rqd: 0,
}, },
}, },
description: 'Returns a blank value.', description: 'Returns a blank value(null)',
syntax: 'BLANK()', syntax: 'BLANK()',
examples: ['BLANK()'], examples: ['BLANK()'],
}, },
@ -493,7 +493,7 @@ const formulas: Record<string, any> = {
min: 1, min: 1,
}, },
}, },
description: 'Returns true if an odd number of arguments are true.', description: 'Returns true if an odd number of arguments are true, and false otherwise.',
syntax: 'XOR(expression, [exp2, ...])', syntax: 'XOR(expression, [exp2, ...])',
examples: ['XOR(TRUE(), FALSE(), TRUE())'], examples: ['XOR(TRUE(), FALSE(), TRUE())'],
}, },
@ -504,7 +504,7 @@ const formulas: Record<string, any> = {
rqd: 1, rqd: 1,
}, },
}, },
description: 'Returns the smallest even integer that is greater than or equal to the specified value.', description: 'Returns the nearest even integer that is greater than or equal to the specified value',
syntax: 'EVEN(value)', syntax: 'EVEN(value)',
examples: ['EVEN({column})'], examples: ['EVEN({column})'],
}, },
@ -515,7 +515,7 @@ const formulas: Record<string, any> = {
rqd: 1, rqd: 1,
}, },
}, },
description: 'Rounds positive value up the the nearest odd number and negative value down to the nearest odd number.', description: 'Returns the nearest odd integer that is greater than or equal to the specified value',
syntax: 'ODD(value)', syntax: 'ODD(value)',
examples: ['ODD({column})'], examples: ['ODD({column})'],
}, },
@ -525,7 +525,7 @@ const formulas: Record<string, any> = {
rqd: 0, rqd: 0,
}, },
}, },
description: 'Returns ID of the current record.', description: 'Returns the record id of the current record',
syntax: 'RECORD_ID()', syntax: 'RECORD_ID()',
examples: ['RECORD_ID()'], examples: ['RECORD_ID()'],
}, },
@ -535,9 +535,9 @@ const formulas: Record<string, any> = {
min: 1, min: 1,
}, },
}, },
description: '', description: 'Counts the number of non-empty arguments',
syntax: 'COUNTA()', syntax: 'COUNTA(value1, [value2, ...])',
examples: ['COUNTA()'], examples: ['COUNTA({field1}, {field2})'],
}, },
COUNT: { COUNT: {
validation: { validation: {
@ -545,9 +545,9 @@ const formulas: Record<string, any> = {
min: 1, min: 1,
}, },
}, },
description: '', description: 'Count the number of arguments that are numbers',
syntax: 'COUNT()', syntax: 'COUNT(value1, [value2, ...])',
examples: ['COUNT()'], examples: ['COUNT({field1}, {field2})'],
}, },
COUNTALL: { COUNTALL: {
validation: { validation: {
@ -555,9 +555,9 @@ const formulas: Record<string, any> = {
min: 1, min: 1,
}, },
}, },
description: '', description: 'Counts the number of arguments',
syntax: 'COUNTALL()', syntax: 'COUNTALL(value1, [value2, ...])',
examples: ['COUNTALL()'], examples: ['COUNTALL({field1}, {field2})'],
}, },
ROUNDDOWN: { ROUNDDOWN: {
type: formulaTypes.NUMERIC, type: formulaTypes.NUMERIC,
@ -567,9 +567,10 @@ const formulas: Record<string, any> = {
max: 2, max: 2,
}, },
}, },
description: '', description:
syntax: 'ROUNDDOWN()', 'Round down the value after the decimal point to the number of decimal places given by "precision"(default is 0)',
examples: ['ROUNDDOWN()'], syntax: 'ROUNDDOWN(value, [precision])',
examples: ['ROUNDDOWN({field1})', 'ROUNDDOWN({field1}, 2)'],
}, },
ROUNDUP: { ROUNDUP: {
type: formulaTypes.NUMERIC, type: formulaTypes.NUMERIC,
@ -579,9 +580,9 @@ const formulas: Record<string, any> = {
max: 2, max: 2,
}, },
}, },
description: '', description: 'Round up the value after the decimal point to the number of decimal places given by "precision"(default is 0)',
syntax: 'ROUNDUP()', syntax: 'ROUNDUP(value, [precision])',
examples: ['ROUNDUP()'], examples: ['ROUNDUP({field1})', 'ROUNDUP({field1}, 2)'],
}, },
VALUE: { VALUE: {
validation: { validation: {
@ -589,9 +590,10 @@ const formulas: Record<string, any> = {
rqd: 1, rqd: 1,
}, },
}, },
description: '', description:
syntax: 'VALUE()', 'Extract the numeric value from a string, if `%` or `-` is present, it will handle it accordingly and return the numeric value',
examples: ['VALUE()'], syntax: 'VALUE(value)',
examples: ['VALUE({field})', 'VALUE("abc10000%")', 'VALUE("$10000")'],
}, },
CREATED_TIME: { CREATED_TIME: {
validation: { validation: {

2
tests/playwright/tests/db/columns/columnFormula.spec.ts

@ -103,7 +103,7 @@ const formulaDataByDbType = (context: NcContext, index: number) => {
}, },
{ {
formula: 'REGEX_MATCH({City}, "a[a-z]a")', formula: 'REGEX_MATCH({City}, "a[a-z]a")',
result: ['false', 'false', 'false', 'false', 'true'], result: ['0', '0', '0', '0', '1'],
}, },
{ {
formula: 'REGEX_EXTRACT({City}, "a[a-z]a")', formula: 'REGEX_EXTRACT({City}, "a[a-z]a")',

Loading…
Cancel
Save