feat: add Kanban.useCreateResource

This commit is contained in:
chenos 2021-08-27 11:06:21 +08:00
parent 622a6d5a27
commit 52699b0302
2 changed files with 24 additions and 0 deletions

View File

@ -384,6 +384,9 @@ function generateCardItemSchema(component) {
type: 'void',
title: '创建数据',
'x-decorator': 'Form',
'x-decorator-props': {
useResource: '{{ Kanban.useCreateResource }}',
},
'x-component': 'Action.Drawer',
'x-component-props': {
useOkAction: '{{ Kanban.useCreateAction }}',

View File

@ -415,6 +415,27 @@ export const Kanban: any = observer((props: any) => {
);
});
Kanban.useCreateResource = ({ onSuccess }) => {
const { props } = useKanban();
const column = useContext(KanbanColumnContext);
const { collection } = useCollectionContext();
const resource = Resource.make({
resourceName: collection?.name || props.collectionName,
});
const groupField = props.groupField;
const service = useRequest(
(params?: any) => {
return Promise.resolve({
[groupField.name]: column.value
});
},
{
onSuccess,
},
);
return { resource, service, initialValues: service.data, ...service };
};
Kanban.useCreateAction = () => {
const { service, resource, props } = useKanban();
const column = useContext(KanbanColumnContext);