Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

💄 style(conversation): move topic Share into the header menu inside workspaces (#22019)

AmAzing-c6812c6a906e
diff --git a/src/features/SharePopover/index.tsx b/src/features/SharePopover/index.tsx
index 5fb26a360d4..da1a81b5815 100644
--- a/src/features/SharePopover/index.tsx
+++ b/src/features/SharePopover/index.tsx
@@ -11,6 +11,7 @@ import {
Icon,
Input,
Popover,
+ type PopoverPlacement,
Switch,
Text,
toast,
@@ -27,8 +28,8 @@ import {
PaperclipIcon,
WrenchIcon,
} from 'lucide-react';
-import { type ReactNode } from 'react';
-import { memo, useCallback, useRef, useState } from 'react';
+import { type ReactNode, type RefObject } from 'react';
+import { memo, useCallback, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { ArticleSkeleton } from '@/components/Skeleton';
@@ -280,32 +281,49 @@ const SharePopoverContent = memo<SharePopoverContentProps>(({ agentId, onOpenMod
interface SharePopoverProps {
/** Owner of the topic — carries the agent-level topic-share policy. */
agentId?: string;
+ /**
+ * Positions the popover against this element instead of `children`, for a
+ * popover opened programmatically (e.g. from a menu item) rather than by
+ * pressing its own trigger. Focus returns here when it closes.
+ */
+ anchor?: RefObject<HTMLElement | null>;
children?: ReactNode;
+ onOpenChange?: (open: boolean) => void;
onOpenModal?: () => void;
+ open?: boolean;
+ placement?: PopoverPlacement;
topicId?: string;
}
-const SharePopover = memo<SharePopoverProps>(({ agentId, children, onOpenModal, topicId }) => {
- const isMobile = useIsMobile();
+const SharePopover = memo<SharePopoverProps>(
+ ({ agentId, anchor, children, onOpenChange, onOpenModal, open, placement, topicId }) => {
+ const isMobile = useIsMobile();
+ const positionerProps = useMemo(() => (anchor ? { anchor } : undefined), [anchor]);
+ const popupProps = useMemo(() => (anchor ? { finalFocus: anchor } : undefined), [anchor]);
- return (
- <Popover
- arrow={false}
- placement={isMobile ? 'top' : 'bottomRight'}
- trigger={['click']}
- content={
- <SharePopoverContent agentId={agentId} topicId={topicId} onOpenModal={onOpenModal} />
- }
- styles={{
- content: {
- padding: 0,
- width: isMobile ? '100vw' : 366,
- },
- }}
- >
- {children}
- </Popover>
- );
-});
+ return (
+ <Popover
+ arrow={false}
+ open={open}
+ placement={placement ?? (isMobile ? 'top' : 'bottomRight')}
+ popupProps={popupProps}
+ positionerProps={positionerProps}
+ trigger={['click']}
+ content={
+ <SharePopoverContent agentId={agentId} topicId={topicId} onOpenModal={onOpenModal} />
+ }
+ styles={{
+ content: {
+ padding: 0,
+ width: isMobile ? '100vw' : 366,
+ },
+ }}
+ onOpenChange={onOpenChange}
+ >
+ {children}
+ </Popover>
+ );
+ },
+);
export default SharePopover;
diff --git a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/index.test.tsx b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/index.test.tsx
index c89047ded17..2722010df14 100644
--- a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/index.test.tsx
+++ b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/index.test.tsx
@@ -1,16 +1,66 @@
import { fireEvent, render, screen } from '@testing-library/react';
-import { describe, expect, it, vi } from 'vitest';
+import type { ReactNode } from 'react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
import HeaderActions from './index';
+const mocks = vi.hoisted(() => ({
+ canShare: true,
+ enableBusinessFeatures: true,
+ openShareModal: vi.fn(),
+ workspaceId: null as string | null,
+}));
+
vi.mock('./useMenu', () => ({
- useMenu: () => ({
+ useMenu: ({ share }: { share?: { disabled?: boolean; onClick: () => void } } = {}) => ({
menuHeader: <div data-testid={'topic-info-header'} />,
- menuItems: [],
+ menuItems: share
+ ? [{ disabled: share.disabled, key: 'share', label: 'Share', onClick: share.onClick }]
+ : [],
}),
}));
+vi.mock('@/business/client/hooks/useActiveWorkspaceId', () => ({
+ useActiveWorkspaceId: () => mocks.workspaceId,
+}));
+
+vi.mock('@/features/Conversation/useAgentContext', () => ({
+ useAgentContext: () => ({ agentId: 'agent-1', topicId: 'topic-1' }),
+}));
+
+vi.mock('@/features/ShareModal', () => ({
+ useShareModal: () => ({ openShareModal: mocks.openShareModal }),
+}));
+
+vi.mock('@/features/SharePopover/lazy', () => ({
+ LazySharePopover: ({ open }: { children?: ReactNode; open?: boolean }) => (
+ <div data-open={String(!!open)} data-testid={'share-popover'} />
+ ),
+}));
+
+vi.mock('@/hooks/usePermission', () => ({
+ usePermission: () => ({ allowed: mocks.canShare }),
+}));
+
+vi.mock('@/store/serverConfig', () => ({
+ useServerConfigStore: (selector: (state: { enableBusinessFeatures: boolean }) => unknown) =>
+ selector({ enableBusinessFeatures: mocks.enableBusinessFeatures }),
+}));
+
+vi.mock('@/store/serverConfig/selectors', () => ({
+ serverConfigSelectors: {
+ enableBusinessFeatures: (s: { enableBusinessFeatures: boolean }) => s.enableBusinessFeatures,
+ },
+}));
+
describe('Conversation header actions', () => {
+ beforeEach(() => {
+ mocks.canShare = true;
+ mocks.enableBusinessFeatures = true;
+ mocks.openShareModal.mockClear();
+ mocks.workspaceId = null;
+ });
+
it('renders the overflow actions button', () => {
render(<HeaderActions />);
@@ -24,4 +74,41 @@ describe('Conversation header actions', () => {
expect(await screen.findByTestId('topic-info-header')).toBeInTheDocument();
});
+
+ it('keeps Share out of the menu in personal scope, where the header has its own button', async () => {
+ render(<HeaderActions />);
+
+ fireEvent.click(screen.getByRole('button'));
+ await screen.findByTestId('topic-info-header');
+
+ expect(screen.queryByText('Share')).toBeNull();
+ expect(screen.queryByTestId('share-popover')).toBeNull();
+ });
+
+ it('opens the share popover from the menu inside a workspace once the menu has closed', async () => {
+ mocks.workspaceId = 'ws-1';
+ render(<HeaderActions />);
+
+ expect(screen.getByTestId('share-popover')).toHaveAttribute('data-open', 'false');
+
+ fireEvent.click(screen.getByRole('button'));
+ fireEvent.click(await screen.findByText('Share'));
+
+ await vi.waitFor(() =>
+ expect(screen.getByTestId('share-popover')).toHaveAttribute('data-open', 'true'),
+ );
+ expect(mocks.openShareModal).not.toHaveBeenCalled();
+ });
+
+ it('goes straight to the export modal when link sharing is unavailable', async () => {
+ mocks.workspaceId = 'ws-1';
+ mocks.enableBusinessFeatures = false;
+ render(<HeaderActions />);
+
+ fireEvent.click(screen.getByRole('button'));
+ fireEvent.click(await screen.findByText('Share'));
+
+ expect(mocks.openShareModal).toHaveBeenCalledTimes(1);
+ expect(screen.queryByTestId('share-popover')).toBeNull();
+ });
});
diff --git a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/index.tsx b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/index.tsx
index e0535f0c553..585a516f714 100644
--- a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/index.tsx
+++ b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/index.tsx
@@ -2,21 +2,84 @@
import { ActionIcon, DropdownMenu } from '@lobehub/ui';
import { MoreHorizontal } from 'lucide-react';
-import { memo } from 'react';
+import { memo, useCallback, useMemo, useRef, useState } from 'react';
+import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';
+import { useAgentContext } from '@/features/Conversation/useAgentContext';
+import { useShareModal } from '@/features/ShareModal';
+import { LazySharePopover as SharePopover } from '@/features/SharePopover/lazy';
+import { usePermission } from '@/hooks/usePermission';
import HeaderSlot from '@/routes/(main)/agent/(chat)/_layout/HeaderSlot';
+import { useServerConfigStore } from '@/store/serverConfig';
+import { serverConfigSelectors } from '@/store/serverConfig/selectors';
import { useMenu } from './useMenu';
const HeaderActions = memo(() => {
- const { menuHeader, menuItems } = useMenu();
+ const { agentId, topicId } = useAgentContext();
+ const workspaceId = useActiveWorkspaceId();
+ const enableTopicLinkShare = useServerConfigStore(serverConfigSelectors.enableBusinessFeatures);
+ const { allowed: canShare } = usePermission('edit_own_content');
+ const { openShareModal } = useShareModal();
+
+ const triggerRef = useRef<HTMLButtonElement>(null);
+ const sharePendingRef = useRef(false);
+ const [shareOpen, setShareOpen] = useState(false);
+
+ // Inside a workspace the header ShareButton gives way to comments, so Share
+ // moves into this menu; the personal header keeps its own button.
+ const shareInMenu = !!workspaceId && !!topicId;
+
+ const share = useMemo(
+ () =>
+ shareInMenu
+ ? {
+ disabled: !canShare,
+ onClick: () => {
+ if (!enableTopicLinkShare) {
+ void openShareModal();
+ return;
+ }
+ // The menu hands focus back to its trigger as it closes, which a
+ // popover opened any earlier reads as focus-out and dismisses.
+ sharePendingRef.current = true;
+ },
+ }
+ : undefined,
+ [canShare, enableTopicLinkShare, openShareModal, shareInMenu],
+ );
+
+ const { menuHeader, menuItems } = useMenu({ share });
+
+ const handleMenuOpenChangeComplete = useCallback((open: boolean) => {
+ if (open || !sharePendingRef.current) return;
+
+ sharePendingRef.current = false;
+ setShareOpen(true);
+ }, []);
return (
<>
<HeaderSlot.Outlet />
- <DropdownMenu header={menuHeader} items={menuItems}>
- <ActionIcon icon={MoreHorizontal} size={'small'} />
+ <DropdownMenu
+ header={menuHeader}
+ items={menuItems}
+ onOpenChangeComplete={handleMenuOpenChangeComplete}
+ >
+ <ActionIcon icon={MoreHorizontal} ref={triggerRef} size={'small'} />
</DropdownMenu>
+ {shareInMenu && enableTopicLinkShare && canShare && (
+ <SharePopover
+ agentId={agentId}
+ anchor={triggerRef}
+ open={shareOpen}
+ placement={'bottomLeft'}
+ onOpenChange={setShareOpen}
+ onOpenModal={openShareModal}
+ >
+ <span hidden />
+ </SharePopover>
+ )}
</>
);
});
diff --git a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.test.tsx b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.test.tsx
index 3ba33aa98cc..ee8cbbecbe3 100644
--- a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.test.tsx
+++ b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.test.tsx
@@ -237,6 +237,30 @@ describe('Conversation header action menu', () => {
});
});
+ it('leads the topic-actions group with Share only when the caller provides it', () => {
+ useLocationMock.mockReturnValue({ pathname: '/agent/agent-1' });
+ const onShare = vi.fn();
+ const keysOf = (items: unknown[]) =>
+ items.map((item) => (isActionItem(item) ? item.key : undefined)).filter(Boolean);
+
+ const { result: personal } = renderHook(() => useMenu());
+ expect(keysOf(personal.current.menuItems())).not.toContain('share');
+
+ const { result } = renderHook(() => useMenu({ share: { disabled: true, onClick: onShare } }));
+ const items = result.current.menuItems();
+ const keys = keysOf(items);
+ expect(keys.slice(keys.indexOf('share'), keys.indexOf('share') + 2)).toEqual([
+ 'share',
+ 'copyWorkingDirectory',
+ ]);
+
+ const shareItem = items.find((item) => isActionItem(item) && item.key === 'share');
+ expect(shareItem).toMatchObject({ disabled: true, label: 'common:share' });
+ if (!isActionItem(shareItem)) throw new Error('Expected share action');
+ shareItem.onClick?.();
+ expect(onShare).toHaveBeenCalledTimes(1);
+ });
+
it('offers Favorites for the open topic beside Pin, without the hotkey', () => {
const { result } = renderHook(() => useMenu());
diff --git a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.tsx b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.tsx
index 8165e976991..b5a61711d9a 100644
--- a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.tsx
+++ b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.tsx
@@ -21,6 +21,7 @@ import {
PencilLine,
Pin,
PinOff,
+ Share2,
Trash,
Wand2,
} from 'lucide-react';
@@ -79,7 +80,18 @@ const TopicInfoHeader = ({ authorName, title, updatedAtLabel }: TopicInfoHeaderP
</Block>
);
-export const useMenu = (): { menuHeader?: ReactNode; menuItems: () => DropdownItem[] } => {
+interface UseMenuOptions {
+ /**
+ * Share entry for the topic. Passed only where Share is not already a header
+ * button (inside a workspace, where comments take that slot).
+ */
+ share?: { disabled?: boolean; onClick: () => void };
+}
+
+export const useMenu = ({ share }: UseMenuOptions = {}): {
+ menuHeader?: ReactNode;
+ menuItems: () => DropdownItem[];
+} => {
const { t } = useTranslation(['chat', 'topic', 'common', 'file']);
const { pathname } = useLocation();
@@ -288,6 +300,16 @@ export const useMenu = (): { menuHeader?: ReactNode; menuItems: () => DropdownIt
{ type: 'divider' as const },
);
+ if (share) {
+ items.push({
+ disabled: share.disabled,
+ icon: <Icon icon={Share2} />,
+ key: 'share',
+ label: t('share', { ns: 'common' }),
+ onClick: share.onClick,
+ });
+ }
+
if (isDesktop && workingDirectory) {
items.push({
icon: <Icon icon={Copy} />,
@@ -377,6 +399,7 @@ export const useMenu = (): { menuHeader?: ReactNode; menuItems: () => DropdownIt
enableTopicBugReport,
isFavorite,
favoriteMenuItem,
+ share,
activeAgentId,
pathname,
workingDirectory,
diff --git a/src/routes/(main)/agent/features/Conversation/Header/ShareButton/index.test.tsx b/src/routes/(main)/agent/features/Conversation/Header/ShareButton/index.test.tsx
index beef50eeb66..cffdb2a5f2d 100644
--- a/src/routes/(main)/agent/features/Conversation/Header/ShareButton/index.test.tsx
+++ b/src/routes/(main)/agent/features/Conversation/Header/ShareButton/index.test.tsx
@@ -15,6 +15,7 @@ const mocks = vi.hoisted(() => ({
allowed: true,
reason: 'requires member',
},
+ workspaceId: null as string | null,
}));
const actionIconPropsSpy = vi.hoisted(() => vi.fn());
@@ -30,11 +31,14 @@ vi.mock('@lobehub/ui', async (importOriginal) => {
};
});
-vi.mock('next/dynamic', () => ({
- default: () =>
- function DynamicComponent({ children }: { children?: ReactNode }) {
- return <div data-testid="share-popover">{children}</div>;
- },
+vi.mock('@/features/SharePopover/lazy', () => ({
+ LazySharePopover: ({ children }: { children?: ReactNode }) => (
+ <div data-testid="share-popover">{children}</div>
+ ),
+}));
+
+vi.mock('@/business/client/hooks/useActiveWorkspaceId', () => ({
+ useActiveWorkspaceId: () => mocks.workspaceId,
}));
vi.mock('@/components/withSuspense', () => ({
@@ -73,9 +77,35 @@ describe('Conversation ShareButton', () => {
mocks.activeTopicId = 'topic-1';
mocks.enableBusinessFeatures = true;
mocks.permission.allowed = true;
+ mocks.workspaceId = null;
actionIconPropsSpy.mockClear();
});
+ it('renders the share entry in personal scope', () => {
+ const { getByTestId } = render(<ShareButton />);
+
+ expect(getByTestId('share-popover')).toBeInTheDocument();
+ expect(actionIconPropsSpy).toHaveBeenCalledWith(expect.objectContaining({ disabled: false }));
+ });
+
+ it('keeps the mobile share entry inside a workspace, where no header menu hosts it', () => {
+ mocks.workspaceId = 'ws-1';
+
+ const { getByTestId } = render(<ShareButton mobile />);
+
+ expect(getByTestId('share-popover')).toBeInTheDocument();
+ expect(actionIconPropsSpy).toHaveBeenCalledWith(expect.objectContaining({ disabled: false }));
+ });
+
+ it('hides the share entry inside a workspace, where comments take the slot', () => {
+ mocks.workspaceId = 'ws-1';
+
+ const { container } = render(<ShareButton />);
+
+ expect(actionIconPropsSpy).not.toHaveBeenCalled();
+ expect(container).toBeEmptyDOMElement();
+ });
+
it('does not open share popover for workspace viewers', () => {
mocks.permission.allowed = false;
diff --git a/src/routes/(main)/agent/features/Conversation/Header/ShareButton/index.tsx b/src/routes/(main)/agent/features/Conversation/Header/ShareButton/index.tsx
index 957ec7ca023..edf5421253e 100644
--- a/src/routes/(main)/agent/features/Conversation/Header/ShareButton/index.tsx
+++ b/src/routes/(main)/agent/features/Conversation/Header/ShareButton/index.tsx
@@ -5,6 +5,7 @@ import { Share2 } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
+import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspaceId';
import { withSuspense } from '@/components/withSuspense';
import { DESKTOP_HEADER_ICON_SMALL_SIZE, MOBILE_HEADER_ICON_SIZE } from '@/const/layoutTokens';
import { useAgentContext } from '@/features/Conversation/useAgentContext';
@@ -26,9 +27,15 @@ const ShareButton = memo<ShareButtonProps>(({ mobile, setOpen, open }) => {
const { agentId, topicId } = useAgentContext();
const enableTopicLinkShare = useServerConfigStore(serverConfigSelectors.enableBusinessFeatures);
const { allowed: canShare, reason } = usePermission('edit_own_content');
+ const workspaceId = useActiveWorkspaceId();
// Hide share button when no topic exists (no messages sent yet)
if (!topicId) return null;
+ // Inside a workspace teammates already reach the topic and collaborate through
+ // comments, which take this desktop header slot (TopicCommentButton) while
+ // Share moves into the header "..." menu. The mobile header has no such menu,
+ // so it keeps the button as the only entry to the link-sharing popover.
+ if (workspaceId && !mobile) return null;
const iconButton = (
<ActionIcon