fix: template with fields only (#517)
This commit is contained in:
parent
2b3f3bd5c3
commit
929dd9b22e
@ -201,8 +201,12 @@ export const useRecordCollectionDataSourceItems = (componentName, item = null, c
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const collection = useCollection();
|
const collection = useCollection();
|
||||||
const { getTemplatesByCollection } = useSchemaTemplateManager();
|
const { getTemplatesByCollection } = useSchemaTemplateManager();
|
||||||
const templates = getTemplatesByCollection(collectionName || collection.name, resourceName || collectionName || collection.name).filter((template) => {
|
const templates = getTemplatesByCollection(collectionName || collection.name)
|
||||||
|
.filter((template) => {
|
||||||
return componentName && template.componentName === componentName;
|
return componentName && template.componentName === componentName;
|
||||||
|
})
|
||||||
|
.filter((template) => {
|
||||||
|
return ['FormItem', 'ReadPrettyFormItem'].includes(componentName) || (template.resourceName === resourceName);
|
||||||
});
|
});
|
||||||
if (!templates.length) {
|
if (!templates.length) {
|
||||||
return [];
|
return [];
|
||||||
@ -226,7 +230,7 @@ export const useRecordCollectionDataSourceItems = (componentName, item = null, c
|
|||||||
title: t('Duplicate template'),
|
title: t('Duplicate template'),
|
||||||
children: templates.map((template) => {
|
children: templates.map((template) => {
|
||||||
const templateName =
|
const templateName =
|
||||||
template?.componentName === 'ReadPrettyFormItem' ? `${template?.name} ${t('(Fields only)')}` : template?.name;
|
['FormItem', 'ReadPrettyFormItem'].includes(template?.componentName) ? `${template?.name} ${t('(Fields only)')}` : template?.name;
|
||||||
return {
|
return {
|
||||||
type: 'item',
|
type: 'item',
|
||||||
mode: 'copy',
|
mode: 'copy',
|
||||||
@ -244,7 +248,7 @@ export const useRecordCollectionDataSourceItems = (componentName, item = null, c
|
|||||||
title: t('Reference template'),
|
title: t('Reference template'),
|
||||||
children: templates.map((template) => {
|
children: templates.map((template) => {
|
||||||
const templateName =
|
const templateName =
|
||||||
template?.componentName === 'ReadPrettyFormItem' ? `${template?.name} ${t('(Fields only)')}` : template?.name;
|
['FormItem', 'ReadPrettyFormItem'].includes(template?.componentName) ? `${template?.name} ${t('(Fields only)')}` : template?.name;
|
||||||
return {
|
return {
|
||||||
type: 'item',
|
type: 'item',
|
||||||
mode: 'reference',
|
mode: 'reference',
|
||||||
@ -270,8 +274,8 @@ export const useCollectionDataSourceItems = (componentName) => {
|
|||||||
children: collections
|
children: collections
|
||||||
?.filter((item) => !item.inherit)
|
?.filter((item) => !item.inherit)
|
||||||
?.map((item, index) => {
|
?.map((item, index) => {
|
||||||
const templates = getTemplatesByCollection(item.name, item.name).filter((template) => {
|
const templates = getTemplatesByCollection(item.name).filter((template) => {
|
||||||
return componentName && template.componentName === componentName;
|
return componentName && template.componentName === componentName && (!template.resourceName || template.resourceName === item.name);
|
||||||
});
|
});
|
||||||
if (!templates.length) {
|
if (!templates.length) {
|
||||||
return {
|
return {
|
||||||
|
@ -120,7 +120,7 @@ export const useSchemaTemplateManager = () => {
|
|||||||
return templates?.find((template) => template.key === key);
|
return templates?.find((template) => template.key === key);
|
||||||
},
|
},
|
||||||
getTemplatesByCollection(collectionName: string, resourceName: string = null) {
|
getTemplatesByCollection(collectionName: string, resourceName: string = null) {
|
||||||
const items = templates?.filter?.((template) => (!template.resourceName && template.collectionName === collectionName) || (template.resourceName && template.resourceName === resourceName));
|
const items = templates?.filter?.((template) => (template.collectionName === collectionName));
|
||||||
return items || [];
|
return items || [];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user