fix(approval): temp fixed approval form value (#1401)
Reviewed-on: daoyoucloud/tachybase#1401 Reviewed-by: sealday <zhanglin@daoyoucloud.com> Co-authored-by: bai.zixv <bai.zixv@foxmail.com> Co-committed-by: bai.zixv <bai.zixv@foxmail.com>
This commit is contained in:
parent
ba9dc69086
commit
f819c0c33b
@ -9,7 +9,7 @@ export function useApprovalDetailBlockProps() {
|
||||
|
||||
useEffect(() => {
|
||||
form.setValues(snapshot);
|
||||
}, [form, snapshot]);
|
||||
}, [form, snapshot, form?.values?.account_pay_id]);
|
||||
|
||||
return { form };
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { APPROVAL_ACTION_STATUS } from '../../../constants';
|
||||
import { useContextApprovalExecutions } from './Pd.ApprovalExecutions';
|
||||
import { useContextApprovalRecords } from './Pd.ApprovalExecutions';
|
||||
|
||||
export const ProviderApprovalUpdateForm = (props) => {
|
||||
const { status } = useContextApprovalExecutions();
|
||||
const { status } = useContextApprovalRecords();
|
||||
if (status === APPROVAL_ACTION_STATUS.PENDING) {
|
||||
return props.children;
|
||||
} else {
|
||||
|
@ -16,10 +16,10 @@ import { createForm, RecursionField, useField, useFieldSchema } from '@tachybase
|
||||
import _ from 'lodash';
|
||||
|
||||
import { useFlowContext } from '../../../../../FlowContext';
|
||||
import { useContextApprovalExecutions } from './Pd.ApprovalExecutions';
|
||||
import { useContextApprovalRecords } from './Pd.ApprovalExecutions';
|
||||
|
||||
export function ApprovalFormBlockDecorator(props) {
|
||||
const approvalExecutions = useContextApprovalExecutions();
|
||||
const approvalExecutions = useContextApprovalRecords();
|
||||
const { job } = approvalExecutions;
|
||||
const omitApproval = _.omit(approvalExecutions, ['approval', 'job', 'node', 'snapshot']);
|
||||
const { execution, workflow } = useFlowContext();
|
||||
|
@ -5,10 +5,10 @@ import { str2moment } from '@tachybase/utils/client';
|
||||
import { Space, Tag } from 'antd';
|
||||
|
||||
import { approvalStatusConfigObj } from '../../../constants';
|
||||
import { useContextApprovalExecutions } from './Pd.ApprovalExecutions';
|
||||
import { useContextApprovalRecords } from './Pd.ApprovalExecutions';
|
||||
|
||||
export function ActionBarProvider(props) {
|
||||
const { status } = useContextApprovalExecutions();
|
||||
const { status } = useContextApprovalRecords();
|
||||
|
||||
if (status) {
|
||||
return <ComponentUserInfo />;
|
||||
@ -19,7 +19,7 @@ export function ActionBarProvider(props) {
|
||||
|
||||
const ComponentUserInfo = () => {
|
||||
const compile = useCompile();
|
||||
const { status, updatedAt, user } = useContextApprovalExecutions() as any;
|
||||
const { status, updatedAt, user } = useContextApprovalRecords() as any;
|
||||
const configObj = approvalStatusConfigObj[status];
|
||||
return (
|
||||
<Space>
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { createContext, useContext } from 'react';
|
||||
|
||||
import { useContextApprovalExecutions } from './Pd.ApprovalExecutions';
|
||||
import { useContextApprovalRecords } from './Pd.ApprovalExecutions';
|
||||
|
||||
interface ApprovalAction {
|
||||
status: number | null;
|
||||
@ -9,7 +9,7 @@ interface ApprovalAction {
|
||||
const ContextApprovalAction = createContext<Partial<ApprovalAction>>({});
|
||||
|
||||
export function ApprovalActionProvider({ children, ...props }) {
|
||||
const { status } = useContextApprovalExecutions();
|
||||
const { status } = useContextApprovalRecords();
|
||||
|
||||
if (!status || status === props.status) {
|
||||
return <ContextApprovalAction.Provider value={props}>{children}</ContextApprovalAction.Provider>;
|
||||
|
@ -30,8 +30,8 @@ interface ApprovalExecutions {
|
||||
userId?: any;
|
||||
}
|
||||
|
||||
export const ContextApprovalExecutions = createContext<Partial<ApprovalExecutions>>({});
|
||||
export const ContextApprovalRecords = createContext<Partial<ApprovalExecutions>>({});
|
||||
|
||||
export function useContextApprovalExecutions() {
|
||||
return useContext(ContextApprovalExecutions);
|
||||
export function useContextApprovalRecords() {
|
||||
return useContext(ContextApprovalRecords);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import { useApprovalFormBlockProps } from './hooks/useApprovalFormBlockProps';
|
||||
import { useSubmit } from './hooks/useSubmit';
|
||||
import { ActionBarProvider } from './Pd.ActionBarProvider';
|
||||
import { ApprovalActionProvider } from './Pd.ApprovalAction';
|
||||
import { ContextApprovalExecutions } from './Pd.ApprovalExecutions';
|
||||
import { ContextApprovalRecords } from './Pd.ApprovalExecutions';
|
||||
|
||||
// 审批-待办-查看: 内容
|
||||
export const ViewActionTodosContent = () => {
|
||||
@ -87,7 +87,7 @@ export const ViewActionTodosContent = () => {
|
||||
<ExecutionContextProvider workflow={omitWorkflow} nodes={nodes} execution={execution}>
|
||||
<ApprovalContext.Provider value={approval}>
|
||||
<ContextApprovalExecution.Provider value={approvalExecution}>
|
||||
<ContextApprovalExecutions.Provider value={data.data}>
|
||||
<ContextApprovalRecords.Provider value={data.data}>
|
||||
<SchemaComponent
|
||||
components={{
|
||||
SchemaComponentProvider,
|
||||
@ -150,7 +150,7 @@ export const ViewActionTodosContent = () => {
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</ContextApprovalExecutions.Provider>
|
||||
</ContextApprovalRecords.Provider>
|
||||
</ContextApprovalExecution.Provider>
|
||||
</ApprovalContext.Provider>
|
||||
</ExecutionContextProvider>
|
||||
|
@ -1,15 +1,19 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useFormBlockContext } from '@tachybase/client';
|
||||
|
||||
import { useContextApprovalExecutions } from '../Pd.ApprovalExecutions';
|
||||
import { useContextApprovalRecords } from '../Pd.ApprovalExecutions';
|
||||
|
||||
export function useApprovalDetailBlockProps() {
|
||||
const { snapshot } = useContextApprovalExecutions();
|
||||
const { snapshot } = useContextApprovalRecords();
|
||||
const { form } = useFormBlockContext();
|
||||
|
||||
useEffect(() => {
|
||||
form.setValues(snapshot);
|
||||
}, [form, snapshot]);
|
||||
// NOTE: 暂时的解决办法, form?.values?.account_pay_id 这个条件解决了问题, 意思是如果被修改了值, 然后重新修改回来. 在这个审批的特殊条件下, 写法是没问题的. 但是不是根源的解决办法, 也依赖了字段 account_pay_id
|
||||
// XXX: 需要重构, 寻找为何发生多次渲染, 导致设置的值, 被表单组件的默认值覆盖的问题.
|
||||
// 参考文件1: client/src/block-provider/FormBlockProvider.tsx
|
||||
// 参考文件1: src/client/features/approval/common/FormBlock.provider.tsx
|
||||
}, [form, snapshot, form?.values?.account_pay_id]);
|
||||
|
||||
return { form };
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { useField, useForm } from '@tachybase/schema';
|
||||
|
||||
import { useHandleRefresh } from '../../common/useHandleRefresh';
|
||||
import { useContextApprovalAction } from '../Pd.ApprovalAction';
|
||||
import { useContextApprovalExecutions } from '../Pd.ApprovalExecutions';
|
||||
import { useContextApprovalRecords } from '../Pd.ApprovalExecutions';
|
||||
|
||||
export function useSubmit(props: any = {}) {
|
||||
const { refreshTable } = useHandleRefresh();
|
||||
@ -11,7 +11,7 @@ export function useSubmit(props: any = {}) {
|
||||
const api = useAPIClient();
|
||||
const form = useForm();
|
||||
const collection = useCollection();
|
||||
const approvalExecutions = useContextApprovalExecutions();
|
||||
const approvalExecutions = useContextApprovalRecords();
|
||||
const { status } = useContextApprovalAction();
|
||||
const { source } = props;
|
||||
const needUpdateRecord = source === 'updateRecord';
|
||||
|
Loading…
Reference in New Issue
Block a user