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