fix(plugin-workflow): fix migration for calculation (#1476)
This commit is contained in:
parent
c7295e067f
commit
68062b969b
@ -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} `)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user