refactor: restrict the use of tree table in data selectors (#2581)

* refactor: limitthe using of tree in recordPicker

* refactor: limitthe using of tree in recordPicker
This commit is contained in:
katherinehhh 2023-09-01 10:57:20 +08:00 committed by GitHub
parent ee0d2175b8
commit d9bda04aa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 14 deletions

View File

@ -98,11 +98,7 @@ export const TableBlockProvider = (props) => {
<SchemaComponentOptions scope={{ treeTable }}>
<FormContext.Provider value={form}>
<BlockProvider {...props} params={params} runWhenParamsChanged>
<InternalTableBlockProvider
{...props}
childrenColumnName={childrenColumnName}
params={params}
/>
<InternalTableBlockProvider {...props} childrenColumnName={childrenColumnName} params={params} />
</BlockProvider>
</FormContext.Provider>
</SchemaComponentOptions>

View File

@ -79,7 +79,7 @@ const useAssociationNames2 = (collection) => {
return names;
};
const recursiveParent = (schema: Schema, component) => {
export const recursiveParent = (schema: Schema, component) => {
return schema['x-component'] === component
? schema
: schema.parent
@ -149,7 +149,7 @@ export const TableSelectorProvider = (props: TableSelectorProviderProps) => {
if (props.dragSort) {
params['sort'] = ['sort'];
}
if (collection?.tree && treeTable !== false) {
if (collectionField?.target === collectionField?.collectionName && collection?.tree && treeTable !== false) {
params['tree'] = true;
if (collectionFieldSchema.name === 'parent') {
params.filter = {

View File

@ -43,9 +43,8 @@ export const TableBlockDesigner = () => {
const template = useSchemaTemplate();
const collection = useCollection();
const { dragSort, resource } = field.decoratorProps;
const treeCollection = resource?.includes('.')
? getCollection(getCollectionField(resource)?.target)?.tree
: !!collection?.tree;
const collectionField = getCollectionField(resource);
const treeCollection = resource?.includes('.') ? getCollection(collectionField?.target)?.tree : !!collection?.tree;
const dataScopeSchema = useMemo(() => {
return {
type: 'object',
@ -84,11 +83,10 @@ export const TableBlockDesigner = () => {
},
[field],
);
return (
<GeneralSchemaDesigner template={template} title={title || name}>
<SchemaSettings.BlockTitleItem />
{collection?.tree && (
{collection?.tree && collectionField?.collectionName === collectionField?.target && (
<SchemaSettings.SwitchItem
title={t('Tree table')}
defaultChecked={true}

View File

@ -4,16 +4,18 @@ import { cloneDeep } from 'lodash';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useTableSelectorContext } from '../../../block-provider';
import { useCollection } from '../../../collection-manager';
import { useCollection, useCollectionManager } from '../../../collection-manager';
import { useCollectionFilterOptions, useSortFields } from '../../../collection-manager/action-hooks';
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
import { useSchemaTemplate } from '../../../schema-templates';
import { useDesignable } from '../../hooks';
import { removeNullCondition } from '../filter';
import { FilterDynamicComponent } from './FilterDynamicComponent';
import { recursiveParent } from '../../../block-provider/TableSelectorProvider';
export const TableSelectorDesigner = () => {
const { name, title } = useCollection();
const { getCollectionJoinField } = useCollectionManager();
const field = useField();
const fieldSchema = useFieldSchema();
const dataSource = useCollectionFilterOptions(name);
@ -23,6 +25,8 @@ export const TableSelectorDesigner = () => {
const { dn } = useDesignable();
const defaultFilter = fieldSchema?.['x-decorator-props']?.params?.filter || {};
const defaultSort = fieldSchema?.['x-decorator-props']?.params?.sort || [];
const collectionFieldSchema = recursiveParent(fieldSchema, 'CollectionField');
const collectionField = getCollectionJoinField(collectionFieldSchema?.['x-collection-field']);
const sort = defaultSort?.map((item: string) => {
return item.startsWith('-')
? {
@ -83,7 +87,7 @@ export const TableSelectorDesigner = () => {
});
}}
/>
{collection?.tree && (
{collection?.tree && collectionField?.target === collectionField?.collectionName && (
<SchemaSettings.SwitchItem
title={t('Tree table')}
defaultChecked={true}