feat: add pagination for chunk list

This commit is contained in:
shiweisong.ssw 2023-06-29 11:15:25 +08:00
parent ba3bfcdc3b
commit cca8634cc6
2 changed files with 52 additions and 4 deletions

View File

@ -2,12 +2,15 @@
import { useSearchParams } from 'next/navigation' import { useSearchParams } from 'next/navigation'
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import { Table } from '@/lib/mui' import { Table, Stack } from '@/lib/mui'
import { Popover } from 'antd' import { Popover, Pagination } from 'antd'
const page_size = 20;
const ChunkList = () => { const ChunkList = () => {
const spaceName = useSearchParams().get('spacename') const spaceName = useSearchParams().get('spacename')
const documentId = useSearchParams().get('documentid') const documentId = useSearchParams().get('documentid')
const [total, setTotal] = useState<number>(0);
const [current, setCurrent] = useState<number>(0);
const [chunkList, setChunkList] = useState<any>([]) const [chunkList, setChunkList] = useState<any>([])
useEffect(() => { useEffect(() => {
async function fetchChunks() { async function fetchChunks() {
@ -19,13 +22,17 @@ const ChunkList = () => {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
body: JSON.stringify({ body: JSON.stringify({
document_id: documentId document_id: documentId,
page: 1,
page_size
}) })
} }
) )
const data = await res.json() const data = await res.json()
if (data.success) { if (data.success) {
setChunkList(data.data) setChunkList(data.data.data)
setTotal(data.data.total);
setCurrent(data.data.page);
} }
} }
fetchChunks() fetchChunks()
@ -69,6 +76,30 @@ const ChunkList = () => {
))} ))}
</tbody> </tbody>
</Table> </Table>
<Stack direction="row" justifyContent="flex-end">
<Pagination current={current} total={total} onChange={async page => {
const res = await fetch(
`http://localhost:8000/knowledge/${spaceName}/chunk/list`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
document_id: documentId,
page,
page_size
})
}
)
const data = await res.json()
if (data.success) {
setChunkList(data.data.data)
setTotal(data.data.total);
setCurrent(data.data.page);
}
}} hideOnSinglePage />
</Stack>
</div> </div>
) )
} }

View File

@ -11,3 +11,20 @@ body {
line-height: var(--joy-lineHeight-md, 1.5); line-height: var(--joy-lineHeight-md, 1.5);
background-color: var(--joy-palette-background-body); background-color: var(--joy-palette-background-body);
} }
.ant-pagination .ant-pagination-prev * {
color: rgb(145, 35, 167) !important;
}
.ant-pagination .ant-pagination-next * {
color: rgb(145, 35, 167) !important;
}
.ant-pagination .ant-pagination-item {
border-color: rgb(145, 35, 167) !important;
background-color: rgb(145, 35, 167) !important;
}
.ant-pagination .ant-pagination-item.ant-pagination-item-active a {
color: white !important;
}