fix: initializer use useAassociationName

This commit is contained in:
katherinehhh 2024-04-11 19:19:53 +08:00
parent fa815aeb3c
commit c613eee2c0
6 changed files with 16 additions and 11 deletions

View File

@ -1,5 +1,5 @@
import React, { FC, ReactNode, createContext, useContext } from 'react';
import { CollectionFieldProvider } from '../collection-field';
import { CollectionFieldProvider, useCollectionField } from '../collection-field';
import { CollectionDeletedPlaceholder } from '../components/CollectionDeletedPlaceholder';
import { Collection } from './Collection';
import { useCollectionManager } from './CollectionManagerProvider';
@ -41,3 +41,8 @@ export const AssociationProvider: FC<AssociationProviderProps> = (props) => {
</CollectionProvider>
);
};
export const useAssociationName = () => {
const field = useCollectionField();
return field ? `${field.collectionName}.${field.name}` : null;
};

View File

@ -1,11 +1,11 @@
import { FormOutlined } from '@ant-design/icons';
import React, { useCallback } from 'react';
import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from '../../../../application';
import { useBlockAssociationContext } from '../../../../block-provider';
import { useCollection_deprecated } from '../../../../collection-manager';
import { useRecordCollectionDataSourceItems } from '../../../../schema-initializer/utils';
import { useSchemaTemplateManager } from '../../../../schema-templates';
import { createDetailsUISchema } from './createDetailsUISchema';
import { useAssociationName } from '../../../../data-source';
export const RecordReadPrettyFormBlockInitializer = () => {
const itemConfig = useSchemaInitializerItem();
@ -27,7 +27,7 @@ export const RecordReadPrettyFormBlockInitializer = () => {
export function useCreateSingleDetailsSchema() {
const { insert } = useSchemaInitializer();
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
const association = useBlockAssociationContext();
const association = useAssociationName();
const templateWrap = useCallback(
(templateSchema, options) => {

View File

@ -2,11 +2,11 @@ import { FormOutlined } from '@ant-design/icons';
import React from 'react';
import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from '../../../../application';
import { useBlockAssociationContext } from '../../../../block-provider';
import { useCollection_deprecated } from '../../../../collection-manager';
import { useRecordCollectionDataSourceItems } from '../../../../schema-initializer/utils';
import { useSchemaTemplateManager } from '../../../../schema-templates';
import { createCreateFormBlockUISchema } from './createCreateFormBlockUISchema';
import { useAssociationName } from '../../../../data-source';
// TODO: `SchemaInitializerItem` items
export const CreateFormBlockInitializer = () => {
@ -14,7 +14,7 @@ export const CreateFormBlockInitializer = () => {
const { onCreateBlockSchema, componentType, createBlockSchema, ...others } = itemConfig;
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
const { insert } = useSchemaInitializer();
const association = useBlockAssociationContext();
const association = useAssociationName();
const collection = useCollection_deprecated();
return (
<SchemaInitializerItem

View File

@ -1,7 +1,7 @@
import { FormOutlined } from '@ant-design/icons';
import React, { useCallback } from 'react';
import { SchemaInitializerItem, useSchemaInitializer, useSchemaInitializerItem } from '../../../../application';
import { useBlockAssociationContext } from '../../../../block-provider';
import { useAssociationName } from '../../../../data-source';
import { useCollection_deprecated } from '../../../../collection-manager';
import { useRecordCollectionDataSourceItems } from '../../../../schema-initializer/utils';
import { useSchemaTemplateManager } from '../../../../schema-templates';
@ -39,7 +39,7 @@ export const RecordFormBlockInitializer = () => {
export function useCreateEditFormBlock() {
const { insert } = useSchemaInitializer();
const association = useBlockAssociationContext();
const association = useAssociationName();
const createEditFormBlock = useCallback(
({ item }) => {

View File

@ -2,12 +2,12 @@ import { FormOutlined } from '@ant-design/icons';
import {
SchemaInitializerItem,
createCreateFormBlockUISchema,
useBlockAssociationContext,
useCollection_deprecated,
useRecordCollectionDataSourceItems,
useSchemaInitializer,
useSchemaInitializerItem,
useSchemaTemplateManager,
useAssociationName,
} from '@nocobase/client';
import React from 'react';
import { createBulkEditBlockUISchema } from './createBulkEditBlockUISchema';
@ -17,7 +17,7 @@ export const CreateFormBulkEditBlockInitializer = () => {
const { onCreateBlockSchema, componentType, createBlockSchema, ...others } = itemConfig;
const { insert } = useSchemaInitializer();
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
const association = useBlockAssociationContext();
const association = useAssociationName();
const collection = useCollection_deprecated();
return (
<SchemaInitializerItem

View File

@ -1,7 +1,6 @@
import React from 'react';
import { FormOutlined } from '@ant-design/icons';
import {
useBlockAssociationContext,
useCollection_deprecated,
useSchemaTemplateManager,
useRecordCollectionDataSourceItems,
@ -9,6 +8,7 @@ import {
useSchemaInitializer,
SchemaInitializerItem,
useSchemaInitializerItem,
useAssociationName,
} from '@nocobase/client';
import { ISchema } from '@formily/react';
import { uid } from '@formily/shared';
@ -73,7 +73,7 @@ export const SnapshotBlockInitializersDetailItem = () => {
const { getTemplateSchemaByMode } = useSchemaTemplateManager();
// eslint-disable-next-line react-hooks/rules-of-hooks
const collection = targetCollection || useCollection_deprecated();
const association = useBlockAssociationContext();
const association = useAssociationName();
const { block } = useBlockRequestContext();
const actionInitializers =
block !== 'TableField' ? itemConfig.actionInitializers || 'details:configureActions' : null;