From 943db605c8655a7dd9124273f10584d75231912c Mon Sep 17 00:00:00 2001 From: sealday Date: Thu, 13 Jun 2024 03:46:45 +0800 Subject: [PATCH] perf: form item (#1171) Co-authored-by: sealday Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1171 --- .../antd/association-field/InternalPicker.tsx | 14 ++- .../antd/form-item/FormItem.tsx | 111 +++++++++--------- .../LinkageRules/ValueDynamicComponent.tsx | 10 +- .../src/schema-settings/SchemaSettings.tsx | 3 +- .../core/components/src/form-item/index.tsx | 30 ++--- .../src/client/TableTransfer.tsx | 10 +- 6 files changed, 92 insertions(+), 86 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx b/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx index 324bb0457..fbc883379 100644 --- a/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx +++ b/packages/core/client/src/schema-component/antd/association-field/InternalPicker.tsx @@ -1,7 +1,9 @@ -import { observer, RecursionField, useField, useFieldSchema } from '@tachybase/schema'; -import { Input, Select } from 'antd'; -import { differenceBy, unionBy } from 'lodash'; import React, { useContext, useMemo, useState } from 'react'; +import { observer, RecursionField, useField, useFieldSchema } from '@tachybase/schema'; + +import { Select, Space } from 'antd'; +import { differenceBy, unionBy } from 'lodash'; + import { FormProvider, RecordPickerContext, @@ -9,7 +11,7 @@ import { SchemaComponentOptions, useActionContext, } from '../..'; -import { CollectionProvider_deprecated, RecordProvider, useFormBlockContext, useCollectionRecordData } from '../../../'; +import { CollectionProvider_deprecated, RecordProvider, useCollectionRecordData, useFormBlockContext } from '../../../'; import { TableSelectorParamsProvider, useTableSelectorProps as useTsp, @@ -133,7 +135,7 @@ export const InternalPicker = observer( }; return ( <> - +
{ {modeMap[mode]} - + ); }; diff --git a/packages/core/client/src/schema-settings/SchemaSettings.tsx b/packages/core/client/src/schema-settings/SchemaSettings.tsx index 97d73023a..7d02d7837 100644 --- a/packages/core/client/src/schema-settings/SchemaSettings.tsx +++ b/packages/core/client/src/schema-settings/SchemaSettings.tsx @@ -1293,7 +1293,7 @@ export const SchemaSettingsLinkageRules = function LinkageRules(props) { 'x-use-component-props': () => { // eslint-disable-next-line react-hooks/rules-of-hooks const options = useLinkageCollectionFilterOptions(collectionName); - return { + const result = { options, defaultValues: gridSchema?.['x-linkage-rules'] || fieldSchema?.['x-linkage-rules'], type, @@ -1306,6 +1306,7 @@ export const SchemaSettingsLinkageRules = function LinkageRules(props) { record, formBlockType, }; + return result; }, }, }, diff --git a/packages/core/components/src/form-item/index.tsx b/packages/core/components/src/form-item/index.tsx index c160523f5..1de686a3f 100644 --- a/packages/core/components/src/form-item/index.tsx +++ b/packages/core/components/src/form-item/index.tsx @@ -1,11 +1,13 @@ +import React, { useState } from 'react'; + import { CheckCircleOutlined, CloseCircleOutlined, ExclamationCircleOutlined } from '@ant-design/icons'; import { isVoidField } from '@formily/core'; import { connect, mapProps, ReactFC } from '@formily/react'; import { Popover, Tooltip } from 'antd'; -import cls from 'classnames'; -import React, { useState } from 'react'; -import { FormLayoutShallowContext } from '../form-layout'; +import cx from 'classnames'; + import { pickDataProps, usePrefixCls } from '../__builtins__'; +import { FormLayoutShallowContext } from '../form-layout'; import { useFormItemLayout, useOverflow } from './hooks'; import useStyle from './style'; import { IFormItemProps } from './types'; @@ -88,7 +90,7 @@ export const BaseItem: React.FC> = ({ ch placement="top" content={
> = ({ ch if (!label) return null; return (
> = ({ ch ...gridStyles, }} data-grid-span={props.gridSpan} - className={cls( + className={cx( props.className, { [`${prefixCls}`]: true, @@ -211,28 +213,28 @@ export const BaseItem: React.FC> = ({ ch > {renderLabel()}
-
- {addonBefore &&
{addonBefore}
} +
+ {addonBefore &&
{addonBefore}
}
{formatChildren} - {feedbackIcon &&
{feedbackIcon}
} + {feedbackIcon &&
{feedbackIcon}
}
- {addonAfter &&
{addonAfter}
} + {addonAfter &&
{addonAfter}
}
{!!feedbackText && feedbackLayout !== 'popover' && feedbackLayout !== 'none' && (
> = ({ ch {feedbackText}
)} - {extra &&
{extra}
} + {extra &&
{extra}
}
, ); diff --git a/packages/plugins/@tachybase/plugin-multi-app-share-collection/src/client/TableTransfer.tsx b/packages/plugins/@tachybase/plugin-multi-app-share-collection/src/client/TableTransfer.tsx index dd079f57b..fcbc0148f 100644 --- a/packages/plugins/@tachybase/plugin-multi-app-share-collection/src/client/TableTransfer.tsx +++ b/packages/plugins/@tachybase/plugin-multi-app-share-collection/src/client/TableTransfer.tsx @@ -3,7 +3,7 @@ import { css, useCollectionManager_deprecated, useRecord, useRequest, useToken } import { connect } from '@tachybase/schema'; import { CollectionsGraph, lodash } from '@tachybase/utils/client'; -import { App, Col, Input, Row, Select, Spin, Table, Tag } from 'antd'; +import { App, Col, Input, Row, Select, Space, Spin, Table, Tag } from 'antd'; import { useTranslation } from 'react-i18next'; const excludeCollections = ['users', 'roles', 'applications']; @@ -232,7 +232,7 @@ export const TableTransfer = connect((props) => { `} > {t('Unshared collections')} - + { @@ -336,7 +336,7 @@ export const TableTransfer = connect((props) => { placeholder={t('Enter name or title...')} allowClear /> - +