refactor: view collection support add m2o association field (#2422)

* refactor: view collection support add m2o association field

* refactor: code improve
This commit is contained in:
katherinehhh 2023-09-22 11:09:53 +08:00 committed by GitHub
parent 9f147085a5
commit 49b75b6ab6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 55 deletions

View File

@ -274,7 +274,6 @@ export const RenderChildrenWithAssociationFilter: React.FC<any> = (props) => {
};
export const BlockProvider = (props) => {
console.log(props);
const { collection, association } = props;
const resource = useResource(props);
const params = { ...props.params };

View File

@ -240,28 +240,47 @@ export const AddFieldAction = (props) => {
return optionArr;
}, [getTemplate, record]);
const items = useMemo<MenuProps['items']>(() => {
return getFieldOptions().map((option) => {
if (option.children.length === 0) {
return null;
}
return {
type: 'group',
label: compile(option.label),
title: compile(option.label),
key: option.label,
children: option.children
.filter((child) => !['o2o', 'subTable', 'linkTo'].includes(child.name))
.map((child) => {
return {
label: compile(child.title),
title: compile(child.title),
key: child.name,
dataTargetScope: child.targetScope,
};
}),
};
});
return getFieldOptions()
.map((option) => {
if (option.children.length === 0) {
return null;
}
if (record.template === 'view') {
return {
type: 'group',
label: compile(option.label),
title: compile(option.label),
key: option.label,
children: option.children
.filter((child) => ['m2o'].includes(child.name))
.map((child) => {
return {
label: compile(child.title),
title: compile(child.title),
key: child.name,
dataTargetScope: child.targetScope,
};
}),
};
}
return {
type: 'group',
label: compile(option.label),
title: compile(option.label),
key: option.label,
children: option.children
.filter((child) => !['o2o', 'subTable', 'linkTo'].includes(child.name))
.map((child) => {
return {
label: compile(child.title),
title: compile(child.title),
key: child.name,
dataTargetScope: child.targetScope,
};
}),
};
})
.filter((v) => v.children.length);
}, [getFieldOptions]);
const menu = useMemo<MenuProps>(() => {
return {
@ -283,37 +302,35 @@ export const AddFieldAction = (props) => {
};
}, [getInterface, items, record]);
return (
record.template !== 'view' && (
<RecordProvider record={record}>
<ActionContextProvider value={{ visible, setVisible }}>
<Dropdown getPopupContainer={getContainer} trigger={trigger} align={align} menu={menu}>
{children || (
<Button icon={<PlusOutlined />} type={'primary'}>
{t('Add field')}
</Button>
)}
</Dropdown>
<SchemaComponent
schema={schema}
components={{ ...components, ArrayTable }}
scope={{
getContainer,
useCancelAction,
createOnly: true,
isOverride: false,
override: false,
useCreateCollectionField,
record,
showReverseFieldConfig: true,
targetScope,
collections: currentCollections,
isDialect,
disabledJSONB: false,
...scope,
}}
/>
</ActionContextProvider>
</RecordProvider>
)
<RecordProvider record={record}>
<ActionContextProvider value={{ visible, setVisible }}>
<Dropdown getPopupContainer={getContainer} trigger={trigger} align={align} menu={menu}>
{children || (
<Button icon={<PlusOutlined />} type={'primary'}>
{t('Add field')}
</Button>
)}
</Dropdown>
<SchemaComponent
schema={schema}
components={{ ...components, ArrayTable }}
scope={{
getContainer,
useCancelAction,
createOnly: true,
isOverride: false,
override: false,
useCreateCollectionField,
record,
showReverseFieldConfig: true,
targetScope,
collections: currentCollections,
isDialect,
disabledJSONB: false,
...scope,
}}
/>
</ActionContextProvider>
</RecordProvider>
);
};