fix: 修改组件创建树形结构时默认为级联组件 (#948)
Reviewed-on: daoyoucloud/tachybase#948 Reviewed-by: sealday <zhanglin@daoyoucloud.com> Co-authored-by: wjh <wwwjh0710@163.com> Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
parent
3bf232d952
commit
3072cd67db
@ -2,21 +2,24 @@ import { Field } from '@tachybase/schema';
|
||||
import { useField, useFieldSchema } from '@tachybase/schema';
|
||||
import { useIsFileField } from '../schema-component/antd/form-item/FormItem.Settings';
|
||||
import { useColumnSchema } from '../schema-component/antd/table-v2/Table.Column.Decorator';
|
||||
import { useCollectionField } from '../data-source';
|
||||
import { useCollectionField, useCollectionManager } from '../data-source';
|
||||
|
||||
export function useFieldComponentName(): string {
|
||||
const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = useColumnSchema();
|
||||
const field = useField<Field>();
|
||||
const cm = useCollectionManager();
|
||||
const isFileField = useIsFileField();
|
||||
const schema = useFieldSchema();
|
||||
const targetCollectionField = useCollectionField();
|
||||
const targetCollection = cm.getCollection(targetCollectionField?.target);
|
||||
const isTreeCollection = targetCollection?.template === 'tree';
|
||||
const fieldSchema = tableColumnSchema || schema;
|
||||
const collectionField = tableColumnField || targetCollectionField;
|
||||
|
||||
const map = {
|
||||
// AssociationField 的 mode 默认值是 Select
|
||||
AssociationField: 'Select',
|
||||
AssociationField: isTreeCollection ? 'Cascader' : 'Select',
|
||||
};
|
||||
|
||||
const fieldComponentName =
|
||||
fieldSchema?.['x-component-props']?.['mode'] ||
|
||||
field?.componentProps?.['mode'] ||
|
||||
|
@ -23,8 +23,16 @@ export const AssociationFieldProvider = observer(
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[fieldSchema['x-collection-field']],
|
||||
);
|
||||
const isTreeCollection = useMemo(
|
||||
() => getCollection(collectionField?.target)?.template === 'tree',
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[fieldSchema['x-collection-field']],
|
||||
);
|
||||
|
||||
const currentMode = useMemo(
|
||||
() => fieldSchema['x-component-props']?.mode || (isFileCollection ? 'FileManager' : 'Select'),
|
||||
() =>
|
||||
fieldSchema['x-component-props']?.mode ||
|
||||
(isTreeCollection ? 'Cascader' : isFileCollection ? 'FileManager' : 'Select'),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[fieldSchema['x-component-props']?.mode],
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user