fix(plugin-workflow): fix migration for calculation (#1476)

This commit is contained in:
Junyi 2023-02-20 23:40:15 +08:00 committed by GitHub
parent c7295e067f
commit 68062b969b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,40 +27,41 @@ const calculatorsMap = {
'divide': '/',
'mod': '%',
includes(a, b) {
return `SEARCH(${addQuote(b)}, ${addQuote(a)}) >= 0`;
return `SEARCH(${b}, ${a}) >= 0`;
},
notIncludes(a, b) {
return `SEARCH(${addQuote(b)}, ${addQuote(a)}) < 0`;
return `SEARCH(${b}, ${a}) < 0`;
},
startsWith(a, b) {
return `SEARCH(${addQuote(b)}, ${addQuote(a)}) == 0`
return `SEARCH(${b}, ${a}) == 0`
},
endsWith(a, b) {
return `RIGHT(${addQuote(a)}, LEN(${addQuote(b)})) == ${addQuote(b)}`;
return `RIGHT(${a}, LEN(${b})) == ${b}`;
},
notStartsWith(a, b) {
return `SEARCH(${addQuote(b)}, ${addQuote(a)}) != 0`;
return `SEARCH(${b}, ${a}) != 0`;
},
notEndsWith(a, b) {
return `RIGHT(${addQuote(a)}, LEN(${addQuote(b)})) != ${addQuote(b)}`;
return `RIGHT(${a}, LEN(${b})) != ${b}`;
},
concat(a, b) {
return `CONCATENATE(${addQuote(a)}, ${addQuote(b)})`;
return `CONCATENATE(${a}, ${b})`;
}
}
function migrateConfig({ calculation }) {
if (!calculation?.calculator || !calculation?.operands) {
if (!calculation?.calculator || !calculation?.operands?.length) {
return {};
}
const calculator = calculatorsMap[calculation.calculator];
const operands = calculator.operands.map(operand => addQuote(operand));
return {
engine: 'formula.js',
expression: typeof calculator === 'function'
? calculator(...calculation.operands)
: calculation.operands.join(` ${calculator ?? calculation.calculator} `)
? calculator(...operands)
: operands.join(` ${calculator ?? calculation.calculator} `)
}
}