2022-06-29 17:32:10 +08:00
|
|
|
import React, { useContext } from 'react';
|
2022-11-11 23:37:41 +08:00
|
|
|
import { PluginManagerContext, RouteSwitchContext, SettingsCenterProvider } from '@nocobase/client';
|
2022-06-29 17:32:10 +08:00
|
|
|
import { WorkflowPage } from './WorkflowPage';
|
2022-09-18 14:10:01 +08:00
|
|
|
import { WorkflowPane, WorkflowShortcut } from './WorkflowShortcut';
|
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';
|
|
|
|
|
|
|
|
export const WorkflowContext = React.createContext({});
|
|
|
|
|
|
|
|
export function useWorkflowContext() {
|
|
|
|
return useContext(WorkflowContext);
|
|
|
|
}
|
2022-06-29 17:32:10 +08:00
|
|
|
|
|
|
|
export const WorkflowProvider = (props) => {
|
|
|
|
const ctx = useContext(PluginManagerContext);
|
|
|
|
const { routes, components, ...others } = useContext(RouteSwitchContext);
|
|
|
|
routes[1].routes.unshift({
|
|
|
|
type: 'route',
|
2022-10-30 11:54:14 +08:00
|
|
|
path: '/admin/settings/workflow/workflows/:id',
|
2022-06-29 17:32:10 +08:00
|
|
|
component: 'WorkflowPage',
|
2022-10-30 11:54:14 +08:00
|
|
|
}, {
|
|
|
|
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: {
|
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
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
2022-10-30 11:54:14 +08:00
|
|
|
<RouteSwitchContext.Provider value={{ components: { ...components, WorkflowPage, ExecutionPage }, ...others, routes }}>
|
2022-11-11 23:37:41 +08:00
|
|
|
<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
|
|
|
);
|
|
|
|
};
|