fix: table settings get collectionField (#3837)

* fix: table settings get collectionField

* fix: remove duplicate useCollectionField

* fix: bug

* refactor: tagComponentFieldSettings

---------

Co-authored-by: katherinehhh <katherine_15995@163.com>
This commit is contained in:
jack zhang 2024-03-29 09:12:52 +08:00 committed by GitHub
parent 1f59d4bed2
commit a38e34cf9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 18 additions and 42 deletions

View File

@ -2,19 +2,7 @@ import { Field } from '@formily/core';
import { useField, useFieldSchema } from '@formily/react';
import { useIsFileField } from '../schema-component/antd/form-item/FormItem.Settings';
import { useColumnSchema } from '../schema-component/antd/table-v2/Table.Column.Decorator';
import { useCollectionManager_deprecated, useCollection_deprecated } from '../collection-manager';
/**
*
* @returns
*/
function useCollectionField() {
const { getCollectionJoinField } = useCollectionManager_deprecated();
const { getField } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
return collectionField;
}
import { useCollectionField } from '../data-source';
export function useFieldComponentName(): string {
const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = useColumnSchema();

View File

@ -22,7 +22,7 @@ export const CollectionFieldProvider: FC<CollectionFieldProviderProps> = (props)
const collectionManager = useCollectionManager();
const value = useMemo(() => {
if (!collection || allowNull) return null;
if (!collection) return null;
const field = fieldSchema?.['x-component-props']?.['field'];
return (
collectionManager.getCollectionField(fieldSchema?.['x-collection-field']) ||
@ -31,7 +31,7 @@ export const CollectionFieldProvider: FC<CollectionFieldProviderProps> = (props)
);
}, [collection, fieldSchema, name, collectionManager]);
if (!collection || allowNull) {
if (!value && allowNull) {
return <>{children}</>;
}

View File

@ -6,7 +6,7 @@ import { useFieldComponentName } from '../../../../common/useFieldComponentName'
import { useDesignable, useFieldModeOptions, useIsAddNewForm } from '../../../../schema-component';
import { isSubMode } from '../../../../schema-component/antd/association-field/util';
import { useTitleFieldOptions } from '../../../../schema-component/antd/form-item/FormItem.Settings';
import { useCollectionField } from '../utils';
import { useCollectionField } from '../../../../data-source';
const fieldComponent: any = {
name: 'fieldComponent',

View File

@ -9,7 +9,7 @@ import {
useIsFieldReadPretty,
useIsFormReadPretty,
} from '../../../../schema-component/antd/form-item/FormItem.Settings';
import { useCollectionField } from '../utils';
import { useCollectionField } from '../../../../data-source';
import { useFormBlockType } from '../../../../block-provider';
const allowMultiple: any = {

View File

@ -10,7 +10,7 @@ import {
useTitleFieldOptions,
} from '../../../../schema-component/antd/form-item/FormItem.Settings';
import { useColumnSchema } from '../../../../schema-component/antd/table-v2/Table.Column.Decorator';
import { useCollectionField } from '../utils';
import { useCollectionField } from '../../../../data-source';
export const titleField: any = {
name: 'titleField',

View File

@ -6,7 +6,7 @@ import { useFieldComponentName } from '../../../../common/useFieldComponentName'
import { useDesignable, useFieldModeOptions, useIsAddNewForm } from '../../../../schema-component';
import { isSubMode } from '../../../../schema-component/antd/association-field/util';
import { useIsFieldReadPretty } from '../../../../schema-component/antd/form-item/FormItem.Settings';
import { useCollectionField } from '../utils';
import { useCollectionField } from '../../../../data-source';
import { useColumnSchema } from '../../../../schema-component/antd/table-v2/Table.Column.Decorator';
import { titleField } from '../Picker/recordPickerComponentFieldSettings';

View File

@ -23,7 +23,7 @@ import { SchemaSettingsDataScope } from '../../../../schema-settings/SchemaSetti
import { SchemaSettingsSortingRule } from '../../../../schema-settings/SchemaSettingsSortingRule';
import { useIsShowMultipleSwitch } from '../../../../schema-settings/hooks/useIsShowMultipleSwitch';
import { useLocalVariables, useVariables } from '../../../../variables';
import { useCollectionField } from '../utils';
import { useCollectionField } from '../../../../data-source';
const enableLink = {
name: 'enableLink',

View File

@ -8,7 +8,7 @@ import { isSubMode } from '../../../../schema-component/antd/association-field/u
import { useTitleFieldOptions } from '../../../../schema-component/antd/form-item/FormItem.Settings';
import { useColorFields } from '../../../../schema-component/antd/table-v2/Table.Column.Designer';
import { useColumnSchema } from '../../../../schema-component/antd/table-v2/Table.Column.Decorator';
import { useCollectionField } from '../utils';
import { useCollectionField } from '../../../../data-source';
const enableLink = {
name: 'enableLink',
@ -140,9 +140,12 @@ export const tagComponentFieldSettings = new SchemaSettings({
useComponentProps() {
const { t } = useTranslation();
const field = useField<Field>();
const fieldSchema = useFieldSchema();
const schema = useFieldSchema();
const targetCollectionField = useCollectionField();
const { fieldSchema: tableColumnSchema, collectionField: tableColumnField } = useColumnSchema();
const fieldSchema = tableColumnSchema || schema;
const collectionField = tableColumnField || targetCollectionField;
const { dn } = useDesignable();
const collectionField = useCollectionField();
const colorFieldOptions = useColorFields(collectionField?.target ?? collectionField?.targetCollection);
return {
title: t('Tag color field'),

View File

@ -1,14 +0,0 @@
import { useFieldSchema } from '@formily/react';
import { useCollection_deprecated, useCollectionManager_deprecated } from '../../../collection-manager';
/**
*
* @returns
*/
export function useCollectionField() {
const { getCollectionJoinField } = useCollectionManager_deprecated();
const { getField } = useCollection_deprecated();
const fieldSchema = useFieldSchema();
const collectionField = getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
return collectionField;
}

View File

@ -67,16 +67,15 @@ export const FormItem: any = observer(
},
);
}, [showTitle]);
const fieldSchema = useFieldSchema();
return (
<BlockItem className={'nb-form-item'}>
<CollectionFieldProvider name={fieldSchema.name} allowNull={!fieldSchema['x-collection-field']}>
<CollectionFieldProvider allowNull={true}>
<BlockItem className={'nb-form-item'}>
<ACLCollectionFieldProvider>
<Item className={className} {...props} extra={extra} />
</ACLCollectionFieldProvider>
</CollectionFieldProvider>
</BlockItem>
</BlockItem>
</CollectionFieldProvider>
);
},
{ displayName: 'FormItem' },