feat: action loading
This commit is contained in:
parent
aca91bd2cf
commit
7677617329
@ -1,4 +1,4 @@
|
|||||||
import { useFieldSchema, useForm } from '@formily/react';
|
import { useField, useFieldSchema, useForm } from '@formily/react';
|
||||||
import { Modal } from 'antd';
|
import { Modal } from 'antd';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
@ -59,6 +59,7 @@ export const useCreateActionProps = () => {
|
|||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const actionSchema = useFieldSchema();
|
const actionSchema = useFieldSchema();
|
||||||
|
const actionField = useField();
|
||||||
const { fields, getField } = useCollection();
|
const { fields, getField } = useCollection();
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
return {
|
return {
|
||||||
@ -100,12 +101,15 @@ export const useCreateActionProps = () => {
|
|||||||
values[key] = form.values[key];
|
values[key] = form.values[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
actionField.data = field.data || {};
|
||||||
|
actionField.data.loading = true;
|
||||||
await resource.create({
|
await resource.create({
|
||||||
values: {
|
values: {
|
||||||
...values,
|
...values,
|
||||||
...overwriteValues,
|
...overwriteValues,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
actionField.data.loading = false;
|
||||||
__parent?.service?.refresh?.();
|
__parent?.service?.refresh?.();
|
||||||
setVisible?.(false);
|
setVisible?.(false);
|
||||||
const onSuccess = actionSchema?.['x-action-settings']?.onSuccess;
|
const onSuccess = actionSchema?.['x-action-settings']?.onSuccess;
|
||||||
@ -138,6 +142,7 @@ export const useUpdateActionProps = () => {
|
|||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { fields, getField } = useCollection();
|
const { fields, getField } = useCollection();
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
|
const actionField = useField();
|
||||||
return {
|
return {
|
||||||
async onClick() {
|
async onClick() {
|
||||||
const skipValidator = actionSchema?.['x-action-settings']?.skipValidator;
|
const skipValidator = actionSchema?.['x-action-settings']?.skipValidator;
|
||||||
@ -154,7 +159,7 @@ export const useUpdateActionProps = () => {
|
|||||||
values[key] = form.values[key];
|
values[key] = form.values[key];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!field.added.has(key)) {
|
if (field.added && !field.added.has(key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const items = form.values[key];
|
const items = form.values[key];
|
||||||
@ -184,6 +189,8 @@ export const useUpdateActionProps = () => {
|
|||||||
values[key] = form.values[key];
|
values[key] = form.values[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
actionField.data = field.data || {};
|
||||||
|
actionField.data.loading = true;
|
||||||
await resource.update({
|
await resource.update({
|
||||||
filterByTk,
|
filterByTk,
|
||||||
values: {
|
values: {
|
||||||
@ -191,6 +198,7 @@ export const useUpdateActionProps = () => {
|
|||||||
...overwriteValues,
|
...overwriteValues,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
actionField.data.loading = false;
|
||||||
__parent?.service?.refresh?.();
|
__parent?.service?.refresh?.();
|
||||||
if (!(resource instanceof TableFieldResource)) {
|
if (!(resource instanceof TableFieldResource)) {
|
||||||
__parent?.__parent?.service?.refresh?.();
|
__parent?.__parent?.service?.refresh?.();
|
||||||
|
@ -81,13 +81,14 @@ export const Action: ComposedAction = observer((props: any) => {
|
|||||||
const { onClick } = useProps(props);
|
const { onClick } = useProps(props);
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const Designer = useDesigner();
|
const Designer = useDesigner();
|
||||||
const field = useField();
|
const field = useField<any>();
|
||||||
const { run } = useAction();
|
const { run } = useAction();
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const designerProps = fieldSchema['x-designer-props'];
|
const designerProps = fieldSchema['x-designer-props'];
|
||||||
const renderButton = () => (
|
const renderButton = () => (
|
||||||
<SortableItem
|
<SortableItem
|
||||||
{...others}
|
{...others}
|
||||||
|
loading={field?.data?.loading}
|
||||||
icon={<Icon type={icon} />}
|
icon={<Icon type={icon} />}
|
||||||
onClick={(e: React.MouseEvent) => {
|
onClick={(e: React.MouseEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user