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.

🐛 fix(sidebar): let agent groups be hidden from the sidebar like agents (#23072)

Rdmclin26fdec2d61516
diff --git a/src/features/HomeSidebar/Body/Agent/List/AgentGroupItem/useDropdownMenu.test.tsx b/src/features/HomeSidebar/Body/Agent/List/AgentGroupItem/useDropdownMenu.test.tsx
new file mode 100644
index 00000000000..f2cffeb60af
--- /dev/null
+++ b/src/features/HomeSidebar/Body/Agent/List/AgentGroupItem/useDropdownMenu.test.tsx
@@ -0,0 +1,175 @@
+import { renderHook } from '@testing-library/react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { useGroupDropdownMenu } from './useDropdownMenu';
+
+const mocks = vi.hoisted(() => ({
+ activeWorkspaceId: null as string | null,
+ canEdit: true,
+ canEditResource: true,
+ canManage: true,
+ home: {
+ duplicateAgentGroup: vi.fn(),
+ pinAgentGroup: vi.fn(),
+ removeAgentGroup: vi.fn(),
+ },
+ isSidebarItemVisible: vi.fn(() => true),
+ isTeamPinned: false,
+ openAgentInNewWindow: vi.fn(),
+ setSidebarItemVisible: vi.fn(),
+ toastError: vi.fn(),
+}));
+
+vi.mock('@lobehub/ui', async (importOriginal) => ({
+ ...(await importOriginal<object>()),
+ confirmModal: vi.fn(),
+ toast: { error: mocks.toastError, success: vi.fn() },
+}));
+
+vi.mock('@/business/client/hooks/useActiveWorkspaceId', () => ({
+ useActiveWorkspaceId: () => mocks.activeWorkspaceId,
+}));
+
+vi.mock('@/business/client/hooks/useAgentGroupTransferMenuItem', () => ({
+ useAgentGroupTransferMenuItem: () => null,
+}));
+
+vi.mock('@/business/client/hooks/useAgentGroupTransferToMemberMenuItem', () => ({
+ useAgentGroupTransferToMemberMenuItem: () => null,
+}));
+
+vi.mock('@/features/EditingPopover/store', () => ({ openEditingPopover: vi.fn() }));
+
+vi.mock('@/features/ResourcePermission/useResourceAccess', () => ({
+ useResourceAccess: () => ({ canEditResource: mocks.canEditResource, isAccessResolved: true }),
+}));
+
+vi.mock('@/hooks/usePermission', () => ({
+ usePermission: () => ({ allowed: mocks.canEdit, reason: '' }),
+}));
+
+vi.mock('@/hooks/useResourceManageable', () => ({
+ useResourceManageable: () => mocks.canManage,
+}));
+
+vi.mock('@/store/global', () => ({
+ useGlobalStore: (selector: (state: { openAgentInNewWindow: typeof vi.fn }) => unknown) =>
+ selector({ openAgentInNewWindow: mocks.openAgentInNewWindow }),
+}));
+
+vi.mock('@/store/home', () => ({
+ useHomeStore: (selector: (state: typeof mocks.home) => unknown) => selector(mocks.home),
+}));
+
+vi.mock('../../useSidebarItemVisibility', () => ({
+ useSidebarItemVisibility: () => ({
+ isSidebarItemVisible: mocks.isSidebarItemVisible,
+ setSidebarItemVisible: mocks.setSidebarItemVisible,
+ }),
+}));
+
+vi.mock('../../useSidebarPinMenuItems', () => ({
+ useSidebarPinMenuItems: () => ({
+ isTeamPinned: mocks.isTeamPinned,
+ menuItems: mocks.activeWorkspaceId ? [{ key: 'pin', label: 'pin' }] : [],
+ }),
+}));
+
+type MenuItems = ReturnType<ReturnType<typeof useGroupDropdownMenu>>;
+
+const getMenuKeys = (items: MenuItems) =>
+ (items ?? []).flatMap((item) =>
+ item && typeof item === 'object' && 'key' in item && item.key ? [item.key] : [],
+ );
+
+const renderGroupMenu = (options: Partial<Parameters<typeof useGroupDropdownMenu>[0]> = {}) =>
+ renderHook(() =>
+ useGroupDropdownMenu({
+ anchor: null,
+ id: 'cg_1',
+ pinned: false,
+ title: 'Launch Team',
+ userId: 'user-1',
+ ...options,
+ }),
+ );
+
+describe('useGroupDropdownMenu', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ mocks.activeWorkspaceId = null;
+ mocks.canEdit = true;
+ mocks.canEditResource = true;
+ mocks.canManage = true;
+ mocks.isSidebarItemVisible.mockReturnValue(true);
+ mocks.isTeamPinned = false;
+ });
+
+ it('hides a group through the caller sidebar preference, like an Agent row', async () => {
+ const { result } = renderGroupMenu();
+
+ const hideItem = (result.current() ?? []).find(
+ (item) => item && typeof item === 'object' && 'key' in item && item.key === 'hideFromSidebar',
+ );
+ if (!hideItem || !('onClick' in hideItem) || !hideItem.onClick) {
+ throw new Error('Expected hide-from-sidebar menu item');
+ }
+
+ await hideItem.onClick({ domEvent: { stopPropagation: vi.fn() } } as never);
+
+ expect(mocks.setSidebarItemVisible).toHaveBeenCalledWith('cg_1', false);
+ expect(mocks.isSidebarItemVisible).toHaveBeenCalledWith(
+ expect.objectContaining({ id: 'cg_1', type: 'group' }),
+ );
+ });
+
+ it('places the hide action right after pin', () => {
+ const { result } = renderGroupMenu();
+
+ expect(getMenuKeys(result.current()).slice(0, 3)).toEqual(['pin', 'hideFromSidebar', 'rename']);
+ });
+
+ it('offers hide to a member who cannot configure the group', () => {
+ mocks.canEditResource = false;
+ const { result } = renderGroupMenu();
+
+ const keys = getMenuKeys(result.current());
+ expect(keys).toContain('hideFromSidebar');
+ expect(keys).not.toContain('rename');
+ });
+
+ it('reports a failed hide instead of failing silently', async () => {
+ mocks.setSidebarItemVisible.mockRejectedValueOnce(new Error('offline'));
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
+ const { result } = renderGroupMenu();
+
+ const hideItem = (result.current() ?? []).find(
+ (item) => item && typeof item === 'object' && 'key' in item && item.key === 'hideFromSidebar',
+ ) as { onClick: (info: unknown) => Promise<void> };
+ await hideItem.onClick({ domEvent: { stopPropagation: vi.fn() } });
+
+ expect(mocks.toastError).toHaveBeenCalledWith('operationFailed');
+ errorSpy.mockRestore();
+ });
+
+ it('omits hide for a group already hidden from the sidebar', () => {
+ mocks.isSidebarItemVisible.mockReturnValue(false);
+ const { result } = renderGroupMenu();
+
+ expect(getMenuKeys(result.current())).not.toContain('hideFromSidebar');
+ });
+
+ it('omits hide for lists that ignore the sidebar preference', () => {
+ const { result } = renderGroupMenu({ sidebarVisibilityEnabled: false });
+
+ expect(getMenuKeys(result.current())).not.toContain('hideFromSidebar');
+ });
+
+ it('omits hide on a team-pinned workspace group, which every member sees', () => {
+ mocks.activeWorkspaceId = 'workspace-1';
+ mocks.isTeamPinned = true;
+ const { result } = renderGroupMenu({ pinned: true, visibility: 'public' });
+
+ expect(getMenuKeys(result.current())).not.toContain('hideFromSidebar');
+ });
+});
diff --git a/src/features/HomeSidebar/Body/Agent/List/AgentGroupItem/useDropdownMenu.tsx b/src/features/HomeSidebar/Body/Agent/List/AgentGroupItem/useDropdownMenu.tsx
index 1c817e0a48c..d89a39e4313 100644
--- a/src/features/HomeSidebar/Body/Agent/List/AgentGroupItem/useDropdownMenu.tsx
+++ b/src/features/HomeSidebar/Body/Agent/List/AgentGroupItem/useDropdownMenu.tsx
@@ -1,7 +1,15 @@
import type { SidebarVisibility } from '@lobechat/types';
import { type DropdownItem } from '@lobehub/ui';
import { confirmModal, Icon, toast } from '@lobehub/ui';
-import { LucideCopy, Pen, PictureInPicture2Icon, Pin, PinOff, Trash } from 'lucide-react';
+import {
+ EyeOffIcon,
+ LucideCopy,
+ Pen,
+ PictureInPicture2Icon,
+ Pin,
+ PinOff,
+ Trash,
+} from 'lucide-react';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
@@ -16,6 +24,7 @@ import { useGlobalStore } from '@/store/global';
import { useHomeStore } from '@/store/home';
import { getDeleteErrorMessageKey } from '@/utils/forbiddenError';
+import { useSidebarItemVisibility } from '../../useSidebarItemVisibility';
import { useSidebarPinMenuItems } from '../../useSidebarPinMenuItems';
interface UseGroupDropdownMenuParams {
@@ -26,6 +35,12 @@ interface UseGroupDropdownMenuParams {
id: string;
memberAvatars?: { avatar?: string; background?: string }[];
pinned: boolean;
+ /**
+ * Offer "Remove from sidebar". Off for lists that ignore the sidebar
+ * visibility preference (the `im_layout` Messages list), where it would
+ * change nothing visible. Defaults to on.
+ */
+ sidebarVisibilityEnabled?: boolean;
title: string;
userId?: string | null;
visibility?: SidebarVisibility;
@@ -39,6 +54,7 @@ export const useGroupDropdownMenu = ({
id,
memberAvatars,
pinned,
+ sidebarVisibilityEnabled = true,
title,
userId,
visibility,
@@ -72,30 +88,59 @@ export const useGroupDropdownMenu = ({
const activeWorkspaceId = useActiveWorkspaceId();
// Workspace: personal pin for every member + owner/admin team pin on public
// groups. Personal mode keeps the single column-backed pin.
- const { menuItems: workspacePinItems } = useSidebarPinMenuItems({
+ const { isTeamPinned, menuItems: workspacePinItems } = useSidebarPinMenuItems({
id,
pinned,
type: 'group',
visibility,
});
+ // Same per-member show/hide as Agent rows: the sidebar filters agents and
+ // groups through one membership predicate keyed by row id, so hiding a
+ // group only needs the menu entry. Restore it from the Agents page.
+ const { isSidebarItemVisible, setSidebarItemVisible } = useSidebarItemVisibility();
+ const isShownInSidebar =
+ sidebarVisibilityEnabled && isSidebarItemVisible({ id, type: 'group', userId });
+
return useMemo(
() => () =>
[
- ...(activeWorkspaceId ? workspacePinItems : []),
+ ...(activeWorkspaceId
+ ? workspacePinItems
+ : canConfigure
+ ? [
+ {
+ icon: <Icon icon={pinned ? PinOff : Pin} />,
+ key: 'pin',
+ label: t(pinned ? 'pinOff' : 'pin'),
+ onClick: () => pinAgentGroup(id, !pinned),
+ sfSymbol: pinned ? 'pin.slash' : 'pin',
+ },
+ ]
+ : []),
+ // Team-pinned rows are the fixed section every member sees; hiding
+ // them would do nothing there.
+ ...(isShownInSidebar && !isTeamPinned
+ ? [
+ {
+ icon: <Icon icon={EyeOffIcon} />,
+ key: 'hideFromSidebar',
+ label: t('agentViewAll.removeFromSidebar', { ns: 'common' }),
+ onClick: async ({ domEvent }: any) => {
+ domEvent?.stopPropagation();
+ try {
+ await setSidebarItemVisible(id, false);
+ } catch (error) {
+ console.error('Failed to hide group from sidebar:', error);
+ toast.error(t('operationFailed', { ns: 'common' }));
+ }
+ },
+ sfSymbol: 'sidebar.left',
+ },
+ ]
+ : []),
...(canConfigure
? [
- ...(activeWorkspaceId
- ? []
- : [
- {
- icon: <Icon icon={pinned ? PinOff : Pin} />,
- key: 'pin',
- label: t(pinned ? 'pinOff' : 'pin'),
- onClick: () => pinAgentGroup(id, !pinned),
- sfSymbol: pinned ? 'pin.slash' : 'pin',
- },
- ]),
{
icon: <Icon icon={Pen} />,
key: 'rename',
@@ -179,6 +224,9 @@ export const useGroupDropdownMenu = ({
[
activeWorkspaceId,
workspacePinItems,
+ isShownInSidebar,
+ isTeamPinned,
+ setSidebarItemVisible,
anchor,
avatar,
backgroundColor,
diff --git a/src/features/MessageList/GroupConversation.tsx b/src/features/MessageList/GroupConversation.tsx
index f247767a1b3..887cc089092 100644
--- a/src/features/MessageList/GroupConversation.tsx
+++ b/src/features/MessageList/GroupConversation.tsx
@@ -34,6 +34,8 @@ const GroupConversation = memo<GroupConversationProps>(({ active, conversation }
id,
memberAvatars,
pinned: pinned ?? false,
+ // The Messages list ignores the sidebar visibility preference.
+ sidebarVisibilityEnabled: false,
title,
userId,
visibility,