From 996c5156e581cdd875ca0cf3aa7dcd1ac47269ae Mon Sep 17 00:00:00 2001 From: euvre <93761161+euvre@users.noreply.github.com> Date: Tue, 28 Jul 2026 19:30:28 +0800 Subject: [PATCH] Fix: go back to previous page when last card on the last page is deleted (#17409) --- web/src/hooks/logic-hooks.ts | 18 ++++++++++++++++++ web/src/pages/agents/index.tsx | 2 ++ web/src/pages/datasets/index.tsx | 2 ++ web/src/pages/memories/index.tsx | 3 +++ web/src/pages/next-chats/index.tsx | 2 ++ web/src/pages/next-searches/index.tsx | 3 +++ 6 files changed, 30 insertions(+) diff --git a/web/src/hooks/logic-hooks.ts b/web/src/hooks/logic-hooks.ts index 52876e7900..c329e3c3d5 100644 --- a/web/src/hooks/logic-hooks.ts +++ b/web/src/hooks/logic-hooks.ts @@ -110,6 +110,24 @@ export const useGetPaginationWithRouter = () => { }; }; +// When the current page becomes empty (e.g. after deleting the last card on +// the last page), navigate back to the previous page automatically. +export const useGoToPreviousPageOnEmpty = ( + listLength: number | undefined, + loading: boolean = false, +) => { + const { pagination, setPagination } = useGetPaginationWithRouter(); + + useEffect(() => { + if (!loading && listLength === 0 && pagination.current > 1) { + setPagination({ + page: pagination.current - 1, + pageSize: pagination.pageSize, + }); + } + }, [listLength, loading, pagination, setPagination]); +}; + export const useHandleSearchChange = () => { const [searchString, setSearchString] = useState(''); const { pagination, setPagination } = useGetPaginationWithRouter(); diff --git a/web/src/pages/agents/index.tsx b/web/src/pages/agents/index.tsx index 40e328f880..3b95090817 100644 --- a/web/src/pages/agents/index.tsx +++ b/web/src/pages/agents/index.tsx @@ -11,6 +11,7 @@ import { DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { RAGFlowPagination } from '@/components/ui/ragflow-pagination'; +import { useGoToPreviousPageOnEmpty } from '@/hooks/logic-hooks'; import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks'; import { useFetchAgentListByPage } from '@/hooks/use-agent-request'; import { useDeleteCompilationTemplateGroup } from '@/hooks/use-compilation-template-group-request'; @@ -82,6 +83,7 @@ export default function Agents() { }, [setPagination], ); + useGoToPreviousPageOnEmpty(data?.length, listLoading); const handleEditCompilation = useCallback( (id: string) => () => { diff --git a/web/src/pages/datasets/index.tsx b/web/src/pages/datasets/index.tsx index 2663efbacb..b792257e10 100644 --- a/web/src/pages/datasets/index.tsx +++ b/web/src/pages/datasets/index.tsx @@ -6,6 +6,7 @@ import { RenameDialog } from '@/components/rename-dialog'; import { Button } from '@/components/ui/button'; import { RAGFlowPagination } from '@/components/ui/ragflow-pagination'; import { Spin } from '@/components/ui/spin'; +import { useGoToPreviousPageOnEmpty } from '@/hooks/logic-hooks'; import { useFetchNextKnowledgeListByPage } from '@/hooks/use-knowledge-request'; import { useQueryClient } from '@tanstack/react-query'; import { pick } from 'lodash'; @@ -58,6 +59,7 @@ export default function Datasets() { }, [setPagination], ); + useGoToPreviousPageOnEmpty(kbs?.length, loading); const [searchUrl, setSearchUrl] = useSearchParams(); const isCreate = searchUrl.get('isCreate') === 'true'; const queryClient = useQueryClient(); diff --git a/web/src/pages/memories/index.tsx b/web/src/pages/memories/index.tsx index d37c5dadf9..f7d5c31a24 100644 --- a/web/src/pages/memories/index.tsx +++ b/web/src/pages/memories/index.tsx @@ -5,6 +5,7 @@ import ListFilterBar from '@/components/list-filter-bar'; import { Button } from '@/components/ui/button'; import { RAGFlowPagination } from '@/components/ui/ragflow-pagination'; import { useTranslate } from '@/hooks/common-hooks'; +import { useGoToPreviousPageOnEmpty } from '@/hooks/logic-hooks'; import { pick } from 'lodash'; import { Plus } from 'lucide-react'; import { useCallback, useEffect, useState } from 'react'; @@ -22,6 +23,7 @@ export default function MemoryList() { // const [isEdit, setIsEdit] = useState(false); const { data: list, + isLoading, pagination, searchString, handleInputChange, @@ -56,6 +58,7 @@ export default function MemoryList() { }, [setPagination], ); + useGoToPreviousPageOnEmpty(list?.data?.memory_list?.length, isLoading); const [searchUrl, setMemoryUrl] = useSearchParams(); const { filters } = useSelectFilters(); diff --git a/web/src/pages/next-chats/index.tsx b/web/src/pages/next-chats/index.tsx index c27256fe8b..b3aa7f2a15 100644 --- a/web/src/pages/next-chats/index.tsx +++ b/web/src/pages/next-chats/index.tsx @@ -6,6 +6,7 @@ import { RenameDialog } from '@/components/rename-dialog'; import { Button } from '@/components/ui/button'; import { RAGFlowPagination } from '@/components/ui/ragflow-pagination'; import { Spin } from '@/components/ui/spin'; +import { useGoToPreviousPageOnEmpty } from '@/hooks/logic-hooks'; import { useFetchChatList } from '@/hooks/use-chat-request'; import { buildOwnersFilter } from '@/utils/list-filter-util'; import { pick } from 'lodash'; @@ -53,6 +54,7 @@ export default function ChatList() { }, [setPagination], ); + useGoToPreviousPageOnEmpty(data?.chats?.length, loading); const handleShowCreateModal = useCallback(() => { showCreateChatModal(); diff --git a/web/src/pages/next-searches/index.tsx b/web/src/pages/next-searches/index.tsx index 9c6194ca14..f99e81645f 100644 --- a/web/src/pages/next-searches/index.tsx +++ b/web/src/pages/next-searches/index.tsx @@ -6,6 +6,7 @@ import { RenameDialog } from '@/components/rename-dialog'; import { Button } from '@/components/ui/button'; import { RAGFlowPagination } from '@/components/ui/ragflow-pagination'; import { useTranslate } from '@/hooks/common-hooks'; +import { useGoToPreviousPageOnEmpty } from '@/hooks/logic-hooks'; import { buildOwnersFilter } from '@/utils/list-filter-util'; import { pick } from 'lodash'; import { Plus } from 'lucide-react'; @@ -21,6 +22,7 @@ export default function SearchList() { // const [isEdit, setIsEdit] = useState(false); const { data: list, + isLoading, pagination, searchString, handleInputChange, @@ -59,6 +61,7 @@ export default function SearchList() { }, [setPagination], ); + useGoToPreviousPageOnEmpty(list?.data?.search_apps?.length, isLoading); const [searchUrl, setSearchUrl] = useSearchParams(); const isCreate = searchUrl.get('isCreate') === 'true';