mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 11:56:29 +00:00
fix(Collapse): fix error for chinaRegions (#3925)
* fix: fix error for chinaRegions * fix: collapse
This commit is contained in:
parent
4006b17a53
commit
59c1aea942
@ -155,9 +155,9 @@ export const RenderChildrenWithAssociationFilter: React.FC<any> = (props) => {
|
|||||||
<Row style={{ height: '100%' }} gutter={16} wrap={false}>
|
<Row style={{ height: '100%' }} gutter={16} wrap={false}>
|
||||||
<Col
|
<Col
|
||||||
style={{
|
style={{
|
||||||
...(props.associationFilterStyle || {}),
|
|
||||||
width: 200,
|
width: 200,
|
||||||
flex: '0 0 auto',
|
flex: '0 0 auto',
|
||||||
|
...(props.associationFilterStyle || {}),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<RecursionField
|
<RecursionField
|
||||||
|
@ -1158,12 +1158,12 @@ export const useAssociationFilterProps = () => {
|
|||||||
export const useOptionalFieldList = () => {
|
export const useOptionalFieldList = () => {
|
||||||
const { currentFields = [] } = useCollection_deprecated();
|
const { currentFields = [] } = useCollection_deprecated();
|
||||||
|
|
||||||
return currentFields.filter((field) => isOptionalField(field) && field.uiSchema.enum);
|
return currentFields.filter((field) => isOptionalField(field));
|
||||||
};
|
};
|
||||||
|
|
||||||
const isOptionalField = (field) => {
|
const isOptionalField = (field) => {
|
||||||
const optionalInterfaces = ['select', 'multipleSelect', 'checkbox', 'checkboxGroup', 'chinaRegion'];
|
const optionalInterfaces = ['select', 'multipleSelect', 'checkbox', 'checkboxGroup', 'chinaRegion'];
|
||||||
return optionalInterfaces.includes(field.interface);
|
return optionalInterfaces.includes(field.interface) && field.uiSchema.enum;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useAssociationFilterBlockProps = () => {
|
export const useAssociationFilterBlockProps = () => {
|
||||||
@ -1206,16 +1206,16 @@ export const useAssociationFilterBlockProps = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 由于 选项字段不需要触发当前请求,所以请求单独在 关系字段的时候触发
|
// 由于 选项字段不需要触发当前请求,所以请求单独在 关系字段的时候触发
|
||||||
if (!isOptionalField(fieldSchema)) {
|
if (!isOptionalField(collectionField)) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
}, [labelKey, valueKey, JSON.stringify(field.componentProps?.params || {}), isOptionalField(fieldSchema)]);
|
}, [collectionField, labelKey, run, valueKey]);
|
||||||
|
|
||||||
if (!collectionField) {
|
if (!collectionField) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isOptionalField(fieldSchema)) {
|
if (isOptionalField(collectionField)) {
|
||||||
const field = optionalFieldList.find((field) => field.name === fieldSchema.name);
|
const field = optionalFieldList.find((field) => field.name === fieldSchema.name);
|
||||||
const operatorMap = {
|
const operatorMap = {
|
||||||
select: '$in',
|
select: '$in',
|
||||||
|
@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { SchemaSettings } from '../../../../application/schema-settings/SchemaSettings';
|
import { SchemaSettings } from '../../../../application/schema-settings/SchemaSettings';
|
||||||
import { useFormBlockContext } from '../../../../block-provider';
|
import { useFormBlockContext } from '../../../../block-provider';
|
||||||
import { useCollectionManager_deprecated, useCollection_deprecated } from '../../../../collection-manager';
|
import { useCollectionManager_deprecated, useCollection_deprecated } from '../../../../collection-manager';
|
||||||
|
import { useCollectionManager } from '../../../../data-source/collection/CollectionManagerProvider';
|
||||||
import { useCompile, useDesignable } from '../../../../schema-component';
|
import { useCompile, useDesignable } from '../../../../schema-component';
|
||||||
import { SchemaSettingsDefaultSortingRules } from '../../../../schema-settings';
|
import { SchemaSettingsDefaultSortingRules } from '../../../../schema-settings';
|
||||||
import { SchemaSettingsDataScope } from '../../../../schema-settings/SchemaSettingsDataScope';
|
import { SchemaSettingsDataScope } from '../../../../schema-settings/SchemaSettingsDataScope';
|
||||||
@ -150,10 +151,10 @@ export const filterCollapseItemFieldSettings = new SchemaSettings({
|
|||||||
const { getField } = useCollection_deprecated();
|
const { getField } = useCollection_deprecated();
|
||||||
const collectionField =
|
const collectionField =
|
||||||
getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
||||||
const { getCollectionFields } = useCollectionManager_deprecated();
|
const cm = useCollectionManager();
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const { dn } = useDesignable();
|
const { dn } = useDesignable();
|
||||||
const targetFields = collectionField?.target ? getCollectionFields(collectionField?.target) : [];
|
const targetFields = collectionField?.target ? cm.getCollectionFields(collectionField?.target) : [];
|
||||||
const options = targetFields
|
const options = targetFields
|
||||||
.filter((field) => !field?.target && field.type !== 'boolean')
|
.filter((field) => !field?.target && field.type !== 'boolean')
|
||||||
.map((field) => ({
|
.map((field) => ({
|
||||||
|
@ -4,11 +4,7 @@ import { useOptionalFieldList } from '../../../../block-provider/hooks';
|
|||||||
import { useCollectionManager_deprecated } from '../../../../collection-manager';
|
import { useCollectionManager_deprecated } from '../../../../collection-manager';
|
||||||
import { useAssociatedFields } from '../../../../filter-provider/utils';
|
import { useAssociatedFields } from '../../../../filter-provider/utils';
|
||||||
|
|
||||||
/**
|
const commonOptions: any = {
|
||||||
* @deprecated
|
|
||||||
*/
|
|
||||||
export const associationFilterFilterBlockInitializer = new SchemaInitializer({
|
|
||||||
name: 'AssociationFilter.FilterBlockInitializer',
|
|
||||||
style: { marginTop: 16 },
|
style: { marginTop: 16 },
|
||||||
icon: 'SettingOutlined',
|
icon: 'SettingOutlined',
|
||||||
title: '{{t("Configure fields")}}',
|
title: '{{t("Configure fields")}}',
|
||||||
@ -18,6 +14,7 @@ export const associationFilterFilterBlockInitializer = new SchemaInitializer({
|
|||||||
name: 'associationFields',
|
name: 'associationFields',
|
||||||
title: '{{t("Association fields")}}',
|
title: '{{t("Association fields")}}',
|
||||||
useChildren() {
|
useChildren() {
|
||||||
|
const cm = useCollectionManager_deprecated();
|
||||||
const associatedFields = useAssociatedFields();
|
const associatedFields = useAssociatedFields();
|
||||||
const children = associatedFields.map((field) => ({
|
const children = associatedFields.map((field) => ({
|
||||||
name: field.key,
|
name: field.key,
|
||||||
@ -34,7 +31,7 @@ export const associationFilterFilterBlockInitializer = new SchemaInitializer({
|
|||||||
'x-use-component-props': 'useAssociationFilterBlockProps',
|
'x-use-component-props': 'useAssociationFilterBlockProps',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
fieldNames: {
|
fieldNames: {
|
||||||
label: field.targetKey || 'id',
|
label: field.targetKey || cm.getCollection(field.target)?.getPrimaryKey() || 'id',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
properties: {},
|
properties: {},
|
||||||
@ -77,6 +74,14 @@ export const associationFilterFilterBlockInitializer = new SchemaInitializer({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
export const associationFilterFilterBlockInitializer = new SchemaInitializer({
|
||||||
|
name: 'AssociationFilter.FilterBlockInitializer',
|
||||||
|
...commonOptions,
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,149 +90,13 @@ export const associationFilterFilterBlockInitializer = new SchemaInitializer({
|
|||||||
*/
|
*/
|
||||||
export const filterCollapseItemInitializer_deprecated = new CompatibleSchemaInitializer({
|
export const filterCollapseItemInitializer_deprecated = new CompatibleSchemaInitializer({
|
||||||
name: 'AssociationFilterInitializers',
|
name: 'AssociationFilterInitializers',
|
||||||
style: { marginTop: 16 },
|
...commonOptions,
|
||||||
icon: 'SettingOutlined',
|
|
||||||
title: '{{t("Configure fields")}}',
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
type: 'itemGroup',
|
|
||||||
name: 'associationFields',
|
|
||||||
title: '{{t("Association fields")}}',
|
|
||||||
useChildren() {
|
|
||||||
const associatedFields = useAssociatedFields();
|
|
||||||
const cm = useCollectionManager_deprecated();
|
|
||||||
const children = associatedFields.map((field) => ({
|
|
||||||
name: field.key,
|
|
||||||
title: field.uiSchema?.title,
|
|
||||||
Component: 'AssociationFilterDesignerDisplayField',
|
|
||||||
schema: {
|
|
||||||
name: field.name,
|
|
||||||
title: field.uiSchema?.title,
|
|
||||||
type: 'void',
|
|
||||||
// 'x-designer': 'AssociationFilter.Item.Designer',
|
|
||||||
'x-toolbar': 'CollapseItemSchemaToolbar',
|
|
||||||
'x-settings': 'fieldSettings:FilterCollapseItem',
|
|
||||||
'x-component': 'AssociationFilter.Item',
|
|
||||||
'x-use-component-props': 'useAssociationFilterBlockProps',
|
|
||||||
'x-component-props': {
|
|
||||||
fieldNames: {
|
|
||||||
label: cm.getCollection(field.target)?.getPrimaryKey() || 'id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
properties: {},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
return children;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'choicesFields',
|
|
||||||
type: 'itemGroup',
|
|
||||||
title: '{{t("Choices fields")}}',
|
|
||||||
hideIfNoChildren: true,
|
|
||||||
useChildren() {
|
|
||||||
const optionalList = useOptionalFieldList();
|
|
||||||
const optionalChildren = optionalList.map((field) => ({
|
|
||||||
name: field.key,
|
|
||||||
title: field.uiSchema.title,
|
|
||||||
Component: 'AssociationFilterDesignerDisplayField',
|
|
||||||
schema: {
|
|
||||||
name: field.name,
|
|
||||||
title: field.uiSchema.title,
|
|
||||||
interface: field.interface,
|
|
||||||
type: 'void',
|
|
||||||
// 'x-designer': 'AssociationFilter.Item.Designer',
|
|
||||||
'x-toolbar': 'CollapseItemSchemaToolbar',
|
|
||||||
'x-settings': 'fieldSettings:FilterCollapseItem',
|
|
||||||
'x-component': 'AssociationFilter.Item',
|
|
||||||
'x-use-component-props': 'useAssociationFilterBlockProps',
|
|
||||||
'x-component-props': {
|
|
||||||
fieldNames: {
|
|
||||||
label: field.name,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
properties: {},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
return optionalChildren;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const filterCollapseItemInitializer = new CompatibleSchemaInitializer(
|
export const filterCollapseItemInitializer = new CompatibleSchemaInitializer(
|
||||||
{
|
{
|
||||||
name: 'filterCollapse:configureFields',
|
name: 'filterCollapse:configureFields',
|
||||||
style: { marginTop: 16 },
|
...commonOptions,
|
||||||
icon: 'SettingOutlined',
|
|
||||||
title: '{{t("Configure fields")}}',
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
type: 'itemGroup',
|
|
||||||
name: 'associationFields',
|
|
||||||
title: '{{t("Association fields")}}',
|
|
||||||
useChildren() {
|
|
||||||
const associatedFields = useAssociatedFields();
|
|
||||||
const cm = useCollectionManager_deprecated();
|
|
||||||
const children = associatedFields.map((field) => ({
|
|
||||||
name: field.key,
|
|
||||||
title: field.uiSchema?.title,
|
|
||||||
Component: 'AssociationFilterDesignerDisplayField',
|
|
||||||
schema: {
|
|
||||||
name: field.name,
|
|
||||||
title: field.uiSchema?.title,
|
|
||||||
type: 'void',
|
|
||||||
// 'x-designer': 'AssociationFilter.Item.Designer',
|
|
||||||
'x-toolbar': 'CollapseItemSchemaToolbar',
|
|
||||||
'x-settings': 'fieldSettings:FilterCollapseItem',
|
|
||||||
'x-component': 'AssociationFilter.Item',
|
|
||||||
'x-use-component-props': 'useAssociationFilterBlockProps',
|
|
||||||
'x-component-props': {
|
|
||||||
fieldNames: {
|
|
||||||
label: cm.getCollection(field.target)?.getPrimaryKey() || 'id',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
properties: {},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
return children;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'choicesFields',
|
|
||||||
type: 'itemGroup',
|
|
||||||
title: '{{t("Choices fields")}}',
|
|
||||||
hideIfNoChildren: true,
|
|
||||||
useChildren() {
|
|
||||||
const optionalList = useOptionalFieldList();
|
|
||||||
const optionalChildren = optionalList.map((field) => ({
|
|
||||||
name: field.key,
|
|
||||||
title: field.uiSchema.title,
|
|
||||||
Component: 'AssociationFilterDesignerDisplayField',
|
|
||||||
schema: {
|
|
||||||
name: field.name,
|
|
||||||
title: field.uiSchema.title,
|
|
||||||
interface: field.interface,
|
|
||||||
type: 'void',
|
|
||||||
// 'x-designer': 'AssociationFilter.Item.Designer',
|
|
||||||
'x-toolbar': 'CollapseItemSchemaToolbar',
|
|
||||||
'x-settings': 'fieldSettings:FilterCollapseItem',
|
|
||||||
'x-component': 'AssociationFilter.Item',
|
|
||||||
'x-use-component-props': 'useAssociationFilterBlockProps',
|
|
||||||
'x-component-props': {
|
|
||||||
fieldNames: {
|
|
||||||
label: field.name,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
properties: {},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
return optionalChildren;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
filterCollapseItemInitializer_deprecated,
|
filterCollapseItemInitializer_deprecated,
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user