mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 08:55:33 +00:00
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:
parent
6d342d0643
commit
89938191a3
@ -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 {
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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()}
|
||||||
|
@ -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),
|
||||||
|
Loading…
Reference in New Issue
Block a user