Browse Source

feat: WEEKDAY validation

pull/2706/head
Wing-Kam Wong 2 years ago
parent
commit
d9b972be1b
  1. 35
      packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue

35
packages/nc-gui/components/project/spreadsheet/components/editColumn/FormulaOptions.vue

@ -108,7 +108,6 @@ export default {
props: ['nodes', 'column', 'meta', 'isSQLite', 'alias', 'value', 'sqlUi'], props: ['nodes', 'column', 'meta', 'isSQLite', 'alias', 'value', 'sqlUi'],
data: () => ({ data: () => ({
formula: {}, formula: {},
// formulas: ['AVERAGE()', 'COUNT()', 'COUNTA()', 'COUNTALL()', 'SUM()', 'MIN()', 'MAX()', 'AND()', 'OR()', 'TRUE()', 'FALSE()', 'NOT()', 'XOR()', 'ISERROR()', 'IF()', 'LEN()', 'MID()', 'LEFT()', 'RIGHT()', 'FIND()', 'CONCATENATE()', 'T()', 'VALUE()', 'ARRAYJOIN()', 'ARRAYUNIQUE()', 'ARRAYCOMPACT()', 'ARRAYFLATTEN()', 'ROUND()', 'ROUNDUP()', 'ROUNDDOWN()', 'INT()', 'EVEN()', 'ODD()', 'MOD()', 'LOG()', 'EXP()', 'POWER()', 'SQRT()', 'CEILING()', 'FLOOR()', 'ABS()', 'RECORD_ID()', 'CREATED_TIME()', 'ERROR()', 'BLANK()', 'YEAR()', 'MONTH()', 'DAY()', 'HOUR()', 'MINUTE()', 'SECOND()', 'TODAY()', 'NOW()', 'WORKDAY()', 'DATETIME_PARSE()', 'DATETIME_FORMAT()', 'SET_LOCALE()', 'SET_TIMEZONE()', 'DATESTR()', 'TIMESTR()', 'TONOW()', 'FROMNOW()', 'DATEADD()', 'WEEKDAY()', 'WEEKNUM()', 'DATETIME_DIFF()', 'WORKDAY_DIFF()', 'IS_BEFORE()', 'IS_SAME()', 'IS_AFTER()', 'REPLACE()', 'REPT()', 'LOWER()', 'UPPER()', 'TRIM()', 'SUBSTITUTE()', 'SEARCH()', 'SWITCH()', 'LAST_MODIFIED_TIME()', 'ENCODE_URL_COMPONENT()', 'REGEX_EXTRACT()', 'REGEX_MATCH()', 'REGEX_REPLACE()']
availableFunctions: formulaList, availableFunctions: formulaList,
availableBinOps: ['+', '-', '*', '/', '>', '<', '==', '<=', '>=', '!='], availableBinOps: ['+', '-', '*', '/', '>', '<', '==', '<=', '>=', '!='],
autocomplete: false, autocomplete: false,
@ -257,7 +256,39 @@ export default {
if (parsedTree.callee.type === jsep.IDENTIFIER) { if (parsedTree.callee.type === jsep.IDENTIFIER) {
const expectedType = formulas[parsedTree.callee.name].type; const expectedType = formulas[parsedTree.callee.name].type;
if (expectedType === formulaTypes.NUMERIC) { if (expectedType === formulaTypes.NUMERIC) {
parsedTree.arguments.map(arg => this.validateAgainstType(arg, expectedType, null, typeErrors)); if (parsedTree.callee.name === 'WEEKDAY') {
// parsedTree.arguments[0] = date
this.validateAgainstType(
parsedTree.arguments[0],
formulaTypes.DATE,
v => {
if (!(v instanceof Date)) {
typeErrors.add('The first parameter of WEEKDAY() should have date value');
}
},
typeErrors
);
// parsedTree.arguments[1] = startDayOfWeek (optional)
this.validateAgainstType(
parsedTree.arguments[1],
formulaTypes.STRING,
v => {
if (
typeof v !== 'string' ||
!['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'].includes(
v.toLowerCase()
)
) {
typeErrors.add(
'The second parameter of WEEKDAY() should have the value either "sunday", "monday", "tuesday", "wednesday", "thursday", "friday" or "saturday"'
);
}
},
typeErrors
);
} else {
parsedTree.arguments.map(arg => this.validateAgainstType(arg, expectedType, null, typeErrors));
}
} else if (expectedType === formulaTypes.DATE) { } else if (expectedType === formulaTypes.DATE) {
if (parsedTree.callee.name === 'DATEADD') { if (parsedTree.callee.name === 'DATEADD') {
// parsedTree.arguments[0] = date // parsedTree.arguments[0] = date

Loading…
Cancel
Save