fix(linkage-rule): condition variable field is allow select To many association fields (#1798)

* fix: linkage rule condiction variables allow select to manyassociation field

* fix: linkage rule condiction variables filter

* fix: linkage rule condiction variables filter
This commit is contained in:
katherinehhh 2023-05-05 10:59:33 +08:00 committed by GitHub
parent 6d342d0643
commit 89938191a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 7 deletions

View File

@ -62,7 +62,9 @@ export const linkageMergeAction = ({ operator, value }, field, condition, values
try { try {
const result = evaluate(value.result || value.value, { ...scope, now: () => new Date().toString() }); const result = evaluate(value.result || value.value, { ...scope, now: () => new Date().toString() });
valueResult.push(result); valueResult.push(result);
} catch (error) {} } catch (error) {
console.log(error);
}
} else if (value?.mode === 'constant') { } else if (value?.mode === 'constant') {
valueResult.push(value?.value || value); valueResult.push(value?.value || value);
} else { } else {

View File

@ -61,7 +61,7 @@ const getValue = (str: string, values) => {
const regex = /{{(.*?)}}/; const regex = /{{(.*?)}}/;
const matches = str?.match?.(regex); const matches = str?.match?.(regex);
if (matches) { if (matches) {
return getVariableValue(str, values); return getVariableValue(str, flat(values));
} else { } else {
return str; return str;
} }

View File

@ -11,7 +11,7 @@ type Props = {
export function FilterDynamicComponent(props: Props) { export function FilterDynamicComponent(props: Props) {
const { value, onChange, renderSchemaComponent, collectionName } = props; const { value, onChange, renderSchemaComponent, collectionName } = props;
const scope = useVariableOptions(collectionName); const scope = useVariableOptions(collectionName, ['o2m', 'm2m']);
return ( return (
<Variable.Input value={value} onChange={onChange} scope={scope}> <Variable.Input value={value} onChange={onChange} scope={scope}>
{renderSchemaComponent()} {renderSchemaComponent()}

View File

@ -2,6 +2,7 @@ import { useCompile } from '../../schema-component';
import { useCollectionManager, useCollection } from '../../collection-manager'; import { useCollectionManager, useCollection } from '../../collection-manager';
const supportsType = [ const supportsType = [
'id',
'checkbox', 'checkbox',
'number', 'number',
'percent', 'percent',
@ -24,7 +25,7 @@ const supportsType = [
'o2m', 'o2m',
'm2m', 'm2m',
]; ];
const useVariableTypes = (currentCollection) => { const useVariableTypes = (currentCollection, excludes = []) => {
const { getCollectionFields, getInterface, getCollection } = useCollectionManager(); const { getCollectionFields, getInterface, getCollection } = useCollectionManager();
const collection = getCollection(currentCollection); const collection = getCollection(currentCollection);
const fields = getCollectionFields(currentCollection); const fields = getCollectionFields(currentCollection);
@ -34,7 +35,7 @@ const useVariableTypes = (currentCollection) => {
value: currentCollection, value: currentCollection,
options() { options() {
const field2option = (field, depth) => { const field2option = (field, depth) => {
if (!field.interface || !supportsType.includes(field.interface)) { if (!field.interface || !supportsType.filter((v) => !excludes.includes(v)).includes(field.interface)) {
return; return;
} }
const fieldInterface = getInterface(field.interface); const fieldInterface = getInterface(field.interface);
@ -92,9 +93,9 @@ const useVariableTypes = (currentCollection) => {
]; ];
}; };
export function useVariableOptions(collectionName) { export function useVariableOptions(collectionName, excludes?) {
const compile = useCompile(); const compile = useCompile();
const options = useVariableTypes(collectionName).map((item) => { const options = useVariableTypes(collectionName, excludes).map((item) => {
const options = typeof item.options === 'function' ? item.options() : item.options; const options = typeof item.options === 'function' ? item.options() : item.options;
return { return {
label: compile(item.title), label: compile(item.title),