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
This commit is contained in:
katherinehhh 2023-08-14 17:47:15 +08:00 committed by GitHub
parent 2f6bfa65f7
commit 274d53988a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 30 deletions

View File

@ -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']],

View File

@ -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 <InputReadPretty.Html {...props} />;
}),

View File

@ -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 <SchemaComponent schema={schema} />;
},
},
@ -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)
);
};

View File

@ -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,8 +31,7 @@ const getChildren = (
getIsSameOrChildCollection,
): Option[] => {
const result = options
.map(
(option): Option => {
.map((option): Option => {
const disabled = !getIsSameOrChildCollection(option.target, collectionField?.target);
if (!option.target) {
return {
@ -59,8 +57,7 @@ const getChildren = (
depth,
loadChildren,
};
},
)
})
.filter(Boolean);
return result;
};