fix: useValuesFromRecord with cloneDeep (#2902)

* fix: useValuesFromRecord with cloneDeep

* fix: omit uiSchema.rawTitle

* fix: disabled
This commit is contained in:
chenos 2023-10-25 08:58:45 +08:00 committed by GitHub
parent e2a420afcd
commit d492471ed5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 10 deletions

View File

@ -38,7 +38,7 @@ const useEditCategry = () => {
const useValuesFromRecord = (options) => { const useValuesFromRecord = (options) => {
const record = useRecord(); const record = useRecord();
const result = useRequest(() => Promise.resolve({ data: { ...record } }), { const result = useRequest(() => Promise.resolve({ data: cloneDeep(record) }), {
...options, ...options,
manual: true, manual: true,
}); });

View File

@ -81,7 +81,10 @@ export const useValuesFromRecord = (options) => {
const result = useRequest( const result = useRequest(
() => () =>
Promise.resolve({ 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, ...options,

View File

@ -2,17 +2,18 @@ import { ArrayTable } from '@formily/antd-v5';
import { ISchema, useForm } from '@formily/react'; import { ISchema, useForm } from '@formily/react';
import { uid } from '@formily/shared'; import { uid } from '@formily/shared';
import cloneDeep from 'lodash/cloneDeep'; import cloneDeep from 'lodash/cloneDeep';
import omit from 'lodash/omit';
import set from 'lodash/set'; import set from 'lodash/set';
import React, { useMemo, useState } from 'react'; import React, { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useAPIClient, useRequest } from '../../api-client'; import { useAPIClient, useRequest } from '../../api-client';
import { RecordProvider, useRecord } from '../../record-provider'; import { RecordProvider, useRecord } from '../../record-provider';
import { ActionContextProvider, SchemaComponent, useActionContext, useCompile } from '../../schema-component'; import { ActionContextProvider, SchemaComponent, useActionContext, useCompile } from '../../schema-component';
import { useResourceActionContext, useResourceContext } from '../ResourceActionProvider';
import { useCancelAction, useUpdateAction } from '../action-hooks'; import { useCancelAction, useUpdateAction } from '../action-hooks';
import { useCollectionManager } from '../hooks'; import { useCollectionManager } from '../hooks';
import useDialect from '../hooks/useDialect'; import useDialect from '../hooks/useDialect';
import { IField } from '../interfaces/types'; import { IField } from '../interfaces/types';
import { useResourceActionContext, useResourceContext } from '../ResourceActionProvider';
import * as components from './components'; import * as components from './components';
const getSchema = (schema: IField, record: any, compile, getContainer): ISchema => { const getSchema = (schema: IField, record: any, compile, getContainer): ISchema => {
@ -64,7 +65,7 @@ const getSchema = (schema: IField, record: any, compile, getContainer): ISchema
return useRequest( return useRequest(
() => () =>
Promise.resolve({ Promise.resolve({
data: cloneDeep(schema.default), data: cloneDeep(omit(schema.default, ['uiSchema.rawTitle'])),
}), }),
options, options,
); );

View File

@ -1,5 +1,6 @@
import { useField, useForm } from '@formily/react'; import { useField, useForm } from '@formily/react';
import { message } from 'antd'; import { message } from 'antd';
import cloneDeep from 'lodash/cloneDeep';
import omit from 'lodash/omit'; import omit from 'lodash/omit';
import { useEffect, useMemo } from 'react'; import { useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@ -23,10 +24,13 @@ export const useCancelAction = () => {
export const useValuesFromRecord = (options) => { export const useValuesFromRecord = (options) => {
const record = useRecord(); const record = useRecord();
const result = useRequest(() => Promise.resolve({ data: omit(record, ['__parent', '__collectionName']) }), { const result = useRequest(
...options, () => Promise.resolve({ data: omit(cloneDeep(record), ['__parent', '__collectionName']) }),
manual: true, {
}); ...options,
manual: true,
},
);
const ctx = useActionContext(); const ctx = useActionContext();
useEffect(() => { useEffect(() => {
if (ctx.visible) { if (ctx.visible) {

View File

@ -10,12 +10,13 @@ import {
} from '@nocobase/client'; } from '@nocobase/client';
import { error, lodash } from '@nocobase/utils/client'; import { error, lodash } from '@nocobase/utils/client';
import { Select, message } from 'antd'; import { Select, message } from 'antd';
import cloneDeep from 'lodash/cloneDeep';
import React, { useContext, useEffect } from 'react'; import React, { useContext, useEffect } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { GraphCollectionContext } from './components/CollectionNodeProvder'; import { GraphCollectionContext } from './components/CollectionNodeProvder';
export const useValuesFromRecord = (options, data) => { export const useValuesFromRecord = (options, data) => {
const result = useRequest(() => Promise.resolve({ data }), { const result = useRequest(() => Promise.resolve({ data: cloneDeep(data) }), {
...options, ...options,
manual: true, manual: true,
}); });

View File

@ -110,7 +110,7 @@ export const formSchema: ISchema = {
name: { name: {
'x-component': 'CollectionField', 'x-component': 'CollectionField',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-visible': '{{ !!createOnly }}', 'x-disabled': '{{ !createOnly }}',
}, },
pinned: { pinned: {
'x-component': 'CollectionField', 'x-component': 'CollectionField',