From 23283af6693c0330a998648628afed7699a12e96 Mon Sep 17 00:00:00 2001 From: sealday Date: Thu, 30 May 2024 19:15:59 +0800 Subject: [PATCH] fix: design menu not show (#1083) Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1083 --- .../src/block-provider/FormBlockProvider.tsx | 11 ++++++----- .../collection-field/CollectionField.tsx | 17 ++++++++--------- .../CollectionFieldProvider.tsx | 6 ++---- .../hooks/useIsAllowToSetDefaultValue.tsx | 10 +++++----- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/packages/core/client/src/block-provider/FormBlockProvider.tsx b/packages/core/client/src/block-provider/FormBlockProvider.tsx index adb2b30d2..ea9e0c7c2 100644 --- a/packages/core/client/src/block-provider/FormBlockProvider.tsx +++ b/packages/core/client/src/block-provider/FormBlockProvider.tsx @@ -1,16 +1,17 @@ -import { createForm } from '@tachybase/schema'; -import { RecursionField, Schema, useField, useFieldSchema } from '@tachybase/schema'; -import { Spin } from 'antd'; import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react'; +import { createForm, RecursionField, Schema, useField, useFieldSchema } from '@tachybase/schema'; + +import { Spin } from 'antd'; + +import { withDynamicSchemaProps } from '../application/hoc/withDynamicSchemaProps'; import { useCollection_deprecated } from '../collection-manager'; import { CollectionRecord, useCollectionParentRecordData, useCollectionRecord } from '../data-source'; import { RecordProvider, useRecord } from '../record-provider'; import { useActionContext, useDesignable } from '../schema-component'; import { Templates as DataTemplateSelect } from '../schema-component/antd/form-v2/Templates'; import { BlockProvider, useBlockRequestContext } from './BlockProvider'; -import { TemplateBlockProvider } from './TemplateBlockProvider'; import { FormActiveFieldsProvider } from './hooks/useFormActiveFields'; -import { withDynamicSchemaProps } from '../application/hoc/withDynamicSchemaProps'; +import { TemplateBlockProvider } from './TemplateBlockProvider'; export const FormBlockContext = createContext<{ form?: any; diff --git a/packages/core/client/src/data-source/collection-field/CollectionField.tsx b/packages/core/client/src/data-source/collection-field/CollectionField.tsx index 617a3e8c9..e63f32314 100644 --- a/packages/core/client/src/data-source/collection-field/CollectionField.tsx +++ b/packages/core/client/src/data-source/collection-field/CollectionField.tsx @@ -1,8 +1,8 @@ -import { Field } from '@tachybase/schema'; -import { connect, useField, useFieldSchema } from '@tachybase/schema'; -import { merge } from '@tachybase/schema'; -import { concat } from 'lodash'; import React, { useEffect, useMemo } from 'react'; +import { connect, Field, merge, useField, useFieldSchema } from '@tachybase/schema'; + +import { concat } from 'lodash'; + import { useFormBlockContext } from '../../block-provider/FormBlockProvider'; import { useCompile, useComponent } from '../../schema-component'; import { useIsAllowToSetDefaultValue } from '../../schema-settings/hooks/useIsAllowToSetDefaultValue'; @@ -14,17 +14,16 @@ type Props = { }; /** - * TODO: 初步适配 * @internal */ -export const CollectionFieldInternalField: React.FC = (props: Props) => { +export const CollectionFieldInternalField = (props: Props) => { const { component } = props; const compile = useCompile(); const field = useField(); const fieldSchema = useFieldSchema(); const { uiSchema: uiSchemaOrigin, defaultValue } = useCollectionField(); const { isAllowToSetDefaultValue } = useIsAllowToSetDefaultValue(); - const uiSchema = useMemo(() => compile(uiSchemaOrigin), [JSON.stringify(uiSchemaOrigin)]); + const uiSchema = compile(uiSchemaOrigin); const Component = useComponent(component || uiSchema?.['x-component'] || 'Input'); const setFieldProps = (key, value) => { field[key] = typeof field[key] === 'undefined' ? value : field[key]; @@ -42,7 +41,6 @@ export const CollectionFieldInternalField: React.FC = (props: Props) => { ctx.field.added.add(fieldSchema.name); } }); - // TODO: 初步适配 useEffect(() => { if (!uiSchema) { return; @@ -71,7 +69,8 @@ export const CollectionFieldInternalField: React.FC = (props: Props) => { const originalProps = compile(uiSchema['x-component-props']) || {}; const componentProps = merge(originalProps, field.componentProps || {}); field.component = [Component, componentProps]; - }, [JSON.stringify(uiSchema)]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [uiSchema]); if (!uiSchema) { return null; } diff --git a/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx b/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx index 650509a2e..1c8eddae8 100644 --- a/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx +++ b/packages/core/client/src/data-source/collection-field/CollectionFieldProvider.tsx @@ -1,9 +1,7 @@ -import React, { FC, ReactNode, createContext, useContext, useMemo } from 'react'; - +import React, { createContext, FC, ReactNode, useContext, useMemo } from 'react'; import { useFieldSchema, type SchemaKey } from '@tachybase/schema'; -import type { CollectionFieldOptions } from '../collection'; -import { useCollection, useCollectionManager } from '../collection'; +import { useCollection, useCollectionManager, type CollectionFieldOptions } from '../collection'; import { CollectionDeletedPlaceholder } from '../components/CollectionDeletedPlaceholder'; export const CollectionFieldContext = createContext(null); diff --git a/packages/core/client/src/schema-settings/hooks/useIsAllowToSetDefaultValue.tsx b/packages/core/client/src/schema-settings/hooks/useIsAllowToSetDefaultValue.tsx index 680150640..9c4dfcee2 100644 --- a/packages/core/client/src/schema-settings/hooks/useIsAllowToSetDefaultValue.tsx +++ b/packages/core/client/src/schema-settings/hooks/useIsAllowToSetDefaultValue.tsx @@ -1,12 +1,12 @@ -import { Form } from '@tachybase/schema'; -import { Schema, useFieldSchema } from '@tachybase/schema'; import React, { useContext, useMemo } from 'react'; +import { Form, Schema, useFieldSchema } from '@tachybase/schema'; + import { CollectionFieldOptions_deprecated } from '../..'; -import { isSystemField } from '../SchemaSettings'; -import { isPatternDisabled } from '../isPatternDisabled'; import { useFormBlockContext, useFormBlockType } from '../../block-provider'; -import { useCollectionManager_deprecated } from '../../collection-manager/hooks/useCollectionManager_deprecated'; import { useCollection_deprecated } from '../../collection-manager/hooks/useCollection_deprecated'; +import { useCollectionManager_deprecated } from '../../collection-manager/hooks/useCollectionManager_deprecated'; +import { isPatternDisabled } from '../isPatternDisabled'; +import { isSystemField } from '../SchemaSettings'; interface DefaultValueProviderProps { isAllowToSetDefaultValue: (params: IsAllowToSetDefaultValueParams) => boolean;