diff --git a/packages/core/client/src/block-provider/BlockProvider.tsx b/packages/core/client/src/block-provider/BlockProvider.tsx index 0c4e92cad7..a49a2da9a8 100644 --- a/packages/core/client/src/block-provider/BlockProvider.tsx +++ b/packages/core/client/src/block-provider/BlockProvider.tsx @@ -155,9 +155,9 @@ export const RenderChildrenWithAssociationFilter: React.FC = (props) => { { 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', diff --git a/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseItemFieldSettings.ts b/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseItemFieldSettings.ts index 79ea353863..2f56624bb0 100644 --- a/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseItemFieldSettings.ts +++ b/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseItemFieldSettings.ts @@ -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) => ({ diff --git a/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseItemInitializer.tsx b/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseItemInitializer.tsx index e712c4589c..cf9b6ac5a9 100644 --- a/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseItemInitializer.tsx +++ b/packages/core/client/src/modules/blocks/filter-blocks/collapse/filterCollapseItemInitializer.tsx @@ -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, );