mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 03:56:16 +00:00
fix(linkageRules): fix an exception when the condition contains a association field (#5037)
This commit is contained in:
parent
c42a2040e2
commit
d6c2cfe602
@ -100,7 +100,9 @@ export const conditionAnalyses = async ({
|
||||
}
|
||||
|
||||
const targetVariableName = targetFieldToVariableString(getTargetField(condition));
|
||||
const targetValue = variables.parseVariable(targetVariableName, localVariables);
|
||||
const targetValue = variables.parseVariable(targetVariableName, localVariables, {
|
||||
doNotRequest: true,
|
||||
});
|
||||
|
||||
const parsingResult = isVariable(jsonlogic?.value)
|
||||
? [variables.parseVariable(jsonlogic?.value, localVariables), targetValue]
|
||||
|
@ -76,6 +76,8 @@ const VariablesProvider = ({ children }) => {
|
||||
options?: {
|
||||
/** 第一次请求时,需要包含的关系字段 */
|
||||
appends?: string[];
|
||||
/** do not request when the association field is empty */
|
||||
doNotRequest?: boolean;
|
||||
},
|
||||
) => {
|
||||
const list = variablePath.split('.');
|
||||
@ -100,7 +102,7 @@ const VariablesProvider = ({ children }) => {
|
||||
const collectionPrimaryKey = getCollection(collectionName)?.getPrimaryKey();
|
||||
if (Array.isArray(current)) {
|
||||
const result = current.map((item) => {
|
||||
if (shouldToRequest(item?.[key]) && item?.[collectionPrimaryKey] != null) {
|
||||
if (!options?.doNotRequest && shouldToRequest(item?.[key]) && item?.[collectionPrimaryKey] != null) {
|
||||
if (associationField?.target) {
|
||||
const url = `/${collectionName}/${
|
||||
item[associationField.sourceKey || collectionPrimaryKey]
|
||||
@ -128,7 +130,12 @@ const VariablesProvider = ({ children }) => {
|
||||
return item?.[key];
|
||||
});
|
||||
current = removeThroughCollectionFields(_.flatten(await Promise.all(result)), associationField);
|
||||
} else if (shouldToRequest(current[key]) && current[collectionPrimaryKey] != null && associationField?.target) {
|
||||
} else if (
|
||||
!options?.doNotRequest &&
|
||||
shouldToRequest(current[key]) &&
|
||||
current[collectionPrimaryKey] != null &&
|
||||
associationField?.target
|
||||
) {
|
||||
const url = `/${collectionName}/${
|
||||
current[associationField.sourceKey || collectionPrimaryKey]
|
||||
}/${key}:${getAction(associationField.type)}`;
|
||||
@ -228,6 +235,8 @@ const VariablesProvider = ({ children }) => {
|
||||
options?: {
|
||||
/** 第一次请求时,需要包含的关系字段 */
|
||||
appends?: string[];
|
||||
/** do not request when the association field is empty */
|
||||
doNotRequest?: boolean;
|
||||
},
|
||||
) => {
|
||||
if (!isVariable(str)) {
|
||||
|
@ -303,6 +303,18 @@ describe('useVariables', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('set doNotRequest to true to ensure the result is empty', async () => {
|
||||
const { result } = renderHook(() => useVariables(), {
|
||||
wrapper: Providers,
|
||||
});
|
||||
|
||||
await waitFor(async () => {
|
||||
expect(await result.current.parseVariable('{{ $user.belongsToField }}', undefined, { doNotRequest: true })).toBe(
|
||||
null,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('long variable path', async () => {
|
||||
const { result } = renderHook(() => useVariables(), {
|
||||
wrapper: Providers,
|
||||
|
@ -44,6 +44,8 @@ export interface VariablesContextType {
|
||||
options?: {
|
||||
/** 第一次请求时,需要包含的关系字段 */
|
||||
appends?: string[];
|
||||
/** do not request when the association field is empty */
|
||||
doNotRequest?: boolean;
|
||||
},
|
||||
) => Promise<any>;
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user