perf(LinkageRules): solve lagging problems (#4090)

This commit is contained in:
Zeke Zhang 2024-04-18 16:52:34 +08:00 committed by GitHub
parent 8f17456d93
commit ca29515bcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 24 deletions

View File

@ -1,6 +1,6 @@
import { createForm, Form, IFormProps } from '@formily/core';
import { FormProvider, Observer, observer, ReactFC } from '@formily/react';
import { toJS } from '@formily/reactive';
import { untracked } from '@formily/reactive';
import { applyMiddleware, IMiddleware, isBool, isFn, isNum, isStr } from '@formily/shared';
import { Modal, ModalProps, ThemeConfig } from 'antd';
import React, { Fragment, useLayoutEffect, useRef, useState } from 'react';
@ -161,7 +161,9 @@ export function FormDialog(title: any, id: any, renderer?: any, theme?: any): IF
env.form
?.submit(async () => {
await applyMiddleware(env.form, env.confirmMiddlewares);
resolve(toJS(env.form?.values));
untracked(() => {
resolve({ ...env.form?.values });
});
formDialog.close();
})
.catch(() => {});

View File

@ -1,7 +1,7 @@
import { css } from '@emotion/css';
import { Form } from '@formily/core';
import { observer, useFieldSchema } from '@formily/react';
import React, { useMemo } from 'react';
import { withDynamicSchemaProps } from '../../application/hoc/withDynamicSchemaProps';
import { FormBlockContext } from '../../block-provider';
import { useCollectionManager_deprecated } from '../../collection-manager';
import { useCollectionParentRecordData } from '../../data-source/collection-record/CollectionRecordProvider';
@ -9,26 +9,10 @@ import { RecordProvider } from '../../record-provider';
import { SchemaComponent, useProps } from '../../schema-component';
import { DynamicComponentProps } from '../../schema-component/antd/filter/DynamicComponent';
import { FilterContext } from '../../schema-component/antd/filter/context';
import { VariableOption, VariablesContextType } from '../../variables/types';
import { VariableInput, getShouldChange } from '../VariableInput/VariableInput';
import { LinkageRuleActionGroup } from './LinkageRuleActionGroup';
import { EnableLinkage } from './components/EnableLinkage';
import { ArrayCollapse } from './components/LinkageHeader';
import { withDynamicSchemaProps } from '../../application/hoc/withDynamicSchemaProps';
interface usePropsReturn {
options: any;
defaultValues: any[];
collectionName: string;
form: Form;
variables: VariablesContextType;
localVariables: VariableOption | VariableOption[];
record: Record<string, any>;
/**
* create update
*/
formBlockType: 'create' | 'update';
}
interface Props {
dynamicComponent: any;
@ -124,10 +108,7 @@ export const FormLinkageRules = withDynamicSchemaProps(
},
action: {
type: 'void',
'x-component': LinkageRuleActionGroup,
'x-component-props': {
...props,
},
'x-component': (_props) => <LinkageRuleActionGroup {..._props} {...props} />,
},
},
},
@ -167,7 +148,17 @@ export const FormLinkageRules = withDynamicSchemaProps(
},
},
}),
[collectionName, defaultValues, form, localVariables, options, props, record, variables],
[
collectionName,
defaultValues,
form,
getAllCollectionsInheritChain,
localVariables,
options,
props,
record,
variables,
],
);
const value = useMemo(
() => ({ field: options, fieldSchema, dynamicComponent, options: options || [] }),