mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-05 05:38:23 +08:00
fix(data-templates): fix unselectable problem
This commit is contained in:
parent
d79af627ec
commit
5fa490e9a1
@ -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 || [],
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user