mirror of
https://github.com/langgenius/dify.git
synced 2026-01-14 06:07:33 +08:00
fix: restore query param behavior
This commit is contained in:
parent
e97857ef7f
commit
20d10d42b9
@ -57,13 +57,15 @@ const Logs: FC<ILogsProps> = ({ 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<ILogsProps> = ({ appDetail }) => {
|
||||
{(total && total > APP_PAGE_LIMIT)
|
||||
? (
|
||||
<Pagination
|
||||
current={queryParams.page - 1}
|
||||
current={page - 1}
|
||||
onChange={handlePageChange}
|
||||
total={total}
|
||||
limit={queryParams.limit}
|
||||
limit={limit}
|
||||
onLimitChange={handleLimitChange}
|
||||
/>
|
||||
)
|
||||
|
||||
@ -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<DocumentListQuery>) => {
|
||||
setQuery(prev => ({ ...prev, ...updates }))
|
||||
setQuery(prev => normalizeDocumentListQuery({ ...prev, ...updates }))
|
||||
}
|
||||
|
||||
const resetQuery = () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user