diff --git a/packages/core/client/src/collection-manager/Configuration/schemas/collections.ts b/packages/core/client/src/collection-manager/Configuration/schemas/collections.ts index 7395b2ecd..3f7b8e032 100644 --- a/packages/core/client/src/collection-manager/Configuration/schemas/collections.ts +++ b/packages/core/client/src/collection-manager/Configuration/schemas/collections.ts @@ -258,7 +258,7 @@ export const collectionSchema: ISchema = { 'x-component': 'Action', 'x-component-props': { type: 'primary', - useAction: '{{ cm.useUpdateActionAndRefreshCM }}', + useAction: '{{ cm.useUpdateCollectionActionAndRefreshCM }}', }, }, }, diff --git a/packages/core/client/src/collection-manager/action-hooks.ts b/packages/core/client/src/collection-manager/action-hooks.ts index 0894d34bc..81b7a8d2f 100644 --- a/packages/core/client/src/collection-manager/action-hooks.ts +++ b/packages/core/client/src/collection-manager/action-hooks.ts @@ -1,5 +1,6 @@ import { useForm } from '@formily/react'; import { message } from 'antd'; +import omit from 'lodash/omit'; import { useEffect } from 'react'; import { useCollection, useCollectionManager } from '.'; 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) => { const record = useRecord(); const result = useRequest(() => Promise.resolve({ data: record }), {