fix(collection-manager): filter out empty

This commit is contained in:
chenos 2023-03-11 09:42:00 +08:00
parent 0832a56868
commit 186da56bdc

View File

@ -19,11 +19,11 @@ export const useCollectionManager = () => {
}, },
[], [],
); );
return inheritedFields; return inheritedFields.filter(Boolean);
}; };
const getCollectionFields = (name: string): CollectionFieldOptions[] => { const getCollectionFields = (name: string): CollectionFieldOptions[] => {
const currentFields = collections?.find((collection) => collection.name === name)?.fields; const currentFields = collections?.find((collection) => collection.name === name)?.fields || [];
const inheritedFields = getInheritedFields(name); const inheritedFields = getInheritedFields(name);
const totalFields = unionBy(currentFields?.concat(inheritedFields) || [], 'name').filter((v: any) => { const totalFields = unionBy(currentFields?.concat(inheritedFields) || [], 'name').filter((v: any) => {
return !v.isForeignKey; return !v.isForeignKey;
@ -174,8 +174,8 @@ export const useCollectionManager = () => {
return templates[name] ? clone(templates[name] || templates['general']) : null; return templates[name] ? clone(templates[name] || templates['general']) : null;
}, },
getParentCollectionFields: (parentCollection, currentCollection) => { getParentCollectionFields: (parentCollection, currentCollection) => {
const currentFields = collections?.find((collection) => collection.name === currentCollection)?.fields; const currentFields = collections?.find((collection) => collection.name === currentCollection)?.fields || [];
const parentFields = collections?.find((collection) => collection.name === parentCollection)?.fields; const parentFields = collections?.find((collection) => collection.name === parentCollection)?.fields || [];
const inheritKeys = getInheritCollections(currentCollection); const inheritKeys = getInheritCollections(currentCollection);
const index = inheritKeys.indexOf(parentCollection); const index = inheritKeys.indexOf(parentCollection);
let filterFields = currentFields; let filterFields = currentFields;