refactor: make more stable

This commit is contained in:
Zeke Zhang 2024-07-29 15:23:35 +08:00
parent 9d6d18ad8a
commit 0fb2cc7278
2 changed files with 24 additions and 16 deletions

View File

@ -11,29 +11,29 @@ import { ExtendCollectionsProvider, storePopupContext } from '@nocobase/client';
import React, { FC } from 'react'; import React, { FC } from 'react';
import { getWorkflowTodoViewActionSchema, nodeCollection, todoCollection, workflowCollection } from './WorkflowTodo'; import { getWorkflowTodoViewActionSchema, nodeCollection, todoCollection, workflowCollection } from './WorkflowTodo';
const collections = [nodeCollection, workflowCollection, todoCollection];
/** /**
* 1. collection collection * 1. collection collection
* @param props * @param props
* @returns * @returns
*/ */
export const WorkflowManualProvider: FC = (props) => { export const WorkflowManualProvider: FC = (props) => {
return ( return <ExtendCollectionsProvider collections={collections}>{props.children}</ExtendCollectionsProvider>;
<ExtendCollectionsProvider collections={[nodeCollection, workflowCollection, todoCollection]}>
{props.children}
</ExtendCollectionsProvider>
);
}; };
/** /**
* 2. Schema Schema URL * 2. Schema Schema URL
*/ */
function cacheSchema() { function cacheSchema(collectionNameList: string[]) {
const workflowTodoViewActionSchema = getWorkflowTodoViewActionSchema({ defaultOpenMode: 'drawer' }); collectionNameList.forEach((collectionName) => {
const workflowTodoViewActionSchema = getWorkflowTodoViewActionSchema({ defaultOpenMode: 'drawer', collectionName });
storePopupContext(workflowTodoViewActionSchema['x-uid'], { storePopupContext(workflowTodoViewActionSchema['x-uid'], {
schema: workflowTodoViewActionSchema, schema: workflowTodoViewActionSchema,
...workflowTodoViewActionSchema['x-action-context'], ...workflowTodoViewActionSchema['x-action-context'],
}); });
});
} }
cacheSchema(); cacheSchema(Object.values(collections).map((collection) => collection.name));

View File

@ -12,7 +12,14 @@ import { Space, Spin, Tag } from 'antd';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import React, { createContext, useContext, useEffect, useState } from 'react'; 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 { import {
SchemaComponent, SchemaComponent,
@ -227,6 +234,7 @@ function UserJobStatusColumn(props) {
export const WorkflowTodo: React.FC & { Drawer: React.FC; Decorator: React.FC } = () => { export const WorkflowTodo: React.FC & { Drawer: React.FC; Decorator: React.FC } = () => {
const { defaultOpenMode } = useOpenModeContext(); const { defaultOpenMode } = useOpenModeContext();
const collection = useCollection();
return ( return (
<SchemaComponent <SchemaComponent
@ -293,7 +301,7 @@ export const WorkflowTodo: React.FC & { Drawer: React.FC; Decorator: React.FC }
}, },
title: '{{t("Actions")}}', title: '{{t("Actions")}}',
properties: { properties: {
view: getWorkflowTodoViewActionSchema({ defaultOpenMode }), view: getWorkflowTodoViewActionSchema({ defaultOpenMode, collectionName: collection.name }),
}, },
}, },
node: { node: {
@ -381,7 +389,7 @@ export const WorkflowTodo: React.FC & { Drawer: React.FC; Decorator: React.FC }
); );
}; };
export function getWorkflowTodoViewActionSchema({ defaultOpenMode }) { export function getWorkflowTodoViewActionSchema({ defaultOpenMode, collectionName }) {
return { return {
name: 'view', name: 'view',
type: 'void', type: 'void',
@ -393,11 +401,11 @@ export function getWorkflowTodoViewActionSchema({ defaultOpenMode }) {
// 1. “弹窗 URL”需要 Schema 中必须包含 uid // 1. “弹窗 URL”需要 Schema 中必须包含 uid
// 2. 所以,在这里加上一个固定的 uid 用以支持“弹窗 URL” // 2. 所以,在这里加上一个固定的 uid 用以支持“弹窗 URL”
// 3. 然后,把这段 Schema 完整的(加上弹窗的部分)保存到内存中,以便“弹窗 URL”可以直接使用 // 3. 然后,把这段 Schema 完整的(加上弹窗的部分)保存到内存中,以便“弹窗 URL”可以直接使用
'x-uid': 'workflow-todo-view', 'x-uid': `${collectionName}-view`,
'x-action': 'view', 'x-action': 'view',
'x-action-context': { 'x-action-context': {
dataSource: 'main', dataSource: 'main',
collection: 'users_jobs', collection: collectionName,
}, },
properties: { properties: {
drawer: { drawer: {