mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-03 12:47:44 +08:00
refactor(DataBlock): filter collapse block (#3786)
* refactor: filter collapse block * refactor: rename file name
This commit is contained in:
parent
16cad6972e
commit
71005ff9bf
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
});
|
||||
|
@ -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',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
@ -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',
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
@ -0,0 +1 @@
|
||||
export function useCollapseBlockDecoratorProps() {}
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user