feat(plugin-workflow): add modal to edit title when duplicating workflow (#2399)
This commit is contained in:
parent
8615804b6f
commit
d693aad89b
@ -59,10 +59,6 @@ export const ActionModal: ComposedActionDrawer<ModalProps> = observer(
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
.ant-btn {
|
|
||||||
margin-right: 8px;
|
|
||||||
}
|
|
||||||
`}
|
`}
|
||||||
>
|
>
|
||||||
<RecursionField
|
<RecursionField
|
||||||
|
@ -3,9 +3,8 @@ import {
|
|||||||
PluginManagerContext,
|
PluginManagerContext,
|
||||||
SchemaComponent,
|
SchemaComponent,
|
||||||
SettingsCenterProvider,
|
SettingsCenterProvider,
|
||||||
useResourceContext,
|
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import { Card, message } 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';
|
||||||
@ -16,7 +15,6 @@ 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 { triggers } from './triggers';
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
|
|
||||||
// registerField(expressionField.group, 'expression', expressionField);
|
// registerField(expressionField.group, 'expression', expressionField);
|
||||||
|
|
||||||
@ -26,25 +24,11 @@ export function useWorkflowContext() {
|
|||||||
return useContext(WorkflowContext);
|
return useContext(WorkflowContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
function useWorkflowReloadAction() {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const { resource } = useResourceContext();
|
|
||||||
return {
|
|
||||||
async run() {
|
|
||||||
await resource.reload();
|
|
||||||
message.success(t('Operation succeeded'));
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function WorkflowPane() {
|
function WorkflowPane() {
|
||||||
return (
|
return (
|
||||||
<Card bordered={false}>
|
<Card bordered={false}>
|
||||||
<SchemaComponent
|
<SchemaComponent
|
||||||
schema={workflowSchema}
|
schema={workflowSchema}
|
||||||
scope={{
|
|
||||||
useWorkflowReloadAction,
|
|
||||||
}}
|
|
||||||
components={{
|
components={{
|
||||||
WorkflowLink,
|
WorkflowLink,
|
||||||
ExecutionResourceProvider,
|
ExecutionResourceProvider,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ISchema } from '@formily/react';
|
import { ISchema, useForm } from '@formily/react';
|
||||||
import { message } from 'antd';
|
import { message } from 'antd';
|
||||||
import { useTranslation } from 'react-i18next';
|
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 { NAMESPACE } from '../locale';
|
||||||
import { triggers } from '../triggers';
|
import { triggers } from '../triggers';
|
||||||
import { executionSchema } from './executions';
|
import { executionSchema } from './executions';
|
||||||
@ -174,7 +174,16 @@ export const workflowSchema: ISchema = {
|
|||||||
title: `{{t("Reload", { ns: "${NAMESPACE}" })}}`,
|
title: `{{t("Reload", { ns: "${NAMESPACE}" })}}`,
|
||||||
'x-component': 'Action',
|
'x-component': 'Action',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
useAction: '{{ useWorkflowReloadAction }}',
|
useAction() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { resource } = useResourceContext();
|
||||||
|
return {
|
||||||
|
async run() {
|
||||||
|
await resource.reload();
|
||||||
|
message.success(t('Operation succeeded'));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
delete: {
|
delete: {
|
||||||
@ -333,21 +342,63 @@ export const workflowSchema: ISchema = {
|
|||||||
title: `{{t("Duplicate", { ns: "${NAMESPACE}" })}}`,
|
title: `{{t("Duplicate", { ns: "${NAMESPACE}" })}}`,
|
||||||
'x-component': 'Action.Link',
|
'x-component': 'Action.Link',
|
||||||
'x-component-props': {
|
'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() {
|
useAction() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { refresh } = useResourceActionContext();
|
const { refresh } = useResourceActionContext();
|
||||||
const { resource, targetKey } = useResourceContext();
|
const { resource, targetKey } = useResourceContext();
|
||||||
|
const { setVisible } = useActionContext();
|
||||||
const { [targetKey]: filterByTk } = useRecord();
|
const { [targetKey]: filterByTk } = useRecord();
|
||||||
|
const { values } = useForm();
|
||||||
return {
|
return {
|
||||||
async run() {
|
async run() {
|
||||||
await resource.revision({ filterByTk });
|
await resource.revision({ filterByTk, values });
|
||||||
message.success(t('Operation succeeded'));
|
message.success(t('Operation succeeded'));
|
||||||
refresh();
|
refresh();
|
||||||
|
setVisible(false);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
cancel: {
|
||||||
|
type: 'void',
|
||||||
|
title: '{{t("Cancel")}}',
|
||||||
|
'x-component': 'Action',
|
||||||
|
'x-component-props': {
|
||||||
|
useAction: '{{ cm.useCancelAction }}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
// delete: {
|
// delete: {
|
||||||
// type: 'void',
|
// type: 'void',
|
||||||
// title: '{{ t("Delete") }}',
|
// title: '{{ t("Delete") }}',
|
||||||
|
@ -10,6 +10,7 @@ export default {
|
|||||||
Version: '版本',
|
Version: '版本',
|
||||||
'Copy to new version': '复制到新版本',
|
'Copy to new version': '复制到新版本',
|
||||||
Duplicate: '复制',
|
Duplicate: '复制',
|
||||||
|
'Duplicate to new workflow': '复制为新工作流',
|
||||||
'Delete a main version will cause all other revisions to be deleted too.': '删除主版本将导致其他版本一并被删除。',
|
'Delete a main version will cause all other revisions to be deleted too.': '删除主版本将导致其他版本一并被删除。',
|
||||||
Loading: '加载中',
|
Loading: '加载中',
|
||||||
'Load failed': '加载失败',
|
'Load failed': '加载失败',
|
||||||
|
@ -98,7 +98,7 @@ function migrateConfig(config, oldToNew) {
|
|||||||
export async function revision(context: Context, next) {
|
export async function revision(context: Context, next) {
|
||||||
const { db } = context;
|
const { db } = context;
|
||||||
const repository = utils.getRepositoryFromParams(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) => {
|
context.body = await db.sequelize.transaction(async (transaction) => {
|
||||||
const origin = await repository.findOne({
|
const origin = await repository.findOne({
|
||||||
@ -115,7 +115,7 @@ export async function revision(context: Context, next) {
|
|||||||
title: origin.title,
|
title: origin.title,
|
||||||
allExecuted: origin.allExecuted,
|
allExecuted: origin.allExecuted,
|
||||||
}
|
}
|
||||||
: {};
|
: values;
|
||||||
|
|
||||||
const instance = await repository.create({
|
const instance = await repository.create({
|
||||||
values: {
|
values: {
|
||||||
|
Loading…
Reference in New Issue
Block a user