Merge branch 'new-page-framework' of https://github.com/csunny/DB-GPT into new-page-framework

This commit is contained in:
changhuiping.chp 2023-06-30 18:04:26 +08:00
commit 468807cc9b
4 changed files with 625 additions and 388 deletions

View File

@ -1,12 +1,20 @@
'use client' 'use client'
import { useSearchParams } from 'next/navigation' import { useSearchParams, useRouter } from 'next/navigation'
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import { useColorScheme, Table, Stack } from '@/lib/mui' import {
useColorScheme,
Table,
Stack,
Typography,
Breadcrumbs,
Link
} from '@/lib/mui'
import { Popover, Pagination } from 'antd' import { Popover, Pagination } from 'antd'
const page_size = 20 const page_size = 20
const ChunkList = () => { const ChunkList = () => {
const router = useRouter()
const { mode } = useColorScheme() const { mode } = useColorScheme()
const spaceName = useSearchParams().get('spacename') const spaceName = useSearchParams().get('spacename')
const documentId = useSearchParams().get('documentid') const documentId = useSearchParams().get('documentid')
@ -39,12 +47,45 @@ const ChunkList = () => {
fetchChunks() fetchChunks()
}, []) }, [])
return ( return (
<div className="p-4">
<Stack
direction="row"
justifyContent="flex-start"
alignItems="center"
sx={{ marginBottom: '20px' }}
>
<Breadcrumbs aria-label="breadcrumbs">
<Link
onClick={() => {
router.push('/datastores')
}}
key="Knowledge Space"
underline="hover"
color="neutral"
fontSize="inherit"
>
Knowledge Space
</Link>
<Link
onClick={() => {
router.push(`/datastores/documents?name=${spaceName}`)
}}
key="Knowledge Space"
underline="hover"
color="neutral"
fontSize="inherit"
>
Documents
</Link>
<Typography fontSize="inherit">Chunks</Typography>
</Breadcrumbs>
</Stack>
<div className="p-4"> <div className="p-4">
{chunkList.length ? ( {chunkList.length ? (
<> <>
<Table <Table
color="info" color="primary"
variant="soft" variant="plain"
size="lg" size="lg"
sx={{ sx={{
'& tbody tr: hover': { '& tbody tr: hover': {
@ -79,7 +120,11 @@ const ChunkList = () => {
<td> <td>
{ {
<Popover <Popover
content={JSON.stringify(row.meta_info || '{}', null, 2)} content={JSON.stringify(
row.meta_info || '{}',
null,
2
)}
trigger="hover" trigger="hover"
> >
{row.meta_info.length > 10 {row.meta_info.length > 10
@ -134,6 +179,7 @@ const ChunkList = () => {
<></> <></>
)} )}
</div> </div>
</div>
) )
} }

View File

@ -13,12 +13,18 @@ import {
Input, Input,
Textarea, Textarea,
Chip, Chip,
Switch,
Typography,
Breadcrumbs,
Link,
styled styled
} from '@/lib/mui' } from '@/lib/mui'
import moment from 'moment' import moment from 'moment'
import { InboxOutlined } from '@ant-design/icons' import { InboxOutlined } from '@ant-design/icons'
import CheckCircleOutlinedIcon from '@mui/icons-material/CheckCircleOutlined';
import CachedIcon from '@mui/icons-material/Cached';
import type { UploadProps } from 'antd' import type { UploadProps } from 'antd'
import { Upload, Pagination, message } from 'antd' import { Upload, Pagination, Popover, message } from 'antd'
const { Dragger } = Upload const { Dragger } = Upload
const Item = styled(Sheet)(({ theme }) => ({ const Item = styled(Sheet)(({ theme }) => ({
@ -71,6 +77,7 @@ const Documents = () => {
const [originFileObj, setOriginFileObj] = useState<any>(null) const [originFileObj, setOriginFileObj] = useState<any>(null)
const [total, setTotal] = useState<number>(0) const [total, setTotal] = useState<number>(0)
const [current, setCurrent] = useState<number>(0) const [current, setCurrent] = useState<number>(0)
const [synchChecked, setSynchChecked] = useState<boolean>(true)
const props: UploadProps = { const props: UploadProps = {
name: 'file', name: 'file',
multiple: false, multiple: false,
@ -111,24 +118,38 @@ const Documents = () => {
}, []) }, [])
return ( return (
<div className="p-4"> <div className="p-4">
<Sheet <Stack
sx={{ direction="row"
display: 'flex', justifyContent="space-between"
flexDirection: 'row-reverse' alignItems="center"
}} sx={{ marginBottom: '20px' }}
> >
<Breadcrumbs aria-label="breadcrumbs">
<Link
onClick={() => {
router.push('/datastores')
}}
key="Knowledge Space"
underline="hover"
color="neutral"
fontSize="inherit"
>
Knowledge Space
</Link>
<Typography fontSize="inherit">Documents</Typography>
</Breadcrumbs>
<Button <Button
variant="outlined" variant="outlined"
onClick={() => setIsAddDocumentModalShow(true)} onClick={() => setIsAddDocumentModalShow(true)}
> >
+ Add Datasource + Add Datasource
</Button> </Button>
</Sheet> </Stack>
{documents.length ? ( {documents.length ? (
<> <>
<Table <Table
color="info" color="primary"
variant="soft" variant="plain"
size="lg" size="lg"
sx={{ sx={{
'& tbody tr: hover': { '& tbody tr: hover': {
@ -147,6 +168,7 @@ const Documents = () => {
<th>Size</th> <th>Size</th>
<th>Last Synch</th> <th>Last Synch</th>
<th>Status</th> <th>Status</th>
<th>Result</th>
<th>Operation</th> <th>Operation</th>
</tr> </tr>
</thead> </thead>
@ -155,11 +177,7 @@ const Documents = () => {
<tr key={row.id}> <tr key={row.id}>
<td>{row.doc_name}</td> <td>{row.doc_name}</td>
<td> <td>
<Chip <Chip variant="solid" color="neutral" sx={{ opacity: 0.5 }}>
variant="soft"
color="neutral"
sx={{ fontWeight: 300 }}
>
{row.doc_type} {row.doc_type}
</Chip> </Chip>
</td> </td>
@ -167,8 +185,8 @@ const Documents = () => {
<td>{moment(row.last_sync).format('YYYY-MM-DD HH:MM:SS')}</td> <td>{moment(row.last_sync).format('YYYY-MM-DD HH:MM:SS')}</td>
<td> <td>
<Chip <Chip
sx={{ fontWeight: 300 }} sx={{ opacity: 0.5 }}
variant="soft" variant="solid"
color={(function () { color={(function () {
switch (row.status) { switch (row.status) {
case 'TODO': case 'TODO':
@ -185,12 +203,46 @@ const Documents = () => {
{row.status} {row.status}
</Chip> </Chip>
</td> </td>
<td>
{(function () {
if (row.status === 'TODO' || row.status === 'RUNNING') {
return ''
} else if (row.status === 'FINISHED') {
return (
<Popover content={row.result} trigger="hover">
<Chip
variant="solid"
color="success"
sx={{ opacity: 0.5 }}
>
SUCCESS
</Chip>
</Popover>
)
} else {
return (
<Popover content={row.result} trigger="hover">
<Chip
variant="solid"
color="danger"
sx={{ opacity: 0.5 }}
>
FAILED
</Chip>
</Popover>
)
}
})()}
</td>
<td> <td>
{ {
<> <>
<Button <Button
variant="outlined" variant="outlined"
size="sm" size="sm"
sx={{
marginRight: '20px'
}}
onClick={async () => { onClick={async () => {
const res = await fetch( const res = await fetch(
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/sync`, `${process.env.API_BASE_URL}/knowledge/${spaceName}/document/sync`,
@ -212,7 +264,7 @@ const Documents = () => {
} }
}} }}
> >
Synch Synch<CachedIcon />
</Button> </Button>
<Button <Button
variant="outlined" variant="outlined"
@ -223,7 +275,7 @@ const Documents = () => {
) )
}} }}
> >
Detail of Chunks Details
</Button> </Button>
</> </>
} }
@ -296,9 +348,13 @@ const Documents = () => {
{stepsOfAddingDocument.map((item: any, index: number) => ( {stepsOfAddingDocument.map((item: any, index: number) => (
<Item <Item
key={item} key={item}
sx={{ fontWeight: activeStep === index ? 'bold' : '' }} sx={{
fontWeight: activeStep === index ? 'bold' : '',
color: activeStep === index ? '#814DDE' : ''
}}
> >
{item} {index < activeStep ? <CheckCircleOutlinedIcon /> : `${index + 1}.`}
{`${item}`}
</Item> </Item>
))} ))}
</Stack> </Stack>
@ -386,8 +442,38 @@ const Documents = () => {
/> />
</> </>
)} )}
<Typography
component="label"
sx={{
marginTop: '20px'
}}
endDecorator={
<Switch
checked={synchChecked}
onChange={(event: any) =>
setSynchChecked(event.target.checked)
}
/>
}
>
Synch:
</Typography>
</Box> </Box>
<Stack
direction="row"
justifyContent="flex-start"
alignItems="center"
sx={{ marginBottom: '20px' }}
>
<Button <Button
variant="outlined"
sx={{ marginRight: '20px' }}
onClick={() => setActiveStep(0)}
>
{'< Back'}
</Button>
<Button
variant="outlined"
onClick={async () => { onClick={async () => {
if (documentName === '') { if (documentName === '') {
message.error('Please input the name') message.error('Please input the name')
@ -413,6 +499,20 @@ const Documents = () => {
} }
) )
const data = await res.json() const data = await res.json()
data.success &&
synchChecked &&
fetch(
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddDocumentModalShow(false) setIsAddDocumentModalShow(false)
@ -455,6 +555,20 @@ const Documents = () => {
} }
) )
const data = await res.json() const data = await res.json()
data.success &&
synchChecked &&
fetch(
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddDocumentModalShow(false) setIsAddDocumentModalShow(false)
@ -501,6 +615,20 @@ const Documents = () => {
} }
) )
const data = await res.json() const data = await res.json()
data.success &&
synchChecked &&
fetch(
`${process.env.API_BASE_URL}/knowledge/${spaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddDocumentModalShow(false) setIsAddDocumentModalShow(false)
@ -531,6 +659,7 @@ const Documents = () => {
> >
Finish Finish
</Button> </Button>
</Stack>
</> </>
)} )}
</Sheet> </Sheet>

View File

@ -3,8 +3,9 @@
import { useRouter } from 'next/navigation' import { useRouter } from 'next/navigation'
import React, { useState, useEffect } from 'react' import React, { useState, useEffect } from 'react'
import { InboxOutlined } from '@ant-design/icons' import { InboxOutlined } from '@ant-design/icons'
import CheckCircleOutlinedIcon from '@mui/icons-material/CheckCircleOutlined';
import type { UploadProps } from 'antd' import type { UploadProps } from 'antd'
import { message, Upload } from 'antd' import { message, Upload, Popover } from 'antd'
import { import {
useColorScheme, useColorScheme,
Modal, Modal,
@ -16,6 +17,8 @@ import {
Input, Input,
Textarea, Textarea,
Chip, Chip,
Switch,
Typography,
styled styled
} from '@/lib/mui' } from '@/lib/mui'
@ -33,7 +36,7 @@ const Item = styled(Sheet)(({ theme }) => ({
})) }))
const stepsOfAddingSpace = [ const stepsOfAddingSpace = [
'Knowledge Space Configuration', 'Knowledge Space Config',
'Choose a Datasource type', 'Choose a Datasource type',
'Setup the Datasource' 'Setup the Datasource'
] ]
@ -70,6 +73,7 @@ const Index = () => {
const [textSource, setTextSource] = useState<string>('') const [textSource, setTextSource] = useState<string>('')
const [text, setText] = useState<string>('') const [text, setText] = useState<string>('')
const [originFileObj, setOriginFileObj] = useState<any>(null) const [originFileObj, setOriginFileObj] = useState<any>(null)
const [synchChecked, setSynchChecked] = useState<boolean>(true)
const props: UploadProps = { const props: UploadProps = {
name: 'file', name: 'file',
multiple: false, multiple: false,
@ -127,8 +131,8 @@ const Index = () => {
<div className="page-body p-4"> <div className="page-body p-4">
{knowledgeSpaceList.length ? ( {knowledgeSpaceList.length ? (
<Table <Table
color="info" color="primary"
variant="soft" variant="plain"
size="lg" size="lg"
sx={{ sx={{
'& tbody tr: hover': { '& tbody tr: hover': {
@ -137,6 +141,9 @@ const Index = () => {
}, },
'& tbody tr: hover a': { '& tbody tr: hover a': {
textDecoration: 'underline' textDecoration: 'underline'
},
'& tbody tr a': {
color: 'rgb(13, 96, 217)'
} }
}} }}
> >
@ -145,6 +152,7 @@ const Index = () => {
<th>Name</th> <th>Name</th>
<th>Vector</th> <th>Vector</th>
<th>Owner</th> <th>Owner</th>
<th>Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -164,23 +172,22 @@ const Index = () => {
} }
</td> </td>
<td> <td>
<Chip <Chip variant="solid" color="neutral" sx={{ opacity: 0.5 }}>
variant="soft"
color="neutral"
sx={{ fontWeight: 300 }}
>
{row.vector_type} {row.vector_type}
</Chip> </Chip>
</td> </td>
<td> <td>
<Chip <Chip variant="solid" color="neutral" sx={{ opacity: 0.5 }}>
variant="soft"
color="neutral"
sx={{ fontWeight: 300 }}
>
{row.owner} {row.owner}
</Chip> </Chip>
</td> </td>
<td>
<Popover content={row.desc} trigger="hover">
{row.desc.length > 10
? `${row.desc.slice(0, 10)}...`
: row.desc}
</Popover>
</td>
</tr> </tr>
))} ))}
</tbody> </tbody>
@ -213,9 +220,13 @@ const Index = () => {
{stepsOfAddingSpace.map((item: any, index: number) => ( {stepsOfAddingSpace.map((item: any, index: number) => (
<Item <Item
key={item} key={item}
sx={{ fontWeight: activeStep === index ? 'bold' : '' }} sx={{
fontWeight: activeStep === index ? 'bold' : '',
color: activeStep === index ? '#814DDE' : ''
}}
> >
{item} {index < activeStep ? <CheckCircleOutlinedIcon /> : `${index + 1}.`}
{`${item}`}
</Item> </Item>
))} ))}
</Stack> </Stack>
@ -236,7 +247,9 @@ const Index = () => {
message.error('please input the name') message.error('please input the name')
return return
} }
const res = await fetch(`${process.env.API_BASE_URL}/knowledge/space/add`, { const res = await fetch(
`${process.env.API_BASE_URL}/knowledge/space/add`,
{
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
@ -247,7 +260,8 @@ const Index = () => {
owner: 'keting', owner: 'keting',
desc: 'test1' desc: 'test1'
}) })
}) }
)
const data = await res.json() const data = await res.json()
if (data.success) { if (data.success) {
message.success('success') message.success('success')
@ -357,8 +371,38 @@ const Index = () => {
/> />
</> </>
)} )}
<Typography
component="label"
sx={{
marginTop: '20px'
}}
endDecorator={
<Switch
checked={synchChecked}
onChange={(event: any) =>
setSynchChecked(event.target.checked)
}
/>
}
>
Synch:
</Typography>
</Box> </Box>
<Stack
direction="row"
justifyContent="flex-start"
alignItems="center"
sx={{ marginBottom: '20px' }}
>
<Button <Button
variant="outlined"
sx={{ marginRight: '20px' }}
onClick={() => setActiveStep(1)}
>
{'< Back'}
</Button>
<Button
variant="outlined"
onClick={async () => { onClick={async () => {
if (documentName === '') { if (documentName === '') {
message.error('Please input the name') message.error('Please input the name')
@ -387,6 +431,19 @@ const Index = () => {
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddKnowledgeSpaceModalShow(false) setIsAddKnowledgeSpaceModalShow(false)
synchChecked &&
fetch(
`${process.env.API_BASE_URL}/knowledge/${knowledgeSpaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
} else { } else {
message.error(data.err_msg || 'failed') message.error(data.err_msg || 'failed')
} }
@ -410,6 +467,19 @@ const Index = () => {
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddKnowledgeSpaceModalShow(false) setIsAddKnowledgeSpaceModalShow(false)
synchChecked &&
fetch(
`${process.env.API_BASE_URL}/knowledge/${knowledgeSpaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
} else { } else {
message.error(data.err_msg || 'failed') message.error(data.err_msg || 'failed')
} }
@ -437,6 +507,19 @@ const Index = () => {
if (data.success) { if (data.success) {
message.success('success') message.success('success')
setIsAddKnowledgeSpaceModalShow(false) setIsAddKnowledgeSpaceModalShow(false)
synchChecked &&
fetch(
`${process.env.API_BASE_URL}/knowledge/${knowledgeSpaceName}/document/sync`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
doc_ids: [data.data]
})
}
)
} else { } else {
message.error(data.err_msg || 'failed') message.error(data.err_msg || 'failed')
} }
@ -445,6 +528,7 @@ const Index = () => {
> >
Finish Finish
</Button> </Button>
</Stack>
</> </>
)} )}
</Sheet> </Sheet>

View File

@ -12,28 +12,6 @@ body {
background-color: var(--joy-palette-background-body); background-color: var(--joy-palette-background-body);
} }
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
text-align: left;
padding: 8px;
}
th {
background-color: #f2f2f2;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
body .ant-btn-primary { body .ant-btn-primary {
background-color: #1677ff; background-color: #1677ff;
} }