From 20d10d42b98a4e7170fa6acf9bbb4e5933461bea Mon Sep 17 00:00:00 2001 From: yyh Date: Tue, 30 Dec 2025 12:41:30 +0800 Subject: [PATCH] fix: restore query param behavior --- web/app/components/app/log/index.tsx | 10 +++-- .../hooks/use-document-list-query-state.ts | 42 +++++++++++++------ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/web/app/components/app/log/index.tsx b/web/app/components/app/log/index.tsx index 90eb061313..d66f4ce9c6 100644 --- a/web/app/components/app/log/index.tsx +++ b/web/app/components/app/log/index.tsx @@ -57,13 +57,15 @@ const Logs: FC = ({ appDetail }) => { ) const debouncedQueryParams = useDebounce(queryParams, { wait: 500 }) + const page = queryParams.page > 0 ? queryParams.page : 1 + const limit = queryParams.limit > 0 ? queryParams.limit : APP_PAGE_LIMIT // Get the app type first const isChatMode = appDetail.mode !== AppModeEnum.COMPLETION const query = { - page: queryParams.page, - limit: queryParams.limit, + page, + limit, ...((debouncedQueryParams.period !== '9') ? { start: dayjs().subtract(TIME_PERIOD_MAPPING[debouncedQueryParams.period].value, 'day').startOf('day').format('YYYY-MM-DD HH:mm'), @@ -117,10 +119,10 @@ const Logs: FC = ({ appDetail }) => { {(total && total > APP_PAGE_LIMIT) ? ( ) diff --git a/web/app/components/datasets/documents/hooks/use-document-list-query-state.ts b/web/app/components/datasets/documents/hooks/use-document-list-query-state.ts index dd5418927d..2683812597 100644 --- a/web/app/components/datasets/documents/hooks/use-document-list-query-state.ts +++ b/web/app/components/datasets/documents/hooks/use-document-list-query-state.ts @@ -20,6 +20,14 @@ export type DocumentListQuery = { sort: SortType } +type DocumentListQueryInput = { + page?: number + limit?: number + keyword?: string | null + status?: string | null + sort?: string | null +} + const DEFAULT_QUERY: DocumentListQuery = { page: 1, limit: 10, @@ -28,6 +36,24 @@ const DEFAULT_QUERY: DocumentListQuery = { sort: '-created_at', } +const normalizeKeywordValue = (value?: string | null) => (value && value.trim() ? value : '') + +const normalizeDocumentListQuery = (query: DocumentListQueryInput): DocumentListQuery => { + const page = (query.page && query.page > 0) ? query.page : DEFAULT_QUERY.page + const limit = (query.limit && query.limit > 0 && query.limit <= 100) ? query.limit : DEFAULT_QUERY.limit + const keyword = normalizeKeywordValue(query.keyword ?? DEFAULT_QUERY.keyword) + const status = sanitizeStatusValue(query.status ?? DEFAULT_QUERY.status) + const sort = sanitizeSortValue(query.sort ?? DEFAULT_QUERY.sort) + + return { + page, + limit, + keyword, + status, + sort, + } +} + function useDocumentListQueryState() { const [query, setQuery] = useQueryStates( { @@ -38,6 +64,7 @@ function useDocumentListQueryState() { sort: parseAsString.withDefault(DEFAULT_QUERY.sort), }, { + history: 'push', urlKeys: { page: 'page', limit: 'limit', @@ -48,21 +75,10 @@ function useDocumentListQueryState() { }, ) - const finalQuery = useMemo(() => { - const page = query.page > 0 ? query.page : 1 - const limit = (query.limit > 0 && query.limit <= 100) ? query.limit : 10 - - return { - ...query, - page, - limit, - status: sanitizeStatusValue(query.status), - sort: sanitizeSortValue(query.sort), - } - }, [query]) + const finalQuery = useMemo(() => normalizeDocumentListQuery(query), [query]) const updateQuery = (updates: Partial) => { - setQuery(prev => ({ ...prev, ...updates })) + setQuery(prev => normalizeDocumentListQuery({ ...prev, ...updates })) } const resetQuery = () => {