From 2180c7aad844a7502d9db84b1dc70dce198be4ed Mon Sep 17 00:00:00 2001 From: Katherine Date: Mon, 9 Sep 2024 19:36:49 +0800 Subject: [PATCH] refactor:action panel for mobile to support mobile:addBlock (#5235) * refactor: action panel for mobile to support mobile:addBlock * fix: test --- .../hooks/useSchemaInitializerRender.tsx | 5 +++-- .../client/src/modules/popup/OpenModeProvider.tsx | 13 +++++++++++-- .../WorkbenchPopupActionSchemaInitializerItem.tsx | 6 +++--- .../plugin-mobile/src/client/mobile/Mobile.tsx | 1 + 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/core/client/src/application/schema-initializer/hooks/useSchemaInitializerRender.tsx b/packages/core/client/src/application/schema-initializer/hooks/useSchemaInitializerRender.tsx index b05a170aa0..ea5bf8af72 100644 --- a/packages/core/client/src/application/schema-initializer/hooks/useSchemaInitializerRender.tsx +++ b/packages/core/client/src/application/schema-initializer/hooks/useSchemaInitializerRender.tsx @@ -15,7 +15,7 @@ import { SchemaInitializerButton } from '../components/SchemaInitializerButton'; import { SchemaInitializer } from '../SchemaInitializer'; import { SchemaInitializerOptions } from '../types'; import { withInitializer } from '../withInitializer'; - +import { useOpenModeContext } from '../../../modules/popup/OpenModeProvider'; const InitializerComponent: FC> = React.memo((options) => { const Component: any = options.Component || SchemaInitializerButton; @@ -38,13 +38,14 @@ export function useSchemaInitializerRender( options?: Omit, 'name'>, ) { const app = useApp(); + const { isMobile } = useOpenModeContext() || {}; // compatible with mobile // TODO: delete this code if ( name === 'popup:common:addBlock' && app.schemaInitializerManager.has('mobile:popup:common:addBlock') && - window.location.pathname.startsWith('/m/') + isMobile ) { name = 'mobile:popup:common:addBlock'; } diff --git a/packages/core/client/src/modules/popup/OpenModeProvider.tsx b/packages/core/client/src/modules/popup/OpenModeProvider.tsx index a3d102e8fe..8a32996563 100644 --- a/packages/core/client/src/modules/popup/OpenModeProvider.tsx +++ b/packages/core/client/src/modules/popup/OpenModeProvider.tsx @@ -30,6 +30,11 @@ interface OpenModeProviderProps { * 隐藏 open mode 的配置选项 */ hideOpenMode?: boolean; + /** + * @default false + * 是否为Mobile路由下 + */ + isMobile?: boolean; } const defaultContext: OpenModeProviderProps = { @@ -46,6 +51,7 @@ const OpenModeContext = React.createContext<{ defaultOpenMode: OpenModeProviderProps['defaultOpenMode']; hideOpenMode: boolean; getComponentByOpenMode: (openMode: OpenMode) => any; + isMobile: boolean; }>(null); /** @@ -66,7 +72,9 @@ export const OpenModeProvider: FC = (props) => { if (props.hideOpenMode !== undefined) { result.hideOpenMode = props.hideOpenMode; } - + if (props.isMobile) { + result.isMobile = props.isMobile; + } return result; }, [props.defaultOpenMode, props.openModeToComponent, props.hideOpenMode]); @@ -88,8 +96,9 @@ export const OpenModeProvider: FC = (props) => { defaultOpenMode: context.defaultOpenMode, hideOpenMode: context.hideOpenMode, getComponentByOpenMode, + isMobile: context.isMobile, }; - }, [context.defaultOpenMode, context.hideOpenMode, getComponentByOpenMode]); + }, [context.defaultOpenMode, context.hideOpenMode, getComponentByOpenMode, context.isMobile]); return {props.children}; }; diff --git a/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchPopupActionSchemaInitializerItem.tsx b/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchPopupActionSchemaInitializerItem.tsx index 4c0c19de8b..0894db145a 100644 --- a/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchPopupActionSchemaInitializerItem.tsx +++ b/packages/plugins/@nocobase/plugin-block-workbench/src/client/WorkbenchPopupActionSchemaInitializerItem.tsx @@ -11,8 +11,8 @@ import { ButtonEditor, SchemaSettingOpenModeSchemaItems, SchemaSettings, - useOpenModeContext, useSchemaInitializer, + useOpenModeContext, } from '@nocobase/client'; import React from 'react'; import { useTranslation } from 'react-i18next'; @@ -61,7 +61,7 @@ export function WorkbenchPopupActionSchemaInitializerItem(props) { // 调用插入功能 const { insert } = useSchemaInitializer(); const { t } = useTranslation(); - const { hideOpenMode } = useOpenModeContext(); + const { isMobile } = useOpenModeContext(); return ( {