fix: design menu not show (#1083)

Reviewed-on: daoyoucloud/tachybase#1083
This commit is contained in:
sealday 2024-05-30 19:15:59 +08:00
parent 53cd459654
commit 23283af669
4 changed files with 21 additions and 23 deletions

View File

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

View File

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

View File

@ -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<CollectionFieldOptions>(null);

View File

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