2023-05-18 19:42:30 +08:00
|
|
|
export * from './Branch';
|
2023-07-07 14:35:22 +08:00
|
|
|
export * from './FlowContext';
|
2023-12-04 14:56:46 +08:00
|
|
|
export * from './constants';
|
2023-07-07 14:35:22 +08:00
|
|
|
export * from './nodes';
|
2023-12-07 21:46:58 +08:00
|
|
|
export { Trigger, useTrigger } from './triggers';
|
|
|
|
export * from './variable';
|
|
|
|
export * from './components';
|
|
|
|
export * from './utils';
|
|
|
|
export * from './hooks/useGetAriaLabelOfAddButton';
|
2023-10-27 11:34:08 +08:00
|
|
|
export { default as useStyles } from './style';
|
2023-12-04 14:56:46 +08:00
|
|
|
export * from './variable';
|
|
|
|
export { getCollectionFieldOptions, useWorkflowVariableOptions } from './variable';
|
2023-07-07 14:35:22 +08:00
|
|
|
|
|
|
|
import React from 'react';
|
2023-12-07 21:46:58 +08:00
|
|
|
|
|
|
|
import { Plugin } from '@nocobase/client';
|
|
|
|
import { Registry } from '@nocobase/utils/client';
|
|
|
|
|
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';
|
|
|
|
import QueryInstruction from './nodes/query';
|
|
|
|
import CreateInstruction from './nodes/create';
|
|
|
|
import UpdateInstruction from './nodes/update';
|
|
|
|
import DestroyInstruction from './nodes/destroy';
|
|
|
|
import { useTriggerWorkflowsActionProps } from './hooks/useTriggerWorkflowActionProps';
|
2023-11-13 11:01:18 +08:00
|
|
|
import { getWorkflowDetailPath, getWorkflowExecutionsPath } from './constant';
|
2023-12-07 21:46:58 +08:00
|
|
|
import { NAMESPACE } from './locale';
|
2023-07-07 14:35:22 +08:00
|
|
|
|
2023-12-07 21:46:58 +08:00
|
|
|
export default class extends Plugin {
|
|
|
|
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
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-07 14:35:22 +08:00
|
|
|
async load() {
|
|
|
|
this.addRoutes();
|
2023-08-09 12:12:57 +08:00
|
|
|
this.addScopes();
|
2023-07-07 14:35:22 +08:00
|
|
|
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
|
|
|
|
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);
|
|
|
|
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
|
|
|
addScopes() {
|
|
|
|
this.app.addScopes({
|
2023-08-09 12:12:57 +08:00
|
|
|
useTriggerWorkflowsActionProps,
|
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 />,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|