mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 13:06:31 +00:00
fix(LinkageRules): fix appends (#3537)
* fix(LinkageRules): fix appends * fix: fix nested rules (T-3152)
This commit is contained in:
parent
bb46697e71
commit
b61cedecb2
@ -1222,12 +1222,15 @@ export const useAssociationNames = () => {
|
|||||||
|
|
||||||
// 根据联动规则中条件的字段获取一些 appends
|
// 根据联动规则中条件的字段获取一些 appends
|
||||||
if (s['x-linkage-rules']) {
|
if (s['x-linkage-rules']) {
|
||||||
const rules = s['x-linkage-rules'];
|
const collectAppends = (obj) => {
|
||||||
rules.forEach(({ condition }) => {
|
const type = Object.keys(obj)[0] || '$and';
|
||||||
const type = Object.keys(condition)[0] || '$and';
|
const list = obj[type];
|
||||||
const list = condition[type];
|
|
||||||
|
|
||||||
list.forEach((item) => {
|
list.forEach((item) => {
|
||||||
|
if ('$and' in item || '$or' in item) {
|
||||||
|
return collectAppends(item);
|
||||||
|
}
|
||||||
|
|
||||||
const fieldNames = getTargetField(item);
|
const fieldNames = getTargetField(item);
|
||||||
|
|
||||||
// 只应该收集关系字段,只有大于 1 的时候才是关系字段
|
// 只应该收集关系字段,只有大于 1 的时候才是关系字段
|
||||||
@ -1235,6 +1238,11 @@ export const useAssociationNames = () => {
|
|||||||
appends.add(fieldNames.join('.'));
|
appends.add(fieldNames.join('.'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const rules = s['x-linkage-rules'];
|
||||||
|
rules.forEach(({ condition }) => {
|
||||||
|
collectAppends(condition);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ export const linkageAction = async ({
|
|||||||
|
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case ActionType.Visible:
|
case ActionType.Visible:
|
||||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
if (await conditionAnalyses({ ruleGroup: condition, variables, localVariables })) {
|
||||||
displayResult.push(operator);
|
displayResult.push(operator);
|
||||||
field.data = field.data || {};
|
field.data = field.data || {};
|
||||||
field.data.hidden = false;
|
field.data.hidden = false;
|
||||||
@ -101,7 +101,7 @@ export const linkageAction = async ({
|
|||||||
field.display = last(displayResult);
|
field.display = last(displayResult);
|
||||||
break;
|
break;
|
||||||
case ActionType.Hidden:
|
case ActionType.Hidden:
|
||||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
if (await conditionAnalyses({ ruleGroup: condition, variables, localVariables })) {
|
||||||
field.data = field.data || {};
|
field.data = field.data || {};
|
||||||
field.data.hidden = true;
|
field.data.hidden = true;
|
||||||
} else {
|
} else {
|
||||||
@ -110,7 +110,7 @@ export const linkageAction = async ({
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ActionType.Disabled:
|
case ActionType.Disabled:
|
||||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
if (await conditionAnalyses({ ruleGroup: condition, variables, localVariables })) {
|
||||||
disableResult.push(true);
|
disableResult.push(true);
|
||||||
}
|
}
|
||||||
field.stateOfLinkageRules = {
|
field.stateOfLinkageRules = {
|
||||||
@ -121,7 +121,7 @@ export const linkageAction = async ({
|
|||||||
field.componentProps['disabled'] = last(disableResult);
|
field.componentProps['disabled'] = last(disableResult);
|
||||||
break;
|
break;
|
||||||
case ActionType.Active:
|
case ActionType.Active:
|
||||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
if (await conditionAnalyses({ ruleGroup: condition, variables, localVariables })) {
|
||||||
disableResult.push(false);
|
disableResult.push(false);
|
||||||
}
|
}
|
||||||
field.stateOfLinkageRules = {
|
field.stateOfLinkageRules = {
|
||||||
|
@ -46,14 +46,18 @@ export const collectFieldStateOfLinkageRules = ({
|
|||||||
|
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case ActionType.Required:
|
case ActionType.Required:
|
||||||
requiredResult.push(getTempFieldState(conditionAnalyses({ rules: condition, variables, localVariables }), true));
|
requiredResult.push(
|
||||||
|
getTempFieldState(conditionAnalyses({ ruleGroup: condition, variables, localVariables }), true),
|
||||||
|
);
|
||||||
field.stateOfLinkageRules = {
|
field.stateOfLinkageRules = {
|
||||||
...field.stateOfLinkageRules,
|
...field.stateOfLinkageRules,
|
||||||
required: requiredResult,
|
required: requiredResult,
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case ActionType.InRequired:
|
case ActionType.InRequired:
|
||||||
requiredResult.push(getTempFieldState(conditionAnalyses({ rules: condition, variables, localVariables }), false));
|
requiredResult.push(
|
||||||
|
getTempFieldState(conditionAnalyses({ ruleGroup: condition, variables, localVariables }), false),
|
||||||
|
);
|
||||||
field.stateOfLinkageRules = {
|
field.stateOfLinkageRules = {
|
||||||
...field.stateOfLinkageRules,
|
...field.stateOfLinkageRules,
|
||||||
required: requiredResult,
|
required: requiredResult,
|
||||||
@ -63,7 +67,7 @@ export const collectFieldStateOfLinkageRules = ({
|
|||||||
case ActionType.None:
|
case ActionType.None:
|
||||||
case ActionType.Hidden:
|
case ActionType.Hidden:
|
||||||
displayResult.push(
|
displayResult.push(
|
||||||
getTempFieldState(conditionAnalyses({ rules: condition, variables, localVariables }), operator),
|
getTempFieldState(conditionAnalyses({ ruleGroup: condition, variables, localVariables }), operator),
|
||||||
);
|
);
|
||||||
field.stateOfLinkageRules = {
|
field.stateOfLinkageRules = {
|
||||||
...field.stateOfLinkageRules,
|
...field.stateOfLinkageRules,
|
||||||
@ -74,7 +78,7 @@ export const collectFieldStateOfLinkageRules = ({
|
|||||||
case ActionType.ReadOnly:
|
case ActionType.ReadOnly:
|
||||||
case ActionType.ReadPretty:
|
case ActionType.ReadPretty:
|
||||||
patternResult.push(
|
patternResult.push(
|
||||||
getTempFieldState(conditionAnalyses({ rules: condition, variables, localVariables }), operator),
|
getTempFieldState(conditionAnalyses({ ruleGroup: condition, variables, localVariables }), operator),
|
||||||
);
|
);
|
||||||
field.stateOfLinkageRules = {
|
field.stateOfLinkageRules = {
|
||||||
...field.stateOfLinkageRules,
|
...field.stateOfLinkageRules,
|
||||||
@ -111,7 +115,7 @@ export const collectFieldStateOfLinkageRules = ({
|
|||||||
valueResult.push(getTempFieldState(true, getValue()));
|
valueResult.push(getTempFieldState(true, getValue()));
|
||||||
} else {
|
} else {
|
||||||
valueResult.push(
|
valueResult.push(
|
||||||
getTempFieldState(conditionAnalyses({ rules: condition, variables, localVariables }), getValue()),
|
getTempFieldState(conditionAnalyses({ ruleGroup: condition, variables, localVariables }), getValue()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
field.stateOfLinkageRules = {
|
field.stateOfLinkageRules = {
|
||||||
|
@ -66,24 +66,23 @@ function getAllKeys(obj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const conditionAnalyses = async ({
|
export const conditionAnalyses = async ({
|
||||||
rules,
|
ruleGroup,
|
||||||
variables,
|
variables,
|
||||||
localVariables,
|
localVariables,
|
||||||
}: {
|
}: {
|
||||||
rules;
|
ruleGroup;
|
||||||
variables: VariablesContextType;
|
variables: VariablesContextType;
|
||||||
localVariables: VariableOption[];
|
localVariables: VariableOption[];
|
||||||
}) => {
|
}) => {
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
const type = Object.keys(ruleGroup)[0] || '$and';
|
||||||
if (!variables) {
|
const conditions = ruleGroup[type];
|
||||||
throw new Error(`conditionAnalyses: variables cannot be ${variables}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const type = Object.keys(rules)[0] || '$and';
|
|
||||||
const conditions = rules[type];
|
|
||||||
|
|
||||||
let results = conditions.map(async (condition) => {
|
let results = conditions.map(async (condition) => {
|
||||||
|
// fix https://nocobase.height.app/T-3152
|
||||||
|
if ('$and' in condition || '$or' in condition) {
|
||||||
|
return await conditionAnalyses({ ruleGroup: condition, variables, localVariables });
|
||||||
|
}
|
||||||
|
|
||||||
const jsonlogic = getInnermostKeyAndValue(condition);
|
const jsonlogic = getInnermostKeyAndValue(condition);
|
||||||
const operator = jsonlogic?.key;
|
const operator = jsonlogic?.key;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user