mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 08:36:44 +00:00
refactor: make more stable
This commit is contained in:
parent
9d6d18ad8a
commit
0fb2cc7278
@ -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 (
|
||||
<ExtendCollectionsProvider collections={[nodeCollection, workflowCollection, todoCollection]}>
|
||||
{props.children}
|
||||
</ExtendCollectionsProvider>
|
||||
);
|
||||
return <ExtendCollectionsProvider collections={collections}>{props.children}</ExtendCollectionsProvider>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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));
|
||||
|
@ -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 (
|
||||
<SchemaComponent
|
||||
@ -293,7 +301,7 @@ export const WorkflowTodo: React.FC & { Drawer: React.FC; Decorator: React.FC }
|
||||
},
|
||||
title: '{{t("Actions")}}',
|
||||
properties: {
|
||||
view: getWorkflowTodoViewActionSchema({ defaultOpenMode }),
|
||||
view: getWorkflowTodoViewActionSchema({ defaultOpenMode, collectionName: collection.name }),
|
||||
},
|
||||
},
|
||||
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 {
|
||||
name: 'view',
|
||||
type: 'void',
|
||||
@ -393,11 +401,11 @@ export function getWorkflowTodoViewActionSchema({ defaultOpenMode }) {
|
||||
// 1. “弹窗 URL”需要 Schema 中必须包含 uid
|
||||
// 2. 所以,在这里加上一个固定的 uid 用以支持“弹窗 URL”
|
||||
// 3. 然后,把这段 Schema 完整的(加上弹窗的部分)保存到内存中,以便“弹窗 URL”可以直接使用
|
||||
'x-uid': 'workflow-todo-view',
|
||||
'x-uid': `${collectionName}-view`,
|
||||
'x-action': 'view',
|
||||
'x-action-context': {
|
||||
dataSource: 'main',
|
||||
collection: 'users_jobs',
|
||||
collection: collectionName,
|
||||
},
|
||||
properties: {
|
||||
drawer: {
|
||||
|
Loading…
Reference in New Issue
Block a user