From f0c18a349d7f1a65039dce09294ee85380285167 Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Wed, 13 Nov 2024 08:49:46 +0800 Subject: [PATCH] fix(DataSources): fix table error issue --- packages/core/client/src/acl/ACLProvider.tsx | 6 ++++++ .../collection-field/CollectionFieldProvider.tsx | 12 +++++++----- .../client/src/formily/NocoBaseRecursionField.tsx | 2 +- .../schema-component/antd/table/Table.Array.tsx | 14 ++++---------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/core/client/src/acl/ACLProvider.tsx b/packages/core/client/src/acl/ACLProvider.tsx index 7863858a42..f92f85c72d 100644 --- a/packages/core/client/src/acl/ACLProvider.tsx +++ b/packages/core/client/src/acl/ACLProvider.tsx @@ -7,6 +7,9 @@ * For more information, please refer to: https://www.nocobase.com/agreement. */ +// 注意: 这行必须放到顶部,否则会导致 Data sources 页面报错,原因未知 +import { useBlockRequestContext } from '../block-provider/BlockProvider'; + import { Field } from '@formily/core'; import { Schema, useField, useFieldSchema } from '@formily/react'; import { omit } from 'lodash'; @@ -27,6 +30,9 @@ import { SchemaComponentOptions, useDesignable } from '../schema-component'; import { useApp } from '../application'; +// 注意: 必须要对 useBlockRequestContext 进行引用,否则会导致 Data sources 页面报错,原因未知 +useBlockRequestContext; + export const ACLContext = createContext({}); ACLContext.displayName = 'ACLContext'; diff --git a/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx b/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx index e201aebb02..faef4a7fb5 100644 --- a/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx +++ b/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx @@ -9,7 +9,7 @@ import React, { FC, ReactNode, createContext, useContext, useMemo } from 'react'; -import { useFieldSchema, type SchemaKey } from '@formily/react'; +import { Schema, useFieldSchema, type SchemaKey } from '@formily/react'; import type { CollectionFieldOptions } from '../collection'; import { useCollection, useCollectionManager } from '../collection'; @@ -25,23 +25,25 @@ export type CollectionFieldProviderProps = { name?: SchemaKey; children?: ReactNode; allowNull?: boolean; + schema?: Schema; }; export const CollectionFieldProvider: FC = (props) => { - const { name, children, allowNull } = props; + const { name, children, allowNull, schema } = props; const fieldSchema = useFieldSchema(); const collection = useCollection(); const collectionManager = useCollectionManager(); const value = useMemo(() => { if (!collection) return null; - const field = fieldSchema?.['x-component-props']?.['field']; + const _schema = schema || fieldSchema; + const field = _schema?.['x-component-props']?.['field']; return ( - collectionManager.getCollectionField(fieldSchema?.['x-collection-field']) || + collectionManager.getCollectionField(_schema?.['x-collection-field']) || field || collection.getField(field?.name || name) ); - }, [collection, fieldSchema, name, collectionManager]); + }, [collection, schema, fieldSchema, collectionManager, name]); if (!value && allowNull) { return <>{children}; diff --git a/packages/core/client/src/formily/NocoBaseRecursionField.tsx b/packages/core/client/src/formily/NocoBaseRecursionField.tsx index 99e2d412dc..f8d20901e4 100644 --- a/packages/core/client/src/formily/NocoBaseRecursionField.tsx +++ b/packages/core/client/src/formily/NocoBaseRecursionField.tsx @@ -130,7 +130,7 @@ const propertiesToReactElement = ({ if (schema['x-component'] === 'CollectionField') { return ( - + {isBool(propsRecursion) && propsRecursion ? ( { @@ -55,7 +49,7 @@ const useTableColumns = () => { }, []) .map((s: Schema) => { return { - title: , + title: , dataIndex: s.name, key: s.name, render: (v, record) => { @@ -73,7 +67,7 @@ const useTableColumns = () => { } `} > - +