feat(plugin-workflow): add modal to edit title when duplicating workflow (#2399)

This commit is contained in:
Junyi 2023-08-05 08:08:18 +07:00 committed by GitHub
parent 8615804b6f
commit d693aad89b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 37 deletions

View File

@ -59,10 +59,6 @@ export const ActionModal: ComposedActionDrawer<ModalProps> = observer(
display: flex;
justify-content: flex-end;
width: 100%;
.ant-btn {
margin-right: 8px;
}
`}
>
<RecursionField

View File

@ -3,9 +3,8 @@ import {
PluginManagerContext,
SchemaComponent,
SettingsCenterProvider,
useResourceContext,
} from '@nocobase/client';
import { Card, message } from 'antd';
import { Card } from 'antd';
import React, { useContext } from 'react';
import { ExecutionLink } from './ExecutionLink';
import { ExecutionResourceProvider } from './ExecutionResourceProvider';
@ -16,7 +15,6 @@ import { lang } from './locale';
import { instructions } from './nodes';
import { workflowSchema } from './schemas/workflows';
import { triggers } from './triggers';
import { useTranslation } from 'react-i18next';
// registerField(expressionField.group, 'expression', expressionField);
@ -26,25 +24,11 @@ export function useWorkflowContext() {
return useContext(WorkflowContext);
}
function useWorkflowReloadAction() {
const { t } = useTranslation();
const { resource } = useResourceContext();
return {
async run() {
await resource.reload();
message.success(t('Operation succeeded'));
},
};
}
function WorkflowPane() {
return (
<Card bordered={false}>
<SchemaComponent
schema={workflowSchema}
scope={{
useWorkflowReloadAction,
}}
components={{
WorkflowLink,
ExecutionResourceProvider,

View File

@ -1,7 +1,7 @@
import { ISchema } from '@formily/react';
import { ISchema, useForm } from '@formily/react';
import { message } from 'antd';
import { useTranslation } from 'react-i18next';
import { useRecord, useResourceActionContext, useResourceContext } from '@nocobase/client';
import { useActionContext, useRecord, useResourceActionContext, useResourceContext } from '@nocobase/client';
import { NAMESPACE } from '../locale';
import { triggers } from '../triggers';
import { executionSchema } from './executions';
@ -174,7 +174,16 @@ export const workflowSchema: ISchema = {
title: `{{t("Reload", { ns: "${NAMESPACE}" })}}`,
'x-component': 'Action',
'x-component-props': {
useAction: '{{ useWorkflowReloadAction }}',
useAction() {
const { t } = useTranslation();
const { resource } = useResourceContext();
return {
async run() {
await resource.reload();
message.success(t('Operation succeeded'));
},
};
},
},
},
delete: {
@ -333,21 +342,63 @@ export const workflowSchema: ISchema = {
title: `{{t("Duplicate", { ns: "${NAMESPACE}" })}}`,
'x-component': 'Action.Link',
'x-component-props': {
openSize: 'small',
},
properties: {
modal: {
type: 'void',
title: `{{t("Duplicate to new workflow", { ns: "${NAMESPACE}" })}}`,
'x-decorator': 'FormV2',
'x-component': 'Action.Modal',
properties: {
title: {
type: 'string',
title: '{{t("Title")}}',
'x-decorator': 'FormItem',
'x-component': 'Input',
},
footer: {
type: 'void',
'x-component': 'Action.Modal.Footer',
properties: {
submit: {
type: 'void',
title: '{{t("Submit")}}',
'x-component': 'Action',
'x-component-props': {
type: 'primary',
useAction() {
const { t } = useTranslation();
const { refresh } = useResourceActionContext();
const { resource, targetKey } = useResourceContext();
const { setVisible } = useActionContext();
const { [targetKey]: filterByTk } = useRecord();
const { values } = useForm();
return {
async run() {
await resource.revision({ filterByTk });
await resource.revision({ filterByTk, values });
message.success(t('Operation succeeded'));
refresh();
setVisible(false);
},
};
},
},
},
cancel: {
type: 'void',
title: '{{t("Cancel")}}',
'x-component': 'Action',
'x-component-props': {
useAction: '{{ cm.useCancelAction }}',
},
},
},
},
},
},
},
},
// delete: {
// type: 'void',
// title: '{{ t("Delete") }}',

View File

@ -10,6 +10,7 @@ export default {
Version: '版本',
'Copy to new version': '复制到新版本',
Duplicate: '复制',
'Duplicate to new workflow': '复制为新工作流',
'Delete a main version will cause all other revisions to be deleted too.': '删除主版本将导致其他版本一并被删除。',
Loading: '加载中',
'Load failed': '加载失败',

View File

@ -98,7 +98,7 @@ function migrateConfig(config, oldToNew) {
export async function revision(context: Context, next) {
const { db } = context;
const repository = utils.getRepositoryFromParams(context);
const { filterByTk, filter = {} } = context.action.params;
const { filterByTk, filter = {}, values = {} } = context.action.params;
context.body = await db.sequelize.transaction(async (transaction) => {
const origin = await repository.findOne({
@ -115,7 +115,7 @@ export async function revision(context: Context, next) {
title: origin.title,
allExecuted: origin.allExecuted,
}
: {};
: values;
const instance = await repository.create({
values: {