chore: rename-general-event-trigger (#1201)

Reviewed-on: daoyoucloud/tachybase#1201
This commit is contained in:
sealday 2024-06-18 13:43:11 +08:00
parent a8191ba6c5
commit 266c934ce6
13 changed files with 87 additions and 5 deletions

View File

@ -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() {

View File

@ -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.`,
);

View File

@ -49,7 +49,7 @@ const triggerWorkflowLinkItem = {
};
export class PluginOmniTrigger extends Plugin {
async load() {
this.app.pm.get<PluginWorkflow>('workflow').registerTrigger('omni-action', OmniActionTrigger);
this.app.pm.get<PluginWorkflow>('workflow').registerTrigger('general-action', OmniActionTrigger);
this.app.addScopes({
useFormWorkflowCustomActionProps,
useRecordWorkflowCustomTriggerActionProps,

View File

@ -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)
);
}
}

View File

@ -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,
};
}
}

View File

@ -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<PluginWorkflow>('workflow').registerInstruction('trigger-instruction', TriggerInstruction);
}
}

View File

@ -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."
}

View File

@ -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</1> (Commercial plugin).": "SQL 执行的结果可在 <1>JSON 解析节点</1> 中使用(商业插件)。"
}

View File

@ -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 {

View File

@ -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,
};
}
}

View File

@ -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>(PluginWorkflow);
// register instruction
workflowPlugin.registerInstruction('trigger-instruction', TriggerInstruction);
}
}