feat(ui): paginate tasks table

pull/5871/head
Pavel Zavora 2022-02-24 15:32:10 +01:00
parent 40bee687c6
commit bd7d7a90f7
1 changed files with 25 additions and 4 deletions

View File

@ -13,13 +13,15 @@ import {
notifyAlertRuleStatusUpdateFailed,
} from 'src/shared/copy/notifications'
import useDebounce from '../../utils/useDebounce'
import {Button, ButtonShape, IconFont} from 'src/reusable_ui'
import {Button, ButtonShape, IconFont, PaginationBar} from 'src/reusable_ui'
import {isCancellationError} from 'src/types/promises'
import TasksTable from '../components/TasksTable'
import {Link} from 'react-router'
import {sortBy} from 'lodash'
// max size of a limited fetch
const LIMITED_FETCH_SIZE = 100
const PAGE_SIZE = LIMITED_FETCH_SIZE
const Contents = ({
kapacitor,
@ -57,6 +59,14 @@ const Contents = ({
}
return true
}, [filter, reloadRequired])
const [page, setPage] = useState(0)
const listPage = useMemo(() => {
if (list.length <= PAGE_SIZE) {
return list
}
const start = Math.max(page * PAGE_SIZE, 0)
return list.slice(start, Math.min(start + PAGE_SIZE, list.length))
}, [page, list])
useEffect(() => {
setLoading(true)
@ -70,7 +80,8 @@ const Contents = ({
const {
data: {rules},
} = await getRules(kapacitor, {signal: ac.signal, params})
setAllList(rules)
const sorted = sortBy(rules, t => t.name.toLowerCase())
setAllList(sorted)
} catch (e) {
if (!isCancellationError(e)) {
console.error(e)
@ -210,11 +221,21 @@ const Contents = ({
) : undefined}
<TasksTable
kapacitorLink={kapacitorLink}
tasks={list}
tasks={listPage}
sorted={true}
onViewRule={onViewRule}
onDelete={onDelete}
onChangeRuleStatus={onChangeRuleStatus}
/>
>
{listPage !== list ? (
<PaginationBar
page={page}
total={list.length}
pageSize={PAGE_SIZE}
onChange={p => setPage(p)}
/>
) : undefined}
</TasksTable>
</>
)}
</div>