-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### What problem does this PR solve? fix: #567 use modal to upload files in the knowledge base ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
- Loading branch information
Showing
13 changed files
with
262 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.uploader { | ||
:global { | ||
.ant-upload-list { | ||
max-height: 40vh; | ||
overflow-y: auto; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { useTranslate } from '@/hooks/commonHooks'; | ||
import { IModalProps } from '@/interfaces/common'; | ||
import { InboxOutlined } from '@ant-design/icons'; | ||
import { | ||
Flex, | ||
Modal, | ||
Segmented, | ||
Tabs, | ||
TabsProps, | ||
Upload, | ||
UploadFile, | ||
UploadProps, | ||
} from 'antd'; | ||
import { Dispatch, SetStateAction, useState } from 'react'; | ||
|
||
import styles from './index.less'; | ||
|
||
const { Dragger } = Upload; | ||
|
||
const FileUpload = ({ | ||
directory, | ||
fileList, | ||
setFileList, | ||
}: { | ||
directory: boolean; | ||
fileList: UploadFile[]; | ||
setFileList: Dispatch<SetStateAction<UploadFile[]>>; | ||
}) => { | ||
const { t } = useTranslate('fileManager'); | ||
const props: UploadProps = { | ||
multiple: true, | ||
onRemove: (file) => { | ||
const index = fileList.indexOf(file); | ||
const newFileList = fileList.slice(); | ||
newFileList.splice(index, 1); | ||
setFileList(newFileList); | ||
}, | ||
beforeUpload: (file) => { | ||
setFileList((pre) => { | ||
return [...pre, file]; | ||
}); | ||
|
||
return false; | ||
}, | ||
directory, | ||
fileList, | ||
}; | ||
|
||
return ( | ||
<Dragger {...props} className={styles.uploader}> | ||
<p className="ant-upload-drag-icon"> | ||
<InboxOutlined /> | ||
</p> | ||
<p className="ant-upload-text">{t('uploadTitle')}</p> | ||
<p className="ant-upload-hint">{t('uploadDescription')}</p> | ||
</Dragger> | ||
); | ||
}; | ||
|
||
const FileUploadModal = ({ | ||
visible, | ||
hideModal, | ||
loading, | ||
onOk: onFileUploadOk, | ||
}: IModalProps<UploadFile[]>) => { | ||
const { t } = useTranslate('fileManager'); | ||
const [value, setValue] = useState<string | number>('local'); | ||
const [fileList, setFileList] = useState<UploadFile[]>([]); | ||
const [directoryFileList, setDirectoryFileList] = useState<UploadFile[]>([]); | ||
|
||
const onOk = async () => { | ||
const ret = await onFileUploadOk?.([...fileList, ...directoryFileList]); | ||
if (ret !== undefined && ret === 0) { | ||
setFileList([]); | ||
setDirectoryFileList([]); | ||
} | ||
return ret; | ||
}; | ||
|
||
const items: TabsProps['items'] = [ | ||
{ | ||
key: '1', | ||
label: t('file'), | ||
children: ( | ||
<FileUpload | ||
directory={false} | ||
fileList={fileList} | ||
setFileList={setFileList} | ||
></FileUpload> | ||
), | ||
}, | ||
{ | ||
key: '2', | ||
label: t('directory'), | ||
children: ( | ||
<FileUpload | ||
directory | ||
fileList={directoryFileList} | ||
setFileList={setDirectoryFileList} | ||
></FileUpload> | ||
), | ||
}, | ||
]; | ||
|
||
return ( | ||
<> | ||
<Modal | ||
title={t('uploadFile')} | ||
open={visible} | ||
onOk={onOk} | ||
onCancel={hideModal} | ||
confirmLoading={loading} | ||
> | ||
<Flex gap={'large'} vertical> | ||
<Segmented | ||
options={[ | ||
{ label: t('local'), value: 'local' }, | ||
{ label: t('s3'), value: 's3' }, | ||
]} | ||
block | ||
value={value} | ||
onChange={setValue} | ||
/> | ||
{value === 'local' ? ( | ||
<Tabs defaultActiveKey="1" items={items} /> | ||
) : ( | ||
t('comingSoon', { keyPrefix: 'common' }) | ||
)} | ||
</Flex> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export default FileUploadModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
.modelWrapper { | ||
width: 100%; | ||
} | ||
|
||
.modelContainer { | ||
width: 100%; | ||
.factoryOperationWrapper { | ||
text-align: right; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.