fix(plugin-workflow): fix migration for calculation (#1476)
This commit is contained in:
parent
c7295e067f
commit
68062b969b
@ -27,40 +27,41 @@ const calculatorsMap = {
|
|||||||
'divide': '/',
|
'divide': '/',
|
||||||
'mod': '%',
|
'mod': '%',
|
||||||
includes(a, b) {
|
includes(a, b) {
|
||||||
return `SEARCH(${addQuote(b)}, ${addQuote(a)}) >= 0`;
|
return `SEARCH(${b}, ${a}) >= 0`;
|
||||||
},
|
},
|
||||||
notIncludes(a, b) {
|
notIncludes(a, b) {
|
||||||
return `SEARCH(${addQuote(b)}, ${addQuote(a)}) < 0`;
|
return `SEARCH(${b}, ${a}) < 0`;
|
||||||
},
|
},
|
||||||
startsWith(a, b) {
|
startsWith(a, b) {
|
||||||
return `SEARCH(${addQuote(b)}, ${addQuote(a)}) == 0`
|
return `SEARCH(${b}, ${a}) == 0`
|
||||||
},
|
},
|
||||||
endsWith(a, b) {
|
endsWith(a, b) {
|
||||||
return `RIGHT(${addQuote(a)}, LEN(${addQuote(b)})) == ${addQuote(b)}`;
|
return `RIGHT(${a}, LEN(${b})) == ${b}`;
|
||||||
},
|
},
|
||||||
notStartsWith(a, b) {
|
notStartsWith(a, b) {
|
||||||
return `SEARCH(${addQuote(b)}, ${addQuote(a)}) != 0`;
|
return `SEARCH(${b}, ${a}) != 0`;
|
||||||
},
|
},
|
||||||
notEndsWith(a, b) {
|
notEndsWith(a, b) {
|
||||||
return `RIGHT(${addQuote(a)}, LEN(${addQuote(b)})) != ${addQuote(b)}`;
|
return `RIGHT(${a}, LEN(${b})) != ${b}`;
|
||||||
},
|
},
|
||||||
concat(a, b) {
|
concat(a, b) {
|
||||||
return `CONCATENATE(${addQuote(a)}, ${addQuote(b)})`;
|
return `CONCATENATE(${a}, ${b})`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function migrateConfig({ calculation }) {
|
function migrateConfig({ calculation }) {
|
||||||
if (!calculation?.calculator || !calculation?.operands) {
|
if (!calculation?.calculator || !calculation?.operands?.length) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const calculator = calculatorsMap[calculation.calculator];
|
const calculator = calculatorsMap[calculation.calculator];
|
||||||
|
const operands = calculator.operands.map(operand => addQuote(operand));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
engine: 'formula.js',
|
engine: 'formula.js',
|
||||||
expression: typeof calculator === 'function'
|
expression: typeof calculator === 'function'
|
||||||
? calculator(...calculation.operands)
|
? calculator(...operands)
|
||||||
: calculation.operands.join(` ${calculator ?? calculation.calculator} `)
|
: operands.join(` ${calculator ?? calculation.calculator} `)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user