2022-06-29 17:32:10 +08:00
|
|
|
import React, { useContext } from 'react';
|
2023-01-04 22:24:41 +08:00
|
|
|
import { Card } from 'antd';
|
2023-04-25 13:12:14 +08:00
|
|
|
import {
|
|
|
|
CollectionManagerContext,
|
|
|
|
PluginManagerContext,
|
|
|
|
RouteSwitchContext,
|
|
|
|
SchemaComponent,
|
|
|
|
SchemaComponentOptions,
|
|
|
|
SettingsCenterProvider,
|
|
|
|
registerField,
|
|
|
|
useCollectionDataSource,
|
|
|
|
} from '@nocobase/client';
|
2023-04-08 10:52:31 +08:00
|
|
|
|
2022-06-29 17:32:10 +08:00
|
|
|
import { WorkflowPage } from './WorkflowPage';
|
2022-10-30 11:54:14 +08:00
|
|
|
import { ExecutionPage } from './ExecutionPage';
|
2022-11-11 23:37:41 +08:00
|
|
|
import { triggers } from './triggers';
|
|
|
|
import { instructions } from './nodes';
|
|
|
|
import { lang } from './locale';
|
2023-01-04 22:24:41 +08:00
|
|
|
import { workflowSchema } from './schemas/workflows';
|
|
|
|
import { WorkflowLink } from './WorkflowLink';
|
|
|
|
import { ExecutionResourceProvider } from './ExecutionResourceProvider';
|
|
|
|
import { ExecutionLink } from './ExecutionLink';
|
|
|
|
import OpenDrawer from './components/OpenDrawer';
|
2023-02-20 11:52:06 +08:00
|
|
|
import { WorkflowTodo } from './nodes/manual/WorkflowTodo';
|
|
|
|
import { WorkflowTodoBlockInitializer } from './nodes/manual/WorkflowTodoBlockInitializer';
|
2023-04-08 10:52:31 +08:00
|
|
|
import { DynamicExpression } from './components/DynamicExpression';
|
|
|
|
import expressionField from './interfaces/expression';
|
|
|
|
|
|
|
|
// registerField(expressionField.group, 'expression', expressionField);
|
2022-11-11 23:37:41 +08:00
|
|
|
|
|
|
|
export const WorkflowContext = React.createContext({});
|
|
|
|
|
|
|
|
export function useWorkflowContext() {
|
|
|
|
return useContext(WorkflowContext);
|
|
|
|
}
|
2022-06-29 17:32:10 +08:00
|
|
|
|
2023-01-04 22:24:41 +08:00
|
|
|
function WorkflowPane() {
|
|
|
|
return (
|
|
|
|
<Card bordered={false}>
|
|
|
|
<SchemaComponent
|
|
|
|
schema={workflowSchema}
|
|
|
|
components={{
|
|
|
|
WorkflowLink,
|
|
|
|
ExecutionResourceProvider,
|
|
|
|
ExecutionLink,
|
2023-04-25 13:12:14 +08:00
|
|
|
OpenDrawer,
|
2023-01-04 22:24:41 +08:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
);
|
2023-04-25 13:12:14 +08:00
|
|
|
}
|
2023-01-04 22:24:41 +08:00
|
|
|
|
2022-06-29 17:32:10 +08:00
|
|
|
export const WorkflowProvider = (props) => {
|
2023-04-08 10:52:31 +08:00
|
|
|
const pmCtx = useContext(PluginManagerContext);
|
|
|
|
const cmCtx = useContext(CollectionManagerContext);
|
2022-06-29 17:32:10 +08:00
|
|
|
const { routes, components, ...others } = useContext(RouteSwitchContext);
|
2023-01-09 07:35:48 +08:00
|
|
|
routes[1].routes.unshift(
|
|
|
|
{
|
|
|
|
type: 'route',
|
|
|
|
path: '/admin/settings/workflow/workflows/:id',
|
|
|
|
component: 'WorkflowPage',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'route',
|
|
|
|
path: '/admin/settings/workflow/executions/:id',
|
|
|
|
component: 'ExecutionPage',
|
|
|
|
},
|
|
|
|
);
|
2022-06-29 17:32:10 +08:00
|
|
|
return (
|
2022-09-18 14:10:01 +08:00
|
|
|
<SettingsCenterProvider
|
|
|
|
settings={{
|
|
|
|
workflow: {
|
|
|
|
icon: 'PartitionOutlined',
|
2022-11-11 23:37:41 +08:00
|
|
|
// title: `{{t("Workflow", { ns: "${NAMESPACE}" })}}`,
|
|
|
|
title: lang('Workflow'),
|
2022-09-18 14:10:01 +08:00
|
|
|
tabs: {
|
|
|
|
workflows: {
|
2023-01-09 07:35:48 +08:00
|
|
|
isBookmark: true,
|
2022-11-11 23:37:41 +08:00
|
|
|
title: lang('Workflow'),
|
2022-09-18 14:10:01 +08:00
|
|
|
component: WorkflowPane,
|
|
|
|
},
|
|
|
|
},
|
2022-06-29 17:32:10 +08:00
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
2022-09-18 14:10:01 +08:00
|
|
|
<PluginManagerContext.Provider
|
|
|
|
value={{
|
|
|
|
components: {
|
2023-04-08 10:52:31 +08:00
|
|
|
...pmCtx?.components,
|
2022-11-11 23:37:41 +08:00
|
|
|
// WorkflowShortcut,
|
2022-09-18 14:10:01 +08:00
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
2023-04-25 13:12:14 +08:00
|
|
|
<RouteSwitchContext.Provider
|
|
|
|
value={{ components: { ...components, WorkflowPage, ExecutionPage }, ...others, routes }}
|
|
|
|
>
|
2023-04-08 10:52:31 +08:00
|
|
|
<SchemaComponentOptions
|
|
|
|
components={{
|
|
|
|
WorkflowTodo,
|
|
|
|
WorkflowTodoBlockInitializer,
|
2023-04-25 13:12:14 +08:00
|
|
|
DynamicExpression,
|
2023-04-08 10:52:31 +08:00
|
|
|
}}
|
|
|
|
scope={{
|
2023-04-25 13:12:14 +08:00
|
|
|
useCollectionDataSource,
|
2023-04-08 10:52:31 +08:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<CollectionManagerContext.Provider
|
|
|
|
value={{
|
|
|
|
...cmCtx,
|
|
|
|
interfaces: {
|
|
|
|
...cmCtx.interfaces,
|
2023-04-25 13:12:14 +08:00
|
|
|
expression: expressionField,
|
|
|
|
},
|
2023-04-08 10:52:31 +08:00
|
|
|
}}
|
|
|
|
>
|
2023-04-25 13:12:14 +08:00
|
|
|
<WorkflowContext.Provider value={{ triggers, instructions }}>{props.children}</WorkflowContext.Provider>
|
2023-04-08 10:52:31 +08:00
|
|
|
</CollectionManagerContext.Provider>
|
2023-02-20 11:52:06 +08:00
|
|
|
</SchemaComponentOptions>
|
2022-09-18 14:10:01 +08:00
|
|
|
</RouteSwitchContext.Provider>
|
|
|
|
</PluginManagerContext.Provider>
|
|
|
|
</SettingsCenterProvider>
|
2022-06-29 17:32:10 +08:00
|
|
|
);
|
|
|
|
};
|