From 03538ee82f7b7cd73367d9904e4ac3c87d7a4345 Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 15 Aug 2022 13:09:41 +0800 Subject: [PATCH] fix(collection-manager): update collection without fields --- .../Configuration/schemas/collections.ts | 2 +- .../src/collection-manager/action-hooks.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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 }), {