fix(collection-manager): update collection without fields

This commit is contained in:
chenos 2022-08-15 13:09:41 +08:00
parent a260d29222
commit 03538ee82f
2 changed files with 21 additions and 1 deletions

View File

@ -258,7 +258,7 @@ export const collectionSchema: ISchema = {
'x-component': 'Action', 'x-component': 'Action',
'x-component-props': { 'x-component-props': {
type: 'primary', type: 'primary',
useAction: '{{ cm.useUpdateActionAndRefreshCM }}', useAction: '{{ cm.useUpdateCollectionActionAndRefreshCM }}',
}, },
}, },
}, },

View File

@ -1,5 +1,6 @@
import { useForm } from '@formily/react'; import { useForm } from '@formily/react';
import { message } from 'antd'; import { message } from 'antd';
import omit from 'lodash/omit';
import { useEffect } from 'react'; import { useEffect } from 'react';
import { useCollection, useCollectionManager } from '.'; import { useCollection, useCollectionManager } from '.';
import { useRequest } from '../api-client'; import { useRequest } from '../api-client';
@ -257,6 +258,25 @@ export const useBulkDestroyAction = () => {
}; };
}; };
export const useUpdateCollectionActionAndRefreshCM = (options) => {
const { refreshCM } = useCollectionManager();
const form = useForm();
const ctx = useActionContext();
const { refresh } = useResourceActionContext();
const { resource, targetKey } = useResourceContext();
const { [targetKey]: filterByTk } = useRecord();
return {
async run() {
await form.submit();
await resource.update({ filterByTk, values: omit(form.values, ['fields']) });
ctx.setVisible(false);
await form.reset();
refresh();
await refreshCM();
},
};
}
export const useValuesFromRecord = (options) => { export const useValuesFromRecord = (options) => {
const record = useRecord(); const record = useRecord();
const result = useRequest(() => Promise.resolve({ data: record }), { const result = useRequest(() => Promise.resolve({ data: record }), {