From 266c934ce6c4f58f70e8bbeabbb0e577fe05f52e Mon Sep 17 00:00:00 2001 From: sealday Date: Tue, 18 Jun 2024 13:43:11 +0800 Subject: [PATCH] chore: rename-general-event-trigger (#1201) Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1201 --- .../plugin-workflow/src/client/Plugin.tsx | 2 ++ .../omni-trigger/OmniActionTrigger.tsx | 2 +- .../client/features/omni-trigger/index.tsx | 2 +- .../src/client/features/response/index.ts | 3 +- .../TriggerInstruction.tsx | 32 +++++++++++++++++++ .../features/trigger-instruction/index.ts | 0 .../features/trigger-instruction/plugin.ts | 10 ++++++ .../plugin-workflow/src/locale/en-US.json | 2 +- .../plugin-workflow/src/locale/zh-CN.json | 2 +- .../plugin-workflow/src/server/Plugin.ts | 2 ++ .../trigger-instruction/TriggerInstruction.ts | 21 ++++++++++++ .../features/trigger-instruction/index.ts | 0 .../features/trigger-instruction/plugin.ts | 14 ++++++++ 13 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 packages/plugins/@tachybase/plugin-workflow/src/client/features/trigger-instruction/TriggerInstruction.tsx create mode 100644 packages/plugins/@tachybase/plugin-workflow/src/client/features/trigger-instruction/index.ts create mode 100644 packages/plugins/@tachybase/plugin-workflow/src/client/features/trigger-instruction/plugin.ts create mode 100644 packages/plugins/@tachybase/plugin-workflow/src/server/features/trigger-instruction/TriggerInstruction.ts create mode 100644 packages/plugins/@tachybase/plugin-workflow/src/server/features/trigger-instruction/index.ts create mode 100644 packages/plugins/@tachybase/plugin-workflow/src/server/features/trigger-instruction/plugin.ts diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/Plugin.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/Plugin.tsx index 0ece251a8..75b6f5454 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/Plugin.tsx +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/Plugin.tsx @@ -18,6 +18,7 @@ import { PluginParallel } from './features/parallel'; import { PluginRequest } from './features/request'; import { PluginResponse } from './features/response'; import { PluginSql } from './features/sql'; +import { PluginTriggerInstruction } from './features/trigger-instruction/plugin'; import { PluginVariables } from './features/variables'; import { NAMESPACE } from './locale'; import { Instruction } from './nodes'; @@ -89,6 +90,7 @@ export class PluginWorkflow extends Plugin { await this.pm.add(PluginVariables); await this.pm.add(PluginResponse); await this.pm.add(PluginOmniTrigger); + await this.pm.add(PluginTriggerInstruction); } async load() { diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/omni-trigger/OmniActionTrigger.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/features/omni-trigger/OmniActionTrigger.tsx index 1769f7797..49bf7a1b8 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/omni-trigger/OmniActionTrigger.tsx +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/omni-trigger/OmniActionTrigger.tsx @@ -7,7 +7,7 @@ import { Trigger } from '../../triggers'; import { getCollectionFieldOptions, UseVariableOptions } from '../../variable'; export class OmniActionTrigger extends Trigger { - title = tval('Omni action event'); + title = tval('General event'); description = tval( `Omni Trigger is a versatile trigger. You can use it to trigger workflows in a table, trigger it from another workflow, or trigger it with a form button.`, ); diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/omni-trigger/index.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/features/omni-trigger/index.tsx index 6fcb27279..d8f30770c 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/omni-trigger/index.tsx +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/omni-trigger/index.tsx @@ -49,7 +49,7 @@ const triggerWorkflowLinkItem = { }; export class PluginOmniTrigger extends Plugin { async load() { - this.app.pm.get('workflow').registerTrigger('omni-action', OmniActionTrigger); + this.app.pm.get('workflow').registerTrigger('general-action', OmniActionTrigger); this.app.addScopes({ useFormWorkflowCustomActionProps, useRecordWorkflowCustomTriggerActionProps, diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/response/index.ts b/packages/plugins/@tachybase/plugin-workflow/src/client/features/response/index.ts index 73b30f8a4..f74e8edc6 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/response/index.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/response/index.ts @@ -28,7 +28,8 @@ class ResponseInstruction extends Instruction { }; isAvailable({ workflow }) { return ( - workflow.type === 'request-interception' || (['action', 'omni-action'].includes(workflow.type) && workflow.sync) + workflow.type === 'request-interception' || + (['action', 'general-action'].includes(workflow.type) && workflow.sync) ); } } diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/trigger-instruction/TriggerInstruction.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/features/trigger-instruction/TriggerInstruction.tsx new file mode 100644 index 000000000..d83338bfa --- /dev/null +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/trigger-instruction/TriggerInstruction.tsx @@ -0,0 +1,32 @@ +import { ISchema } from '@tachybase/schema'; + +import { tval } from '../../locale'; +import { Instruction } from '../../nodes'; +import { VariableOption } from '../../variable'; + +export class TriggerInstruction extends Instruction { + title = tval('Trigger'); + type = 'trigger-instruction'; + group = 'extended'; + fieldset = { + workflowKey: { + type: 'string', + title: tval('workflow'), + name: 'workflowKey', + 'x-decorator': 'FormItem', + 'x-component': 'WorkflowSelect', + 'x-component-props': { + buttonAction: 'customize:triggerWorkflows', + label: 'title', + value: 'key', + }, + required: true, + } as ISchema, + }; + useVariables(node, options): VariableOption { + return { + value: node.key, + label: node.title, + }; + } +} diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/trigger-instruction/index.ts b/packages/plugins/@tachybase/plugin-workflow/src/client/features/trigger-instruction/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/trigger-instruction/plugin.ts b/packages/plugins/@tachybase/plugin-workflow/src/client/features/trigger-instruction/plugin.ts new file mode 100644 index 000000000..1005b6d64 --- /dev/null +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/trigger-instruction/plugin.ts @@ -0,0 +1,10 @@ +import { Plugin } from '@tachybase/client'; + +import { PluginWorkflow } from '../../Plugin'; +import { TriggerInstruction } from './TriggerInstruction'; + +export class PluginTriggerInstruction extends Plugin { + async load() { + this.app.pm.get('workflow').registerInstruction('trigger-instruction', TriggerInstruction); + } +} diff --git a/packages/plugins/@tachybase/plugin-workflow/src/locale/en-US.json b/packages/plugins/@tachybase/plugin-workflow/src/locale/en-US.json index ca44bcf89..c47d42efd 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/locale/en-US.json +++ b/packages/plugins/@tachybase/plugin-workflow/src/locale/en-US.json @@ -192,6 +192,6 @@ "Ignore failed request and continue workflow": "Ignore failed request and continue workflow", "SQL action": "SQL action", "Execute a SQL statement in database": "Execute a SQL statement in database", - "Omni action event": "Omni action event", + "General event": "General event", "Usage of SQL query result is not supported yet.": "Usage of SQL query result is not supported yet." } diff --git a/packages/plugins/@tachybase/plugin-workflow/src/locale/zh-CN.json b/packages/plugins/@tachybase/plugin-workflow/src/locale/zh-CN.json index f726b6e6b..cebf743e0 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/locale/zh-CN.json +++ b/packages/plugins/@tachybase/plugin-workflow/src/locale/zh-CN.json @@ -258,7 +258,7 @@ "Ignore failed request and continue workflow": "忽略失败的请求并继续工作流", "SQL action": "SQL 操作", "Execute a SQL statement in database.": "在数据库中执行一个 SQL 语句", - "Omni action event": "万能操作事件", + "General event": "通用事件", "Select a data source to execute SQL.": "选择一个数据源来执行 SQL", "SQL query result could be used through <1>JSON query node (Commercial plugin).": "SQL 执行的结果可在 <1>JSON 解析节点 中使用(商业插件)。" } diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/Plugin.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/Plugin.ts index 0395a4127..35d7ec822 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/Plugin.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/Plugin.ts @@ -23,6 +23,7 @@ import { PluginParallel } from './features/parallel/Plugin'; import { PluginRequest } from './features/request/Plugin'; import { PluginResponse } from './features/response'; import { PluginSql } from './features/sql/Plugin'; +import { PluginTriggerInstruction } from './features/trigger-instruction/plugin'; import { PluginVariables } from './features/variables'; import initFunctions, { CustomFunction } from './functions'; import { Instruction, InstructionInterface } from './instructions'; @@ -78,6 +79,7 @@ export default class PluginWorkflowServer extends Plugin { this.addFeature(PluginVariables); this.addFeature(PluginResponse); this.addFeature(PluginOmniTrigger); + this.addFeature(PluginTriggerInstruction); } getLogger(workflowId: ID): Logger { diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/trigger-instruction/TriggerInstruction.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/trigger-instruction/TriggerInstruction.ts new file mode 100644 index 000000000..71d628597 --- /dev/null +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/trigger-instruction/TriggerInstruction.ts @@ -0,0 +1,21 @@ +import { JOB_STATUS } from '../../constants'; +import Instruction from '../../instructions'; + +export class TriggerInstruction extends Instruction { + async run(node, input, processor) { + const workflowKey = node.config.workflowKey; + const wfRepo = this.workflow.db.getRepository('workflows'); + const wf = await wfRepo.findOne({ filter: { key: workflowKey, enabled: true } }); + const p = await this.workflow.trigger(wf, { data: 'not-support' }); + if (!p) { + return { + status: JOB_STATUS.FAILED, + }; + } + const { lastSavedJob } = processor; + return { + status: JOB_STATUS.RESOLVED, + result: lastSavedJob.result, + }; + } +} diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/trigger-instruction/index.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/trigger-instruction/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/trigger-instruction/plugin.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/trigger-instruction/plugin.ts new file mode 100644 index 000000000..e3676e1a1 --- /dev/null +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/trigger-instruction/plugin.ts @@ -0,0 +1,14 @@ +import { Plugin } from '@tachybase/server'; + +import { PluginWorkflow } from '../..'; +import { TriggerInstruction } from './TriggerInstruction'; + +export class PluginTriggerInstruction extends Plugin { + async load() { + // get workflow plugin instance + const workflowPlugin = this.app.getPlugin(PluginWorkflow); + + // register instruction + workflowPlugin.registerInstruction('trigger-instruction', TriggerInstruction); + } +}