From c613eee2c0601ce64662c05fa059f8f00ce0fed5 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Thu, 11 Apr 2024 19:19:53 +0800 Subject: [PATCH] fix: initializer use useAassociationName --- .../src/data-source/collection/AssociationProvider.tsx | 7 ++++++- .../RecordReadPrettyFormBlockInitializer.tsx | 4 ++-- .../blocks/data-blocks/form/CreateFormBlockInitializer.tsx | 4 ++-- .../blocks/data-blocks/form/RecordFormBlockInitializer.tsx | 4 ++-- .../src/client/CreateFormBulkEditBlockInitializer.tsx | 4 ++-- .../SnapshotBlockInitializersDetailItem.tsx | 4 ++-- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/core/client/src/data-source/collection/AssociationProvider.tsx b/packages/core/client/src/data-source/collection/AssociationProvider.tsx index 5d67577863..747a0ca5e4 100644 --- a/packages/core/client/src/data-source/collection/AssociationProvider.tsx +++ b/packages/core/client/src/data-source/collection/AssociationProvider.tsx @@ -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 = (props) => { ); }; + +export const useAssociationName = () => { + const field = useCollectionField(); + return field ? `${field.collectionName}.${field.name}` : null; +}; diff --git a/packages/core/client/src/modules/blocks/data-blocks/details-single/RecordReadPrettyFormBlockInitializer.tsx b/packages/core/client/src/modules/blocks/data-blocks/details-single/RecordReadPrettyFormBlockInitializer.tsx index c88a1518c7..18b3ea249d 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/details-single/RecordReadPrettyFormBlockInitializer.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/details-single/RecordReadPrettyFormBlockInitializer.tsx @@ -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) => { diff --git a/packages/core/client/src/modules/blocks/data-blocks/form/CreateFormBlockInitializer.tsx b/packages/core/client/src/modules/blocks/data-blocks/form/CreateFormBlockInitializer.tsx index d5728269c0..a210d497ac 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/form/CreateFormBlockInitializer.tsx +++ b/packages/core/client/src/modules/blocks/data-blocks/form/CreateFormBlockInitializer.tsx @@ -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 ( { export function useCreateEditFormBlock() { const { insert } = useSchemaInitializer(); - const association = useBlockAssociationContext(); + const association = useAssociationName(); const createEditFormBlock = useCallback( ({ item }) => { diff --git a/packages/plugins/@nocobase/plugin-action-bulk-edit/src/client/CreateFormBulkEditBlockInitializer.tsx b/packages/plugins/@nocobase/plugin-action-bulk-edit/src/client/CreateFormBulkEditBlockInitializer.tsx index ab2291b42a..aa042673e1 100644 --- a/packages/plugins/@nocobase/plugin-action-bulk-edit/src/client/CreateFormBulkEditBlockInitializer.tsx +++ b/packages/plugins/@nocobase/plugin-action-bulk-edit/src/client/CreateFormBulkEditBlockInitializer.tsx @@ -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 ( { 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;