mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 13:06:31 +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 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));
|
||||||
|
@ -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: {
|
||||||
|
Loading…
Reference in New Issue
Block a user