Fix: go back to previous page when last card on the last page is deleted (#17409)

This commit is contained in:
euvre
2026-07-28 19:30:28 +08:00
committed by GitHub
parent 679bce8f8d
commit 996c5156e5
6 changed files with 30 additions and 0 deletions

View File

@@ -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();

View File

@@ -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) => () => {

View File

@@ -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();

View File

@@ -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();

View File

@@ -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();

View File

@@ -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';