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(topic): move Add folder into the Topics ... menu (#21025)

Rdmclin2918b790ab2d3
diff --git a/src/features/AgentSidebar/Topic/index.tsx b/src/features/AgentSidebar/Topic/index.tsx
index 7aab1f386f2..def2eb4dcd3 100644
--- a/src/features/AgentSidebar/Topic/index.tsx
+++ b/src/features/AgentSidebar/Topic/index.tsx
@@ -21,7 +21,6 @@ import { useChatStore } from '@/store/chat';
import { operationSelectors, topicSelectors } from '@/store/chat/selectors';
import Actions from './Actions';
-import AddFolder from './AddFolder';
import Filter from './Filter';
import List from './List';
import ToggleGroups from './ToggleGroups';
@@ -139,7 +138,6 @@ const Topic = memo<TopicProps>(({ expanded, itemKey }) => {
)}
>
<Flexbox horizontal align="center" gap={2}>
- <AddFolder />
<ToggleGroups />
<Filter />
<Actions />
diff --git a/src/features/AgentSidebar/Topic/AddFolder.tsx b/src/features/AgentSidebar/Topic/useAddFolderMenuItem.tsx
similarity index 79%
rename from src/features/AgentSidebar/Topic/AddFolder.tsx
rename to src/features/AgentSidebar/Topic/useAddFolderMenuItem.tsx
index dd7a0f25199..e26e9f4e84d 100644
--- a/src/features/AgentSidebar/Topic/AddFolder.tsx
+++ b/src/features/AgentSidebar/Topic/useAddFolderMenuItem.tsx
@@ -1,7 +1,8 @@
import { AGENT_CHAT_URL, isDesktop } from '@lobechat/const';
-import { ActionIcon, toast } from '@lobehub/ui/base-ui';
+import { Icon, type MenuProps } from '@lobehub/ui';
+import { toast } from '@lobehub/ui/base-ui';
import { FolderPlusIcon } from 'lucide-react';
-import { memo, useMemo } from 'react';
+import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
@@ -21,15 +22,21 @@ import { useElectronStore } from '@/store/electron';
import { buildPrefixedAgentRoutePath, parseAgentPathname } from '../utils/agentPathname';
+type MenuItem = NonNullable<MenuProps['items']>[number];
+
/**
- * Topics header action for heterogeneous agents: pick (or create) a folder on
- * the agent's target device and open a new conversation in it β€” the header
+ * Topics menu action for heterogeneous agents: pick (or create) a folder on
+ * the agent's target device and open a new conversation in it β€” the menu
* counterpart of a project group's "+". The folder becomes the agent's default
* for that device and joins the device's recent list; the topic row (and so
* the folder group) appears once the first message is sent.
+ *
+ * Only heterogeneous (CLI) agents work inside folders, so others get `null`.
*/
-const AddFolderAction = memo<{ agentId: string }>(({ agentId }) => {
+export const useAddFolderMenuItem = (): MenuItem | null => {
const { t } = useTranslation('device');
+ const agentId = useAgentStore((s) => s.activeAgentId) ?? '';
+ const isHeterogeneous = !!useAgentStore(agentSelectors.currentAgentHeterogeneousProviderType);
const { agencyConfig, workspaceScoped } = useEffectiveAgencyConfig(agentId, { topicId: null });
const currentDeviceId = useElectronStore((s) => s.gatewayDeviceInfo?.deviceId);
const targetDeviceId = resolveTargetDeviceId(agencyConfig, currentDeviceId, {
@@ -82,32 +89,13 @@ const AddFolderAction = memo<{ agentId: string }>(({ agentId }) => {
}
};
- if (!targetDeviceId) return null;
-
- return (
- <ActionIcon
- aria-label={t('workingDirectory.addFolder')}
- disabled={isPreferenceLoading}
- icon={FolderPlusIcon}
- size={'small'}
- title={t('workingDirectory.addFolder')}
- onClick={() => void handleClick()}
- />
- );
-});
-
-AddFolderAction.displayName = 'AddFolderAction';
+ if (!agentId || !isHeterogeneous || !targetDeviceId) return null;
-/** Only heterogeneous (CLI) agents work inside folders, so others get no action. */
-const AddFolder = memo(() => {
- const agentId = useAgentStore((s) => s.activeAgentId);
- const isHeterogeneous = !!useAgentStore(agentSelectors.currentAgentHeterogeneousProviderType);
-
- if (!agentId || !isHeterogeneous) return null;
-
- return <AddFolderAction agentId={agentId} />;
-});
-
-AddFolder.displayName = 'AddFolder';
-
-export default AddFolder;
+ return {
+ disabled: isPreferenceLoading,
+ icon: <Icon icon={FolderPlusIcon} />,
+ key: 'addFolder',
+ label: t('workingDirectory.addFolder'),
+ onClick: () => void handleClick(),
+ };
+};
diff --git a/src/features/AgentSidebar/Topic/useDropdownMenu.test.tsx b/src/features/AgentSidebar/Topic/useDropdownMenu.test.tsx
index 6719148d93a..99b3fd0788b 100644
--- a/src/features/AgentSidebar/Topic/useDropdownMenu.test.tsx
+++ b/src/features/AgentSidebar/Topic/useDropdownMenu.test.tsx
@@ -25,6 +25,13 @@ const chatStoreMock = vi.hoisted(() => ({
}));
const messageMock = vi.hoisted(() => ({ info: vi.fn(), success: vi.fn() }));
+const addFolderMock = vi.hoisted(() => ({
+ item: null as { key: string; label: string; onClick: () => void } | null,
+}));
+
+vi.mock('./useAddFolderMenuItem', () => ({
+ useAddFolderMenuItem: () => addFolderMock.item,
+}));
vi.mock('@/business/client/hooks/useActiveWorkspaceId', () => ({
useActiveWorkspaceId: () => workspaceMock.activeWorkspaceId,
@@ -119,6 +126,31 @@ describe('useTopicActionsDropdownMenu', () => {
chatStoreMock.updateTopicStatus.mockReset();
messageMock.info.mockReset();
messageMock.success.mockReset();
+ addFolderMock.item = null;
+ });
+
+ it('leads the menu with the add-folder action when the agent works in folders', () => {
+ const onClick = vi.fn();
+ addFolderMock.item = { key: 'addFolder', label: 'workingDirectory.addFolder', onClick };
+
+ const { result } = renderHook(() => useTopicActionsDropdownMenu());
+ const items = result.current()!;
+
+ expect(items[0]).toMatchObject({ key: 'addFolder', label: 'workingDirectory.addFolder' });
+ expect(items[1]).toMatchObject({ type: 'divider' });
+ expect(items[2]).toMatchObject({ key: 'displayItems' });
+
+ const addFolderItem = getMenuItem(items, 'addFolder');
+ if (addFolderItem && 'onClick' in addFolderItem) addFolderItem.onClick?.({} as never);
+ expect(onClick).toHaveBeenCalledTimes(1);
+ });
+
+ it('omits the add-folder action for agents that do not work in folders', () => {
+ const { result } = renderHook(() => useTopicActionsDropdownMenu());
+ const items = result.current()!;
+
+ expect(getMenuItem(items, 'addFolder')).toBeUndefined();
+ expect(items[0]).toMatchObject({ key: 'displayItems' });
});
it('disables topic write management actions for workspace viewers', () => {
diff --git a/src/features/AgentSidebar/Topic/useDropdownMenu.tsx b/src/features/AgentSidebar/Topic/useDropdownMenu.tsx
index 3cd0958c8f9..8facfcb91a6 100644
--- a/src/features/AgentSidebar/Topic/useDropdownMenu.tsx
+++ b/src/features/AgentSidebar/Topic/useDropdownMenu.tsx
@@ -19,6 +19,7 @@ import { systemStatusSelectors } from '@/store/global/selectors';
import { useUserStore } from '@/store/user';
import { labPreferSelectors, userProfileSelectors } from '@/store/user/selectors';
+import { useAddFolderMenuItem } from './useAddFolderMenuItem';
import { getMergedPullRequestTopics } from './utils/mergedPullRequestTopics';
const hotArea = css`
@@ -109,6 +110,7 @@ export const useTopicActionsDropdownMenu = (
]);
const enableHeteroSessionImport = useUserStore(labPreferSelectors.enableHeteroSessionImport);
+ const addFolderItem = useAddFolderMenuItem();
return useCallback((): MenuProps['items'] => {
const pageSizeOptions = [20, 40, 60, 100];
@@ -122,6 +124,7 @@ export const useTopicActionsDropdownMenu = (
}));
return [
+ ...(addFolderItem ? [addFolderItem, { type: 'divider' as const }] : []),
{
children: pageSizeItems,
extra: topicPageSize,
@@ -232,6 +235,7 @@ export const useTopicActionsDropdownMenu = (
: []),
].filter(Boolean) as MenuProps['items'];
}, [
+ addFolderItem,
topicPageSize,
updateSystemStatus,
handleImport,