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);
|
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 || [],
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -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);
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
@ -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) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user