From 2181ffdc89ddd2d19567d28b665d1cadd7f0d3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=9E=E6=B3=95=E6=93=8D=E4=BD=9C?= Date: Tue, 25 Nov 2025 15:54:15 +0800 Subject: [PATCH] fix: chatflow log details always navigate to page first (#28626) --- web/app/components/app/log/index.tsx | 33 +++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/web/app/components/app/log/index.tsx b/web/app/components/app/log/index.tsx index 55a3f7d12d..cedf2de74d 100644 --- a/web/app/components/app/log/index.tsx +++ b/web/app/components/app/log/index.tsx @@ -1,11 +1,12 @@ 'use client' import type { FC } from 'react' -import React, { useState } from 'react' +import React, { useCallback, useEffect, useState } from 'react' import useSWR from 'swr' import { useDebounce } from 'ahooks' import { omit } from 'lodash-es' import dayjs from 'dayjs' import { useTranslation } from 'react-i18next' +import { usePathname, useRouter, useSearchParams } from 'next/navigation' import List from './list' import Filter, { TIME_PERIOD_MAPPING } from './filter' import EmptyElement from './empty-element' @@ -28,15 +29,29 @@ export type QueryParam = { const Logs: FC = ({ appDetail }) => { const { t } = useTranslation() + const router = useRouter() + const pathname = usePathname() + const searchParams = useSearchParams() const [queryParams, setQueryParams] = useState({ period: '2', annotation_status: 'all', sort_by: '-created_at', }) - const [currPage, setCurrPage] = React.useState(0) + const getPageFromParams = useCallback(() => { + const pageParam = Number.parseInt(searchParams.get('page') || '1', 10) + if (Number.isNaN(pageParam) || pageParam < 1) + return 0 + return pageParam - 1 + }, [searchParams]) + const [currPage, setCurrPage] = React.useState(() => getPageFromParams()) const [limit, setLimit] = React.useState(APP_PAGE_LIMIT) const debouncedQueryParams = useDebounce(queryParams, { wait: 500 }) + useEffect(() => { + const pageFromParams = getPageFromParams() + setCurrPage(prev => (prev === pageFromParams ? prev : pageFromParams)) + }, [getPageFromParams]) + // Get the app type first const isChatMode = appDetail.mode !== AppModeEnum.COMPLETION @@ -70,6 +85,18 @@ const Logs: FC = ({ appDetail }) => { const total = isChatMode ? chatConversations?.total : completionConversations?.total + const handlePageChange = useCallback((page: number) => { + setCurrPage(page) + const params = new URLSearchParams(searchParams.toString()) + const nextPageValue = page + 1 + if (nextPageValue === 1) + params.delete('page') + else + params.set('page', String(nextPageValue)) + const queryString = params.toString() + router.replace(queryString ? `${pathname}?${queryString}` : pathname, { scroll: false }) + }, [pathname, router, searchParams]) + return (

{t('appLog.description')}

@@ -85,7 +112,7 @@ const Logs: FC = ({ appDetail }) => { {(total && total > APP_PAGE_LIMIT) ?