fix(record-picker): supports adding sub-collection records (#1573)

* fix:  inherited collection block is not displayed when adding  form from the data selector

* fix: judge whether the record is null logical error

---------

Co-authored-by: katherinehhh <katherine_15995@163.com>
This commit is contained in:
chenos 2023-03-15 23:18:49 +08:00 committed by GitHub
parent 9e7e6a6051
commit 3cf06be893
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,20 +49,30 @@ const InternalFormBlockProvider = (props) => {
); );
}; };
const useIsEmptyRecord = () => {
const record = useRecord();
const keys = Object.keys(record);
if (keys.includes('__parent')) {
return keys.length > 1;
}
return keys.length > 0;
};
export const FormBlockProvider = (props) => { export const FormBlockProvider = (props) => {
const record = useRecord(); const record = useRecord();
const { collection } = props; const { collection } = props;
const { __collection } = record; const { __collection } = record;
const currentCollection = useCollection(); const currentCollection = useCollection();
const { designable } = useDesignable(); const { designable } = useDesignable();
const isEmptyRecord = useIsEmptyRecord();
let detailFlag = false; let detailFlag = false;
if (Object.keys(record).length > 0) { if (isEmptyRecord) {
detailFlag = true; detailFlag = true;
if (!designable && __collection) { if (!designable && __collection) {
detailFlag = __collection === collection; detailFlag = __collection === collection;
} }
} }
const createFlag = (currentCollection.name === collection && !Object.keys(record).length) || !currentCollection.name; const createFlag = (currentCollection.name === collection && !isEmptyRecord) || !currentCollection.name;
return ( return (
(detailFlag || createFlag) && ( (detailFlag || createFlag) && (
<BlockProvider {...props} block={'form'}> <BlockProvider {...props} block={'form'}>