fix: linkage rule fireImmediately should be true (#4303)

* fix: linkagerule fireImmediately

* test: test improve

* fix: bug
This commit is contained in:
katherinehhh 2024-05-10 20:33:38 +08:00 committed by GitHub
parent 60c9abf305
commit e2922bed9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 19 deletions

View File

@ -2,9 +2,7 @@
"version": "1.0.0-alpha.9",
"npmClient": "yarn",
"useWorkspaces": true,
"npmClientArgs": [
"--ignore-engines"
],
"npmClientArgs": ["--ignore-engines"],
"command": {
"version": {
"forcePublish": true,

View File

@ -34,11 +34,7 @@ export interface FormProps extends IFormLayoutProps {
form?: FormilyForm;
disabled?: boolean;
}
function hasInitialValues(obj, rule) {
const type = Object.keys(rule.condition)[0] || '$and';
const conditions = rule.condition[type];
return Object.values(obj).some((value) => value !== null) || !conditions.length;
}
const FormComponent: React.FC<FormProps> = (props) => {
const { form, children, ...others } = props;
const field = useField();
@ -163,11 +159,10 @@ const WithForm = (props: WithFormProps) => {
const result = [fieldValuesInCondition, variableValuesInCondition, variableValuesInExpression]
.map((item) => JSON.stringify(item))
.join(',');
return result;
},
getSubscriber(action, field, rule, variables, localVariables),
{ fireImmediately: hasInitialValues(form.initialValues, rule) },
{ fireImmediately: true },
),
);
});

View File

@ -173,13 +173,11 @@ describe('Form', () => {
await userEvent.type(document.querySelector('.ant-input'), 'test');
await waitFor(() => {
expect(document.querySelectorAll('.ant-input')).toHaveLength(1);
});
const element = document.querySelector(
'[data-label="block-item-CollectionField-users-form-users.nickname-Nickname"]',
);
await userEvent.clear(document.querySelector('.ant-input'));
await waitFor(() => {
expect(document.querySelectorAll('.ant-input')).toHaveLength(2);
expect(element).toBeNull();
});
});
});

View File

@ -74,7 +74,7 @@ export const useCurrentFormVariable = ({
}: Props = {}) => {
// const { getActiveFieldsName } = useFormActiveFields() || {};
const { t } = useTranslation();
const { form, collectionName } = useFormBlockContext();
const { form, collectionName, service } = useFormBlockContext();
const currentFormSettings = useBaseVariable({
collectionField,
uiSchema: schema,
@ -98,12 +98,14 @@ export const useCurrentFormVariable = ({
});
const formInstance = _form || form;
return {
/** 变量配置 */
currentFormSettings,
/** 变量值 */
currentFormCtx: formInstance?.values,
currentFormCtx:
formInstance?.values && Object.keys(formInstance?.values)?.length
? formInstance?.values
: service?.data?.data || formInstance?.values,
/** 用来判断是否可以显示`当前表单`变量 */
shouldDisplayCurrentForm: formInstance && !formInstance.readPretty,
};