refactor(plugin-workflow): adjust code (#2663)

This commit is contained in:
Junyi 2023-09-17 11:54:20 +08:00 committed by GitHub
parent 3b4cff15b0
commit 0f4959d217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 38 deletions

View File

@ -5,7 +5,7 @@ import {
SchemaComponentContext, SchemaComponentContext,
SettingsCenterProvider, SettingsCenterProvider,
} from '@nocobase/client'; } from '@nocobase/client';
import { Card, Tooltip } from 'antd'; import { Card } from 'antd';
import React, { useContext } from 'react'; import React, { useContext } from 'react';
import { ExecutionLink } from './ExecutionLink'; import { ExecutionLink } from './ExecutionLink';
import { ExecutionResourceProvider } from './ExecutionResourceProvider'; import { ExecutionResourceProvider } from './ExecutionResourceProvider';
@ -15,7 +15,7 @@ import expressionField from './interfaces/expression';
import { lang } from './locale'; import { lang } from './locale';
import { instructions } from './nodes'; import { instructions } from './nodes';
import { workflowSchema } from './schemas/workflows'; import { workflowSchema } from './schemas/workflows';
import { triggers } from './triggers'; import { getTriggersOptions, triggers } from './triggers';
import { ExecutionStatusSelect } from './components/ExecutionStatusSelect'; import { ExecutionStatusSelect } from './components/ExecutionStatusSelect';
// registerField(expressionField.group, 'expression', expressionField); // registerField(expressionField.group, 'expression', expressionField);
@ -34,13 +34,15 @@ function WorkflowPane() {
<SchemaComponent <SchemaComponent
schema={workflowSchema} schema={workflowSchema}
components={{ components={{
Tooltip,
WorkflowLink, WorkflowLink,
ExecutionResourceProvider, ExecutionResourceProvider,
ExecutionLink, ExecutionLink,
OpenDrawer, OpenDrawer,
ExecutionStatusSelect, ExecutionStatusSelect,
}} }}
scope={{
getTriggersOptions,
}}
/> />
</SchemaComponentContext.Provider> </SchemaComponentContext.Provider>
</Card> </Card>

View File

@ -19,7 +19,7 @@ export class WorkflowPlugin extends Plugin {
this.addRoutes(); this.addRoutes();
this.addScopes(); this.addScopes();
this.addComponents(); this.addComponents();
this.app.use(WorkflowProvider); this.app.addProvider(WorkflowProvider);
} }
addScopes() { addScopes() {

View File

@ -529,7 +529,9 @@ function FooterStatus() {
> >
{dayjs(updatedAt).format('YYYY-MM-DD HH:mm:ss')} {dayjs(updatedAt).format('YYYY-MM-DD HH:mm:ss')}
</time> </time>
<Tag icon={statusOption.icon} color={statusOption.color}>{compile(statusOption.label)}</Tag> <Tag icon={statusOption.icon} color={statusOption.color}>
{compile(statusOption.label)}
</Tag>
</Space> </Space>
) : null; ) : null;
} }
@ -565,7 +567,7 @@ function Drawer() {
content: { content: {
type: 'void', type: 'void',
'x-component': 'FooterStatus', 'x-component': 'FooterStatus',
} },
}, },
}, },
}, },
@ -586,7 +588,7 @@ function Decorator({ params = {}, children }) {
sort: ['-createdAt'], sort: ['-createdAt'],
...params, ...params,
appends: ['user', 'node', 'workflow'], appends: ['user', 'node', 'workflow'],
except: ['node.config', 'workflow.config'], except: ['node.config', 'workflow.config', 'workflow.options'],
}, },
rowKey: 'id', rowKey: 'id',
showIndex: true, showIndex: true,

View File

@ -104,6 +104,10 @@ function CustomFormBlockInitializer({ insert, ...props }) {
'x-component': 'ActionBar', 'x-component': 'ActionBar',
'x-component-props': { 'x-component-props': {
layout: 'one-column', layout: 'one-column',
style: {
marginTop: '1.5em',
flexWrap: 'wrap',
},
}, },
'x-initializer': 'AddActionButton', 'x-initializer': 'AddActionButton',
properties: { properties: {

View File

@ -3,7 +3,7 @@ import { message } from 'antd';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useActionContext, useRecord, useResourceActionContext, useResourceContext } from '@nocobase/client'; import { useActionContext, useRecord, useResourceActionContext, useResourceContext } from '@nocobase/client';
import { NAMESPACE } from '../locale'; import { NAMESPACE } from '../locale';
import { triggers } from '../triggers'; // import { triggers } from '../triggers';
import { executionSchema } from './executions'; import { executionSchema } from './executions';
const collection = { const collection = {
@ -27,13 +27,11 @@ const collection = {
uiSchema: { uiSchema: {
title: `{{t("Trigger type", { ns: "${NAMESPACE}" })}}`, title: `{{t("Trigger type", { ns: "${NAMESPACE}" })}}`,
type: 'string', type: 'string',
'x-component': 'Select',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
enum: Array.from(triggers.getEntities()).map(([value, { title }]) => ({ 'x-component': 'Select',
value, 'x-component-props': {
label: title, options: `{{getTriggersOptions()}}`,
color: 'gold', },
})),
required: true, required: true,
} as ISchema, } as ISchema,
}, },
@ -136,7 +134,6 @@ export const workflowSchema: ISchema = {
resource: 'workflows', resource: 'workflows',
action: 'list', action: 'list',
params: { params: {
pageSize: 20,
filter: { filter: {
current: true, current: true,
}, },
@ -221,27 +218,6 @@ export const workflowSchema: ISchema = {
}, },
}, },
}, },
sync: {
type: 'void',
title: `{{t("Sync", { ns: "${NAMESPACE}" })}}`,
'x-decorator': 'Tooltip',
'x-decorator-props': {
title: `{{ t("Sync enabled status of all workflows from database", { ns: "${NAMESPACE}" }) }}`,
},
'x-component': 'Action',
'x-component-props': {
useAction() {
const { t } = useTranslation();
const { resource } = useResourceContext();
return {
async run() {
await resource.sync();
message.success(t('Operation succeeded'));
},
};
},
},
},
delete: { delete: {
type: 'void', type: 'void',
title: '{{t("Delete")}}', title: '{{t("Delete")}}',

View File

@ -325,3 +325,11 @@ export function useTrigger() {
const { workflow } = useFlowContext(); const { workflow } = useFlowContext();
return triggers.get(workflow.type); return triggers.get(workflow.type);
} }
export function getTriggersOptions() {
return Array.from(triggers.getEntities()).map(([value, { title }]) => ({
value,
label: title,
color: 'gold',
}));
}

View File

@ -192,13 +192,13 @@ export function useWorkflowVariableOptions(options: OptionsOfUseVariableOptions
const opts = Object.assign(options, { fieldNames }); const opts = Object.assign(options, { fieldNames });
const compile = useCompile(); const compile = useCompile();
const result = [scopeOptions, nodesOptions, triggerOptions, systemOptions].map((item: any) => { const result = [scopeOptions, nodesOptions, triggerOptions, systemOptions].map((item: any) => {
const children = item.useOptions(opts).filter(Boolean); const children = item.useOptions?.(opts)?.filter(Boolean);
return { return {
[fieldNames.label]: compile(item.label), [fieldNames.label]: compile(item.label),
[fieldNames.value]: item.value, [fieldNames.value]: item.value,
key: item[fieldNames.value], key: item[fieldNames.value],
[fieldNames.children]: children, [fieldNames.children]: children,
disabled: children && !children.length, disabled: !children || !children.length,
}; };
}); });