From d492471ed5a539252b1b9ea5fae564b9edb4226f Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 25 Oct 2023 08:58:45 +0800 Subject: [PATCH] fix: useValuesFromRecord with cloneDeep (#2902) * fix: useValuesFromRecord with cloneDeep * fix: omit uiSchema.rawTitle * fix: disabled --- .../Configuration/EditCategoryAction.tsx | 2 +- .../Configuration/EditCollectionAction.tsx | 5 ++++- .../Configuration/EditFieldAction.tsx | 5 +++-- .../client/src/collection-manager/action-hooks.ts | 12 ++++++++---- .../src/client/action-hooks.tsx | 3 ++- .../src/client/settings/schemas/applications.ts | 2 +- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/core/client/src/collection-manager/Configuration/EditCategoryAction.tsx b/packages/core/client/src/collection-manager/Configuration/EditCategoryAction.tsx index 25cbce96a..bb86088ef 100644 --- a/packages/core/client/src/collection-manager/Configuration/EditCategoryAction.tsx +++ b/packages/core/client/src/collection-manager/Configuration/EditCategoryAction.tsx @@ -38,7 +38,7 @@ const useEditCategry = () => { const useValuesFromRecord = (options) => { const record = useRecord(); - const result = useRequest(() => Promise.resolve({ data: { ...record } }), { + const result = useRequest(() => Promise.resolve({ data: cloneDeep(record) }), { ...options, manual: true, }); diff --git a/packages/core/client/src/collection-manager/Configuration/EditCollectionAction.tsx b/packages/core/client/src/collection-manager/Configuration/EditCollectionAction.tsx index 39589b3a6..4ee458dbf 100644 --- a/packages/core/client/src/collection-manager/Configuration/EditCollectionAction.tsx +++ b/packages/core/client/src/collection-manager/Configuration/EditCollectionAction.tsx @@ -81,7 +81,10 @@ export const useValuesFromRecord = (options) => { const result = useRequest( () => Promise.resolve({ - data: { ...omit(record, ['__parent', '__collectionName']), category: record?.category.map((v) => v.id) }, + data: { + ...omit(cloneDeep(record), ['__parent', '__collectionName']), + category: record?.category.map((v) => v.id), + }, }), { ...options, diff --git a/packages/core/client/src/collection-manager/Configuration/EditFieldAction.tsx b/packages/core/client/src/collection-manager/Configuration/EditFieldAction.tsx index 570f001ed..aec30af65 100644 --- a/packages/core/client/src/collection-manager/Configuration/EditFieldAction.tsx +++ b/packages/core/client/src/collection-manager/Configuration/EditFieldAction.tsx @@ -2,17 +2,18 @@ import { ArrayTable } from '@formily/antd-v5'; import { ISchema, useForm } from '@formily/react'; import { uid } from '@formily/shared'; import cloneDeep from 'lodash/cloneDeep'; +import omit from 'lodash/omit'; import set from 'lodash/set'; import React, { useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useAPIClient, useRequest } from '../../api-client'; import { RecordProvider, useRecord } from '../../record-provider'; import { ActionContextProvider, SchemaComponent, useActionContext, useCompile } from '../../schema-component'; +import { useResourceActionContext, useResourceContext } from '../ResourceActionProvider'; import { useCancelAction, useUpdateAction } from '../action-hooks'; import { useCollectionManager } from '../hooks'; import useDialect from '../hooks/useDialect'; import { IField } from '../interfaces/types'; -import { useResourceActionContext, useResourceContext } from '../ResourceActionProvider'; import * as components from './components'; const getSchema = (schema: IField, record: any, compile, getContainer): ISchema => { @@ -64,7 +65,7 @@ const getSchema = (schema: IField, record: any, compile, getContainer): ISchema return useRequest( () => Promise.resolve({ - data: cloneDeep(schema.default), + data: cloneDeep(omit(schema.default, ['uiSchema.rawTitle'])), }), options, ); diff --git a/packages/core/client/src/collection-manager/action-hooks.ts b/packages/core/client/src/collection-manager/action-hooks.ts index b98d0d553..14de39366 100644 --- a/packages/core/client/src/collection-manager/action-hooks.ts +++ b/packages/core/client/src/collection-manager/action-hooks.ts @@ -1,5 +1,6 @@ import { useField, useForm } from '@formily/react'; import { message } from 'antd'; +import cloneDeep from 'lodash/cloneDeep'; import omit from 'lodash/omit'; import { useEffect, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; @@ -23,10 +24,13 @@ export const useCancelAction = () => { export const useValuesFromRecord = (options) => { const record = useRecord(); - const result = useRequest(() => Promise.resolve({ data: omit(record, ['__parent', '__collectionName']) }), { - ...options, - manual: true, - }); + const result = useRequest( + () => Promise.resolve({ data: omit(cloneDeep(record), ['__parent', '__collectionName']) }), + { + ...options, + manual: true, + }, + ); const ctx = useActionContext(); useEffect(() => { if (ctx.visible) { diff --git a/packages/plugins/@nocobase/plugin-graph-collection-manager/src/client/action-hooks.tsx b/packages/plugins/@nocobase/plugin-graph-collection-manager/src/client/action-hooks.tsx index f5476f153..230b4d489 100644 --- a/packages/plugins/@nocobase/plugin-graph-collection-manager/src/client/action-hooks.tsx +++ b/packages/plugins/@nocobase/plugin-graph-collection-manager/src/client/action-hooks.tsx @@ -10,12 +10,13 @@ import { } from '@nocobase/client'; import { error, lodash } from '@nocobase/utils/client'; import { Select, message } from 'antd'; +import cloneDeep from 'lodash/cloneDeep'; import React, { useContext, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { GraphCollectionContext } from './components/CollectionNodeProvder'; export const useValuesFromRecord = (options, data) => { - const result = useRequest(() => Promise.resolve({ data }), { + const result = useRequest(() => Promise.resolve({ data: cloneDeep(data) }), { ...options, manual: true, }); diff --git a/packages/plugins/@nocobase/plugin-multi-app-manager/src/client/settings/schemas/applications.ts b/packages/plugins/@nocobase/plugin-multi-app-manager/src/client/settings/schemas/applications.ts index c9b8211a1..1541cbc66 100644 --- a/packages/plugins/@nocobase/plugin-multi-app-manager/src/client/settings/schemas/applications.ts +++ b/packages/plugins/@nocobase/plugin-multi-app-manager/src/client/settings/schemas/applications.ts @@ -110,7 +110,7 @@ export const formSchema: ISchema = { name: { 'x-component': 'CollectionField', 'x-decorator': 'FormItem', - 'x-visible': '{{ !!createOnly }}', + 'x-disabled': '{{ !createOnly }}', }, pinned: { 'x-component': 'CollectionField',