fix(data-templates): should also show data-templates option when add new subrecord

This commit is contained in:
Rairn 2023-04-16 18:56:15 +08:00
parent 221c90d835
commit 11fb951b55
2 changed files with 4 additions and 5 deletions

View File

@ -1,12 +1,11 @@
import { ArrayItems } from '@formily/antd'; import { ArrayItems } from '@formily/antd';
import { ISchema, useField, useFieldSchema } from '@formily/react'; import { ISchema, useField, useFieldSchema } from '@formily/react';
import _ from 'lodash';
import React from 'react'; import React from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useFormBlockContext } from '../../../block-provider';
import { useDetailsBlockContext } from '../../../block-provider/DetailsBlockProvider'; import { useDetailsBlockContext } from '../../../block-provider/DetailsBlockProvider';
import { useCollection } from '../../../collection-manager'; import { useCollection } from '../../../collection-manager';
import { useCollectionFilterOptions, useSortFields } from '../../../collection-manager/action-hooks'; import { useCollectionFilterOptions, useSortFields } from '../../../collection-manager/action-hooks';
import { useRecord } from '../../../record-provider';
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings'; import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
import { useSchemaTemplate } from '../../../schema-templates'; import { useSchemaTemplate } from '../../../schema-templates';
import { useDesignable } from '../../hooks'; import { useDesignable } from '../../hooks';
@ -18,14 +17,15 @@ export const FormDesigner = () => {
const template = useSchemaTemplate(); const template = useSchemaTemplate();
const fieldSchema = useFieldSchema(); const fieldSchema = useFieldSchema();
const defaultResource = fieldSchema?.['x-decorator-props']?.resource; const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
const record = useRecord(); const { action } = useFormBlockContext();
return ( return (
<GeneralSchemaDesigner template={template} title={title || name}> <GeneralSchemaDesigner template={template} title={title || name}>
{/* <SchemaSettings.Template componentName={'FormItem'} collectionName={name} /> */} {/* <SchemaSettings.Template componentName={'FormItem'} collectionName={name} /> */}
<SchemaSettings.BlockTitleItem /> <SchemaSettings.BlockTitleItem />
<SchemaSettings.LinkageRules collectionName={name} /> <SchemaSettings.LinkageRules collectionName={name} />
{_.isEmpty(record) ? <SchemaSettings.DataTemplates collectionName={name} /> : null} {/* 当 action 没有值的时候,说明是在用表单创建新数据,此时需要显示数据模板 */}
{!action ? <SchemaSettings.DataTemplates collectionName={name} /> : null}
<SchemaSettings.Divider /> <SchemaSettings.Divider />
<SchemaSettings.FormItemTemplate <SchemaSettings.FormItemTemplate
componentName={'FormItem'} componentName={'FormItem'}

View File

@ -989,7 +989,6 @@ export const createFormBlockSchema = (options) => {
}, },
}, },
}; };
console.log(JSON.stringify(schema, null, 2));
return schema; return schema;
}; };