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.

✨ feat: archive topics with merged pull requests (#16995)

Arvin Xubb039e6be957
diff --git a/locales/en-US/topic.json b/locales/en-US/topic.json
index dc3b92374df..594aac12e44 100644
--- a/locales/en-US/topic.json
+++ b/locales/en-US/topic.json
@@ -1,6 +1,10 @@
{
"actions.addNewTopic": "Start New Topic",
"actions.addNewTopicInProject": "Start new topic in {{directory}}",
+ "actions.archiveMergedPullRequests": "Archive Topics with Merged PRs",
+ "actions.archiveMergedPullRequestsNone": "No topics with merged PRs found.",
+ "actions.archiveMergedPullRequestsSuccess_one": "Archived {{count}} topic with a merged PR.",
+ "actions.archiveMergedPullRequestsSuccess_other": "Archived {{count}} topics with merged PRs.",
"actions.autoRename": "Smart Rename",
"actions.confirmRemoveAll": "You are about to delete all topics. This action cannot be undone.",
"actions.confirmRemoveTopic": "You are about to delete this topic. This action cannot be undone.",
diff --git a/locales/zh-CN/topic.json b/locales/zh-CN/topic.json
index 4ab9b91888a..cb878e7755c 100644
--- a/locales/zh-CN/topic.json
+++ b/locales/zh-CN/topic.json
@@ -1,6 +1,10 @@
{
"actions.addNewTopic": "开启新话题",
"actions.addNewTopicInProject": "在 {{directory}} 中开启新话题",
+ "actions.archiveMergedPullRequests": "归档 PR 已合并的话题",
+ "actions.archiveMergedPullRequestsNone": "没有找到 PR 已合并的话题",
+ "actions.archiveMergedPullRequestsSuccess_one": "已归档 {{count}} 个 PR 已合并的话题",
+ "actions.archiveMergedPullRequestsSuccess_other": "已归档 {{count}} 个 PR 已合并的话题",
"actions.autoRename": "智能重命名",
"actions.confirmRemoveAll": "您即将删除所有话题,此操作无法撤销。",
"actions.confirmRemoveTopic": "您即将删除此话题,此操作无法撤销。",
diff --git a/packages/locales/src/default/topic.ts b/packages/locales/src/default/topic.ts
index bd3e8885252..f382d2e3737 100644
--- a/packages/locales/src/default/topic.ts
+++ b/packages/locales/src/default/topic.ts
@@ -2,6 +2,10 @@ export default {
'actions.addNewTopic': 'Start New Topic',
'actions.addNewTopicInProject': 'Start new topic in {{directory}}',
'actions.autoRename': 'Smart Rename',
+ 'actions.archiveMergedPullRequests': 'Archive Topics with Merged PRs',
+ 'actions.archiveMergedPullRequestsNone': 'No topics with merged PRs found.',
+ 'actions.archiveMergedPullRequestsSuccess_one': 'Archived {{count}} topic with a merged PR.',
+ 'actions.archiveMergedPullRequestsSuccess_other': 'Archived {{count}} topics with merged PRs.',
'actions.confirmRemoveAll': 'You are about to delete all topics. This action cannot be undone.',
'actions.confirmRemoveTopic': 'You are about to delete this topic. This action cannot be undone.',
'actions.confirmRemoveTopicFiles': 'Also delete images and files uploaded in this topic',
diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/ToggleGroups.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/ToggleGroups.tsx
index 0e3a212208e..83c3a674c4e 100644
--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/ToggleGroups.tsx
+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/ToggleGroups.tsx
@@ -18,11 +18,18 @@ const ToggleGroups = memo(() => {
const { t } = useTranslation('topic');
const topicPageSize = useGlobalStore(systemStatusSelectors.topicPageSize);
const topicSortBy = useUserStore(preferenceSelectors.topicSortBy);
+ const topicIncludeCompleted = useUserStore(preferenceSelectors.topicIncludeCompleted);
const { topicGroupMode } = useAgentTopicGroupMode();
const groupSelector = useMemo(
- () => topicSelectors.groupedTopicsForSidebar(topicPageSize, topicSortBy, topicGroupMode),
- [topicPageSize, topicSortBy, topicGroupMode],
+ () =>
+ topicSelectors.groupedTopicsForSidebar(
+ topicPageSize,
+ topicSortBy,
+ topicGroupMode,
+ topicIncludeCompleted,
+ ),
+ [topicPageSize, topicSortBy, topicGroupMode, topicIncludeCompleted],
);
const groupTopics = useChatStore(groupSelector, isEqual);
diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx
index 8b15c3643fd..ca92cc92d08 100644
--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx
+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx
@@ -24,6 +24,7 @@ const FlatMode = memo(() => {
const navigate = useNavigate();
const topicPageSize = useGlobalStore(systemStatusSelectors.topicPageSize);
const topicSortBy = useUserStore(preferenceSelectors.topicSortBy);
+ const topicIncludeCompleted = useUserStore(preferenceSelectors.topicIncludeCompleted);
const [activeTopicId, activeThreadId, hasMore, isExpandingPageSize, activeAgentId] = useChatStore(
(s) => [
@@ -36,7 +37,7 @@ const FlatMode = memo(() => {
);
const activeTopicList = useChatStore(
- topicSelectors.displayTopicsForSidebar(topicPageSize, topicSortBy),
+ topicSelectors.displayTopicsForSidebar(topicPageSize, topicSortBy, topicIncludeCompleted),
isEqual,
);
diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/GroupedAccordion.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/GroupedAccordion.tsx
index c365bb3e00a..1c6ab25aaae 100644
--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/GroupedAccordion.tsx
+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/TopicListContent/GroupedAccordion.tsx
@@ -37,6 +37,7 @@ const GroupedAccordion = memo<GroupedAccordionProps>(({ GroupItem }) => {
const navigate = useNavigate();
const topicPageSize = useGlobalStore(systemStatusSelectors.topicPageSize);
const topicSortBy = useUserStore(preferenceSelectors.topicSortBy);
+ const topicIncludeCompleted = useUserStore(preferenceSelectors.topicIncludeCompleted);
const { topicGroupMode } = useAgentTopicGroupMode();
const [hasMore, isExpandingPageSize, activeAgentId] = useChatStore((s) => [
@@ -47,8 +48,14 @@ const GroupedAccordion = memo<GroupedAccordionProps>(({ GroupItem }) => {
const [activeTopicId, activeThreadId] = useChatStore((s) => [s.activeTopicId, s.activeThreadId]);
const groupSelector = useMemo(
- () => topicSelectors.groupedTopicsForSidebar(topicPageSize, topicSortBy, topicGroupMode),
- [topicPageSize, topicSortBy, topicGroupMode],
+ () =>
+ topicSelectors.groupedTopicsForSidebar(
+ topicPageSize,
+ topicSortBy,
+ topicGroupMode,
+ topicIncludeCompleted,
+ ),
+ [topicPageSize, topicSortBy, topicGroupMode, topicIncludeCompleted],
);
const groupTopics = useChatStore(groupSelector, isEqual);
diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/useDropdownMenu.test.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/useDropdownMenu.test.tsx
index 2e029f86bfc..82c1ffe0efe 100644
--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/useDropdownMenu.test.tsx
+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/useDropdownMenu.test.tsx
@@ -12,6 +12,14 @@ const permissionMock = vi.hoisted(() => ({
edit_own_content: true,
}));
+const chatStoreMock = vi.hoisted(() => ({
+ refreshTopic: vi.fn(),
+ topics: [] as Array<Record<string, unknown>>,
+ updateTopicStatus: vi.fn(),
+}));
+
+const messageMock = vi.hoisted(() => ({ info: vi.fn(), success: vi.fn() }));
+
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string) => key,
@@ -26,6 +34,7 @@ vi.mock('antd', () => {
return {
App: {
useApp: () => ({
+ message: messageMock,
modal: {
confirm: vi.fn(),
error: vi.fn(),
@@ -49,9 +58,16 @@ vi.mock('@/store/chat', () => ({
importTopic: vi.fn(),
removeSessionTopics: vi.fn(),
removeUnstarredTopic: vi.fn(),
+ refreshTopic: chatStoreMock.refreshTopic,
+ topics: chatStoreMock.topics,
+ updateTopicStatus: chatStoreMock.updateTopicStatus,
}),
}));
+vi.mock('@/store/chat/selectors', () => ({
+ topicSelectors: { currentTopics: (s: { topics: Array<Record<string, unknown>> }) => s.topics },
+}));
+
vi.mock('@/store/global', () => ({
useGlobalStore: (selector: (state: Record<string, unknown>) => unknown) =>
selector({
@@ -75,6 +91,11 @@ describe('useTopicActionsDropdownMenu', () => {
beforeEach(() => {
permissionMock.create_content = true;
permissionMock.edit_own_content = true;
+ chatStoreMock.topics = [];
+ chatStoreMock.refreshTopic.mockReset();
+ chatStoreMock.updateTopicStatus.mockReset();
+ messageMock.info.mockReset();
+ messageMock.success.mockReset();
});
it('disables topic write management actions for workspace viewers', () => {
@@ -84,7 +105,59 @@ describe('useTopicActionsDropdownMenu', () => {
const { result } = renderHook(() => useTopicActionsDropdownMenu());
expect(getMenuItem(result.current!, 'import')).toMatchObject({ disabled: true });
+ expect(getMenuItem(result.current!, 'archiveMergedPullRequests')).toMatchObject({
+ disabled: true,
+ });
expect(getMenuItem(result.current!, 'deleteUnstarred')).toMatchObject({ disabled: true });
expect(getMenuItem(result.current!, 'deleteAll')).toMatchObject({ disabled: true });
});
+
+ it('archives only unfinished topics whose pull requests are merged', async () => {
+ chatStoreMock.topics = [
+ {
+ id: 'merged',
+ metadata: {
+ workingDirectoryConfig: { git: { github: { pullRequest: { state: 'MERGED' } } } },
+ },
+ status: 'active',
+ },
+ {
+ id: 'open',
+ metadata: {
+ workingDirectoryConfig: { git: { github: { pullRequest: { state: 'OPEN' } } } },
+ },
+ status: 'active',
+ },
+ {
+ id: 'completed',
+ metadata: {
+ workingDirectoryConfig: {
+ git: { github: { pullRequest: { mergedAt: '2026-07-10T00:00:00Z' } } },
+ },
+ },
+ status: 'completed',
+ },
+ {
+ id: 'unread',
+ metadata: {
+ workingDirectoryConfig: { git: { github: { pullRequest: { state: 'MERGED' } } } },
+ },
+ status: 'unread',
+ },
+ ];
+
+ const { result } = renderHook(() => useTopicActionsDropdownMenu());
+ const item = getMenuItem(result.current!, 'archiveMergedPullRequests');
+
+ expect(item && 'onClick' in item).toBe(true);
+ if (item && 'onClick' in item) await item.onClick?.({} as never);
+
+ expect(chatStoreMock.updateTopicStatus).toHaveBeenCalledOnce();
+ expect(chatStoreMock.updateTopicStatus).toHaveBeenCalledWith({
+ status: 'completed',
+ topicId: 'merged',
+ });
+ expect(chatStoreMock.refreshTopic).toHaveBeenCalledOnce();
+ expect(messageMock.success).toHaveBeenCalledWith('actions.archiveMergedPullRequestsSuccess');
+ });
});
diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/useDropdownMenu.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/useDropdownMenu.tsx
index fdf275cf6c6..cbed69eed60 100644
--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/useDropdownMenu.tsx
+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/useDropdownMenu.tsx
@@ -3,12 +3,13 @@ import { Icon } from '@lobehub/ui';
import { confirmModal } from '@lobehub/ui/base-ui';
import { App, Upload } from 'antd';
import { css, cx } from 'antd-style';
-import { Hash, Import, LucideCheck, Trash } from 'lucide-react';
+import { Archive, Hash, Import, LucideCheck, Trash } from 'lucide-react';
import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { usePermission } from '@/hooks/usePermission';
import { useChatStore } from '@/store/chat';
+import { topicSelectors } from '@/store/chat/selectors';
import { useGlobalStore } from '@/store/global';
import { systemStatusSelectors } from '@/store/global/selectors';
@@ -29,16 +30,45 @@ export const useTopicActionsDropdownMenu = (
options: UseTopicActionsDropdownMenuOptions = {},
): MenuProps['items'] => {
const { t } = useTranslation(['topic', 'common']);
- const { modal } = App.useApp();
+ const { message, modal } = App.useApp();
const { onUploadClose } = options;
const { allowed: canCreateTopic } = usePermission('create_content');
const { allowed: canEditTopic } = usePermission('edit_own_content');
- const [removeUnstarredTopic, removeAllTopic, importTopic] = useChatStore((s) => [
- s.removeUnstarredTopic,
- s.removeSessionTopics,
- s.importTopic,
- ]);
+ const topics = useChatStore(topicSelectors.currentTopics);
+ const [removeUnstarredTopic, removeAllTopic, importTopic, updateTopicStatus, refreshTopic] =
+ useChatStore((s) => [
+ s.removeUnstarredTopic,
+ s.removeSessionTopics,
+ s.importTopic,
+ s.updateTopicStatus,
+ s.refreshTopic,
+ ]);
+
+ const handleArchiveMergedPullRequests = useCallback(async () => {
+ const mergedTopics = (topics ?? []).filter((topic) => {
+ const pullRequest = topic.metadata?.workingDirectoryConfig?.git?.github?.pullRequest;
+ const isMerged = !!pullRequest?.mergedAt || pullRequest?.state?.toLowerCase() === 'merged';
+
+ return (
+ isMerged &&
+ topic.status !== 'completed' &&
+ topic.status !== 'archived' &&
+ topic.status !== 'unread'
+ );
+ });
+
+ if (mergedTopics.length === 0) {
+ message.info(t('actions.archiveMergedPullRequestsNone'));
+ return;
+ }
+
+ await Promise.all(
+ mergedTopics.map(({ id }) => updateTopicStatus({ status: 'completed', topicId: id })),
+ );
+ await refreshTopic();
+ message.success(t('actions.archiveMergedPullRequestsSuccess', { count: mergedTopics.length }));
+ }, [message, refreshTopic, t, topics, updateTopicStatus]);
const handleImport = useCallback(
async (file: File) => {
@@ -105,6 +135,13 @@ export const useTopicActionsDropdownMenu = (
{
type: 'divider' as const,
},
+ {
+ disabled: !canEditTopic,
+ icon: <Icon icon={Archive} />,
+ key: 'archiveMergedPullRequests',
+ label: t('actions.archiveMergedPullRequests'),
+ onClick: handleArchiveMergedPullRequests,
+ },
{
disabled: !canEditTopic,
icon: <Icon icon={Trash} />,
@@ -144,9 +181,9 @@ export const useTopicActionsDropdownMenu = (
canCreateTopic,
canEditTopic,
onUploadClose,
+ handleArchiveMergedPullRequests,
removeUnstarredTopic,
removeAllTopic,
t,
- modal,
]);
};
diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/index.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/index.tsx
index 4ba189fbff3..06be0a7934a 100644
--- a/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/index.tsx
+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/ByTimeMode/index.tsx
@@ -23,6 +23,7 @@ const ByTimeMode = memo(() => {
const topicPageSize = useGlobalStore(systemStatusSelectors.topicPageSize);
const topicSortBy = useUserStore(preferenceSelectors.topicSortBy);
const topicGroupMode = useUserStore(preferenceSelectors.topicGroupMode);
+ const topicIncludeCompleted = useUserStore(preferenceSelectors.topicIncludeCompleted);
const [hasMore, isExpandingPageSize, openAllTopicsDrawer] = useChatStore((s) => [
topicSelectors.hasMoreTopicsForSidebar(s),
@@ -32,8 +33,14 @@ const ByTimeMode = memo(() => {
const [activeTopicId, activeThreadId] = useChatStore((s) => [s.activeTopicId, s.activeThreadId]);
const groupSelector = useMemo(
- () => topicSelectors.groupedTopicsForSidebar(topicPageSize, topicSortBy, topicGroupMode),
- [topicPageSize, topicSortBy, topicGroupMode],
+ () =>
+ topicSelectors.groupedTopicsForSidebar(
+ topicPageSize,
+ topicSortBy,
+ topicGroupMode,
+ topicIncludeCompleted,
+ ),
+ [topicPageSize, topicSortBy, topicGroupMode, topicIncludeCompleted],
);
const groupTopics = useChatStore(groupSelector, isEqual);
diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx
index 58297e5d810..eecc8e8d4ac 100644
--- a/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx
+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/TopicListContent/FlatMode/index.tsx
@@ -21,6 +21,7 @@ const FlatMode = memo(() => {
const { t } = useTranslation('topic');
const topicPageSize = useGlobalStore(systemStatusSelectors.topicPageSize);
const topicSortBy = useUserStore(preferenceSelectors.topicSortBy);
+ const topicIncludeCompleted = useUserStore(preferenceSelectors.topicIncludeCompleted);
const [activeTopicId, activeThreadId, hasMore, isExpandingPageSize, openAllTopicsDrawer] =
useChatStore((s) => [
@@ -32,7 +33,7 @@ const FlatMode = memo(() => {
]);
const activeTopicList = useChatStore(
- topicSelectors.displayTopicsForSidebar(topicPageSize, topicSortBy),
+ topicSelectors.displayTopicsForSidebar(topicPageSize, topicSortBy, topicIncludeCompleted),
isEqual,
);
diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/useDropdownMenu.test.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/useDropdownMenu.test.tsx
index 889b59146be..bfa5ea9d158 100644
--- a/src/routes/(main)/group/_layout/Sidebar/Topic/useDropdownMenu.test.tsx
+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/useDropdownMenu.test.tsx
@@ -12,6 +12,14 @@ const permissionMock = vi.hoisted(() => ({
edit_own_content: true,
}));
+const chatStoreMock = vi.hoisted(() => ({
+ refreshTopic: vi.fn(),
+ topics: [] as Array<Record<string, unknown>>,
+ updateTopicStatus: vi.fn(),
+}));
+
+const messageMock = vi.hoisted(() => ({ info: vi.fn(), success: vi.fn() }));
+
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string) => key,
@@ -25,6 +33,7 @@ vi.mock('@lobehub/ui', () => ({
vi.mock('antd', () => ({
App: {
useApp: () => ({
+ message: messageMock,
modal: {
confirm: vi.fn(),
error: vi.fn(),
@@ -47,9 +56,16 @@ vi.mock('@/store/chat', () => ({
importTopic: vi.fn(),
removeSessionTopics: vi.fn(),
removeUnstarredTopic: vi.fn(),
+ refreshTopic: chatStoreMock.refreshTopic,
+ topics: chatStoreMock.topics,
+ updateTopicStatus: chatStoreMock.updateTopicStatus,
}),
}));
+vi.mock('@/store/chat/selectors', () => ({
+ topicSelectors: { currentTopics: (s: { topics: Array<Record<string, unknown>> }) => s.topics },
+}));
+
vi.mock('@/store/global', () => ({
useGlobalStore: (selector: (state: Record<string, unknown>) => unknown) =>
selector({
@@ -73,6 +89,11 @@ describe('group useTopicActionsDropdownMenu', () => {
beforeEach(() => {
permissionMock.create_content = true;
permissionMock.edit_own_content = true;
+ chatStoreMock.topics = [];
+ chatStoreMock.refreshTopic.mockReset();
+ chatStoreMock.updateTopicStatus.mockReset();
+ messageMock.info.mockReset();
+ messageMock.success.mockReset();
});
it('disables topic write management actions for workspace viewers', () => {
@@ -82,7 +103,59 @@ describe('group useTopicActionsDropdownMenu', () => {
const { result } = renderHook(() => useTopicActionsDropdownMenu());
expect(getMenuItem(result.current!, 'import')).toMatchObject({ disabled: true });
+ expect(getMenuItem(result.current!, 'archiveMergedPullRequests')).toMatchObject({
+ disabled: true,
+ });
expect(getMenuItem(result.current!, 'deleteUnstarred')).toMatchObject({ disabled: true });
expect(getMenuItem(result.current!, 'deleteAll')).toMatchObject({ disabled: true });
});
+
+ it('archives only unfinished topics whose pull requests are merged', async () => {
+ chatStoreMock.topics = [
+ {
+ id: 'merged',
+ metadata: {
+ workingDirectoryConfig: { git: { github: { pullRequest: { state: 'MERGED' } } } },
+ },
+ status: 'active',
+ },
+ {
+ id: 'open',
+ metadata: {
+ workingDirectoryConfig: { git: { github: { pullRequest: { state: 'OPEN' } } } },
+ },
+ status: 'active',
+ },
+ {
+ id: 'completed',
+ metadata: {
+ workingDirectoryConfig: {
+ git: { github: { pullRequest: { mergedAt: '2026-07-10T00:00:00Z' } } },
+ },
+ },
+ status: 'completed',
+ },
+ {
+ id: 'unread',
+ metadata: {
+ workingDirectoryConfig: { git: { github: { pullRequest: { state: 'MERGED' } } } },
+ },
+ status: 'unread',
+ },
+ ];
+
+ const { result } = renderHook(() => useTopicActionsDropdownMenu());
+ const item = getMenuItem(result.current!, 'archiveMergedPullRequests');
+
+ expect(item && 'onClick' in item).toBe(true);
+ if (item && 'onClick' in item) await item.onClick?.({} as never);
+
+ expect(chatStoreMock.updateTopicStatus).toHaveBeenCalledOnce();
+ expect(chatStoreMock.updateTopicStatus).toHaveBeenCalledWith({
+ status: 'completed',
+ topicId: 'merged',
+ });
+ expect(chatStoreMock.refreshTopic).toHaveBeenCalledOnce();
+ expect(messageMock.success).toHaveBeenCalledWith('actions.archiveMergedPullRequestsSuccess');
+ });
});
diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/useDropdownMenu.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/useDropdownMenu.tsx
index fdf275cf6c6..cbed69eed60 100644
--- a/src/routes/(main)/group/_layout/Sidebar/Topic/useDropdownMenu.tsx
+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/useDropdownMenu.tsx
@@ -3,12 +3,13 @@ import { Icon } from '@lobehub/ui';
import { confirmModal } from '@lobehub/ui/base-ui';
import { App, Upload } from 'antd';
import { css, cx } from 'antd-style';
-import { Hash, Import, LucideCheck, Trash } from 'lucide-react';
+import { Archive, Hash, Import, LucideCheck, Trash } from 'lucide-react';
import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { usePermission } from '@/hooks/usePermission';
import { useChatStore } from '@/store/chat';
+import { topicSelectors } from '@/store/chat/selectors';
import { useGlobalStore } from '@/store/global';
import { systemStatusSelectors } from '@/store/global/selectors';
@@ -29,16 +30,45 @@ export const useTopicActionsDropdownMenu = (
options: UseTopicActionsDropdownMenuOptions = {},
): MenuProps['items'] => {
const { t } = useTranslation(['topic', 'common']);
- const { modal } = App.useApp();
+ const { message, modal } = App.useApp();
const { onUploadClose } = options;
const { allowed: canCreateTopic } = usePermission('create_content');
const { allowed: canEditTopic } = usePermission('edit_own_content');
- const [removeUnstarredTopic, removeAllTopic, importTopic] = useChatStore((s) => [
- s.removeUnstarredTopic,
- s.removeSessionTopics,
- s.importTopic,
- ]);
+ const topics = useChatStore(topicSelectors.currentTopics);
+ const [removeUnstarredTopic, removeAllTopic, importTopic, updateTopicStatus, refreshTopic] =
+ useChatStore((s) => [
+ s.removeUnstarredTopic,
+ s.removeSessionTopics,
+ s.importTopic,
+ s.updateTopicStatus,
+ s.refreshTopic,
+ ]);
+
+ const handleArchiveMergedPullRequests = useCallback(async () => {
+ const mergedTopics = (topics ?? []).filter((topic) => {
+ const pullRequest = topic.metadata?.workingDirectoryConfig?.git?.github?.pullRequest;
+ const isMerged = !!pullRequest?.mergedAt || pullRequest?.state?.toLowerCase() === 'merged';
+
+ return (
+ isMerged &&
+ topic.status !== 'completed' &&
+ topic.status !== 'archived' &&
+ topic.status !== 'unread'
+ );
+ });
+
+ if (mergedTopics.length === 0) {
+ message.info(t('actions.archiveMergedPullRequestsNone'));
+ return;
+ }
+
+ await Promise.all(
+ mergedTopics.map(({ id }) => updateTopicStatus({ status: 'completed', topicId: id })),
+ );
+ await refreshTopic();
+ message.success(t('actions.archiveMergedPullRequestsSuccess', { count: mergedTopics.length }));
+ }, [message, refreshTopic, t, topics, updateTopicStatus]);
const handleImport = useCallback(
async (file: File) => {
@@ -105,6 +135,13 @@ export const useTopicActionsDropdownMenu = (
{
type: 'divider' as const,
},
+ {
+ disabled: !canEditTopic,
+ icon: <Icon icon={Archive} />,
+ key: 'archiveMergedPullRequests',
+ label: t('actions.archiveMergedPullRequests'),
+ onClick: handleArchiveMergedPullRequests,
+ },
{
disabled: !canEditTopic,
icon: <Icon icon={Trash} />,
@@ -144,9 +181,9 @@ export const useTopicActionsDropdownMenu = (
canCreateTopic,
canEditTopic,
onUploadClose,
+ handleArchiveMergedPullRequests,
removeUnstarredTopic,
removeAllTopic,
t,
- modal,
]);
};
diff --git a/src/store/chat/slices/topic/selectors.test.ts b/src/store/chat/slices/topic/selectors.test.ts
index 6e5b4be58a7..21f38241596 100644
--- a/src/store/chat/slices/topic/selectors.test.ts
+++ b/src/store/chat/slices/topic/selectors.test.ts
@@ -378,6 +378,32 @@ describe('topicSelectors', () => {
});
});
+ describe('displayTopicsForSidebar', () => {
+ it('hides completed topics immediately when completed topics are excluded', () => {
+ const now = Date.now();
+ const state = merge(initialStore, {
+ activeAgentId: 'agent-1',
+ topicDataMap: {
+ [topicMapKey({ agentId: 'agent-1' })]: {
+ currentPage: 0,
+ hasMore: false,
+ items: [
+ { createdAt: now, id: 'active', status: 'active', updatedAt: now },
+ { createdAt: now, id: 'completed', status: 'completed', updatedAt: now },
+ ],
+ pageSize: 20,
+ total: 2,
+ },
+ },
+ });
+
+ expect(topicSelectors.displayTopicsForSidebar(20, 'updatedAt', false)(state)).toEqual([
+ expect.objectContaining({ id: 'active' }),
+ ]);
+ expect(topicSelectors.displayTopicsForSidebar(20, 'updatedAt', true)(state)).toHaveLength(2);
+ });
+ });
+
describe('groupedTopicsForSidebar', () => {
const now = Date.now();
const lastYear = dayjs(now).subtract(1, 'year').valueOf();
diff --git a/src/store/chat/slices/topic/selectors.ts b/src/store/chat/slices/topic/selectors.ts
index a0568164f7c..f221c8b16a2 100644
--- a/src/store/chat/slices/topic/selectors.ts
+++ b/src/store/chat/slices/topic/selectors.ts
@@ -136,14 +136,18 @@ const sortTopics = (topics: ChatTopic[], sortBy: TopicSortBy): ChatTopic[] => {
// Limit topics for sidebar display based on user's page size preference
const displayTopicsForSidebar =
- (pageSize: number, sortBy: TopicSortBy = 'updatedAt') =>
+ (pageSize: number, sortBy: TopicSortBy = 'updatedAt', includeCompleted = true) =>
(s: ChatStoreState): ChatTopic[] | undefined => {
const topics = currentTopicsWithoutCron(s);
if (!topics) return undefined;
+ const visibleTopics = includeCompleted
+ ? topics
+ : topics.filter((topic) => topic.status !== 'completed');
+
// Favorites first, then sorted by the chosen timestamp, then page-sliced
- const favTopics = topics.filter((t) => t.favorite);
- const rest = topics.filter((t) => !t.favorite);
+ const favTopics = visibleTopics.filter((t) => t.favorite);
+ const rest = visibleTopics.filter((t) => !t.favorite);
return [...sortTopics(favTopics, sortBy), ...sortTopics(rest, sortBy)].slice(0, pageSize);
};
@@ -205,9 +209,14 @@ const groupedTopicsSelector =
};
const groupedTopicsForSidebar =
- (pageSize: number, sortBy: TopicSortBy = 'updatedAt', groupMode: TopicGroupMode = 'byTime') =>
+ (
+ pageSize: number,
+ sortBy: TopicSortBy = 'updatedAt',
+ groupMode: TopicGroupMode = 'byTime',
+ includeCompleted = true,
+ ) =>
(s: ChatStoreState): GroupedTopic[] => {
- const limitedTopics = displayTopicsForSidebar(pageSize, sortBy)(s);
+ const limitedTopics = displayTopicsForSidebar(pageSize, sortBy, includeCompleted)(s);
if (!limitedTopics) return [];
// Topics actively streaming on this client surface under "running" even
// though their persisted status says otherwise — that's the one client-only