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:
bai.zixv 2024-07-31 02:31:53 +08:00 committed by sealday
parent ba9dc69086
commit f819c0c33b
9 changed files with 25 additions and 21 deletions

View File

@ -9,7 +9,7 @@ export function useApprovalDetailBlockProps() {
useEffect(() => { useEffect(() => {
form.setValues(snapshot); form.setValues(snapshot);
}, [form, snapshot]); }, [form, snapshot, form?.values?.account_pay_id]);
return { form }; return { form };
} }

View File

@ -1,8 +1,8 @@
import { APPROVAL_ACTION_STATUS } from '../../../constants'; import { APPROVAL_ACTION_STATUS } from '../../../constants';
import { useContextApprovalExecutions } from './Pd.ApprovalExecutions'; import { useContextApprovalRecords } from './Pd.ApprovalExecutions';
export const ProviderApprovalUpdateForm = (props) => { export const ProviderApprovalUpdateForm = (props) => {
const { status } = useContextApprovalExecutions(); const { status } = useContextApprovalRecords();
if (status === APPROVAL_ACTION_STATUS.PENDING) { if (status === APPROVAL_ACTION_STATUS.PENDING) {
return props.children; return props.children;
} else { } else {

View File

@ -16,10 +16,10 @@ import { createForm, RecursionField, useField, useFieldSchema } from '@tachybase
import _ from 'lodash'; import _ from 'lodash';
import { useFlowContext } from '../../../../../FlowContext'; import { useFlowContext } from '../../../../../FlowContext';
import { useContextApprovalExecutions } from './Pd.ApprovalExecutions'; import { useContextApprovalRecords } from './Pd.ApprovalExecutions';
export function ApprovalFormBlockDecorator(props) { export function ApprovalFormBlockDecorator(props) {
const approvalExecutions = useContextApprovalExecutions(); const approvalExecutions = useContextApprovalRecords();
const { job } = approvalExecutions; const { job } = approvalExecutions;
const omitApproval = _.omit(approvalExecutions, ['approval', 'job', 'node', 'snapshot']); const omitApproval = _.omit(approvalExecutions, ['approval', 'job', 'node', 'snapshot']);
const { execution, workflow } = useFlowContext(); const { execution, workflow } = useFlowContext();

View File

@ -5,10 +5,10 @@ import { str2moment } from '@tachybase/utils/client';
import { Space, Tag } from 'antd'; import { Space, Tag } from 'antd';
import { approvalStatusConfigObj } from '../../../constants'; import { approvalStatusConfigObj } from '../../../constants';
import { useContextApprovalExecutions } from './Pd.ApprovalExecutions'; import { useContextApprovalRecords } from './Pd.ApprovalExecutions';
export function ActionBarProvider(props) { export function ActionBarProvider(props) {
const { status } = useContextApprovalExecutions(); const { status } = useContextApprovalRecords();
if (status) { if (status) {
return <ComponentUserInfo />; return <ComponentUserInfo />;
@ -19,7 +19,7 @@ export function ActionBarProvider(props) {
const ComponentUserInfo = () => { const ComponentUserInfo = () => {
const compile = useCompile(); const compile = useCompile();
const { status, updatedAt, user } = useContextApprovalExecutions() as any; const { status, updatedAt, user } = useContextApprovalRecords() as any;
const configObj = approvalStatusConfigObj[status]; const configObj = approvalStatusConfigObj[status];
return ( return (
<Space> <Space>

View File

@ -1,6 +1,6 @@
import React, { createContext, useContext } from 'react'; import React, { createContext, useContext } from 'react';
import { useContextApprovalExecutions } from './Pd.ApprovalExecutions'; import { useContextApprovalRecords } from './Pd.ApprovalExecutions';
interface ApprovalAction { interface ApprovalAction {
status: number | null; status: number | null;
@ -9,7 +9,7 @@ interface ApprovalAction {
const ContextApprovalAction = createContext<Partial<ApprovalAction>>({}); const ContextApprovalAction = createContext<Partial<ApprovalAction>>({});
export function ApprovalActionProvider({ children, ...props }) { export function ApprovalActionProvider({ children, ...props }) {
const { status } = useContextApprovalExecutions(); const { status } = useContextApprovalRecords();
if (!status || status === props.status) { if (!status || status === props.status) {
return <ContextApprovalAction.Provider value={props}>{children}</ContextApprovalAction.Provider>; return <ContextApprovalAction.Provider value={props}>{children}</ContextApprovalAction.Provider>;

View File

@ -30,8 +30,8 @@ interface ApprovalExecutions {
userId?: any; userId?: any;
} }
export const ContextApprovalExecutions = createContext<Partial<ApprovalExecutions>>({}); export const ContextApprovalRecords = createContext<Partial<ApprovalExecutions>>({});
export function useContextApprovalExecutions() { export function useContextApprovalRecords() {
return useContext(ContextApprovalExecutions); return useContext(ContextApprovalRecords);
} }

View File

@ -25,7 +25,7 @@ import { useApprovalFormBlockProps } from './hooks/useApprovalFormBlockProps';
import { useSubmit } from './hooks/useSubmit'; import { useSubmit } from './hooks/useSubmit';
import { ActionBarProvider } from './Pd.ActionBarProvider'; import { ActionBarProvider } from './Pd.ActionBarProvider';
import { ApprovalActionProvider } from './Pd.ApprovalAction'; import { ApprovalActionProvider } from './Pd.ApprovalAction';
import { ContextApprovalExecutions } from './Pd.ApprovalExecutions'; import { ContextApprovalRecords } from './Pd.ApprovalExecutions';
// 审批-待办-查看: 内容 // 审批-待办-查看: 内容
export const ViewActionTodosContent = () => { export const ViewActionTodosContent = () => {
@ -87,7 +87,7 @@ export const ViewActionTodosContent = () => {
<ExecutionContextProvider workflow={omitWorkflow} nodes={nodes} execution={execution}> <ExecutionContextProvider workflow={omitWorkflow} nodes={nodes} execution={execution}>
<ApprovalContext.Provider value={approval}> <ApprovalContext.Provider value={approval}>
<ContextApprovalExecution.Provider value={approvalExecution}> <ContextApprovalExecution.Provider value={approvalExecution}>
<ContextApprovalExecutions.Provider value={data.data}> <ContextApprovalRecords.Provider value={data.data}>
<SchemaComponent <SchemaComponent
components={{ components={{
SchemaComponentProvider, SchemaComponentProvider,
@ -150,7 +150,7 @@ export const ViewActionTodosContent = () => {
), ),
}} }}
/> />
</ContextApprovalExecutions.Provider> </ContextApprovalRecords.Provider>
</ContextApprovalExecution.Provider> </ContextApprovalExecution.Provider>
</ApprovalContext.Provider> </ApprovalContext.Provider>
</ExecutionContextProvider> </ExecutionContextProvider>

View File

@ -1,15 +1,19 @@
import { useEffect } from 'react'; import { useEffect } from 'react';
import { useFormBlockContext } from '@tachybase/client'; import { useFormBlockContext } from '@tachybase/client';
import { useContextApprovalExecutions } from '../Pd.ApprovalExecutions'; import { useContextApprovalRecords } from '../Pd.ApprovalExecutions';
export function useApprovalDetailBlockProps() { export function useApprovalDetailBlockProps() {
const { snapshot } = useContextApprovalExecutions(); const { snapshot } = useContextApprovalRecords();
const { form } = useFormBlockContext(); const { form } = useFormBlockContext();
useEffect(() => { useEffect(() => {
form.setValues(snapshot); 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 }; return { form };
} }

View File

@ -3,7 +3,7 @@ import { useField, useForm } from '@tachybase/schema';
import { useHandleRefresh } from '../../common/useHandleRefresh'; import { useHandleRefresh } from '../../common/useHandleRefresh';
import { useContextApprovalAction } from '../Pd.ApprovalAction'; import { useContextApprovalAction } from '../Pd.ApprovalAction';
import { useContextApprovalExecutions } from '../Pd.ApprovalExecutions'; import { useContextApprovalRecords } from '../Pd.ApprovalExecutions';
export function useSubmit(props: any = {}) { export function useSubmit(props: any = {}) {
const { refreshTable } = useHandleRefresh(); const { refreshTable } = useHandleRefresh();
@ -11,7 +11,7 @@ export function useSubmit(props: any = {}) {
const api = useAPIClient(); const api = useAPIClient();
const form = useForm(); const form = useForm();
const collection = useCollection(); const collection = useCollection();
const approvalExecutions = useContextApprovalExecutions(); const approvalExecutions = useContextApprovalRecords();
const { status } = useContextApprovalAction(); const { status } = useContextApprovalAction();
const { source } = props; const { source } = props;
const needUpdateRecord = source === 'updateRecord'; const needUpdateRecord = source === 'updateRecord';