fix(linkage rule):multiple select condition judgment failed (#1715)

* fix: linkageCollectionFilterOptions

* fix: multiple select  condition judgment failed

* fix: multiple select  condition judgment failed

* fix: multiple select  condition judgment failed
This commit is contained in:
katherinehhh 2023-04-17 17:19:54 +08:00 committed by GitHub
parent 9fc8f5389b
commit 12f95810d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 81 additions and 7 deletions

View File

@ -200,6 +200,60 @@ export const useCollectionFilterOptions = (collectionName: string) => {
return options;
};
export const useLinkageCollectionFilterOptions = (collectionName: string) => {
const { getCollectionFields, getInterface } = useCollectionManager();
const fields = getCollectionFields(collectionName).filter((v)=>!['o2m', 'm2m'].includes(v.interface))
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).filter((v)=>!['o2m', 'm2m'].includes(v.interface))
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 useFilterDataSource = (options) => {
const { name } = useCollection();
const data = useCollectionFilterOptions(name);

View File

@ -1,4 +1,4 @@
export { useCollectionFilterOptions, useSortFields } from './action-hooks';
export { useCollectionFilterOptions, useSortFields, useLinkageCollectionFilterOptions } from './action-hooks';
export * from './CollectionField';
export * from './CollectionFieldProvider';
export * from './CollectionManagerProvider';

View File

@ -58,7 +58,6 @@ const FormDecorator: React.FC<FormProps> = (props) => {
const getLinkageRules = (fieldSchema) => {
let linkageRules = null;
fieldSchema.mapProperties((schema) => {
console.log(schema);
if (schema['x-linkage-rules']) {
linkageRules = schema['x-linkage-rules'];
}

View File

@ -100,6 +100,30 @@ http://ricostacruz.com/cheatsheets/umdjs.html
if (!a || typeof a.indexOf === 'undefined') return false;
return !(a.indexOf(b) !== -1);
},
$anyOf: function (a, b) {
if (a.length === 0) {
return false;
}
return b.every((item) => a.includes(item));
},
$noneOf: function (a, b) {
if (a.length === 0) {
return true;
}
return b.some((item) => !a.includes(item));
},
$notMatch:function(a,b){
if (a.length !== b.length) {
return true;
}
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return true;
}
}
return false;
},
$isTruly: function (a) {
return a === true || a === 1;
},

View File

@ -35,7 +35,7 @@ import {
findFormBlock,
useAPIClient,
useCollection,
useCollectionFilterOptions,
useLinkageCollectionFilterOptions,
useCollectionManager,
useCompile,
useDesignable,
@ -965,9 +965,7 @@ SchemaSettings.LinkageRules = (props) => {
'x-component': FormLinkageRules,
'x-component-props': {
useProps: () => {
const options = useCollectionFilterOptions(collectionName).filter(
(v) => !['o2m', 'm2m'].includes(v.interface),
);
const options = useLinkageCollectionFilterOptions(collectionName);
return {
options,
defaultValues: gridSchema?.['x-linkage-rules'] || fieldSchema?.['x-linkage-rules'],
@ -1062,7 +1060,6 @@ SchemaSettings.DataTemplates = (props) => {
SchemaSettings.EnableChildCollections = (props) => {
const { collectionName } = props;
const fieldSchema = useFieldSchema();
console.log(fieldSchema);
const { dn } = useDesignable();
const { t } = useTranslation();
const allowAddToCurrent = fieldSchema?.['x-allow-add-to-current'];