diff --git a/packages/core/client/src/block-provider/BlockSchemaComponentProvider.tsx b/packages/core/client/src/block-provider/BlockSchemaComponentProvider.tsx index f453264bd..e5b1b8c69 100644 --- a/packages/core/client/src/block-provider/BlockSchemaComponentProvider.tsx +++ b/packages/core/client/src/block-provider/BlockSchemaComponentProvider.tsx @@ -23,6 +23,7 @@ import * as bp from './hooks'; import { useTableBlockDecoratorProps } from '../modules/blocks/data-blocks/table/hooks/useTableBlockDecoratorProps'; import { useListBlockDecoratorProps } from '../modules/blocks/data-blocks/list/hooks/useListBlockDecoratorProps'; import { useTableSelectorDecoratorProps } from '../modules/blocks/data-blocks/table-selector/hooks/useTableSelectorDecoratorProps'; +import { useCollapseBlockDecoratorProps } from '../modules/blocks/filter-blocks/collapse/hooks/useCollapseBlockDecoratorProps'; // TODO: delete this, replaced by `BlockSchemaComponentPlugin` export const BlockSchemaComponentProvider: React.FC = (props) => { @@ -56,6 +57,7 @@ export const BlockSchemaComponentProvider: React.FC = (props) => { useTableBlockDecoratorProps, useListBlockDecoratorProps, useTableSelectorDecoratorProps, + useCollapseBlockDecoratorProps, }} > {props.children} @@ -106,6 +108,7 @@ export class BlockSchemaComponentPlugin extends Plugin { useTableBlockDecoratorProps, useListBlockDecoratorProps, useTableSelectorDecoratorProps, + useCollapseBlockDecoratorProps, }); } } diff --git a/packages/core/client/src/modules/blocks/filter-blocks/collapse/FilterCollapseBlockInitializer.tsx b/packages/core/client/src/modules/blocks/filter-blocks/collapse/FilterCollapseBlockInitializer.tsx index 075f59343..28016afed 100644 --- a/packages/core/client/src/modules/blocks/filter-blocks/collapse/FilterCollapseBlockInitializer.tsx +++ b/packages/core/client/src/modules/blocks/filter-blocks/collapse/FilterCollapseBlockInitializer.tsx @@ -2,7 +2,7 @@ import { TableOutlined } from '@ant-design/icons'; import React from 'react'; import { useSchemaInitializer, useSchemaInitializerItem } from '../../../../application'; -import { createCollapseBlockSchema } from '../../../../schema-initializer/utils'; +import { createCollapseBlockSchema } from './createFilterCollapseBlockSchema'; import { DataBlockInitializer } from '../../../../schema-initializer/items/DataBlockInitializer'; import { Collection, CollectionFieldOptions } from '../../../../data-source'; @@ -27,7 +27,7 @@ export const FilterCollapseBlockInitializer = ({ onCreateBlockSchema={async ({ item }) => { const schema = createCollapseBlockSchema({ dataSource: item.dataSource, - collection: item.collectionName || item.name, + collectionName: item.collectionName || item.name, // 与数据区块做区分 blockType: 'filter', }); diff --git a/packages/core/client/src/modules/blocks/filter-blocks/collapse/__tests__/createCollapseBlockSchema.test.ts b/packages/core/client/src/modules/blocks/filter-blocks/collapse/__tests__/createCollapseBlockSchema.test.ts new file mode 100644 index 000000000..5fa7b6c27 --- /dev/null +++ b/packages/core/client/src/modules/blocks/filter-blocks/collapse/__tests__/createCollapseBlockSchema.test.ts @@ -0,0 +1,44 @@ +import { createCollapseBlockSchema } from '../createFilterCollapseBlockSchema'; + +vi.mock('@formily/shared', () => ({ + uid: vi.fn().mockReturnValue('mocked-uid'), +})); + +describe('createCollapseBlockSchema', () => { + it('should return the correct schema', () => { + const options = { + collectionName: 'testCollection', + dataSource: 'testDataSource', + blockType: 'testBlockType', + }; + + const schema = createCollapseBlockSchema(options); + + expect(schema).toEqual({ + type: 'void', + 'x-decorator': 'AssociationFilter.Provider', + 'x-use-decorator-props': 'useCollapseBlockDecoratorProps', + 'x-decorator-props': { + collection: 'testCollection', + dataSource: 'testDataSource', + blockType: 'testBlockType', + associationFilterStyle: { + width: '100%', + }, + name: 'filter-collapse', + }, + 'x-toolbar': 'BlockSchemaToolbar', + 'x-settings': 'blockSettings:filterCollapse', + 'x-component': 'CardItem', + 'x-filter-targets': [], + properties: { + 'mocked-uid': { + type: 'void', + 'x-action': 'associateFilter', + 'x-initializer': 'filterCollapse:configureFields', + 'x-component': 'AssociationFilter', + }, + }, + }); + }); +}); diff --git a/packages/core/client/src/modules/blocks/filter-blocks/collapse/createFilterCollapseBlockSchema.ts b/packages/core/client/src/modules/blocks/filter-blocks/collapse/createFilterCollapseBlockSchema.ts new file mode 100644 index 000000000..2d713a61b --- /dev/null +++ b/packages/core/client/src/modules/blocks/filter-blocks/collapse/createFilterCollapseBlockSchema.ts @@ -0,0 +1,37 @@ +import { ISchema } from '@formily/react'; +import { uid } from '@formily/shared'; + +export const createCollapseBlockSchema = (options: { + collectionName: string; + dataSource: string; + blockType: string; +}): ISchema => { + const { collectionName, dataSource, blockType } = options; + + return { + type: 'void', + 'x-decorator': 'AssociationFilter.Provider', + 'x-use-decorator-props': 'useCollapseBlockDecoratorProps', + 'x-decorator-props': { + collection: collectionName, + dataSource, + blockType, + associationFilterStyle: { + width: '100%', + }, + name: 'filter-collapse', + }, + 'x-toolbar': 'BlockSchemaToolbar', + 'x-settings': 'blockSettings:filterCollapse', + 'x-component': 'CardItem', + 'x-filter-targets': [], + properties: { + [uid()]: { + type: 'void', + 'x-action': 'associateFilter', + 'x-initializer': 'filterCollapse:configureFields', + 'x-component': 'AssociationFilter', + }, + }, + }; +}; diff --git a/packages/core/client/src/modules/blocks/filter-blocks/collapse/hooks/useCollapseBlockDecoratorProps.ts b/packages/core/client/src/modules/blocks/filter-blocks/collapse/hooks/useCollapseBlockDecoratorProps.ts new file mode 100644 index 000000000..eadf9277d --- /dev/null +++ b/packages/core/client/src/modules/blocks/filter-blocks/collapse/hooks/useCollapseBlockDecoratorProps.ts @@ -0,0 +1 @@ +export function useCollapseBlockDecoratorProps() {} diff --git a/packages/core/client/src/schema-initializer/utils.ts b/packages/core/client/src/schema-initializer/utils.ts index 01b339c4d..cd1998681 100644 --- a/packages/core/client/src/schema-initializer/utils.ts +++ b/packages/core/client/src/schema-initializer/utils.ts @@ -1383,38 +1383,6 @@ export const createTableBlockSchema = (options) => { return schema; }; -export const createCollapseBlockSchema = (options) => { - const { collection, dataSource, blockType } = options; - const schema: ISchema = { - type: 'void', - 'x-decorator': 'AssociationFilter.Provider', - 'x-decorator-props': { - collection, - dataSource, - blockType, - associationFilterStyle: { - width: '100%', - }, - name: 'filter-collapse', - }, - 'x-toolbar': 'BlockSchemaToolbar', - 'x-settings': 'blockSettings:filterCollapse', - 'x-component': 'CardItem', - 'x-filter-targets': [], - properties: { - [uid()]: { - type: 'void', - 'x-action': 'associateFilter', - 'x-initializer': 'filterCollapse:configureFields', - 'x-component': 'AssociationFilter', - properties: {}, - }, - }, - }; - - return schema; -}; - const getChildren = ({ collections, dataSource,