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); const collection = getCollection(key);
return { return {
key, key,
title: `${t('Inherited fields')} - ` + compile(collection.title), title: `${t('Inherited fields')} - ` + compile(collection?.title),
inherit: true, inherit: true,
fields: collection.fields, fields: collection?.fields || [],
}; };
}), }),
); );

View File

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

View File

@ -87,12 +87,13 @@ export const FormDataTemplates = observer((props: any) => {
targetField: field, targetField: field,
mapOptions(option) { mapOptions(option) {
try { try {
const label = collection?.titleField || 'id'; const label = getLabel(collection);
option[label] = ( option[label] = (
<> <>
#{option.id} {option[label]} #{option.id} {option[label]}
</> </>
); );
return option; return option;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@ -100,7 +101,7 @@ export const FormDataTemplates = observer((props: any) => {
} }
}, },
fieldNames: { fieldNames: {
label: collection?.titleField || 'id', label: getLabel(collection),
value: 'id', 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() { function getCollectionList() {
const collections = getAllCollectionsInheritChain(currentCollectionName); 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) => { const getEnableFieldTree = (collectionName: string) => {