fix: 将过滤按钮的过滤条件放到三级 (#550)

Reviewed-on: daoyoucloud/tachycode#550
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
Co-authored-by: wjh <wwwjh0710@163.com>
Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
wjh 2024-04-01 11:48:22 +08:00 committed by sealday
parent 8c4730a4ab
commit bc9ac59ac2

View File

@ -397,6 +397,59 @@ const findGridSchema = (fieldSchema) => {
}, null);
};
export const useCollectionFilterOptions = (collectionName: string) => {
const { getCollectionFields, getInterface } = useCollectionManager_deprecated();
const fields = getCollectionFields(collectionName);
const field2option = (field, depth) => {
if (!field.interface) {
return;
}
const fieldInterface = getInterface(field.interface);
if (!fieldInterface?.filterable) {
return;
}
const { nested, children, operators } = fieldInterface.filterable;
const option = {
name: field.name,
title: field?.uiSchema?.title || field.name,
schema: field?.uiSchema,
operators:
operators?.filter?.((operator) => {
return !operator?.visible || operator.visible(field);
}) || [],
interface: field.interface,
};
if (field.target && depth > 2) {
return;
}
if (depth > 2) {
return option;
}
if (children?.length) {
option['children'] = children;
}
if (nested) {
const targetFields = getCollectionFields(field.target);
const options = getOptions(targetFields, depth + 1).filter(Boolean);
option['children'] = option['children'] || [];
option['children'].push(...options);
}
return option;
};
const getOptions = (fields, depth) => {
const options = [];
fields.forEach((field) => {
const option = field2option(field, depth);
if (option) {
options.push(option);
}
});
return options;
};
const options = getOptions(fields, 1);
return options;
};
export const SetFilterScope = (props) => {
const { t } = useTranslation();
const fieldSchema = useFieldSchema();
@ -419,7 +472,7 @@ export const SetFilterScope = (props) => {
'x-component': FormFilterScope,
'x-component-props': {
useProps: () => {
const options = useLinkageCollectionFilterOptions(collectionName);
const options = useCollectionFilterOptions(collectionName);
return {
options,
defaultValues: gridSchema?.['x-filter-rules'] || fieldSchema?.['x-filter-rules'],