fix: restore useValuesFromRecord

This commit is contained in:
chenos 2022-11-30 11:45:32 +08:00
parent dea9655573
commit 6799c9615d

View File

@ -1,13 +1,12 @@
import { message } from 'antd';
import omit from 'lodash/omit';
import { useEffect } from 'react';
import { useForm } from '@formily/react'; import { useForm } from '@formily/react';
import { message } from 'antd';
import { useEffect } from 'react';
import { useCollection, useCollectionManager } from '.'; import { useCollection, useCollectionManager } from '.';
import { useRequest } from '../api-client'; import { useRequest } from '../api-client';
import { useRecord } from '../record-provider'; import { useRecord } from '../record-provider';
import { useActionContext } from '../schema-component'; import { useActionContext } from '../schema-component';
import { useFilterFieldOptions, useFilterFieldProps } from '../schema-component/antd/filter/useFilterActionProps';
import { useResourceActionContext, useResourceContext } from './ResourceActionProvider'; import { useResourceActionContext, useResourceContext } from './ResourceActionProvider';
import { useFilterFieldProps, useFilterFieldOptions } from '../schema-component/antd/filter/useFilterActionProps';
export const useCancelAction = () => { export const useCancelAction = () => {
const form = useForm(); const form = useForm();
@ -20,6 +19,21 @@ export const useCancelAction = () => {
}; };
}; };
export const useValuesFromRecord = (options) => {
const record = useRecord();
const result = useRequest(() => Promise.resolve({ data: record }), {
...options,
manual: true,
});
const ctx = useActionContext();
useEffect(() => {
if (ctx.visible) {
result.run();
}
}, [ctx.visible]);
return result;
};
export const useResetFilterAction = () => { export const useResetFilterAction = () => {
const { run } = useResourceActionContext(); const { run } = useResourceActionContext();
const form = useForm(); const form = useForm();
@ -259,7 +273,6 @@ export const useBulkDestroyAction = () => {
}; };
}; };
export const useValuesFromRA = (options) => { export const useValuesFromRA = (options) => {
const ctx = useResourceActionContext(); const ctx = useResourceActionContext();
return useRequest(() => Promise.resolve(ctx.data), { return useRequest(() => Promise.resolve(ctx.data), {