2023-07-07 14:35:22 +08:00
|
|
|
import React from 'react';
|
2023-12-07 21:46:58 +08:00
|
|
|
|
2024-05-08 16:20:31 +08:00
|
|
|
import { Plugin } from '@tachybase/client';
|
|
|
|
import { Registry } from '@tachybase/utils/client';
|
2023-12-07 21:46:58 +08:00
|
|
|
|
2023-07-07 14:35:22 +08:00
|
|
|
import { ExecutionPage } from './ExecutionPage';
|
|
|
|
import { WorkflowPage } from './WorkflowPage';
|
2023-12-07 21:46:58 +08:00
|
|
|
import { WorkflowPane } from './WorkflowPane';
|
|
|
|
import { Trigger } from './triggers';
|
|
|
|
import CollectionTrigger from './triggers/collection';
|
|
|
|
import ScheduleTrigger from './triggers/schedule';
|
|
|
|
import { Instruction } from './nodes';
|
|
|
|
import CalculationInstruction from './nodes/calculation';
|
|
|
|
import ConditionInstruction from './nodes/condition';
|
2024-01-25 22:10:03 +08:00
|
|
|
import EndInstruction from './nodes/end';
|
2023-12-07 21:46:58 +08:00
|
|
|
import QueryInstruction from './nodes/query';
|
|
|
|
import CreateInstruction from './nodes/create';
|
|
|
|
import UpdateInstruction from './nodes/update';
|
|
|
|
import DestroyInstruction from './nodes/destroy';
|
2024-03-25 14:46:22 +08:00
|
|
|
import { getWorkflowDetailPath, getWorkflowExecutionsPath } from './utils';
|
2023-12-07 21:46:58 +08:00
|
|
|
import { NAMESPACE } from './locale';
|
2024-03-03 23:06:24 +08:00
|
|
|
import { customizeSubmitToWorkflowActionSettings } from './settings/customizeSubmitToWorkflowActionSettings';
|
2024-04-29 21:41:13 +08:00
|
|
|
import { PluginSql } from './features/sql';
|
|
|
|
import { PluginRequest } from './features/request';
|
|
|
|
import { PluginParallel } from './features/parallel';
|
|
|
|
import { PluginLoop } from './features/loop';
|
|
|
|
import { PluginDaynamicCalculation } from './features/dynamic-calculation';
|
|
|
|
import { PluginDelay } from './features/delay';
|
|
|
|
import { PluginAggregate } from './features/aggregate';
|
|
|
|
import { PluginActionTrigger } from './features/action-trigger';
|
|
|
|
import { PluginManual } from './features/manual';
|
2023-07-07 14:35:22 +08:00
|
|
|
|
2024-01-06 11:17:28 +08:00
|
|
|
export default class PluginWorkflowClient extends Plugin {
|
2023-12-07 21:46:58 +08:00
|
|
|
triggers = new Registry<Trigger>();
|
|
|
|
instructions = new Registry<Instruction>();
|
|
|
|
getTriggersOptions = () => {
|
|
|
|
return Array.from(this.triggers.getEntities()).map(([value, { title, ...options }]) => ({
|
|
|
|
value,
|
|
|
|
label: title,
|
|
|
|
color: 'gold',
|
|
|
|
options,
|
|
|
|
}));
|
|
|
|
};
|
2023-10-21 21:44:35 +08:00
|
|
|
|
2024-01-25 22:10:03 +08:00
|
|
|
isWorkflowSync(workflow) {
|
|
|
|
return this.triggers.get(workflow.type).sync ?? workflow.sync;
|
|
|
|
}
|
|
|
|
|
2023-12-27 13:55:48 +08:00
|
|
|
registerTrigger(type: string, trigger: Trigger | { new (): Trigger }) {
|
|
|
|
if (typeof trigger === 'function') {
|
|
|
|
this.triggers.register(type, new trigger());
|
|
|
|
} else if (trigger) {
|
|
|
|
this.triggers.register(type, trigger);
|
|
|
|
} else {
|
|
|
|
throw new TypeError('invalid trigger type to register');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
registerInstruction(type: string, instruction: Instruction | { new (): Instruction }) {
|
|
|
|
if (typeof instruction === 'function') {
|
|
|
|
this.instructions.register(type, new instruction());
|
|
|
|
} else if (instruction instanceof Instruction) {
|
|
|
|
this.instructions.register(type, instruction);
|
|
|
|
} else {
|
|
|
|
throw new TypeError('invalid instruction type to register');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-29 21:41:13 +08:00
|
|
|
async afterAdd() {
|
|
|
|
await this.pm.add(PluginSql);
|
|
|
|
await this.pm.add(PluginRequest);
|
|
|
|
await this.pm.add(PluginParallel);
|
|
|
|
await this.pm.add(PluginManual);
|
|
|
|
await this.pm.add(PluginLoop);
|
|
|
|
await this.pm.add(PluginDaynamicCalculation);
|
|
|
|
await this.pm.add(PluginDelay);
|
|
|
|
await this.pm.add(PluginAggregate);
|
|
|
|
await this.pm.add(PluginActionTrigger);
|
|
|
|
}
|
|
|
|
|
2023-07-07 14:35:22 +08:00
|
|
|
async load() {
|
|
|
|
this.addRoutes();
|
|
|
|
this.addComponents();
|
2023-12-04 14:56:46 +08:00
|
|
|
|
2023-11-13 11:01:18 +08:00
|
|
|
this.app.pluginSettingsManager.add(NAMESPACE, {
|
|
|
|
icon: 'PartitionOutlined',
|
|
|
|
title: `{{t("Workflow", { ns: "${NAMESPACE}" })}}`,
|
|
|
|
Component: WorkflowPane,
|
|
|
|
aclSnippet: 'pm.workflow.workflows',
|
|
|
|
});
|
2023-07-07 14:35:22 +08:00
|
|
|
|
2024-03-03 23:06:24 +08:00
|
|
|
this.app.schemaSettingsManager.add(customizeSubmitToWorkflowActionSettings);
|
|
|
|
|
2023-12-27 13:55:48 +08:00
|
|
|
this.registerTrigger('collection', CollectionTrigger);
|
|
|
|
this.registerTrigger('schedule', ScheduleTrigger);
|
2023-12-04 14:56:46 +08:00
|
|
|
|
2023-12-27 13:55:48 +08:00
|
|
|
this.registerInstruction('calculation', CalculationInstruction);
|
|
|
|
this.registerInstruction('condition', ConditionInstruction);
|
2024-01-25 22:10:03 +08:00
|
|
|
this.registerInstruction('end', EndInstruction);
|
|
|
|
|
2023-12-27 13:55:48 +08:00
|
|
|
this.registerInstruction('query', QueryInstruction);
|
|
|
|
this.registerInstruction('create', CreateInstruction);
|
|
|
|
this.registerInstruction('update', UpdateInstruction);
|
|
|
|
this.registerInstruction('destroy', DestroyInstruction);
|
2023-12-04 14:56:46 +08:00
|
|
|
}
|
|
|
|
|
2023-07-07 14:35:22 +08:00
|
|
|
addComponents() {
|
|
|
|
this.app.addComponents({
|
|
|
|
WorkflowPage,
|
|
|
|
ExecutionPage,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addRoutes() {
|
2023-11-13 11:01:18 +08:00
|
|
|
this.app.router.add('admin.workflow.workflows.id', {
|
|
|
|
path: getWorkflowDetailPath(':id'),
|
2023-07-07 14:35:22 +08:00
|
|
|
element: <WorkflowPage />,
|
|
|
|
});
|
2023-11-13 11:01:18 +08:00
|
|
|
this.app.router.add('admin.workflow.executions.id', {
|
|
|
|
path: getWorkflowExecutionsPath(':id'),
|
2023-07-07 14:35:22 +08:00
|
|
|
element: <ExecutionPage />,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2024-03-25 14:46:22 +08:00
|
|
|
|
|
|
|
export * from './Branch';
|
|
|
|
export * from './FlowContext';
|
|
|
|
export * from './constants';
|
|
|
|
export * from './nodes';
|
|
|
|
export { Trigger, useTrigger } from './triggers';
|
|
|
|
export * from './variable';
|
|
|
|
export * from './components';
|
|
|
|
export * from './utils';
|
|
|
|
export * from './hooks';
|
|
|
|
export { default as useStyles } from './style';
|
|
|
|
export * from './variable';
|
|
|
|
export * from './ExecutionContextProvider';
|