From b95f4a723aeec3d02f294c7bc7a7313fa796ba75 Mon Sep 17 00:00:00 2001 From: Rain <958414905@qq.com> Date: Wed, 4 Oct 2023 19:07:44 +0800 Subject: [PATCH] fix: fix duplicate display of Hello plugin --- .../plugin-sample-hello/src/client/index.tsx | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-sample-hello/src/client/index.tsx b/packages/plugins/@nocobase/plugin-sample-hello/src/client/index.tsx index 88e0f2d0d..ed5783964 100644 --- a/packages/plugins/@nocobase/plugin-sample-hello/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-sample-hello/src/client/index.tsx @@ -39,13 +39,22 @@ export const HelloBlockInitializer = (props) => { const HelloProvider = React.memo((props) => { const items = useContext(SchemaInitializerContext); - const children = items.BlockInitializers.items[1].children; - children.push({ - key: 'hello', - type: 'item', - title: '{{t("Hello block")}}', - component: 'HelloBlockInitializer', - }); + const mediaItems = items.BlockInitializers.items.find((item) => item.key === 'media'); + + if (process.env.NODE_ENV !== 'production' && !mediaItems) { + throw new Error('media block initializer not found'); + } + + const children = mediaItems.children; + if (!children.find((item) => item.key === 'hello')) { + children.push({ + key: 'hello', + type: 'item', + title: '{{t("Hello block")}}', + component: 'HelloBlockInitializer', + }); + } + return (