fix(view-collection): field name cannot be edited when there with field source (#1642)

* fix:  field name cannot be edited when there with field source

* fix:  did not bring the uiSchema  when selecting interface
This commit is contained in:
katherinehhh 2023-04-03 12:08:26 +08:00 committed by GitHub
parent ffcf1d9cf1
commit c38dbd1675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -30,7 +30,7 @@ const PreviewCom = (props) => {
const [sourceFields, setSourceFields] = useState([]); const [sourceFields, setSourceFields] = useState([]);
const field: any = useField(); const field: any = useField();
const form = useForm(); const form = useForm();
const { getCollection } = useCollectionManager(); const { getCollection, getInterface } = useCollectionManager();
const compile = useCompile(); const compile = useCompile();
const initOptions = getOptions().filter((v) => !['relation', 'systemInfo'].includes(v.key)); const initOptions = getOptions().filter((v) => !['relation', 'systemInfo'].includes(v.key));
useEffect(() => { useEffect(() => {
@ -148,7 +148,10 @@ const PreviewCom = (props) => {
<Select <Select
defaultValue={text} defaultValue={text}
style={{ width: '100%' }} style={{ width: '100%' }}
onChange={(value) => handleFieldChange({ ...item, interface: value }, index)} onChange={(value) => {
const interfaceConfig = getInterface(value);
handleFieldChange({ ...item, interface: value, uiSchema: interfaceConfig?.default?.uiSchema }, index);
}}
> >
{data.map((group) => ( {data.map((group) => (
<Select.OptGroup key={group.key} label={compile(group.label)}> <Select.OptGroup key={group.key} label={compile(group.label)}>
@ -170,12 +173,12 @@ const PreviewCom = (props) => {
width: 180, width: 180,
render: (text, record, index) => { render: (text, record, index) => {
const item = dataSource[index]; const item = dataSource[index];
return item.source ? ( return (
record?.uiSchema?.title
) : (
<Input <Input
defaultValue={record?.uiSchema?.title} defaultValue={record?.uiSchema?.title}
onChange={(e) => handleFieldChange({ ...item, uiSchema: { title: e.target.value } }, index)} onChange={(e) =>
handleFieldChange({ ...item, uiSchema: { ...item?.uiSchema, title: e.target.value } }, index)
}
/> />
); );
}, },

View File

@ -47,7 +47,7 @@ export const PreviewTable = (props) => {
const fieldSource = typeof item?.source === 'string' ? item?.source?.split('.') : item?.source; const fieldSource = typeof item?.source === 'string' ? item?.source?.split('.') : item?.source;
const sourceField = getCollection(fieldSource?.[0])?.fields.find((v) => v.name === fieldSource?.[1])?.uiSchema const sourceField = getCollection(fieldSource?.[0])?.fields.find((v) => v.name === fieldSource?.[1])?.uiSchema
?.title; ?.title;
const target = sourceField || item?.uiSchema?.title || item.name; const target = item?.uiSchema?.title || sourceField || item.name;
const schema: any = item.source const schema: any = item.source
? getCollectionField(typeof item.source === 'string' ? item.source : item.source.join('.'))?.uiSchema ? getCollectionField(typeof item.source === 'string' ? item.source : item.source.join('.'))?.uiSchema
: getInterface(item.interface)?.default?.uiSchema; : getInterface(item.interface)?.default?.uiSchema;