mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 01:48:04 +08:00
fix: restore query param behavior
This commit is contained in:
@ -57,13 +57,15 @@ const Logs: FC<ILogsProps> = ({ appDetail }) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const debouncedQueryParams = useDebounce(queryParams, { wait: 500 })
|
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
|
// Get the app type first
|
||||||
const isChatMode = appDetail.mode !== AppModeEnum.COMPLETION
|
const isChatMode = appDetail.mode !== AppModeEnum.COMPLETION
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
page: queryParams.page,
|
page,
|
||||||
limit: queryParams.limit,
|
limit,
|
||||||
...((debouncedQueryParams.period !== '9')
|
...((debouncedQueryParams.period !== '9')
|
||||||
? {
|
? {
|
||||||
start: dayjs().subtract(TIME_PERIOD_MAPPING[debouncedQueryParams.period].value, 'day').startOf('day').format('YYYY-MM-DD HH:mm'),
|
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)
|
{(total && total > APP_PAGE_LIMIT)
|
||||||
? (
|
? (
|
||||||
<Pagination
|
<Pagination
|
||||||
current={queryParams.page - 1}
|
current={page - 1}
|
||||||
onChange={handlePageChange}
|
onChange={handlePageChange}
|
||||||
total={total}
|
total={total}
|
||||||
limit={queryParams.limit}
|
limit={limit}
|
||||||
onLimitChange={handleLimitChange}
|
onLimitChange={handleLimitChange}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -20,6 +20,14 @@ export type DocumentListQuery = {
|
|||||||
sort: SortType
|
sort: SortType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DocumentListQueryInput = {
|
||||||
|
page?: number
|
||||||
|
limit?: number
|
||||||
|
keyword?: string | null
|
||||||
|
status?: string | null
|
||||||
|
sort?: string | null
|
||||||
|
}
|
||||||
|
|
||||||
const DEFAULT_QUERY: DocumentListQuery = {
|
const DEFAULT_QUERY: DocumentListQuery = {
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
@ -28,6 +36,24 @@ const DEFAULT_QUERY: DocumentListQuery = {
|
|||||||
sort: '-created_at',
|
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() {
|
function useDocumentListQueryState() {
|
||||||
const [query, setQuery] = useQueryStates(
|
const [query, setQuery] = useQueryStates(
|
||||||
{
|
{
|
||||||
@ -38,6 +64,7 @@ function useDocumentListQueryState() {
|
|||||||
sort: parseAsString.withDefault(DEFAULT_QUERY.sort),
|
sort: parseAsString.withDefault(DEFAULT_QUERY.sort),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
history: 'push',
|
||||||
urlKeys: {
|
urlKeys: {
|
||||||
page: 'page',
|
page: 'page',
|
||||||
limit: 'limit',
|
limit: 'limit',
|
||||||
@ -48,21 +75,10 @@ function useDocumentListQueryState() {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
const finalQuery = useMemo(() => {
|
const finalQuery = useMemo(() => normalizeDocumentListQuery(query), [query])
|
||||||
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 updateQuery = (updates: Partial<DocumentListQuery>) => {
|
const updateQuery = (updates: Partial<DocumentListQuery>) => {
|
||||||
setQuery(prev => ({ ...prev, ...updates }))
|
setQuery(prev => normalizeDocumentListQuery({ ...prev, ...updates }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const resetQuery = () => {
|
const resetQuery = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user