From 0fb2cc7278c52c9c65b03ad77b670c4a28a592b9 Mon Sep 17 00:00:00 2001
From: Zeke Zhang <958414905@qq.com>
Date: Mon, 29 Jul 2024 15:23:35 +0800
Subject: [PATCH] refactor: make more stable
---
.../src/client/WorkflowManualProvider.tsx | 22 +++++++++----------
.../src/client/WorkflowTodo.tsx | 18 ++++++++++-----
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowManualProvider.tsx b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowManualProvider.tsx
index 7d6ff53e64..d05535c727 100644
--- a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowManualProvider.tsx
+++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowManualProvider.tsx
@@ -11,29 +11,29 @@ import { ExtendCollectionsProvider, storePopupContext } from '@nocobase/client';
import React, { FC } from 'react';
import { getWorkflowTodoViewActionSchema, nodeCollection, todoCollection, workflowCollection } from './WorkflowTodo';
+const collections = [nodeCollection, workflowCollection, todoCollection];
+
/**
* 1. 扩展几个工作流相关的 collection,防止在区块中因找不到 collection 而报错;
* @param props
* @returns
*/
export const WorkflowManualProvider: FC = (props) => {
- return (
-
- {props.children}
-
- );
+ return {props.children};
};
/**
* 2. 将区块相关的按钮 Schema 缓存起来,这样就可以在弹窗中获取到 Schema,进而实现“弹窗 URL”的功能;
*/
-function cacheSchema() {
- const workflowTodoViewActionSchema = getWorkflowTodoViewActionSchema({ defaultOpenMode: 'drawer' });
+function cacheSchema(collectionNameList: string[]) {
+ collectionNameList.forEach((collectionName) => {
+ const workflowTodoViewActionSchema = getWorkflowTodoViewActionSchema({ defaultOpenMode: 'drawer', collectionName });
- storePopupContext(workflowTodoViewActionSchema['x-uid'], {
- schema: workflowTodoViewActionSchema,
- ...workflowTodoViewActionSchema['x-action-context'],
+ storePopupContext(workflowTodoViewActionSchema['x-uid'], {
+ schema: workflowTodoViewActionSchema,
+ ...workflowTodoViewActionSchema['x-action-context'],
+ });
});
}
-cacheSchema();
+cacheSchema(Object.values(collections).map((collection) => collection.name));
diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowTodo.tsx b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowTodo.tsx
index 1208cd7615..ad4ef2b30c 100644
--- a/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowTodo.tsx
+++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/client/WorkflowTodo.tsx
@@ -12,7 +12,14 @@ import { Space, Spin, Tag } from 'antd';
import dayjs from 'dayjs';
import React, { createContext, useContext, useEffect, useState } from 'react';
-import { css, useCollectionRecordData, useCompile, useOpenModeContext, usePlugin } from '@nocobase/client';
+import {
+ css,
+ useCollection,
+ useCollectionRecordData,
+ useCompile,
+ useOpenModeContext,
+ usePlugin,
+} from '@nocobase/client';
import {
SchemaComponent,
@@ -227,6 +234,7 @@ function UserJobStatusColumn(props) {
export const WorkflowTodo: React.FC & { Drawer: React.FC; Decorator: React.FC } = () => {
const { defaultOpenMode } = useOpenModeContext();
+ const collection = useCollection();
return (