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,11 +240,29 @@ export const AddFieldAction = (props) => {
return optionArr;
}, [getTemplate, record]);
const items = useMemo<MenuProps['items']>(() => {
return getFieldOptions().map((option) => {
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),
@ -261,7 +279,8 @@ export const AddFieldAction = (props) => {
};
}),
};
});
})
.filter((v) => v.children.length);
}, [getFieldOptions]);
const menu = useMemo<MenuProps>(() => {
return {
@ -283,7 +302,6 @@ 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}>
@ -314,6 +332,5 @@ export const AddFieldAction = (props) => {
/>
</ActionContextProvider>
</RecordProvider>
)
);
};