From 7ca8e562cef25279d344581514992da075a87a0c Mon Sep 17 00:00:00 2001 From: Junyi Date: Wed, 12 Oct 2022 14:53:44 +0800 Subject: [PATCH] feat(plugin-workflow): add concat calculator (#894) (cherry picked from commit 7f3f1bc982379ec2d274ca79fb4d6c65664d3c2d) --- packages/core/client/src/locale/zh_CN.ts | 1 + .../workflow/src/client/calculators.tsx | 23 +++++++++++++++++++ .../workflow/src/server/calculators/index.ts | 6 +++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/core/client/src/locale/zh_CN.ts b/packages/core/client/src/locale/zh_CN.ts index f5a6a6090..15af77f28 100644 --- a/packages/core/client/src/locale/zh_CN.ts +++ b/packages/core/client/src/locale/zh_CN.ts @@ -590,6 +590,7 @@ export default { 'Calculation result': '运算结果', 'True': '真', 'False': '假', + 'concat': '连接', 'Condition': '条件判断', 'Mode': '模式', diff --git a/packages/plugins/workflow/src/client/calculators.tsx b/packages/plugins/workflow/src/client/calculators.tsx index d6f73273e..6825dec8c 100644 --- a/packages/plugins/workflow/src/client/calculators.tsx +++ b/packages/plugins/workflow/src/client/calculators.tsx @@ -18,6 +18,7 @@ function NullRender() { interface Calculator { name: string; + type: 'boolean' | 'number' | 'string' | 'date' | 'unknown' | 'null' | 'array'; group: string; } @@ -25,72 +26,94 @@ export const calculators = new Registry(); calculators.register('equal', { name: '=', + type: 'boolean', group: 'boolean', }); calculators.register('notEqual', { name: '≠', + type: 'boolean', group: 'boolean', }); calculators.register('gt', { name: '>', + type: 'boolean', group: 'boolean', }); calculators.register('gte', { name: '≥', + type: 'boolean', group: 'boolean', }); calculators.register('lt', { name: '<', + type: 'boolean', group: 'boolean', }); calculators.register('lte', { name: '≤', + type: 'boolean', group: 'boolean', }); calculators.register('add', { name: '+', + type: 'number', group: 'number', }); calculators.register('minus', { name: '-', + type: 'number', group: 'number', }); calculators.register('multiple', { name: '*', + type: 'number', group: 'number', }); calculators.register('divide', { name: '/', + type: 'number', group: 'number', }); calculators.register('mod', { name: '%', + type: 'number', group: 'number', }); calculators.register('includes', { name: '{{t("contains")}}', + type: 'boolean', group: 'string' }); calculators.register('notIncludes', { name: '{{t("does not contain")}}', + type: 'boolean', group: 'string' }); calculators.register('startsWith', { name: '{{t("starts with")}}', + type: 'boolean', group: 'string' }); calculators.register('notStartsWith', { name: '{{t("not starts with")}}', + type: 'boolean', group: 'string' }); calculators.register('endsWith', { name: '{{t("ends with")}}', + type: 'boolean', group: 'string' }); calculators.register('notEndsWith', { name: '{{t("not ends with")}}', + type: 'boolean', + group: 'string' +}); +calculators.register('concat', { + name: '{{t("concat")}}', + type: 'string', group: 'string' }); diff --git a/packages/plugins/workflow/src/server/calculators/index.ts b/packages/plugins/workflow/src/server/calculators/index.ts index f8573f5f3..cd0d65e52 100644 --- a/packages/plugins/workflow/src/server/calculators/index.ts +++ b/packages/plugins/workflow/src/server/calculators/index.ts @@ -203,10 +203,12 @@ calculators.register('notStartsWith', notStartsWith); calculators.register('endsWith', endsWith); calculators.register('notEndsWith', notEndsWith); -function before(a: string, b: string) { - return a < b; +function concat(a: string, b: string) { + return a.concat(b); } +calculators.register('concat', concat); + calculators.register('now', () => new Date()); // TODO: add more common calculators