mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 14:16:26 +00:00
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:
parent
2f6bfa65f7
commit
274d53988a
@ -10,19 +10,20 @@ export const Editable = observer((props) => {
|
|||||||
const field: any = useField();
|
const field: any = useField();
|
||||||
const containerRef = useRef(null);
|
const containerRef = useRef(null);
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
|
const value = typeof field.value === 'object' ? field.value?.default : field.value;
|
||||||
const schema: any = {
|
const schema: any = {
|
||||||
name: fieldSchema.name,
|
name: fieldSchema.name,
|
||||||
'x-collection-field': fieldSchema['x-collection-field'],
|
'x-collection-field': fieldSchema['x-collection-field'],
|
||||||
'x-component': 'CollectionField',
|
'x-component': 'CollectionField',
|
||||||
'x-read-pretty': true,
|
'x-read-pretty': true,
|
||||||
default: field.value,
|
default: value,
|
||||||
'x-component-props': fieldSchema['x-component-props'],
|
'x-component-props': fieldSchema['x-component-props'],
|
||||||
};
|
};
|
||||||
const form = useMemo(
|
const form = useMemo(
|
||||||
() =>
|
() =>
|
||||||
createForm({
|
createForm({
|
||||||
values: {
|
values: {
|
||||||
[fieldSchema.name]: field.value,
|
[fieldSchema.name]: value,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
[field.value, fieldSchema['x-component-props']],
|
[field.value, fieldSchema['x-component-props']],
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { connect, mapReadPretty } from '@formily/react';
|
import { connect, mapReadPretty, mapProps } from '@formily/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactQuill from 'react-quill';
|
import ReactQuill from 'react-quill';
|
||||||
import { ReadPretty as InputReadPretty } from '../input';
|
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) => {
|
mapReadPretty((props) => {
|
||||||
return <InputReadPretty.Html {...props} />;
|
return <InputReadPretty.Html {...props} />;
|
||||||
}),
|
}),
|
||||||
|
@ -1516,14 +1516,14 @@ SchemaSettings.DefaultValue = function DefaultValueConfigure(props) {
|
|||||||
|
|
||||||
s['x-read-pretty'] = false;
|
s['x-read-pretty'] = false;
|
||||||
s['x-disabled'] = false;
|
s['x-disabled'] = false;
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
...(s || {}),
|
...(s || {}),
|
||||||
|
'x-decorator': 'FormItem',
|
||||||
'x-component-props': {
|
'x-component-props': {
|
||||||
...s['x-component-props'],
|
...s['x-component-props'],
|
||||||
collectionName: collectionField?.collectionName,
|
collectionName: collectionField?.collectionName,
|
||||||
targetField,
|
targetField,
|
||||||
onChange: props.onChange,
|
onChange: collectionField?.interface !== 'richText' ? props.onChange : null,
|
||||||
defaultValue: getFieldDefaultValue(s, collectionField),
|
defaultValue: getFieldDefaultValue(s, collectionField),
|
||||||
style: {
|
style: {
|
||||||
width: '100%',
|
width: '100%',
|
||||||
@ -1532,7 +1532,6 @@ SchemaSettings.DefaultValue = function DefaultValueConfigure(props) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return <SchemaComponent schema={schema} />;
|
return <SchemaComponent schema={schema} />;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1679,8 +1678,9 @@ SchemaSettings.SortingRule = function SortRuleConfigure(props) {
|
|||||||
// 是否显示默认值配置项
|
// 是否显示默认值配置项
|
||||||
export const isShowDefaultValue = (collectionField: CollectionFieldOptions, getInterface) => {
|
export const isShowDefaultValue = (collectionField: CollectionFieldOptions, getInterface) => {
|
||||||
return (
|
return (
|
||||||
!['o2o', 'oho', 'obo', 'o2m', 'attachment', 'expression'].includes(collectionField?.interface) &&
|
!['o2o', 'oho', 'obo', 'o2m', 'attachment', 'expression', 'point', 'lineString', 'circle', 'polygon'].includes(
|
||||||
!isSystemField(collectionField, getInterface)
|
collectionField?.interface,
|
||||||
|
) && !isSystemField(collectionField, getInterface)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import { FieldOption, Option } from '../type';
|
|||||||
export const useIsSameOrChildCollection = () => {
|
export const useIsSameOrChildCollection = () => {
|
||||||
const { getChildrenCollections } = useCollectionManager();
|
const { getChildrenCollections } = useCollectionManager();
|
||||||
return (contextCollection, targetCollection) => {
|
return (contextCollection, targetCollection) => {
|
||||||
console.log(contextCollection, targetCollection);
|
|
||||||
if (contextCollection === targetCollection) {
|
if (contextCollection === targetCollection) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -32,8 +31,7 @@ const getChildren = (
|
|||||||
getIsSameOrChildCollection,
|
getIsSameOrChildCollection,
|
||||||
): Option[] => {
|
): Option[] => {
|
||||||
const result = options
|
const result = options
|
||||||
.map(
|
.map((option): Option => {
|
||||||
(option): Option => {
|
|
||||||
const disabled = !getIsSameOrChildCollection(option.target, collectionField?.target);
|
const disabled = !getIsSameOrChildCollection(option.target, collectionField?.target);
|
||||||
if (!option.target) {
|
if (!option.target) {
|
||||||
return {
|
return {
|
||||||
@ -59,8 +57,7 @@ const getChildren = (
|
|||||||
depth,
|
depth,
|
||||||
loadChildren,
|
loadChildren,
|
||||||
};
|
};
|
||||||
},
|
})
|
||||||
)
|
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user