mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 14:39:25 +08:00
Merge branch 'next' into develop
This commit is contained in:
commit
0b7e7347c4
@ -8,11 +8,20 @@
|
||||
*/
|
||||
|
||||
import React, { useContext, useEffect } from 'react';
|
||||
import { Card, Tooltip } from 'antd';
|
||||
import { App, Card, Tooltip } from 'antd';
|
||||
import { onFieldChange } from '@formily/core';
|
||||
import { useField, useFormEffects } from '@formily/react';
|
||||
import { useField, useForm, useFormEffects } from '@formily/react';
|
||||
|
||||
import { SchemaComponent, SchemaComponentContext, useApp, usePlugin, useRecord } from '@nocobase/client';
|
||||
import {
|
||||
SchemaComponent,
|
||||
SchemaComponentContext,
|
||||
useActionContext,
|
||||
useApp,
|
||||
usePlugin,
|
||||
useRecord,
|
||||
useResourceActionContext,
|
||||
useResourceContext,
|
||||
} from '@nocobase/client';
|
||||
|
||||
import { ExecutionLink } from './ExecutionLink';
|
||||
import { ExecutionResourceProvider } from './ExecutionResourceProvider';
|
||||
@ -22,6 +31,7 @@ import { workflowSchema } from './schemas/workflows';
|
||||
import { ExecutionStatusSelect, ExecutionStatusColumn } from './components/ExecutionStatus';
|
||||
import WorkflowPlugin, { RadioWithTooltip } from '.';
|
||||
import { useRefreshActionProps } from './hooks/useRefreshActionProps';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
function SyncOptionSelect(props) {
|
||||
const field = useField<any>();
|
||||
@ -59,11 +69,54 @@ function SyncOptionSelect(props) {
|
||||
return <RadioWithTooltip {...props} />;
|
||||
}
|
||||
|
||||
function useWorkflowSyncAction(field) {
|
||||
function useWorkflowSyncReaction(field) {
|
||||
const app = useApp();
|
||||
field.visible = Boolean(usePlugin('multi-app-share-collection') || app.name !== 'main');
|
||||
}
|
||||
|
||||
function useSyncAction() {
|
||||
const { message } = App.useApp();
|
||||
const { t } = useTranslation();
|
||||
const { resource } = useResourceContext();
|
||||
return {
|
||||
async run() {
|
||||
await resource.sync();
|
||||
message.success(t('Operation succeeded'));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function useRevisionAction() {
|
||||
const { message } = App.useApp();
|
||||
const { t } = useTranslation();
|
||||
const { refresh } = useResourceActionContext();
|
||||
const { resource, targetKey } = useResourceContext();
|
||||
const { setVisible } = useActionContext();
|
||||
const { [targetKey]: filterByTk } = useRecord();
|
||||
const form = useForm();
|
||||
const field = useField();
|
||||
|
||||
return {
|
||||
async run() {
|
||||
try {
|
||||
await form.submit();
|
||||
field.data = field.data || {};
|
||||
field.data.loading = true;
|
||||
await resource.revision({ filterByTk, values: form.values });
|
||||
message.success(t('Operation succeeded'));
|
||||
refresh();
|
||||
setVisible(false);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
if (field.data) {
|
||||
field.data.loading = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function WorkflowPane() {
|
||||
const ctx = useContext(SchemaComponentContext);
|
||||
const { useTriggersOptions } = usePlugin(WorkflowPlugin);
|
||||
@ -84,8 +137,10 @@ export function WorkflowPane() {
|
||||
}}
|
||||
scope={{
|
||||
useTriggersOptions,
|
||||
useWorkflowSyncAction,
|
||||
useWorkflowSyncReaction,
|
||||
useSyncAction,
|
||||
useRefreshActionProps,
|
||||
useRevisionAction,
|
||||
}}
|
||||
/>
|
||||
</SchemaComponentContext.Provider>
|
||||
|
@ -8,10 +8,8 @@
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { ISchema, useForm } from '@formily/react';
|
||||
import { useActionContext, useRecord, useResourceActionContext, useResourceContext } from '@nocobase/client';
|
||||
import { message } from 'antd';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ISchema } from '@formily/react';
|
||||
import { useRecord } from '@nocobase/client';
|
||||
import { NAMESPACE } from '../locale';
|
||||
// import { triggers } from '../triggers';
|
||||
import { executionSchema } from './executions';
|
||||
@ -253,20 +251,9 @@ export const workflowSchema: ISchema = {
|
||||
'x-component': 'Action',
|
||||
'x-component-props': {
|
||||
icon: 'SyncOutlined',
|
||||
useAction() {
|
||||
const { t } = useTranslation();
|
||||
const { resource } = useResourceContext();
|
||||
const service = useResourceActionContext();
|
||||
return {
|
||||
async run() {
|
||||
await resource.sync();
|
||||
await service?.refresh();
|
||||
message.success(t('Operation succeeded'));
|
||||
},
|
||||
};
|
||||
},
|
||||
useAction: '{{ useSyncAction }}',
|
||||
},
|
||||
'x-reactions': ['{{useWorkflowSyncAction}}'],
|
||||
'x-reactions': ['{{useWorkflowSyncReaction}}'],
|
||||
},
|
||||
delete: {
|
||||
type: 'void',
|
||||
@ -511,22 +498,7 @@ export const workflowSchema: ISchema = {
|
||||
'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, values });
|
||||
message.success(t('Operation succeeded'));
|
||||
refresh();
|
||||
setVisible(false);
|
||||
},
|
||||
};
|
||||
},
|
||||
useAction: '{{ useRevisionAction }}',
|
||||
},
|
||||
},
|
||||
cancel: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user