mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 11:16:03 +00:00
refactor(plugin-workflow): adjust code (#2663)
This commit is contained in:
parent
3b4cff15b0
commit
0f4959d217
@ -5,7 +5,7 @@ import {
|
||||
SchemaComponentContext,
|
||||
SettingsCenterProvider,
|
||||
} from '@nocobase/client';
|
||||
import { Card, Tooltip } from 'antd';
|
||||
import { Card } from 'antd';
|
||||
import React, { useContext } from 'react';
|
||||
import { ExecutionLink } from './ExecutionLink';
|
||||
import { ExecutionResourceProvider } from './ExecutionResourceProvider';
|
||||
@ -15,7 +15,7 @@ import expressionField from './interfaces/expression';
|
||||
import { lang } from './locale';
|
||||
import { instructions } from './nodes';
|
||||
import { workflowSchema } from './schemas/workflows';
|
||||
import { triggers } from './triggers';
|
||||
import { getTriggersOptions, triggers } from './triggers';
|
||||
import { ExecutionStatusSelect } from './components/ExecutionStatusSelect';
|
||||
|
||||
// registerField(expressionField.group, 'expression', expressionField);
|
||||
@ -34,13 +34,15 @@ function WorkflowPane() {
|
||||
<SchemaComponent
|
||||
schema={workflowSchema}
|
||||
components={{
|
||||
Tooltip,
|
||||
WorkflowLink,
|
||||
ExecutionResourceProvider,
|
||||
ExecutionLink,
|
||||
OpenDrawer,
|
||||
ExecutionStatusSelect,
|
||||
}}
|
||||
scope={{
|
||||
getTriggersOptions,
|
||||
}}
|
||||
/>
|
||||
</SchemaComponentContext.Provider>
|
||||
</Card>
|
||||
|
@ -19,7 +19,7 @@ export class WorkflowPlugin extends Plugin {
|
||||
this.addRoutes();
|
||||
this.addScopes();
|
||||
this.addComponents();
|
||||
this.app.use(WorkflowProvider);
|
||||
this.app.addProvider(WorkflowProvider);
|
||||
}
|
||||
|
||||
addScopes() {
|
||||
|
@ -529,7 +529,9 @@ function FooterStatus() {
|
||||
>
|
||||
{dayjs(updatedAt).format('YYYY-MM-DD HH:mm:ss')}
|
||||
</time>
|
||||
<Tag icon={statusOption.icon} color={statusOption.color}>{compile(statusOption.label)}</Tag>
|
||||
<Tag icon={statusOption.icon} color={statusOption.color}>
|
||||
{compile(statusOption.label)}
|
||||
</Tag>
|
||||
</Space>
|
||||
) : null;
|
||||
}
|
||||
@ -565,7 +567,7 @@ function Drawer() {
|
||||
content: {
|
||||
type: 'void',
|
||||
'x-component': 'FooterStatus',
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -586,7 +588,7 @@ function Decorator({ params = {}, children }) {
|
||||
sort: ['-createdAt'],
|
||||
...params,
|
||||
appends: ['user', 'node', 'workflow'],
|
||||
except: ['node.config', 'workflow.config'],
|
||||
except: ['node.config', 'workflow.config', 'workflow.options'],
|
||||
},
|
||||
rowKey: 'id',
|
||||
showIndex: true,
|
||||
|
@ -104,6 +104,10 @@ function CustomFormBlockInitializer({ insert, ...props }) {
|
||||
'x-component': 'ActionBar',
|
||||
'x-component-props': {
|
||||
layout: 'one-column',
|
||||
style: {
|
||||
marginTop: '1.5em',
|
||||
flexWrap: 'wrap',
|
||||
},
|
||||
},
|
||||
'x-initializer': 'AddActionButton',
|
||||
properties: {
|
||||
|
@ -3,7 +3,7 @@ import { message } from 'antd';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useActionContext, useRecord, useResourceActionContext, useResourceContext } from '@nocobase/client';
|
||||
import { NAMESPACE } from '../locale';
|
||||
import { triggers } from '../triggers';
|
||||
// import { triggers } from '../triggers';
|
||||
import { executionSchema } from './executions';
|
||||
|
||||
const collection = {
|
||||
@ -27,13 +27,11 @@ const collection = {
|
||||
uiSchema: {
|
||||
title: `{{t("Trigger type", { ns: "${NAMESPACE}" })}}`,
|
||||
type: 'string',
|
||||
'x-component': 'Select',
|
||||
'x-decorator': 'FormItem',
|
||||
enum: Array.from(triggers.getEntities()).map(([value, { title }]) => ({
|
||||
value,
|
||||
label: title,
|
||||
color: 'gold',
|
||||
})),
|
||||
'x-component': 'Select',
|
||||
'x-component-props': {
|
||||
options: `{{getTriggersOptions()}}`,
|
||||
},
|
||||
required: true,
|
||||
} as ISchema,
|
||||
},
|
||||
@ -136,7 +134,6 @@ export const workflowSchema: ISchema = {
|
||||
resource: 'workflows',
|
||||
action: 'list',
|
||||
params: {
|
||||
pageSize: 20,
|
||||
filter: {
|
||||
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: {
|
||||
type: 'void',
|
||||
title: '{{t("Delete")}}',
|
||||
|
@ -325,3 +325,11 @@ export function useTrigger() {
|
||||
const { workflow } = useFlowContext();
|
||||
return triggers.get(workflow.type);
|
||||
}
|
||||
|
||||
export function getTriggersOptions() {
|
||||
return Array.from(triggers.getEntities()).map(([value, { title }]) => ({
|
||||
value,
|
||||
label: title,
|
||||
color: 'gold',
|
||||
}));
|
||||
}
|
||||
|
@ -192,13 +192,13 @@ export function useWorkflowVariableOptions(options: OptionsOfUseVariableOptions
|
||||
const opts = Object.assign(options, { fieldNames });
|
||||
const compile = useCompile();
|
||||
const result = [scopeOptions, nodesOptions, triggerOptions, systemOptions].map((item: any) => {
|
||||
const children = item.useOptions(opts).filter(Boolean);
|
||||
const children = item.useOptions?.(opts)?.filter(Boolean);
|
||||
return {
|
||||
[fieldNames.label]: compile(item.label),
|
||||
[fieldNames.value]: item.value,
|
||||
key: item[fieldNames.value],
|
||||
[fieldNames.children]: children,
|
||||
disabled: children && !children.length,
|
||||
disabled: !children || !children.length,
|
||||
};
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user