refactor: formBlockProvider & detailBlockProvider (#3898)

* refactor: formBlockProvider

* refactor: detailBlockProvider

* fix: bug

* fix: bug

* fix: bug

* fix: bug

* refactor: code improve
This commit is contained in:
katherinehhh 2024-04-04 09:29:09 +08:00 committed by GitHub
parent b111f827ed
commit fcd2b766cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,6 +9,9 @@ import { RecordProvider } from '../record-provider';
import { BlockProvider, useBlockRequestContext } from './BlockProvider'; import { BlockProvider, useBlockRequestContext } from './BlockProvider';
import { TemplateBlockProvider } from './TemplateBlockProvider'; import { TemplateBlockProvider } from './TemplateBlockProvider';
import { useParsedFilter } from './hooks'; import { useParsedFilter } from './hooks';
import { useCollectionManager_deprecated } from '../collection-manager';
import { useCollectionRecordData } from '../data-source';
import { useDesignable } from '../schema-component';
/** /**
* @internal * @internal
@ -67,6 +70,21 @@ const InternalDetailsBlockProvider = (props) => {
}; };
export const DetailsBlockProvider = withDynamicSchemaProps((props) => { export const DetailsBlockProvider = withDynamicSchemaProps((props) => {
const record = useCollectionRecordData();
const { association, dataSource } = props;
const { getCollection } = useCollectionManager_deprecated(dataSource);
const { __collection } = record || {};
const { designable } = useDesignable();
const collection = props.collection || getCollection(association, dataSource).name;
let detailFlag = true;
if (!designable && __collection) {
detailFlag = __collection === collection;
}
if (!detailFlag) {
return null;
}
return ( return (
<TemplateBlockProvider> <TemplateBlockProvider>
<BlockProvider name="details" {...props}> <BlockProvider name="details" {...props}>