Commit 94b112fc authored by StyleZhang's avatar StyleZhang

feat: dataset document add notion-page-selector-modal

parent 1f37a3a7
...@@ -11,11 +11,13 @@ type NotionPageSelectorModalProps = { ...@@ -11,11 +11,13 @@ type NotionPageSelectorModalProps = {
isShow: boolean isShow: boolean
onClose: () => void onClose: () => void
onSave: (selectedPages: DataSourceNotionPage[]) => void onSave: (selectedPages: DataSourceNotionPage[]) => void
value?: string[]
} }
const NotionPageSelectorModal = ({ const NotionPageSelectorModal = ({
isShow, isShow,
onClose, onClose,
onSave, onSave,
value,
}: NotionPageSelectorModalProps) => { }: NotionPageSelectorModalProps) => {
const { t } = useTranslation() const { t } = useTranslation()
const [selectedPages, setSelectedPages] = useState<DataSourceNotionPage[]>([]) const [selectedPages, setSelectedPages] = useState<DataSourceNotionPage[]>([])
...@@ -45,6 +47,7 @@ const NotionPageSelectorModal = ({ ...@@ -45,6 +47,7 @@ const NotionPageSelectorModal = ({
</div> </div>
</div> </div>
<NotionPageSelector <NotionPageSelector
value={value}
onSelect={handleSelectPage} onSelect={handleSelectPage}
canPreview={false} canPreview={false}
/> />
......
...@@ -19,7 +19,7 @@ const SearchInput = ({ ...@@ -19,7 +19,7 @@ const SearchInput = ({
}, [onChange]) }, [onChange])
return ( return (
<div className={cn(s['input-wrapper'], 'flex items-center px-2 h-7 border border-gray-300 rounded-md', `${value ? 'bg-white' : 'bg-gray-100'}`)}> <div className={cn(s['input-wrapper'], 'flex items-center px-2 h-7 rounded-md', `${value ? 'bg-white' : 'bg-gray-100'}`)}>
<div className={cn(s['search-icon'], 'mr-[6px] w-4 h-4')} /> <div className={cn(s['search-icon'], 'mr-[6px] w-4 h-4')} />
<input <input
className='grow text-[13px] bg-inherit border-0 outline-0 appearance-none' className='grow text-[13px] bg-inherit border-0 outline-0 appearance-none'
......
...@@ -14,7 +14,11 @@ import Button from '@/app/components/base/button' ...@@ -14,7 +14,11 @@ import Button from '@/app/components/base/button'
import Input from '@/app/components/base/input' import Input from '@/app/components/base/input'
import Pagination from '@/app/components/base/pagination' import Pagination from '@/app/components/base/pagination'
import { get } from '@/service/base' import { get } from '@/service/base'
import { fetchDocuments } from '@/service/datasets' import { createDocument, fetchDocuments } from '@/service/datasets'
import { useDatasetDetailContext } from '@/context/dataset-detail'
import { NotionPageSelectorModal } from '@/app/components/base/notion-page-selector'
import type { DataSourceNotionPage } from '@/models/common'
import type { CreateDocumentReq } from '@/models/datasets'
// Custom page count is not currently supported. // Custom page count is not currently supported.
const limit = 15 const limit = 15
...@@ -75,6 +79,8 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => { ...@@ -75,6 +79,8 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
const [searchValue, setSearchValue] = useState<string>('') const [searchValue, setSearchValue] = useState<string>('')
const [currPage, setCurrPage] = React.useState<number>(0) const [currPage, setCurrPage] = React.useState<number>(0)
const router = useRouter() const router = useRouter()
const { dataset } = useDatasetDetailContext()
const [notionPageSelectorModalVisible, setNotionPageSelectorModalVisible] = useState(false)
const query = useMemo(() => { const query = useMemo(() => {
return { page: currPage + 1, limit, keyword: searchValue } return { page: currPage + 1, limit, keyword: searchValue }
...@@ -89,6 +95,10 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => { ...@@ -89,6 +95,10 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
const total = documentsRes?.total || 0 const total = documentsRes?.total || 0
const routeToDocCreate = () => { const routeToDocCreate = () => {
if (dataset?.data_source_type === 'notion_import') {
setNotionPageSelectorModalVisible(true)
return
}
router.push(`/datasets/${datasetId}/documents/create`) router.push(`/datasets/${datasetId}/documents/create`)
} }
...@@ -96,6 +106,40 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => { ...@@ -96,6 +106,40 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
const isLoading = !documentsRes && !error const isLoading = !documentsRes && !error
const handleSaveNotionPageSelected = async (selectedPages: (DataSourceNotionPage & { workspace_id: string })[]) => {
const params = {
data_source: {
type: dataset?.data_source_type,
info_list: {
data_source_type: dataset?.data_source_type,
notion_info_list: {
workspace_id: selectedPages[0].workspace_id,
pages: selectedPages.map((selectedPage) => {
const { page_id, page_name, page_icon, type } = selectedPage
return {
page_id,
page_name,
page_icon,
type,
}
}),
},
},
},
indexing_technique: dataset?.indexing_technique,
process_rule: {
rules: {},
mode: 'automatic',
},
} as CreateDocumentReq
await createDocument({
datasetId,
body: params,
})
mutate()
}
return ( return (
<div className='flex flex-col h-full overflow-y-auto'> <div className='flex flex-col h-full overflow-y-auto'>
<div className='flex flex-col justify-center gap-1 px-6 pt-4'> <div className='flex flex-col justify-center gap-1 px-6 pt-4'>
...@@ -113,7 +157,11 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => { ...@@ -113,7 +157,11 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
/> />
<Button type='primary' onClick={routeToDocCreate} className='!h-8 !text-[13px]'> <Button type='primary' onClick={routeToDocCreate} className='!h-8 !text-[13px]'>
<PlusIcon className='h-4 w-4 mr-2 stroke-current' /> <PlusIcon className='h-4 w-4 mr-2 stroke-current' />
{t('datasetDocuments.list.addFile')} {
dataset?.data_source_type === 'notion_import'
? t('datasetDocuments.list.addPages')
: t('datasetDocuments.list.addFile')
}
</Button> </Button>
</div> </div>
{isLoading {isLoading
...@@ -126,6 +174,14 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => { ...@@ -126,6 +174,14 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
{(total && total > limit) {(total && total > limit)
? <Pagination current={currPage} onChange={setCurrPage} total={total} limit={limit} /> ? <Pagination current={currPage} onChange={setCurrPage} total={total} limit={limit} />
: null} : null}
<NotionPageSelectorModal
value={(documentsRes?.data || []).map((doc) => {
return doc.data_source_info.notion_page_id
})}
isShow={notionPageSelectorModalVisible}
onClose={() => setNotionPageSelectorModalVisible(false)}
onSave={handleSaveNotionPageSelected}
/>
</div> </div>
</div> </div>
) )
......
import { createContext } from 'use-context-selector' import { createContext, useContext } from 'use-context-selector'
import type { DataSet } from '@/models/datasets' import type { DataSet } from '@/models/datasets'
const DatasetDetailContext = createContext<{ indexingTechnique?: string; dataset?: DataSet }>({}) const DatasetDetailContext = createContext<{ indexingTechnique?: string; dataset?: DataSet }>({})
export const useDatasetDetailContext = () => useContext(DatasetDetailContext)
export default DatasetDetailContext export default DatasetDetailContext
...@@ -3,6 +3,7 @@ const translation = { ...@@ -3,6 +3,7 @@ const translation = {
title: 'Documents', title: 'Documents',
desc: 'All files of the dataset are shown here, and the entire dataset can be linked to Dify citations or indexed via the Chat plugin.', desc: 'All files of the dataset are shown here, and the entire dataset can be linked to Dify citations or indexed via the Chat plugin.',
addFile: 'add file', addFile: 'add file',
addPages: 'Add Pages',
table: { table: {
header: { header: {
fileName: 'FILE NAME', fileName: 'FILE NAME',
......
...@@ -3,6 +3,7 @@ const translation = { ...@@ -3,6 +3,7 @@ const translation = {
title: '文档', title: '文档',
desc: '数据集的所有文件都在这里显示,整个数据集都可以链接到 Dify 引用或通过 Chat 插件进行索引。', desc: '数据集的所有文件都在这里显示,整个数据集都可以链接到 Dify 引用或通过 Chat 插件进行索引。',
addFile: '添加文件', addFile: '添加文件',
addPages: '添加页面',
table: { table: {
header: { header: {
fileName: '文件名', fileName: '文件名',
......
...@@ -109,6 +109,7 @@ export type DataSourceNotionPage = { ...@@ -109,6 +109,7 @@ export type DataSourceNotionPage = {
page_id: string page_id: string
page_name: string page_name: string
parent_id: string parent_id: string
type: string
} }
export type DataSourceNotionWorkspace = { export type DataSourceNotionWorkspace = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment