From 7adeceaf00a778c97a72fbd4e0280237f46a8569 Mon Sep 17 00:00:00 2001 From: "shiweisong.ssw" Date: Wed, 28 Jun 2023 16:19:12 +0800 Subject: [PATCH] feat: upload files --- datacenter/app/datastores/documents/page.tsx | 204 ++++++++++++++----- datacenter/app/datastores/page.tsx | 173 +++++++++++----- 2 files changed, 275 insertions(+), 102 deletions(-) diff --git a/datacenter/app/datastores/documents/page.tsx b/datacenter/app/datastores/documents/page.tsx index aa58b6330..0aff19425 100644 --- a/datacenter/app/datastores/documents/page.tsx +++ b/datacenter/app/datastores/documents/page.tsx @@ -14,8 +14,21 @@ import { styled } from '@/lib/mui' import moment from 'moment' -import { message } from 'antd' +import { InboxOutlined } from '@ant-design/icons' +import type { UploadProps } from 'antd' +import { Upload, message } from 'antd' +const { Dragger } = Upload +const Item = styled(Sheet)(({ theme }) => ({ + width: '50%', + backgroundColor: + theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff', + ...theme.typography.body2, + padding: theme.spacing(1), + textAlign: 'center', + borderRadius: 4, + color: theme.vars.palette.text.secondary +})) const stepsOfAddingDocument = [ 'Choose a Datasource type', 'Setup the Datasource' @@ -37,16 +50,6 @@ const documentTypeList = [ subTitle: 'It can be: PDF, CSV, JSON, Text, PowerPoint, Word, Excel' } ] -const Item = styled(Sheet)(({ theme }) => ({ - width: '50%', - backgroundColor: - theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff', - ...theme.typography.body2, - padding: theme.spacing(1), - textAlign: 'center', - borderRadius: 4, - color: theme.vars.palette.text.secondary -})) const Documents = () => { const router = useRouter() @@ -54,9 +57,25 @@ const Documents = () => { const [isAddDocumentModalShow, setIsAddDocumentModalShow] = useState(false) const [activeStep, setActiveStep] = useState(0) + const [documentType, setDocumentType] = useState('') const [documents, setDocuments] = useState([]) const [webPageUrl, setWebPageUrl] = useState('') - const [documentName, setDocumentName] = useState('') + const [documentName, setDocumentName] = useState('') + const [originFileObj, setOriginFileObj] = useState(null) + const props: UploadProps = { + name: 'file', + multiple: false, + onChange(info) { + console.log(info) + if (info.fileList.length === 0) { + setOriginFileObj(null) + setDocumentName('') + return + } + setOriginFileObj(info.file.originFileObj) + setDocumentName(info.file.originFileObj?.name) + } + } useEffect(() => { async function fetchDocuments() { const res = await fetch( @@ -109,20 +128,24 @@ const Documents = () => { {row.doc_type} {row.chunk_size} {moment(row.last_sync).format('YYYY-MM-DD HH:MM:SS')} - {row.status} + + + {row.status} + + { <> @@ -221,6 +244,7 @@ const Documents = () => { }} onClick={() => { if (item.type === 'webPage') { + setDocumentType(item.type) setActiveStep(1) } }} @@ -243,10 +267,36 @@ const Documents = () => { sx={{ marginBottom: '20px' }} /> Web Page URL: - setWebPageUrl(e.target.value)} - /> + {documentType === 'webPage' ? ( + <> + Web Page URL: + setWebPageUrl(e.target.value)} + /> + + ) : documentType === 'file' ? ( + <> + +

+ +

+

+ Select or Drop file +

+

+ PDF, PowerPoint, Excel, Word, Text, Markdown, +

+
+ + ) : ( + <> + )}