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 record = useRecord();
const result = useRequest(() => Promise.resolve({ data: { ...record } }), {
const result = useRequest(() => Promise.resolve({ data: cloneDeep(record) }), {
...options,
manual: true,
});

View File

@ -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,

View File

@ -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,
);

View File

@ -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']) }), {
const result = useRequest(
() => Promise.resolve({ data: omit(cloneDeep(record), ['__parent', '__collectionName']) }),
{
...options,
manual: true,
});
},
);
const ctx = useActionContext();
useEffect(() => {
if (ctx.visible) {

View File

@ -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,
});

View File

@ -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',