Browse Source

fix: Fixed rebase issues

pull/7281/head
Muhammed Mustafa 9 months ago
parent
commit
037161b7e8
  1. 3
      packages/nc-gui/components/smartsheet/column/FormulaOptions.vue
  2. 135
      packages/nocodb-sdk/src/lib/formulaHelpers.ts

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

@ -310,9 +310,10 @@ onMounted(() => {
:key="example" :key="example"
class="bg-gray-100 py-1 px-2" class="bg-gray-100 py-1 px-2"
:class="{ :class="{
'border-t-1 border-gray-200': index !== 0 || suggestionPreviewed.examples.length === 1, 'border-t-1 border-gray-200': index !== 0,
'rounded-b-md': index === suggestionPreviewed.examples.length - 1 && suggestionPreviewed.examples.length !== 1, 'rounded-b-md': index === suggestionPreviewed.examples.length - 1 && suggestionPreviewed.examples.length !== 1,
'rounded-t-md': index === 0 && suggestionPreviewed.examples.length !== 1, 'rounded-t-md': index === 0 && suggestionPreviewed.examples.length !== 1,
'rounded-md': suggestionPreviewed.examples.length === 1,
}" }"
> >
{{ example }} {{ example }}

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

@ -275,6 +275,7 @@ interface FormulaMeta {
syntax?: string; syntax?: string;
examples?: string[]; examples?: string[];
returnType?: ((args: any[]) => FormulaDataTypes) | FormulaDataTypes; returnType?: ((args: any[]) => FormulaDataTypes) | FormulaDataTypes;
docsUrl?: string;
} }
export const formulas: Record<string, FormulaMeta> = { export const formulas: Record<string, FormulaMeta> = {
@ -293,6 +294,8 @@ export const formulas: Record<string, FormulaMeta> = {
'AVG({column1}, {column2}, {column3})', 'AVG({column1}, {column2}, {column3})',
], ],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#avg',
}, },
ADD: { ADD: {
validation: { validation: {
@ -309,8 +312,12 @@ export const formulas: Record<string, FormulaMeta> = {
'ADD({column1}, {column2}, {column3})', 'ADD({column1}, {column2}, {column3})',
], ],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#add',
}, },
DATEADD: { DATEADD: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#dateadd',
validation: { validation: {
args: { args: {
rqd: 3, rqd: 3,
@ -407,6 +414,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
DATETIME_DIFF: { DATETIME_DIFF: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#datetime_diff',
validation: { validation: {
args: { args: {
min: 2, min: 2,
@ -486,6 +496,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
AND: { AND: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/conditional-expressions#and',
validation: { validation: {
args: { args: {
min: 1, min: 1,
@ -497,6 +510,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.COND_EXP, returnType: FormulaDataTypes.COND_EXP,
}, },
OR: { OR: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/conditional-expressions#or',
validation: { validation: {
args: { args: {
min: 1, min: 1,
@ -508,6 +524,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.COND_EXP, returnType: FormulaDataTypes.COND_EXP,
}, },
CONCAT: { CONCAT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#concat',
validation: { validation: {
args: { args: {
min: 1, min: 1,
@ -522,6 +541,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
TRIM: { TRIM: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#trim',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
@ -537,6 +559,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
UPPER: { UPPER: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#upper',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
@ -549,6 +574,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
LOWER: { LOWER: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#lower',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
@ -561,6 +589,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
LEN: { LEN: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#len',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
@ -573,6 +604,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
MIN: { MIN: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#min',
validation: { validation: {
args: { args: {
min: 1, min: 1,
@ -585,6 +619,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
MAX: { MAX: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#max',
validation: { validation: {
args: { args: {
min: 1, min: 1,
@ -597,6 +634,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
CEILING: { CEILING: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#ceiling',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
@ -609,6 +649,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
FLOOR: { FLOOR: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#floor',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
@ -622,6 +665,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
ROUND: { ROUND: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#round',
validation: { validation: {
args: { args: {
min: 1, min: 1,
@ -640,6 +686,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
MOD: { MOD: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#mod',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
@ -652,6 +701,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
REPEAT: { REPEAT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#repeat',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
@ -666,6 +718,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
LOG: { LOG: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#log',
validation: { validation: {
args: { args: {
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
@ -678,6 +733,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
EXP: { EXP: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#exp',
validation: { validation: {
args: { args: {
type: FormulaDataTypes.NUMERIC, type: FormulaDataTypes.NUMERIC,
@ -689,6 +747,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
POWER: { POWER: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#power',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
@ -701,6 +762,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
SQRT: { SQRT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#sqrt',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
@ -713,6 +777,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
ABS: { ABS: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#abs',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
@ -725,6 +792,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
NOW: { NOW: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#now',
validation: { validation: {
args: { args: {
rqd: 0, rqd: 0,
@ -737,6 +807,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.DATE, returnType: FormulaDataTypes.DATE,
}, },
REPLACE: { REPLACE: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#replace',
validation: { validation: {
args: { args: {
rqd: 3, rqd: 3,
@ -753,6 +826,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
SEARCH: { SEARCH: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#search',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
@ -768,6 +844,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
INT: { INT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#int',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
@ -780,6 +859,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
}, },
RIGHT: { RIGHT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#right',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
@ -792,6 +874,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
LEFT: { LEFT: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#left',
validation: { validation: {
args: { args: {
rqd: 2, rqd: 2,
@ -804,6 +889,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
SUBSTR: { SUBSTR: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#substr',
validation: { validation: {
args: { args: {
min: 2, min: 2,
@ -822,6 +910,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
MID: { MID: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#mid',
validation: { validation: {
args: { args: {
rqd: 3, rqd: 3,
@ -834,6 +925,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
IF: { IF: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/conditional-expressions#if',
validation: { validation: {
args: { args: {
min: 2, min: 2,
@ -871,6 +965,9 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
SWITCH: { SWITCH: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/conditional-expressions#switch',
validation: { validation: {
args: { args: {
min: 3, min: 3,
@ -913,6 +1010,9 @@ export const formulas: Record<string, FormulaMeta> = {
}, },
}, },
URL: { URL: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#url',
validation: { validation: {
args: { args: {
rqd: 1, rqd: 1,
@ -925,6 +1025,9 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
}, },
WEEKDAY: { WEEKDAY: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#weekday',
validation: { validation: {
args: { args: {
min: 1, min: 1,
@ -986,6 +1089,9 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'TRUE()', syntax: 'TRUE()',
examples: ['TRUE()'], examples: ['TRUE()'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
// TODO: Add docs url
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/logical-functions#true',
}, },
FALSE: { FALSE: {
@ -998,6 +1104,9 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'FALSE()', syntax: 'FALSE()',
examples: ['FALSE()'], examples: ['FALSE()'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
// TODO: Add docs url
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/logical-functions#false',
}, },
REGEX_MATCH: { REGEX_MATCH: {
@ -1025,6 +1134,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'REGEX_EXTRACT(string, regex)', syntax: 'REGEX_EXTRACT(string, regex)',
examples: ['REGEX_EXTRACT({title}, "abc.*")'], examples: ['REGEX_EXTRACT({title}, "abc.*")'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#regex_extract',
}, },
REGEX_REPLACE: { REGEX_REPLACE: {
validation: { validation: {
@ -1038,6 +1149,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'REGEX_MATCH(string, regex, replacement)', syntax: 'REGEX_MATCH(string, regex, replacement)',
examples: ['REGEX_EXTRACT({title}, "abc.*", "abcd")'], examples: ['REGEX_EXTRACT({title}, "abc.*", "abcd")'],
returnType: FormulaDataTypes.STRING, returnType: FormulaDataTypes.STRING,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#regex_replace',
}, },
BLANK: { BLANK: {
validation: { validation: {
@ -1049,6 +1162,9 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'BLANK()', syntax: 'BLANK()',
examples: ['BLANK()'], examples: ['BLANK()'],
returnType: FormulaDataTypes.NULL, returnType: FormulaDataTypes.NULL,
// TODO: Add docs url
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/logical-functions#blank',
}, },
XOR: { XOR: {
validation: { validation: {
@ -1062,6 +1178,9 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'XOR(expression, [exp2, ...])', syntax: 'XOR(expression, [exp2, ...])',
examples: ['XOR(TRUE(), FALSE(), TRUE())'], examples: ['XOR(TRUE(), FALSE(), TRUE())'],
returnType: FormulaDataTypes.BOOLEAN, returnType: FormulaDataTypes.BOOLEAN,
// TODO: Add docs url
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/logical-functions#xor',
}, },
EVEN: { EVEN: {
validation: { validation: {
@ -1075,6 +1194,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'EVEN(value)', syntax: 'EVEN(value)',
examples: ['EVEN({column})'], examples: ['EVEN({column})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#even',
}, },
ODD: { ODD: {
validation: { validation: {
@ -1088,6 +1209,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'ODD(value)', syntax: 'ODD(value)',
examples: ['ODD({column})'], examples: ['ODD({column})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#odd',
}, },
RECORD_ID: { RECORD_ID: {
validation: { validation: {
@ -1114,6 +1237,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'COUNTA(value1, [value2, ...])', syntax: 'COUNTA(value1, [value2, ...])',
examples: ['COUNTA({field1}, {field2})'], examples: ['COUNTA({field1}, {field2})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#counta',
}, },
COUNT: { COUNT: {
validation: { validation: {
@ -1125,6 +1250,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'COUNT(value1, [value2, ...])', syntax: 'COUNT(value1, [value2, ...])',
examples: ['COUNT({field1}, {field2})'], examples: ['COUNT({field1}, {field2})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#count',
}, },
COUNTALL: { COUNTALL: {
validation: { validation: {
@ -1136,6 +1263,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'COUNTALL(value1, [value2, ...])', syntax: 'COUNTALL(value1, [value2, ...])',
examples: ['COUNTALL({field1}, {field2})'], examples: ['COUNTALL({field1}, {field2})'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#countall',
}, },
ROUNDDOWN: { ROUNDDOWN: {
validation: { validation: {
@ -1150,6 +1279,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'ROUNDDOWN(value, [precision])', syntax: 'ROUNDDOWN(value, [precision])',
examples: ['ROUNDDOWN({field1})', 'ROUNDDOWN({field1}, 2)'], examples: ['ROUNDDOWN({field1})', 'ROUNDDOWN({field1}, 2)'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#rounddown',
}, },
ROUNDUP: { ROUNDUP: {
validation: { validation: {
@ -1164,6 +1295,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'ROUNDUP(value, [precision])', syntax: 'ROUNDUP(value, [precision])',
examples: ['ROUNDUP({field1})', 'ROUNDUP({field1}, 2)'], examples: ['ROUNDUP({field1})', 'ROUNDUP({field1}, 2)'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#roundup',
}, },
VALUE: { VALUE: {
validation: { validation: {
@ -1176,6 +1309,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'VALUE(value)', syntax: 'VALUE(value)',
examples: ['VALUE({field})', 'VALUE("abc10000%")', 'VALUE("$10000")'], examples: ['VALUE({field})', 'VALUE("abc10000%")', 'VALUE("$10000")'],
returnType: FormulaDataTypes.NUMERIC, returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#value',
}, },
// Disabling these functions for now; these act as alias for CreatedAt & UpdatedAt fields; // Disabling these functions for now; these act as alias for CreatedAt & UpdatedAt fields;
// Issue: Error noticed if CreatedAt & UpdatedAt fields are removed from the table after creating these formulas // Issue: Error noticed if CreatedAt & UpdatedAt fields are removed from the table after creating these formulas

Loading…
Cancel
Save