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:
parent
9fc8f5389b
commit
12f95810d0
@ -200,6 +200,60 @@ export const useCollectionFilterOptions = (collectionName: string) => {
|
|||||||
return options;
|
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) => {
|
export const useFilterDataSource = (options) => {
|
||||||
const { name } = useCollection();
|
const { name } = useCollection();
|
||||||
const data = useCollectionFilterOptions(name);
|
const data = useCollectionFilterOptions(name);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export { useCollectionFilterOptions, useSortFields } from './action-hooks';
|
export { useCollectionFilterOptions, useSortFields, useLinkageCollectionFilterOptions } from './action-hooks';
|
||||||
export * from './CollectionField';
|
export * from './CollectionField';
|
||||||
export * from './CollectionFieldProvider';
|
export * from './CollectionFieldProvider';
|
||||||
export * from './CollectionManagerProvider';
|
export * from './CollectionManagerProvider';
|
||||||
|
@ -58,7 +58,6 @@ const FormDecorator: React.FC<FormProps> = (props) => {
|
|||||||
const getLinkageRules = (fieldSchema) => {
|
const getLinkageRules = (fieldSchema) => {
|
||||||
let linkageRules = null;
|
let linkageRules = null;
|
||||||
fieldSchema.mapProperties((schema) => {
|
fieldSchema.mapProperties((schema) => {
|
||||||
console.log(schema);
|
|
||||||
if (schema['x-linkage-rules']) {
|
if (schema['x-linkage-rules']) {
|
||||||
linkageRules = schema['x-linkage-rules'];
|
linkageRules = schema['x-linkage-rules'];
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,30 @@ http://ricostacruz.com/cheatsheets/umdjs.html
|
|||||||
if (!a || typeof a.indexOf === 'undefined') return false;
|
if (!a || typeof a.indexOf === 'undefined') return false;
|
||||||
return !(a.indexOf(b) !== -1);
|
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) {
|
$isTruly: function (a) {
|
||||||
return a === true || a === 1;
|
return a === true || a === 1;
|
||||||
},
|
},
|
||||||
|
@ -35,7 +35,7 @@ import {
|
|||||||
findFormBlock,
|
findFormBlock,
|
||||||
useAPIClient,
|
useAPIClient,
|
||||||
useCollection,
|
useCollection,
|
||||||
useCollectionFilterOptions,
|
useLinkageCollectionFilterOptions,
|
||||||
useCollectionManager,
|
useCollectionManager,
|
||||||
useCompile,
|
useCompile,
|
||||||
useDesignable,
|
useDesignable,
|
||||||
@ -965,9 +965,7 @@ SchemaSettings.LinkageRules = (props) => {
|
|||||||
'x-component': FormLinkageRules,
|
'x-component': FormLinkageRules,
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
useProps: () => {
|
useProps: () => {
|
||||||
const options = useCollectionFilterOptions(collectionName).filter(
|
const options = useLinkageCollectionFilterOptions(collectionName);
|
||||||
(v) => !['o2m', 'm2m'].includes(v.interface),
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
options,
|
options,
|
||||||
defaultValues: gridSchema?.['x-linkage-rules'] || fieldSchema?.['x-linkage-rules'],
|
defaultValues: gridSchema?.['x-linkage-rules'] || fieldSchema?.['x-linkage-rules'],
|
||||||
@ -1062,7 +1060,6 @@ SchemaSettings.DataTemplates = (props) => {
|
|||||||
SchemaSettings.EnableChildCollections = (props) => {
|
SchemaSettings.EnableChildCollections = (props) => {
|
||||||
const { collectionName } = props;
|
const { collectionName } = props;
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
console.log(fieldSchema);
|
|
||||||
const { dn } = useDesignable();
|
const { dn } = useDesignable();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const allowAddToCurrent = fieldSchema?.['x-allow-add-to-current'];
|
const allowAddToCurrent = fieldSchema?.['x-allow-add-to-current'];
|
||||||
|
Loading…
Reference in New Issue
Block a user