From a18918576b90d91eb35e17f6fb8f5a7743ce273c Mon Sep 17 00:00:00 2001 From: Junyi Date: Wed, 22 Feb 2023 17:35:22 +0800 Subject: [PATCH] fix(plugin-workflow): fix condition config param (#1483) --- .../__tests__/instructions/condition.test.ts | 35 ++++++++----------- .../src/server/instructions/condition.ts | 4 +-- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/packages/plugins/workflow/src/server/__tests__/instructions/condition.test.ts b/packages/plugins/workflow/src/server/__tests__/instructions/condition.test.ts index 02d365009..b6576eef4 100644 --- a/packages/plugins/workflow/src/server/__tests__/instructions/condition.test.ts +++ b/packages/plugins/workflow/src/server/__tests__/instructions/condition.test.ts @@ -44,7 +44,7 @@ describe('workflow > instructions > condition', () => { type: 'condition', config: { engine: 'math.js', - calculation: '1 == 1' + expression: '1 == 1' } }); @@ -81,7 +81,7 @@ describe('workflow > instructions > condition', () => { config: { engine: 'math.js', // false - calculation: '0 == 1' + expression: '0 == 1' } }); @@ -117,13 +117,12 @@ describe('workflow > instructions > condition', () => { const n1 = await workflow.createNode({ type: 'condition', config: { - engine: 'math.js', calculation: { group: { type: 'and', calculations: [ - '1 == 1', - '1 == 1', + { calculator: 'equal', operands: [1, 1] }, + { calculator: 'equal', operands: [1, 1] } ] } } @@ -143,13 +142,12 @@ describe('workflow > instructions > condition', () => { const n1 = await workflow.createNode({ type: 'condition', config: { - engine: 'math.js', calculation: { group: { type: 'and', calculations: [ - '1 == 1', - '0 == 1', + { calculator: 'equal', operands: [1, 1] }, + { calculator: 'equal', operands: [0, 1] } ] } } @@ -169,13 +167,12 @@ describe('workflow > instructions > condition', () => { const n1 = await workflow.createNode({ type: 'condition', config: { - engine: 'math.js', calculation: { group: { type: 'or', calculations: [ - '1 == 1', - '0 == 1', + { calculator: 'equal', operands: [1, 1] }, + { calculator: 'equal', operands: [0, 1] } ] } } @@ -195,13 +192,12 @@ describe('workflow > instructions > condition', () => { const n1 = await workflow.createNode({ type: 'condition', config: { - engine: 'math.js', calculation: { group: { type: 'and', calculations: [ - '0 == 1', - '0 == 1', + { calculator: 'equal', operands: [0, 1] }, + { calculator: 'equal', operands: [0, 1] } ] } } @@ -221,18 +217,17 @@ describe('workflow > instructions > condition', () => { const n1 = await workflow.createNode({ type: 'condition', config: { - engine: 'math.js', calculation: { group: { type: 'and', calculations: [ - '1 == 1', + { calculator: 'equal', operands: [1, 1] }, { group: { type: 'or', calculations: [ - '0 == 1', - '0 == 1', + { calculator: 'equal', operands: [0, 1] }, + { calculator: 'equal', operands: [0, 1] } ] } } @@ -306,7 +301,7 @@ describe('workflow > instructions > condition', () => { type: 'condition', config: { engine: 'math.js', - calculation: '1 == 1' + expression: '1 == 1' } }); @@ -327,7 +322,7 @@ describe('workflow > instructions > condition', () => { type: 'condition', config: { engine: 'formula.js', - calculation: '1 == 1' + expression: '1 == 1' } }); diff --git a/packages/plugins/workflow/src/server/instructions/condition.ts b/packages/plugins/workflow/src/server/instructions/condition.ts index 83a674b1c..1b1d52d42 100644 --- a/packages/plugins/workflow/src/server/instructions/condition.ts +++ b/packages/plugins/workflow/src/server/instructions/condition.ts @@ -21,7 +21,7 @@ export default { async run(node: FlowNodeModel, prevJob, processor: Processor) { // TODO(optimize): loading of jobs could be reduced and turned into incrementally in processor // const jobs = await processor.getJobs(); - const { engine = 'basic', calculation, rejectOnFalse } = node.config || {}; + const { engine = 'basic', calculation, expression, rejectOnFalse } = node.config || {}; const evaluator = processor.options.plugin.calculators.get(engine); if (!evaluator) { return { @@ -34,7 +34,7 @@ export default { let result = true; try { - result = logicCalculate(processor.getParsedValue(calculation), evaluator, scope); + result = logicCalculate(engine === 'basic' ? processor.getParsedValue(calculation) : expression, evaluator, scope); } catch (e) { return { result: e.toString(),