refactor: associationFilterInitializer

This commit is contained in:
Zeke Zhang 2024-03-07 18:59:22 +08:00
parent da186662d5
commit eff813a184
3 changed files with 4 additions and 61 deletions

View File

@ -37,7 +37,7 @@ export const ActionBarAssociationFilterAction = (props) => {
const schema = { const schema = {
type: 'void', type: 'void',
'x-action': 'associateFilter', 'x-action': 'associateFilter',
'x-initializer': 'fieldInitializers:associationFilter', 'x-initializer': 'AssociationFilter.Initializer',
'x-component': 'AssociationFilter', 'x-component': 'AssociationFilter',
properties: {}, properties: {},
}; };

View File

@ -1,11 +1,11 @@
import { CompatibleSchemaInitializer } from '../../../application/schema-initializer/CompatibleSchemaInitializer'; import { SchemaInitializer } from '../../../application/schema-initializer/SchemaInitializer';
import { SchemaInitializerItemType } from '../../../application/schema-initializer/types'; import { SchemaInitializerItemType } from '../../../application/schema-initializer/types';
import { useAssociatedFields } from '../../../filter-provider/utils'; import { useAssociatedFields } from '../../../filter-provider/utils';
/** /**
* @deprecated * @deprecated
*/ */
export const associationFilterInitializer_deprecated = new CompatibleSchemaInitializer({ export const associationFilterInitializer = new SchemaInitializer({
name: 'AssociationFilter.Initializer', name: 'AssociationFilter.Initializer',
style: { style: {
marginTop: 16, marginTop: 16,
@ -57,59 +57,3 @@ export const associationFilterInitializer_deprecated = new CompatibleSchemaIniti
}, },
], ],
}); });
export const associationFilterInitializer = new CompatibleSchemaInitializer(
{
name: 'fieldInitializers:associationFilter',
style: {
marginTop: 16,
},
icon: 'SettingOutlined',
title: '{{t("Configure fields")}}',
items: [
{
name: 'associationFields',
type: 'itemGroup',
title: '{{t("Association fields")}}',
useChildren() {
const associatedFields = useAssociatedFields();
const useProps = '{{useAssociationFilterProps}}';
const children: SchemaInitializerItemType[] = associatedFields.map((field) => ({
type: 'item',
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-component-props': {
fieldNames: {
label: field.targetKey || 'id',
},
useProps,
},
properties: {},
},
}));
return children;
},
},
{
name: 'divider',
type: 'divider',
},
{
name: 'delete',
title: '{{t("Delete")}}',
Component: 'AssociationFilterDesignerDelete',
},
],
},
associationFilterInitializer_deprecated,
);

View File

@ -17,7 +17,7 @@ import {
filterCollapseItemInitializer, filterCollapseItemInitializer,
filterCollapseItemInitializer_deprecated, filterCollapseItemInitializer_deprecated,
} from '../../../modules/blocks/filter-blocks/collapse/filterCollapseItemInitializer'; } from '../../../modules/blocks/filter-blocks/collapse/filterCollapseItemInitializer';
import { associationFilterInitializer, associationFilterInitializer_deprecated } from './AssociationFilter.Initializer'; import { associationFilterInitializer } from './AssociationFilter.Initializer';
export const AssociationFilter = (props) => { export const AssociationFilter = (props) => {
const { token } = useToken(); const { token } = useToken();
@ -107,7 +107,6 @@ export class AssociationFilterPlugin extends Plugin {
this.app.schemaInitializerManager.add(associationFilterFilterBlockInitializer); this.app.schemaInitializerManager.add(associationFilterFilterBlockInitializer);
this.app.schemaInitializerManager.add(filterCollapseItemInitializer_deprecated); this.app.schemaInitializerManager.add(filterCollapseItemInitializer_deprecated);
this.app.schemaInitializerManager.add(filterCollapseItemInitializer); this.app.schemaInitializerManager.add(filterCollapseItemInitializer);
this.app.schemaInitializerManager.add(associationFilterInitializer_deprecated);
this.app.schemaInitializerManager.add(associationFilterInitializer); this.app.schemaInitializerManager.add(associationFilterInitializer);
} }
} }