mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:15:36 +00:00
fix: avoid infinite loop (#2974)
* fix: avoid infinite loop * perf: avoid infinite loop * fix: build errors
This commit is contained in:
parent
ac3f63b110
commit
f1e387e65e
@ -83,13 +83,12 @@ export const Action: ComposedAction = observer(
|
||||
operator: h.operator,
|
||||
field,
|
||||
condition: v.condition,
|
||||
values: record,
|
||||
variables,
|
||||
localVariables,
|
||||
});
|
||||
});
|
||||
});
|
||||
}, [JSON.stringify(linkageRules), record, designable, field]);
|
||||
}, [JSON.stringify(linkageRules), designable, field]);
|
||||
|
||||
const handleButtonClick = useCallback(
|
||||
(e: React.MouseEvent) => {
|
||||
|
@ -75,14 +75,12 @@ export const linkageAction = async ({
|
||||
operator,
|
||||
field,
|
||||
condition,
|
||||
values,
|
||||
variables,
|
||||
localVariables,
|
||||
}: {
|
||||
operator;
|
||||
field;
|
||||
condition;
|
||||
values;
|
||||
variables: VariablesContextType;
|
||||
localVariables: VariableOption[];
|
||||
}) => {
|
||||
@ -91,7 +89,7 @@ export const linkageAction = async ({
|
||||
|
||||
switch (operator) {
|
||||
case ActionType.Visible:
|
||||
if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) {
|
||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
||||
displayResult.push(operator);
|
||||
field.data = field.data || {};
|
||||
field.data.hidden = false;
|
||||
@ -103,7 +101,7 @@ export const linkageAction = async ({
|
||||
field.display = last(displayResult);
|
||||
break;
|
||||
case ActionType.Hidden:
|
||||
if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) {
|
||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
||||
field.data = field.data || {};
|
||||
field.data.hidden = true;
|
||||
} else {
|
||||
@ -112,7 +110,7 @@ export const linkageAction = async ({
|
||||
}
|
||||
break;
|
||||
case ActionType.Disabled:
|
||||
if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) {
|
||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
||||
disableResult.push(true);
|
||||
}
|
||||
field.linkageProperty = {
|
||||
@ -123,7 +121,7 @@ export const linkageAction = async ({
|
||||
field.componentProps['disabled'] = last(disableResult);
|
||||
break;
|
||||
case ActionType.Active:
|
||||
if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) {
|
||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
||||
disableResult.push(false);
|
||||
} else {
|
||||
disableResult.push(true);
|
||||
|
@ -138,7 +138,7 @@ const getEnd = (offset: any, unit: any) => {
|
||||
|
||||
export const getDateRanges = () => {
|
||||
return {
|
||||
now: () => dayjs(),
|
||||
now: () => dayjs().toISOString(),
|
||||
today: () => [getStart(0, 'day'), getEnd(0, 'day')],
|
||||
yesterday: () => [getStart(-1, 'day'), getEnd(-1, 'day')],
|
||||
tomorrow: () => [getStart(1, 'day'), getEnd(1, 'day')],
|
||||
|
@ -2,7 +2,7 @@ import { css } from '@emotion/css';
|
||||
import { FormLayout } from '@formily/antd-v5';
|
||||
import { createForm, Field, Form as FormilyForm, onFieldChange, onFieldInit, onFormInputChange } from '@formily/core';
|
||||
import { FieldContext, FormContext, observer, RecursionField, useField, useFieldSchema } from '@formily/react';
|
||||
import { autorun } from '@formily/reactive';
|
||||
import { autorun, raw } from '@formily/reactive';
|
||||
import { uid } from '@formily/shared';
|
||||
import { ConfigProvider, Spin } from 'antd';
|
||||
import React, { useEffect, useMemo } from 'react';
|
||||
@ -134,7 +134,7 @@ const WithForm = (props: WithFormProps) => {
|
||||
value: h.value,
|
||||
field,
|
||||
condition: v.condition,
|
||||
values: form?.values,
|
||||
values: raw(form?.values),
|
||||
variables,
|
||||
localVariables,
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Field } from '@formily/core';
|
||||
import { evaluators } from '@nocobase/evaluators/client';
|
||||
import { uid } from '@nocobase/utils';
|
||||
import _, { cloneDeep, last } from 'lodash';
|
||||
import _, { last } from 'lodash';
|
||||
import { ActionType } from '../../../schema-settings/LinkageRules/type';
|
||||
import { VariableOption, VariablesContextType } from '../../../variables/types';
|
||||
import { REGEX_OF_VARIABLE } from '../../../variables/utils/isVariable';
|
||||
@ -36,7 +36,7 @@ export const linkageMergeAction = async ({
|
||||
|
||||
switch (operator) {
|
||||
case ActionType.Required:
|
||||
if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) {
|
||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
||||
requiredResult.push(true);
|
||||
}
|
||||
field.linkageProperty = {
|
||||
@ -50,7 +50,7 @@ export const linkageMergeAction = async ({
|
||||
resolve(void 0);
|
||||
});
|
||||
case ActionType.InRequired:
|
||||
if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) {
|
||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
||||
requiredResult.push(false);
|
||||
}
|
||||
field.linkageProperty = {
|
||||
@ -66,7 +66,7 @@ export const linkageMergeAction = async ({
|
||||
case ActionType.Visible:
|
||||
case ActionType.None:
|
||||
case ActionType.Hidden:
|
||||
if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) {
|
||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
||||
displayResult.push(operator);
|
||||
}
|
||||
field.linkageProperty = {
|
||||
@ -82,7 +82,7 @@ export const linkageMergeAction = async ({
|
||||
case ActionType.Editable:
|
||||
case ActionType.ReadOnly:
|
||||
case ActionType.ReadPretty:
|
||||
if (await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables })) {
|
||||
if (await conditionAnalyses({ rules: condition, variables, localVariables })) {
|
||||
patternResult.push(operator);
|
||||
}
|
||||
field.linkageProperty = {
|
||||
@ -96,17 +96,12 @@ export const linkageMergeAction = async ({
|
||||
resolve(void 0);
|
||||
});
|
||||
case ActionType.Value:
|
||||
if (
|
||||
isConditionEmpty(condition) ||
|
||||
(await conditionAnalyses({ rules: condition, formValues: values, variables, localVariables }))
|
||||
) {
|
||||
if (isConditionEmpty(condition) || (await conditionAnalyses({ rules: condition, variables, localVariables }))) {
|
||||
if (value?.mode === 'express') {
|
||||
if ((value.value || value.result) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const scope = cloneDeep(values);
|
||||
|
||||
// 1. 解析如 `{{$user.name}}` 之类的变量
|
||||
const { exp, scope: expScope } = await replaceVariables(value.value || value.result, {
|
||||
variables,
|
||||
@ -115,7 +110,7 @@ export const linkageMergeAction = async ({
|
||||
|
||||
try {
|
||||
// 2. TODO: 需要把里面解析变量的逻辑删除,因为在上一步已经解析过了
|
||||
const result = evaluate(exp, { ...scope, now: () => new Date().toString(), ...expScope });
|
||||
const result = evaluate(exp, { ...values, now: () => new Date().toString(), ...expScope });
|
||||
valueResult.push(result);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
@ -67,12 +67,10 @@ function getAllKeys(obj) {
|
||||
|
||||
export const conditionAnalyses = async ({
|
||||
rules,
|
||||
formValues,
|
||||
variables,
|
||||
localVariables,
|
||||
}: {
|
||||
rules;
|
||||
formValues;
|
||||
variables: VariablesContextType;
|
||||
localVariables: VariableOption[];
|
||||
}) => {
|
||||
|
@ -106,13 +106,12 @@ export const CreateRecordAction = observer(
|
||||
operator: h.operator,
|
||||
field,
|
||||
condition: v.condition,
|
||||
values,
|
||||
variables,
|
||||
localVariables,
|
||||
});
|
||||
});
|
||||
});
|
||||
}, [JSON.stringify(linkageRules), values]);
|
||||
}, [JSON.stringify(linkageRules)]);
|
||||
return (
|
||||
<div className={actionDesignerCss}>
|
||||
<ActionContextProvider value={{ ...ctx, visible, setVisible }}>
|
||||
@ -211,13 +210,12 @@ export const CreateAction = observer(
|
||||
operator: h.operator,
|
||||
field,
|
||||
condition: v.condition,
|
||||
values,
|
||||
variables,
|
||||
localVariables,
|
||||
});
|
||||
});
|
||||
});
|
||||
}, [JSON.stringify(linkageRules), values]);
|
||||
}, [JSON.stringify(linkageRules)]);
|
||||
return (
|
||||
<div className={actionDesignerCss}>
|
||||
<FinallyButton
|
||||
|
@ -9,8 +9,6 @@ const useBuiltInVariables = () => {
|
||||
|
||||
const currentUser = data?.data?.data;
|
||||
const dateVars = getDateRanges();
|
||||
// 使用函数方便测试断言
|
||||
dateVars.now = (() => dayjs().toISOString()) as any;
|
||||
const builtinVariables: VariableOption[] = useMemo(() => {
|
||||
return [
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user