fix(workflow): merge workflow providers

This commit is contained in:
chenos 2022-06-29 17:32:10 +08:00
parent 0348392037
commit 008a7f7f33
4 changed files with 32 additions and 17 deletions

View File

@ -47,7 +47,6 @@ export class Application {
plugins: PluginCallback[] = [];
constructor(options: ApplicationOptions) {
const { WorkflowPage, WorkflowRouteProvider, WorkflowShortcut } = require('../workflow');
this.apiClient = new APIClient({
baseURL: process.env.API_BASE_URL,
headers: {
@ -66,7 +65,6 @@ export class Application {
RouteSchemaComponent,
SigninPage,
SignupPage,
WorkflowPage,
BlockTemplatePage,
BlockTemplateDetails,
},
@ -77,7 +75,6 @@ export class Application {
ACLShortcut,
DesignableSwitch,
CollectionManagerShortcut,
WorkflowShortcut,
SystemSettingsShortcut,
SchemaTemplateShortcut,
FileStorageShortcut,
@ -93,7 +90,7 @@ export class Application {
this.use(AntdSchemaComponentProvider);
this.use(ACLProvider);
this.use(RemoteDocumentTitleProvider);
this.use(WorkflowRouteProvider);
this.use(require('../workflow').WorkflowProvider);
for (const plugin of options.plugins) {
const [component, props] = Array.isArray(plugin) ? plugin : [plugin];
this.use(component, props);

View File

@ -0,0 +1,29 @@
import React, { useContext } from 'react';
import { PluginManagerContext } from '../plugin-manager';
import { RouteSwitchContext } from '../route-switch';
import { WorkflowPage } from './WorkflowPage';
import { WorkflowShortcut } from './WorkflowShortcut';
export const WorkflowProvider = (props) => {
const ctx = useContext(PluginManagerContext);
const { routes, components, ...others } = useContext(RouteSwitchContext);
routes[1].routes.unshift({
type: 'route',
path: '/admin/plugins/workflows/:id',
component: 'WorkflowPage',
});
return (
<PluginManagerContext.Provider
value={{
components: {
...ctx?.components,
WorkflowShortcut,
},
}}
>
<RouteSwitchContext.Provider value={{ components: { ...components, WorkflowPage }, ...others, routes }}>
{props.children}
</RouteSwitchContext.Provider>
</PluginManagerContext.Provider>
);
};

View File

@ -1,12 +0,0 @@
import React, { useContext } from 'react';
import { RouteSwitchContext } from '../route-switch';
export const WorkflowRouteProvider = (props) => {
const { routes, ...others } = useContext(RouteSwitchContext);
routes[1].routes.unshift({
type: 'route',
path: '/admin/plugins/workflows/:id',
component: 'WorkflowPage',
});
return <RouteSwitchContext.Provider value={{ ...others, routes }}>{props.children}</RouteSwitchContext.Provider>;
};

View File

@ -1,5 +1,6 @@
export * from './ExecutionResourceProvider';
export * from './WorkflowLink';
export * from './WorkflowPage';
export * from './WorkflowRouteProvider';
export * from './WorkflowProvider';
export * from './WorkflowShortcut';