From 7677617329282e4ebb054ecc175dbb3daa57d468 Mon Sep 17 00:00:00 2001 From: chenos Date: Sat, 30 Apr 2022 14:13:02 +0800 Subject: [PATCH] feat: action loading --- .../core/client/src/block-provider/hooks/index.ts | 12 ++++++++++-- .../src/schema-component/antd/action/Action.tsx | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/core/client/src/block-provider/hooks/index.ts b/packages/core/client/src/block-provider/hooks/index.ts index 6eea72324..2083d99fd 100644 --- a/packages/core/client/src/block-provider/hooks/index.ts +++ b/packages/core/client/src/block-provider/hooks/index.ts @@ -1,4 +1,4 @@ -import { useFieldSchema, useForm } from '@formily/react'; +import { useField, useFieldSchema, useForm } from '@formily/react'; import { Modal } from 'antd'; import { useTranslation } from 'react-i18next'; import { useHistory } from 'react-router-dom'; @@ -59,6 +59,7 @@ export const useCreateActionProps = () => { const history = useHistory(); const { t } = useTranslation(); const actionSchema = useFieldSchema(); + const actionField = useField(); const { fields, getField } = useCollection(); const compile = useCompile(); return { @@ -100,12 +101,15 @@ export const useCreateActionProps = () => { values[key] = form.values[key]; } } + actionField.data = field.data || {}; + actionField.data.loading = true; await resource.create({ values: { ...values, ...overwriteValues, }, }); + actionField.data.loading = false; __parent?.service?.refresh?.(); setVisible?.(false); const onSuccess = actionSchema?.['x-action-settings']?.onSuccess; @@ -138,6 +142,7 @@ export const useUpdateActionProps = () => { const history = useHistory(); const { fields, getField } = useCollection(); const compile = useCompile(); + const actionField = useField(); return { async onClick() { const skipValidator = actionSchema?.['x-action-settings']?.skipValidator; @@ -154,7 +159,7 @@ export const useUpdateActionProps = () => { values[key] = form.values[key]; continue; } - if (!field.added.has(key)) { + if (field.added && !field.added.has(key)) { continue; } const items = form.values[key]; @@ -184,6 +189,8 @@ export const useUpdateActionProps = () => { values[key] = form.values[key]; } } + actionField.data = field.data || {}; + actionField.data.loading = true; await resource.update({ filterByTk, values: { @@ -191,6 +198,7 @@ export const useUpdateActionProps = () => { ...overwriteValues, }, }); + actionField.data.loading = false; __parent?.service?.refresh?.(); if (!(resource instanceof TableFieldResource)) { __parent?.__parent?.service?.refresh?.(); diff --git a/packages/core/client/src/schema-component/antd/action/Action.tsx b/packages/core/client/src/schema-component/antd/action/Action.tsx index ad0cdea79..244438be1 100644 --- a/packages/core/client/src/schema-component/antd/action/Action.tsx +++ b/packages/core/client/src/schema-component/antd/action/Action.tsx @@ -81,13 +81,14 @@ export const Action: ComposedAction = observer((props: any) => { const { onClick } = useProps(props); const [visible, setVisible] = useState(false); const Designer = useDesigner(); - const field = useField(); + const field = useField(); const { run } = useAction(); const fieldSchema = useFieldSchema(); const designerProps = fieldSchema['x-designer-props']; const renderButton = () => ( } onClick={(e: React.MouseEvent) => { e.preventDefault();