fix(data-templates): fix unselectable problem

This commit is contained in:
Rairn 2023-04-24 16:14:55 +08:00
parent d79af627ec
commit 5fa490e9a1
4 changed files with 13 additions and 8 deletions

View File

@ -361,9 +361,9 @@ export const CollectionFields = (props) => {
const collection = getCollection(key);
return {
key,
title: `${t('Inherited fields')} - ` + compile(collection.title),
title: `${t('Inherited fields')} - ` + compile(collection?.title),
inherit: true,
fields: collection.fields,
fields: collection?.fields || [],
};
}),
);

View File

@ -448,18 +448,18 @@ export const useFilterAssociatedFormItemInitializerFields = () => {
};
export const useInheritsFormItemInitializerFields = (options?) => {
const { name, template } = useCollection();
const { name } = useCollection();
const { getInterface, getInheritCollections, getCollection, getParentCollectionFields } = useCollectionManager();
const inherits = getInheritCollections(name);
const { snapshot } = useActionContext();
const form = useForm();
return inherits?.map((v) => {
const fields = getParentCollectionFields(v, name);
const form = useForm();
const { readPretty = form.readPretty, block = 'Form' } = options || {};
const targetCollection = getCollection(v);
return {
[targetCollection.title]: fields
[targetCollection?.title]: fields
?.filter((field) => field?.interface && !field?.isForeignKey)
?.map((field) => {
const interfaceConfig = getInterface(field.interface);

View File

@ -87,12 +87,13 @@ export const FormDataTemplates = observer((props: any) => {
targetField: field,
mapOptions(option) {
try {
const label = collection?.titleField || 'id';
const label = getLabel(collection);
option[label] = (
<>
#{option.id} {option[label]}
</>
);
return option;
} catch (error) {
console.error(error);
@ -100,7 +101,7 @@ export const FormDataTemplates = observer((props: any) => {
}
},
fieldNames: {
label: collection?.titleField || 'id',
label: getLabel(collection),
value: 'id',
},
},
@ -190,3 +191,7 @@ export const FormDataTemplates = observer((props: any) => {
/>
);
});
function getLabel(collection: any) {
return !collection?.titleField || collection.titleField === 'id' ? 'label' : collection?.titleField;
}

View File

@ -11,7 +11,7 @@ export const useCollectionState = (currentCollectionName: string) => {
function getCollectionList() {
const collections = getAllCollectionsInheritChain(currentCollectionName);
return collections.map((name) => ({ label: getCollection(name).title, value: name }));
return collections.map((name) => ({ label: getCollection(name)?.title, value: name }));
}
const getEnableFieldTree = (collectionName: string) => {