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';
|
|
|
|
import { PluginManagerContext, RouteSwitchContext, SchemaComponent, SettingsCenterProvider } from '@nocobase/client';
|
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';
|
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,
|
|
|
|
OpenDrawer
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-06-29 17:32:10 +08:00
|
|
|
export const WorkflowProvider = (props) => {
|
|
|
|
const ctx = useContext(PluginManagerContext);
|
|
|
|
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: {
|
|
|
|
...ctx?.components,
|
2022-11-11 23:37:41 +08:00
|
|
|
// WorkflowShortcut,
|
2022-09-18 14:10:01 +08:00
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
2023-01-09 07:35:48 +08:00
|
|
|
<RouteSwitchContext.Provider
|
|
|
|
value={{ components: { ...components, WorkflowPage, ExecutionPage }, ...others, routes }}
|
|
|
|
>
|
|
|
|
<WorkflowContext.Provider value={{ triggers, instructions }}>{props.children}</WorkflowContext.Provider>
|
2022-09-18 14:10:01 +08:00
|
|
|
</RouteSwitchContext.Provider>
|
|
|
|
</PluginManagerContext.Provider>
|
|
|
|
</SettingsCenterProvider>
|
2022-06-29 17:32:10 +08:00
|
|
|
);
|
|
|
|
};
|