From 274d53988a116865856a2a7bc12108f6d1b07f5b Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Mon, 14 Aug 2023 17:47:15 +0800 Subject: [PATCH] refactor: default value for field configuration in sub-table (#2425) * refactor: field default value config in sub-table * refactor: richtext default value * refactor: richtext default value * refactor: isShowDefaultValue --- .../antd/quick-edit/QuickEdit.tsx | 5 ++- .../antd/rich-text/RichText.tsx | 9 +++- .../src/schema-settings/SchemaSettings.tsx | 10 ++--- .../hooks/useContextAssociationFields.tsx | 41 +++++++++---------- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/packages/core/client/src/schema-component/antd/quick-edit/QuickEdit.tsx b/packages/core/client/src/schema-component/antd/quick-edit/QuickEdit.tsx index b2fa657d35..611d1d9d3d 100644 --- a/packages/core/client/src/schema-component/antd/quick-edit/QuickEdit.tsx +++ b/packages/core/client/src/schema-component/antd/quick-edit/QuickEdit.tsx @@ -10,19 +10,20 @@ export const Editable = observer((props) => { const field: any = useField(); const containerRef = useRef(null); const fieldSchema = useFieldSchema(); + const value = typeof field.value === 'object' ? field.value?.default : field.value; const schema: any = { name: fieldSchema.name, 'x-collection-field': fieldSchema['x-collection-field'], 'x-component': 'CollectionField', 'x-read-pretty': true, - default: field.value, + default: value, 'x-component-props': fieldSchema['x-component-props'], }; const form = useMemo( () => createForm({ values: { - [fieldSchema.name]: field.value, + [fieldSchema.name]: value, }, }), [field.value, fieldSchema['x-component-props']], diff --git a/packages/core/client/src/schema-component/antd/rich-text/RichText.tsx b/packages/core/client/src/schema-component/antd/rich-text/RichText.tsx index e5d79d7bd8..226ad6a310 100644 --- a/packages/core/client/src/schema-component/antd/rich-text/RichText.tsx +++ b/packages/core/client/src/schema-component/antd/rich-text/RichText.tsx @@ -1,4 +1,4 @@ -import { connect, mapReadPretty } from '@formily/react'; +import { connect, mapReadPretty, mapProps } from '@formily/react'; import React from 'react'; import ReactQuill from 'react-quill'; import { ReadPretty as InputReadPretty } from '../input'; @@ -35,6 +35,13 @@ export const RichText = connect( />, ); }, + mapProps((props) => { + const { value } = props; + return { + ...props, + value: typeof value === 'object' ? value?.default : value, + }; + }), mapReadPretty((props) => { return ; }), diff --git a/packages/core/client/src/schema-settings/SchemaSettings.tsx b/packages/core/client/src/schema-settings/SchemaSettings.tsx index ceb694e57b..eef1603d53 100644 --- a/packages/core/client/src/schema-settings/SchemaSettings.tsx +++ b/packages/core/client/src/schema-settings/SchemaSettings.tsx @@ -1516,14 +1516,14 @@ SchemaSettings.DefaultValue = function DefaultValueConfigure(props) { s['x-read-pretty'] = false; s['x-disabled'] = false; - const schema = { ...(s || {}), + 'x-decorator': 'FormItem', 'x-component-props': { ...s['x-component-props'], collectionName: collectionField?.collectionName, targetField, - onChange: props.onChange, + onChange: collectionField?.interface !== 'richText' ? props.onChange : null, defaultValue: getFieldDefaultValue(s, collectionField), style: { width: '100%', @@ -1532,7 +1532,6 @@ SchemaSettings.DefaultValue = function DefaultValueConfigure(props) { }, }, }; - return ; }, }, @@ -1679,8 +1678,9 @@ SchemaSettings.SortingRule = function SortRuleConfigure(props) { // 是否显示默认值配置项 export const isShowDefaultValue = (collectionField: CollectionFieldOptions, getInterface) => { return ( - !['o2o', 'oho', 'obo', 'o2m', 'attachment', 'expression'].includes(collectionField?.interface) && - !isSystemField(collectionField, getInterface) + !['o2o', 'oho', 'obo', 'o2m', 'attachment', 'expression', 'point', 'lineString', 'circle', 'polygon'].includes( + collectionField?.interface, + ) && !isSystemField(collectionField, getInterface) ); }; diff --git a/packages/core/client/src/schema-settings/VariableInput/hooks/useContextAssociationFields.tsx b/packages/core/client/src/schema-settings/VariableInput/hooks/useContextAssociationFields.tsx index b39171f59c..7c7ad9acd6 100644 --- a/packages/core/client/src/schema-settings/VariableInput/hooks/useContextAssociationFields.tsx +++ b/packages/core/client/src/schema-settings/VariableInput/hooks/useContextAssociationFields.tsx @@ -8,7 +8,6 @@ import { FieldOption, Option } from '../type'; export const useIsSameOrChildCollection = () => { const { getChildrenCollections } = useCollectionManager(); return (contextCollection, targetCollection) => { - console.log(contextCollection, targetCollection); if (contextCollection === targetCollection) { return true; } @@ -32,35 +31,33 @@ const getChildren = ( getIsSameOrChildCollection, ): Option[] => { const result = options - .map( - (option): Option => { - const disabled = !getIsSameOrChildCollection(option.target, collectionField?.target); - if (!option.target) { - return { - key: option.name, - value: option.name, - label: compile(option.title), - disabled: disabled, - isLeaf: true, - depth, - }; - } - - if (depth >= maxDepth) { - return null; - } + .map((option): Option => { + const disabled = !getIsSameOrChildCollection(option.target, collectionField?.target); + if (!option.target) { return { key: option.name, value: option.name, label: compile(option.title), disabled: disabled, isLeaf: true, - field: option, depth, - loadChildren, }; - }, - ) + } + + if (depth >= maxDepth) { + return null; + } + return { + key: option.name, + value: option.name, + label: compile(option.title), + disabled: disabled, + isLeaf: true, + field: option, + depth, + loadChildren, + }; + }) .filter(Boolean); return result; };