mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 09:29:16 +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}>
|
||||
<Col
|
||||
style={{
|
||||
...(props.associationFilterStyle || {}),
|
||||
width: 200,
|
||||
flex: '0 0 auto',
|
||||
...(props.associationFilterStyle || {}),
|
||||
}}
|
||||
>
|
||||
<RecursionField
|
||||
|
@ -1158,12 +1158,12 @@ export const useAssociationFilterProps = () => {
|
||||
export const useOptionalFieldList = () => {
|
||||
const { currentFields = [] } = useCollection_deprecated();
|
||||
|
||||
return currentFields.filter((field) => isOptionalField(field) && field.uiSchema.enum);
|
||||
return currentFields.filter((field) => isOptionalField(field));
|
||||
};
|
||||
|
||||
const isOptionalField = (field) => {
|
||||
const optionalInterfaces = ['select', 'multipleSelect', 'checkbox', 'checkboxGroup', 'chinaRegion'];
|
||||
return optionalInterfaces.includes(field.interface);
|
||||
return optionalInterfaces.includes(field.interface) && field.uiSchema.enum;
|
||||
};
|
||||
|
||||
export const useAssociationFilterBlockProps = () => {
|
||||
@ -1206,16 +1206,16 @@ export const useAssociationFilterBlockProps = () => {
|
||||
|
||||
useEffect(() => {
|
||||
// 由于 选项字段不需要触发当前请求,所以请求单独在 关系字段的时候触发
|
||||
if (!isOptionalField(fieldSchema)) {
|
||||
if (!isOptionalField(collectionField)) {
|
||||
run();
|
||||
}
|
||||
}, [labelKey, valueKey, JSON.stringify(field.componentProps?.params || {}), isOptionalField(fieldSchema)]);
|
||||
}, [collectionField, labelKey, run, valueKey]);
|
||||
|
||||
if (!collectionField) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (isOptionalField(fieldSchema)) {
|
||||
if (isOptionalField(collectionField)) {
|
||||
const field = optionalFieldList.find((field) => field.name === fieldSchema.name);
|
||||
const operatorMap = {
|
||||
select: '$in',
|
||||
|
@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';
|
||||
import { SchemaSettings } from '../../../../application/schema-settings/SchemaSettings';
|
||||
import { useFormBlockContext } from '../../../../block-provider';
|
||||
import { useCollectionManager_deprecated, useCollection_deprecated } from '../../../../collection-manager';
|
||||
import { useCollectionManager } from '../../../../data-source/collection/CollectionManagerProvider';
|
||||
import { useCompile, useDesignable } from '../../../../schema-component';
|
||||
import { SchemaSettingsDefaultSortingRules } from '../../../../schema-settings';
|
||||
import { SchemaSettingsDataScope } from '../../../../schema-settings/SchemaSettingsDataScope';
|
||||
@ -150,10 +151,10 @@ export const filterCollapseItemFieldSettings = new SchemaSettings({
|
||||
const { getField } = useCollection_deprecated();
|
||||
const collectionField =
|
||||
getField(fieldSchema['name']) || getCollectionJoinField(fieldSchema['x-collection-field']);
|
||||
const { getCollectionFields } = useCollectionManager_deprecated();
|
||||
const cm = useCollectionManager();
|
||||
const compile = useCompile();
|
||||
const { dn } = useDesignable();
|
||||
const targetFields = collectionField?.target ? getCollectionFields(collectionField?.target) : [];
|
||||
const targetFields = collectionField?.target ? cm.getCollectionFields(collectionField?.target) : [];
|
||||
const options = targetFields
|
||||
.filter((field) => !field?.target && field.type !== 'boolean')
|
||||
.map((field) => ({
|
||||
|
@ -4,11 +4,7 @@ import { useOptionalFieldList } from '../../../../block-provider/hooks';
|
||||
import { useCollectionManager_deprecated } from '../../../../collection-manager';
|
||||
import { useAssociatedFields } from '../../../../filter-provider/utils';
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export const associationFilterFilterBlockInitializer = new SchemaInitializer({
|
||||
name: 'AssociationFilter.FilterBlockInitializer',
|
||||
const commonOptions: any = {
|
||||
style: { marginTop: 16 },
|
||||
icon: 'SettingOutlined',
|
||||
title: '{{t("Configure fields")}}',
|
||||
@ -18,6 +14,7 @@ export const associationFilterFilterBlockInitializer = new SchemaInitializer({
|
||||
name: 'associationFields',
|
||||
title: '{{t("Association fields")}}',
|
||||
useChildren() {
|
||||
const cm = useCollectionManager_deprecated();
|
||||
const associatedFields = useAssociatedFields();
|
||||
const children = associatedFields.map((field) => ({
|
||||
name: field.key,
|
||||
@ -34,7 +31,7 @@ export const associationFilterFilterBlockInitializer = new SchemaInitializer({
|
||||
'x-use-component-props': 'useAssociationFilterBlockProps',
|
||||
'x-component-props': {
|
||||
fieldNames: {
|
||||
label: field.targetKey || 'id',
|
||||
label: field.targetKey || cm.getCollection(field.target)?.getPrimaryKey() || 'id',
|
||||
},
|
||||
},
|
||||
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({
|
||||
name: 'AssociationFilterInitializers',
|
||||
style: { marginTop: 16 },
|
||||
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;
|
||||
},
|
||||
},
|
||||
],
|
||||
...commonOptions,
|
||||
});
|
||||
|
||||
export const filterCollapseItemInitializer = new CompatibleSchemaInitializer(
|
||||
{
|
||||
name: 'filterCollapse:configureFields',
|
||||
style: { marginTop: 16 },
|
||||
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;
|
||||
},
|
||||
},
|
||||
],
|
||||
...commonOptions,
|
||||
},
|
||||
filterCollapseItemInitializer_deprecated,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user