mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 16:46:31 +00:00
fix(DataSources): fix table error issue
This commit is contained in:
parent
ddb363d935
commit
f0c18a349d
@ -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<any>({});
|
||||
ACLContext.displayName = 'ACLContext';
|
||||
|
||||
|
@ -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<CollectionFieldProviderProps> = (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}</>;
|
||||
|
@ -130,7 +130,7 @@ const propertiesToReactElement = ({
|
||||
|
||||
if (schema['x-component'] === 'CollectionField') {
|
||||
return (
|
||||
<CollectionFieldProvider name={schema.name} key={`${index}-${name}`}>
|
||||
<CollectionFieldProvider name={schema.name} schema={schema} key={`${index}-${name}`}>
|
||||
{isBool(propsRecursion) && propsRecursion ? (
|
||||
<NocoBaseRecursionField
|
||||
propsRecursion={true}
|
||||
|
@ -11,14 +11,7 @@ import { MenuOutlined } from '@ant-design/icons';
|
||||
import { TinyColor } from '@ctrl/tinycolor';
|
||||
import { css } from '@emotion/css';
|
||||
import { ArrayField, Field } from '@formily/core';
|
||||
import {
|
||||
RecursionField,
|
||||
Schema,
|
||||
SchemaExpressionScopeContext,
|
||||
observer,
|
||||
useField,
|
||||
useFieldSchema,
|
||||
} from '@formily/react';
|
||||
import { Schema, SchemaExpressionScopeContext, observer, useField, useFieldSchema } from '@formily/react';
|
||||
import { Table, TableColumnProps } from 'antd';
|
||||
import { default as classNames, default as cls } from 'classnames';
|
||||
import React, { useContext, useState } from 'react';
|
||||
@ -32,6 +25,7 @@ import {
|
||||
useRequest,
|
||||
useSchemaInitializerRender,
|
||||
} from '../../../';
|
||||
import { NocoBaseRecursionField } from '../../../formily/NocoBaseRecursionField';
|
||||
import { useToken } from '../__builtins__';
|
||||
|
||||
const isColumnComponent = (schema: Schema) => {
|
||||
@ -55,7 +49,7 @@ const useTableColumns = () => {
|
||||
}, [])
|
||||
.map((s: Schema) => {
|
||||
return {
|
||||
title: <RecursionField name={s.name} schema={s} onlyRenderSelf />,
|
||||
title: <NocoBaseRecursionField name={s.name} schema={s} onlyRenderSelf />,
|
||||
dataIndex: s.name,
|
||||
key: s.name,
|
||||
render: (v, record) => {
|
||||
@ -73,7 +67,7 @@ const useTableColumns = () => {
|
||||
}
|
||||
`}
|
||||
>
|
||||
<RecursionField schema={s} name={record.__index || index} onlyRenderProperties />
|
||||
<NocoBaseRecursionField schema={s} name={record.__index || index} onlyRenderProperties />
|
||||
</span>
|
||||
</RecordProvider>
|
||||
</RecordIndexProvider>
|
||||
|
Loading…
Reference in New Issue
Block a user