From b6bbe880a067999a9a9bca3ddc9b31054f3ffe29 Mon Sep 17 00:00:00 2001 From: gitlawr Date: Thu, 7 May 2026 14:39:05 +0800 Subject: [PATCH] feat(plugin): expose OrgSwitcher slot in extraRender Add a single host-side mount point in extraRender.tsx: const OrgSwitcher = pluginManager?.components?.OrgSwitcher; ... {OrgSwitcher && } A registered plugin can supply an Org switcher via components.OrgSwitcher. When no plugin provides it, the host renders nothing here, so the build is visually unchanged. --- src/layouts/extraRender.tsx | 5 +++++ src/layouts/index.tsx | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/layouts/extraRender.tsx b/src/layouts/extraRender.tsx index 1182bc0a..a9a6a511 100644 --- a/src/layouts/extraRender.tsx +++ b/src/layouts/extraRender.tsx @@ -120,6 +120,10 @@ export const ExtraContent = (props: { isDarkTheme?: boolean }) => { const { initialState } = initialInfo; const GlobalSettings = pluginManager?.components?.GlobalSettings; + // Plugin slot. A registered plugin can supply an Org switcher via + // components.OrgSwitcher; the host renders nothing when no plugin + // provides it. + const OrgSwitcher = pluginManager?.components?.OrgSwitcher; console.log('plugin+++++++++', pluginManager); const navigate = useNavigate(); @@ -271,6 +275,7 @@ export const ExtraContent = (props: { isDarkTheme?: boolean }) => { return ( {contextHolder} + {OrgSwitcher && }
{ hooks={{ useUserSettings: useUserSettings, useUserSettingsStorage: () => userSettingsStorage, - useIntl: useIntl + useIntl: useIntl, + // Bridge umi's `@@initialState` model so plugins consuming + // `useCurrentUser` from @gpustack/core-ui get the signed-in + // user without depending on @umijs/max directly. Translate + // the host's snake_case fields to core-ui's camelCase + // `CurrentUser` shape, but pass everything else through so + // hosts can carry extra fields. + useCurrentUser: () => { + const cu = useModel?.('@@initialState')?.initialState?.currentUser; + if (!cu) return undefined; + return { + ...cu, + fullName: cu.full_name ?? cu.fullName, + isAdmin: cu.is_admin ?? cu.isAdmin + }; + } }} i18n={intl} locale={{