mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:36:05 +00:00
fix: linkage rule fireImmediately should be true (#4303)
* fix: linkagerule fireImmediately * test: test improve * fix: bug
This commit is contained in:
parent
60c9abf305
commit
e2922bed9e
@ -2,9 +2,7 @@
|
||||
"version": "1.0.0-alpha.9",
|
||||
"npmClient": "yarn",
|
||||
"useWorkspaces": true,
|
||||
"npmClientArgs": [
|
||||
"--ignore-engines"
|
||||
],
|
||||
"npmClientArgs": ["--ignore-engines"],
|
||||
"command": {
|
||||
"version": {
|
||||
"forcePublish": true,
|
||||
|
@ -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 },
|
||||
),
|
||||
);
|
||||
});
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -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,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user