Browse Source

feat: define function return types - WIP

pull/7268/head
Pranav C 11 months ago
parent
commit
e2e2f74183
  1. 19
      packages/nc-gui/utils/formulaUtils.ts

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

@ -26,7 +26,6 @@ interface FormulaMeta {
} }
const formulas: Record<string, FormulaMeta> = { const formulas: Record<string, FormulaMeta> = {
AVG: { AVG: {
type: formulaTypes.NUMERIC, type: formulaTypes.NUMERIC,
validation: { validation: {
@ -425,7 +424,17 @@ const formulas: Record<string, FormulaMeta> = {
description: 'SuccessCase if expr evaluates to TRUE, elseCase otherwise', description: 'SuccessCase if expr evaluates to TRUE, elseCase otherwise',
syntax: 'IF(expr, successCase, elseCase)', syntax: 'IF(expr, successCase, elseCase)',
examples: ['IF(5 > 1, "YES", "NO") => "YES"', 'IF({column} > 1, "YES", "NO")'], examples: ['IF(5 > 1, "YES", "NO") => "YES"', 'IF({column} > 1, "YES", "NO")'],
returnType: formulaTypes.STRING, returnType: (argsTypes: formulaTypes[]) => {
if (argsTypes.slice(1).includes(formulaTypes.STRING)) {
return formulaTypes.STRING
} else if (argsTypes.slice(1).includes(formulaTypes.NUMERIC)) {
return formulaTypes.NUMERIC
} else if (argsTypes.slice(1).includes(formulaTypes.BOOLEAN)) {
return formulaTypes.BOOLEAN
}
return argsTypes[1]
},
}, },
SWITCH: { SWITCH: {
type: formulaTypes.COND_EXP, type: formulaTypes.COND_EXP,
@ -443,8 +452,8 @@ const formulas: Record<string, FormulaMeta> = {
'SWITCH({column1}, 1, "One", 2, "Two", "N/A")', 'SWITCH({column1}, 1, "One", 2, "Two", "N/A")',
], ],
// todo: resolve return type based on the args // todo: resolve return type based on the args
returnType: () => { returnType: (argTypes: formulaTypes[]) => {
return formulaTypes.STRING; return formulaTypes.STRING
}, },
}, },
URL: { URL: {
@ -596,7 +605,7 @@ const formulas: Record<string, FormulaMeta> = {
// todo: resolve return type based on the args // todo: resolve return type based on the args
returnType: () => { returnType: () => {
return formulaTypes.STRING; return formulaTypes.STRING
}, },
}, },
COUNTA: { COUNTA: {

Loading…
Cancel
Save