mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
refactor(plugin-workflow): change tasks api
This commit is contained in:
parent
3c5ff51472
commit
e7ca77a171
@ -8,3 +8,4 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './List';
|
export * from './List';
|
||||||
|
export { useListBlockContext } from './List.Decorator';
|
||||||
|
@ -33,9 +33,12 @@ import {
|
|||||||
useActionContext,
|
useActionContext,
|
||||||
useCurrentUserContext,
|
useCurrentUserContext,
|
||||||
useFormBlockContext,
|
useFormBlockContext,
|
||||||
useTableBlockContext,
|
useListBlockContext,
|
||||||
List,
|
List,
|
||||||
OpenModeProvider,
|
OpenModeProvider,
|
||||||
|
ActionContextProvider,
|
||||||
|
useRequest,
|
||||||
|
CollectionRecordProvider,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import WorkflowPlugin, {
|
import WorkflowPlugin, {
|
||||||
DetailsBlockProvider,
|
DetailsBlockProvider,
|
||||||
@ -46,12 +49,14 @@ import WorkflowPlugin, {
|
|||||||
EXECUTION_STATUS,
|
EXECUTION_STATUS,
|
||||||
JOB_STATUS,
|
JOB_STATUS,
|
||||||
WorkflowTitle,
|
WorkflowTitle,
|
||||||
|
TASK_STATUS,
|
||||||
} from '@nocobase/plugin-workflow/client';
|
} from '@nocobase/plugin-workflow/client';
|
||||||
|
|
||||||
import { NAMESPACE, useLang } from '../locale';
|
import { NAMESPACE, useLang } from '../locale';
|
||||||
import { FormBlockProvider } from './instruction/FormBlockProvider';
|
import { FormBlockProvider } from './instruction/FormBlockProvider';
|
||||||
import { ManualFormType, manualFormTypes } from './instruction/SchemaConfig';
|
import { ManualFormType, manualFormTypes } from './instruction/SchemaConfig';
|
||||||
import { TaskStatusOptionsMap } from '../common/constants';
|
import { TaskStatusOptionsMap } from '../common/constants';
|
||||||
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
|
|
||||||
function TaskStatusColumn(props) {
|
function TaskStatusColumn(props) {
|
||||||
const recordData = useCollectionRecordData();
|
const recordData = useCollectionRecordData();
|
||||||
@ -291,11 +296,12 @@ function useSubmit() {
|
|||||||
const { values, submit } = useForm();
|
const { values, submit } = useForm();
|
||||||
const field = useField();
|
const field = useField();
|
||||||
const buttonSchema = useFieldSchema();
|
const buttonSchema = useFieldSchema();
|
||||||
const { service } = useTableBlockContext();
|
const { service } = useListBlockContext();
|
||||||
const { userJob, execution } = useFlowContext();
|
const { userJob, execution } = useFlowContext();
|
||||||
const { name: actionKey } = buttonSchema;
|
const { name: actionKey } = buttonSchema;
|
||||||
const { name: formKey } = buttonSchema.parent.parent;
|
const { name: formKey } = buttonSchema.parent.parent;
|
||||||
const { assignedValues = {} } = buttonSchema?.['x-action-settings'] ?? {};
|
const { assignedValues = {} } = buttonSchema?.['x-action-settings'] ?? {};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
async run() {
|
async run() {
|
||||||
if (execution.status || userJob.status) {
|
if (execution.status || userJob.status) {
|
||||||
@ -611,57 +617,35 @@ function ContentDetailWithTitle(props) {
|
|||||||
|
|
||||||
function TaskItem() {
|
function TaskItem() {
|
||||||
const token = useAntdToken();
|
const token = useAntdToken();
|
||||||
const [visible, setVisible] = useState(false);
|
|
||||||
const record = useCollectionRecordData();
|
const record = useCollectionRecordData();
|
||||||
const { t } = useTranslation();
|
const navigate = useNavigate();
|
||||||
// const { defaultOpenMode } = useOpenModeContext();
|
const onOpen = useCallback(
|
||||||
// const { openPopup } = usePopupUtils();
|
(e: React.MouseEvent) => {
|
||||||
// const { isPopupVisibleControlledByURL } = usePopupSettings();
|
const targetElement = e.target as Element; // 将事件目标转换为Element类型
|
||||||
const onOpen = useCallback((e: React.MouseEvent) => {
|
const currentTargetElement = e.currentTarget as Element;
|
||||||
const targetElement = e.target as Element; // 将事件目标转换为Element类型
|
if (currentTargetElement.contains(targetElement)) {
|
||||||
const currentTargetElement = e.currentTarget as Element;
|
navigate(`./${record.id}`);
|
||||||
if (currentTargetElement.contains(targetElement)) {
|
}
|
||||||
setVisible(true);
|
e.stopPropagation();
|
||||||
// if (!isPopupVisibleControlledByURL()) {
|
},
|
||||||
// } else {
|
[navigate, record.id],
|
||||||
// openPopup({
|
);
|
||||||
// // popupUidUsedInURL: 'job',
|
|
||||||
// customActionSchema: {
|
|
||||||
// type: 'void',
|
|
||||||
// 'x-uid': 'job-view',
|
|
||||||
// 'x-action-context': {
|
|
||||||
// dataSource: 'main',
|
|
||||||
// collection: 'workflowManualTasks',
|
|
||||||
// doNotUpdateContext: true,
|
|
||||||
// },
|
|
||||||
// properties: {},
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
e.stopPropagation();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Card
|
||||||
<Card
|
onClick={onOpen}
|
||||||
onClick={onOpen}
|
hoverable
|
||||||
hoverable
|
size="small"
|
||||||
size="small"
|
title={record.title}
|
||||||
title={record.title}
|
extra={<WorkflowTitle {...record.workflow} />}
|
||||||
extra={<WorkflowTitle {...record.workflow} />}
|
className={css`
|
||||||
className={css`
|
.ant-card-extra {
|
||||||
.ant-card-extra {
|
color: ${token.colorTextDescription};
|
||||||
color: ${token.colorTextDescription};
|
}
|
||||||
}
|
`}
|
||||||
`}
|
>
|
||||||
>
|
<ContentDetail />
|
||||||
<ContentDetail />
|
</Card>
|
||||||
</Card>
|
|
||||||
<PopupContextProvider visible={visible} setVisible={setVisible} openMode="modal">
|
|
||||||
<Drawer />
|
|
||||||
</PopupContextProvider>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -734,7 +718,9 @@ function TodoExtraActions() {
|
|||||||
export const manualTodo = {
|
export const manualTodo = {
|
||||||
title: `{{t("My manual tasks", { ns: "${NAMESPACE}" })}}`,
|
title: `{{t("My manual tasks", { ns: "${NAMESPACE}" })}}`,
|
||||||
collection: 'workflowManualTasks',
|
collection: 'workflowManualTasks',
|
||||||
|
action: 'listMine',
|
||||||
useActionParams: useTodoActionParams,
|
useActionParams: useTodoActionParams,
|
||||||
component: TaskItem,
|
Actions: TodoExtraActions,
|
||||||
extraActions: TodoExtraActions,
|
Item: TaskItem,
|
||||||
|
Detail: Drawer,
|
||||||
};
|
};
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Context, utils } from '@nocobase/actions';
|
import actions, { Context, utils } from '@nocobase/actions';
|
||||||
import WorkflowPlugin, { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
|
import WorkflowPlugin, { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
|
||||||
|
|
||||||
import ManualInstruction from './ManualInstruction';
|
import ManualInstruction from './ManualInstruction';
|
||||||
@ -111,3 +111,24 @@ export async function submit(context: Context, next) {
|
|||||||
|
|
||||||
plugin.resume(task.job);
|
plugin.resume(task.job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function listMine(context, next) {
|
||||||
|
context.action.mergeParams({
|
||||||
|
filter: {
|
||||||
|
userId: context.state.currentUser.id,
|
||||||
|
$or: [
|
||||||
|
{
|
||||||
|
'workflow.enabled': true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'workflow.enabled': false,
|
||||||
|
status: {
|
||||||
|
$ne: JOB_STATUS.PENDING,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return actions.list(context, next);
|
||||||
|
}
|
||||||
|
@ -14,6 +14,8 @@ import React, { createContext, useCallback, useContext, useEffect, useMemo, useS
|
|||||||
import { Link, Outlet, useNavigate, useParams } from 'react-router-dom';
|
import { Link, Outlet, useNavigate, useParams } from 'react-router-dom';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
ActionContextProvider,
|
||||||
|
CollectionRecordProvider,
|
||||||
css,
|
css,
|
||||||
PinnedPluginListProvider,
|
PinnedPluginListProvider,
|
||||||
SchemaComponent,
|
SchemaComponent,
|
||||||
@ -58,9 +60,11 @@ const contentClass = css`
|
|||||||
export interface TaskTypeOptions {
|
export interface TaskTypeOptions {
|
||||||
title: string;
|
title: string;
|
||||||
collection: string;
|
collection: string;
|
||||||
|
action: string;
|
||||||
useActionParams: Function;
|
useActionParams: Function;
|
||||||
component: React.ComponentType;
|
Actions?: React.ComponentType;
|
||||||
extraActions?: React.ComponentType;
|
Item: React.ComponentType;
|
||||||
|
Detail: React.ComponentType;
|
||||||
// children?: TaskTypeOptions[];
|
// children?: TaskTypeOptions[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +83,7 @@ function MenuLink({ type }: any) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
to={`/admin/workflow/tasks/${type}`}
|
to={`/admin/workflow/tasks/${type}/${TASK_STATUS.PENDING}`}
|
||||||
className={css`
|
className={css`
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@ -99,7 +103,7 @@ function MenuLink({ type }: any) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TASK_STATUS = {
|
export const TASK_STATUS = {
|
||||||
ALL: 'all',
|
ALL: 'all',
|
||||||
PENDING: 'pending',
|
PENDING: 'pending',
|
||||||
COMPLETED: 'completed',
|
COMPLETED: 'completed',
|
||||||
@ -109,7 +113,7 @@ function StatusTabs() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { taskType, status = TASK_STATUS.PENDING } = useParams();
|
const { taskType, status = TASK_STATUS.PENDING } = useParams();
|
||||||
const type = useCurrentTaskType();
|
const type = useCurrentTaskType();
|
||||||
const { extraActions: ExtraActions } = type;
|
const { Actions } = type;
|
||||||
return (
|
return (
|
||||||
<Tabs
|
<Tabs
|
||||||
activeKey={status}
|
activeKey={status}
|
||||||
@ -136,9 +140,9 @@ function StatusTabs() {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
tabBarExtraContent={
|
tabBarExtraContent={
|
||||||
ExtraActions
|
Actions
|
||||||
? {
|
? {
|
||||||
right: <ExtraActions />,
|
right: <Actions />,
|
||||||
}
|
}
|
||||||
: {}
|
: {}
|
||||||
}
|
}
|
||||||
@ -171,18 +175,36 @@ function useCurrentTaskType() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function PopupContext(props: any) {
|
||||||
|
const { popupId } = useParams();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
return (
|
||||||
|
<ActionContextProvider
|
||||||
|
visible={Boolean(popupId)}
|
||||||
|
setVisible={(visible) => {
|
||||||
|
if (!visible) {
|
||||||
|
navigate(-1);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
openMode="modal"
|
||||||
|
>
|
||||||
|
<CollectionRecordProvider record={{ id: popupId }}>{props.children}</CollectionRecordProvider>
|
||||||
|
</ActionContextProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function WorkflowTasks() {
|
export function WorkflowTasks() {
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const { setTitle } = useDocumentTitle();
|
const { setTitle } = useDocumentTitle();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { taskType, status = TASK_STATUS.PENDING } = useParams();
|
const { taskType, status = TASK_STATUS.PENDING, popupId } = useParams();
|
||||||
const {
|
const {
|
||||||
token: { colorBgContainer },
|
token: { colorBgContainer },
|
||||||
} = useToken();
|
} = useToken();
|
||||||
|
|
||||||
const items = useTaskTypeItems();
|
const items = useTaskTypeItems();
|
||||||
|
|
||||||
const { title, collection, useActionParams, component: Component } = useCurrentTaskType();
|
const { title, collection, action = 'list', useActionParams, Item, Detail } = useCurrentTaskType();
|
||||||
|
|
||||||
const params = useActionParams(status);
|
const params = useActionParams(status);
|
||||||
|
|
||||||
@ -234,7 +256,7 @@ export function WorkflowTasks() {
|
|||||||
'x-decorator': 'List.Decorator',
|
'x-decorator': 'List.Decorator',
|
||||||
'x-decorator-props': {
|
'x-decorator-props': {
|
||||||
collection,
|
collection,
|
||||||
action: 'list',
|
action,
|
||||||
params: {
|
params: {
|
||||||
pageSize: 20,
|
pageSize: 20,
|
||||||
sort: ['-createdAt'],
|
sort: ['-createdAt'],
|
||||||
@ -284,17 +306,21 @@ export function WorkflowTasks() {
|
|||||||
item: {
|
item: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
'x-decorator': 'List.Item',
|
'x-decorator': 'List.Item',
|
||||||
'x-component': Component,
|
'x-component': Item,
|
||||||
'x-read-pretty': true,
|
'x-read-pretty': true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
popup: {
|
||||||
|
type: 'void',
|
||||||
|
'x-decorator': PopupContext,
|
||||||
|
'x-component': Detail,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Outlet />
|
|
||||||
</SchemaComponentContext.Provider>
|
</SchemaComponentContext.Provider>
|
||||||
</Layout>
|
</Layout>
|
||||||
</Layout>
|
</Layout>
|
||||||
@ -309,7 +335,7 @@ function WorkflowTasksLink() {
|
|||||||
return types.length ? (
|
return types.length ? (
|
||||||
<Tooltip title={lang('Workflow todos')}>
|
<Tooltip title={lang('Workflow todos')}>
|
||||||
<Button>
|
<Button>
|
||||||
<Link to={`/admin/workflow/tasks/${types[0]}`} onClick={reload}>
|
<Link to={`/admin/workflow/tasks/${types[0]}/${TASK_STATUS.PENDING}`} onClick={reload}>
|
||||||
<Badge count={total} size="small">
|
<Badge count={total} size="small">
|
||||||
<CheckCircleOutlined />
|
<CheckCircleOutlined />
|
||||||
</Badge>
|
</Badge>
|
||||||
@ -370,7 +396,7 @@ function TasksCountsProvider(props: any) {
|
|||||||
return <TasksCountsContext.Provider value={{ reload, total, counts }}>{props.children}</TasksCountsContext.Provider>;
|
return <TasksCountsContext.Provider value={{ reload, total, counts }}>{props.children}</TasksCountsContext.Provider>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TasksProvider = (props: any) => {
|
export function TasksProvider(props: any) {
|
||||||
const isLoggedIn = useIsLoggedIn();
|
const isLoggedIn = useIsLoggedIn();
|
||||||
|
|
||||||
const content = (
|
const content = (
|
||||||
@ -390,4 +416,4 @@ export const TasksProvider = (props: any) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return isLoggedIn ? <TasksCountsProvider>{content}</TasksCountsProvider> : content;
|
return isLoggedIn ? <TasksCountsProvider>{content}</TasksCountsProvider> : content;
|
||||||
};
|
}
|
||||||
|
@ -120,15 +120,10 @@ export default class PluginWorkflowClient extends Plugin {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.router.add('admin.workflow.tasks', {
|
this.router.add('admin.workflow.tasks', {
|
||||||
path: '/admin/workflow/tasks/:taskType/:status?',
|
path: '/admin/workflow/tasks/:taskType/:status/:popupId?',
|
||||||
Component: WorkflowTasks,
|
Component: WorkflowTasks,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.router.add('admin.workflow.tasks.popup', {
|
|
||||||
path: '/admin/workflow/tasks/:taskType/:status/popups/*',
|
|
||||||
Component: PagePopups,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.app.pluginSettingsManager.add(NAMESPACE, {
|
this.app.pluginSettingsManager.add(NAMESPACE, {
|
||||||
icon: 'PartitionOutlined',
|
icon: 'PartitionOutlined',
|
||||||
title: `{{t("Workflow", { ns: "${NAMESPACE}" })}}`,
|
title: `{{t("Workflow", { ns: "${NAMESPACE}" })}}`,
|
||||||
@ -193,3 +188,4 @@ export { default as useStyles } from './style';
|
|||||||
export { Trigger, useTrigger } from './triggers';
|
export { Trigger, useTrigger } from './triggers';
|
||||||
export * from './utils';
|
export * from './utils';
|
||||||
export * from './variable';
|
export * from './variable';
|
||||||
|
export { TASK_STATUS } from './WorkflowTasks';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user