Commit 3c589c44 authored by StyleZhang's avatar StyleZhang

fix: dataset document notion-page-selector-modal

parent 94b112fc
...@@ -112,7 +112,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => { ...@@ -112,7 +112,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
type: dataset?.data_source_type, type: dataset?.data_source_type,
info_list: { info_list: {
data_source_type: dataset?.data_source_type, data_source_type: dataset?.data_source_type,
notion_info_list: { notion_info_list: [{
workspace_id: selectedPages[0].workspace_id, workspace_id: selectedPages[0].workspace_id,
pages: selectedPages.map((selectedPage) => { pages: selectedPages.map((selectedPage) => {
const { page_id, page_name, page_icon, type } = selectedPage const { page_id, page_name, page_icon, type } = selectedPage
...@@ -123,7 +123,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => { ...@@ -123,7 +123,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
type, type,
} }
}), }),
}, }],
}, },
}, },
indexing_technique: dataset?.indexing_technique, indexing_technique: dataset?.indexing_technique,
...@@ -140,6 +140,11 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => { ...@@ -140,6 +140,11 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
mutate() mutate()
} }
const handleSync = async () => {
if (dataset?.data_source_type === 'notion_import')
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'>
...@@ -167,7 +172,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => { ...@@ -167,7 +172,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
{isLoading {isLoading
? <Loading type='app' /> ? <Loading type='app' />
: total > 0 : total > 0
? <List documents={documentsRes?.data || []} datasetId={datasetId} onUpdate={mutate} /> ? <List documents={documentsRes?.data || []} datasetId={datasetId} onUpdate={mutate} onSync={handleSync} />
: <EmptyElement onClick={routeToDocCreate} /> : <EmptyElement onClick={routeToDocCreate} />
} }
{/* Show Pagination only if the total is more than the limit */} {/* Show Pagination only if the total is more than the limit */}
......
...@@ -24,6 +24,7 @@ import { asyncRunSafe } from '@/utils' ...@@ -24,6 +24,7 @@ import { asyncRunSafe } from '@/utils'
import { formatNumber } from '@/utils/format' import { formatNumber } from '@/utils/format'
import { archiveDocument, deleteDocument, disableDocument, enableDocument } from '@/service/datasets' import { archiveDocument, deleteDocument, disableDocument, enableDocument } from '@/service/datasets'
import type { DocumentDisplayStatus, DocumentListResponse } from '@/models/datasets' import type { DocumentDisplayStatus, DocumentListResponse } from '@/models/datasets'
import { syncDataSourceNotion } from '@/service/common'
import type { CommonResponse } from '@/models/common' import type { CommonResponse } from '@/models/common'
export const SettingsIcon: FC<{ className?: string }> = ({ className }) => { export const SettingsIcon: FC<{ className?: string }> = ({ className }) => {
...@@ -32,6 +33,12 @@ export const SettingsIcon: FC<{ className?: string }> = ({ className }) => { ...@@ -32,6 +33,12 @@ export const SettingsIcon: FC<{ className?: string }> = ({ className }) => {
</svg> </svg>
} }
export const SyncIcon: FC<{ className?: string }> = () => {
return <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5.69773 13.1783C7.29715 13.8879 9.20212 13.8494 10.8334 12.9075C13.5438 11.3427 14.4724 7.87704 12.9076 5.16672L12.7409 4.87804M3.09233 10.8335C1.52752 8.12314 2.45615 4.65746 5.16647 3.09265C6.7978 2.15081 8.70277 2.11227 10.3022 2.82185M1.66226 10.8892L3.48363 11.3773L3.97166 9.5559M12.0284 6.44393L12.5164 4.62256L14.3378 5.1106" stroke="#667085" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
}
export const FilePlusIcon: FC<{ className?: string }> = ({ className }) => { export const FilePlusIcon: FC<{ className?: string }> = ({ className }) => {
return <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" className={className ?? ''}> return <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" className={className ?? ''}>
<path d="M13.3332 6.99992V4.53325C13.3332 3.41315 13.3332 2.85309 13.1152 2.42527C12.9234 2.04895 12.6175 1.74299 12.2412 1.55124C11.8133 1.33325 11.2533 1.33325 10.1332 1.33325H5.8665C4.7464 1.33325 4.18635 1.33325 3.75852 1.55124C3.3822 1.74299 3.07624 2.04895 2.88449 2.42527C2.6665 2.85309 2.6665 3.41315 2.6665 4.53325V11.4666C2.6665 12.5867 2.6665 13.1467 2.88449 13.5746C3.07624 13.9509 3.3822 14.2569 3.75852 14.4486C4.18635 14.6666 4.7464 14.6666 5.8665 14.6666H7.99984M9.33317 7.33325H5.33317M6.6665 9.99992H5.33317M10.6665 4.66659H5.33317M11.9998 13.9999V9.99992M9.99984 11.9999H13.9998" stroke="#667085" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" /> <path d="M13.3332 6.99992V4.53325C13.3332 3.41315 13.3332 2.85309 13.1152 2.42527C12.9234 2.04895 12.6175 1.74299 12.2412 1.55124C11.8133 1.33325 11.2533 1.33325 10.1332 1.33325H5.8665C4.7464 1.33325 4.18635 1.33325 3.75852 1.55124C3.3822 1.74299 3.07624 2.04895 2.88449 2.42527C2.6665 2.85309 2.6665 3.41315 2.6665 4.53325V11.4666C2.6665 12.5867 2.6665 13.1467 2.88449 13.5746C3.07624 13.9509 3.3822 14.2569 3.75852 14.4486C4.18635 14.6666 4.7464 14.6666 5.8665 14.6666H7.99984M9.33317 7.33325H5.33317M6.6665 9.99992H5.33317M10.6665 4.66659H5.33317M11.9998 13.9999V9.99992M9.99984 11.9999H13.9998" stroke="#667085" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
...@@ -77,7 +84,7 @@ export const StatusItem: FC<{ ...@@ -77,7 +84,7 @@ export const StatusItem: FC<{
</div> </div>
} }
type OperationName = 'delete' | 'archive' | 'enable' | 'disable' type OperationName = 'delete' | 'archive' | 'enable' | 'disable' | 'sync'
// operation action for list and detail // operation action for list and detail
export const OperationAction: FC<{ export const OperationAction: FC<{
...@@ -85,13 +92,18 @@ export const OperationAction: FC<{ ...@@ -85,13 +92,18 @@ export const OperationAction: FC<{
enabled: boolean enabled: boolean
archived: boolean archived: boolean
id: string id: string
data_source_type: string
data_source_info: {
notion_workspace_id: string
}
} }
datasetId: string datasetId: string
onUpdate: () => void onUpdate: () => void
scene?: 'list' | 'detail' scene?: 'list' | 'detail'
className?: string className?: string
}> = ({ datasetId, detail, onUpdate, scene = 'list', className = '' }) => { onSync: (workspaceId: string) => void
const { id, enabled = false, archived = false } = detail || {} }> = ({ datasetId, detail, onUpdate, scene = 'list', className = '', onSync }) => {
const { id, enabled = false, archived = false, data_source_type, data_source_info } = detail || {}
const [showModal, setShowModal] = useState(false) const [showModal, setShowModal] = useState(false)
const { notify } = useContext(ToastContext) const { notify } = useContext(ToastContext)
const { t } = useTranslation() const { t } = useTranslation()
...@@ -111,6 +123,9 @@ export const OperationAction: FC<{ ...@@ -111,6 +123,9 @@ export const OperationAction: FC<{
case 'disable': case 'disable':
opApi = disableDocument opApi = disableDocument
break break
case 'sync':
onSync(data_source_info.notion_workspace_id)
break
default: default:
opApi = deleteDocument opApi = deleteDocument
break break
...@@ -173,10 +188,14 @@ export const OperationAction: FC<{ ...@@ -173,10 +188,14 @@ export const OperationAction: FC<{
<SettingsIcon /> <SettingsIcon />
<span className={s.actionName}>{t('datasetDocuments.list.action.settings')}</span> <span className={s.actionName}>{t('datasetDocuments.list.action.settings')}</span>
</div> </div>
{/* <div className={s.actionItem} onClick={() => router.push(`/datasets/${datasetId}/documents/create`)}> {
<FilePlusIcon /> data_source_type === 'notion_import' && (
<span className={s.actionName}>{t('datasetDocuments.list.action.uploadFile')}</span> <div className={s.actionItem} onClick={() => onOperate('sync')}>
</div> */} <SyncIcon />
<span className={s.actionName}>{t('datasetDocuments.list.action.sync')}</span>
</div>
)
}
<Divider className='my-1' /> <Divider className='my-1' />
</> </>
)} )}
...@@ -240,12 +259,13 @@ type IDocumentListProps = { ...@@ -240,12 +259,13 @@ type IDocumentListProps = {
documents: DocumentListResponse['data'] documents: DocumentListResponse['data']
datasetId: string datasetId: string
onUpdate: () => void onUpdate: () => void
onSync: () => void
} }
/** /**
* Document list component including basic information * Document list component including basic information
*/ */
const DocumentList: FC<IDocumentListProps> = ({ documents = [], datasetId, onUpdate }) => { const DocumentList: FC<IDocumentListProps> = ({ documents = [], datasetId, onUpdate, onSync }) => {
const { t } = useTranslation() const { t } = useTranslation()
const router = useRouter() const router = useRouter()
const [localDocs, setLocalDocs] = useState<DocumentListResponse['data']>(documents) const [localDocs, setLocalDocs] = useState<DocumentListResponse['data']>(documents)
...@@ -266,6 +286,12 @@ const DocumentList: FC<IDocumentListProps> = ({ documents = [], datasetId, onUpd ...@@ -266,6 +286,12 @@ const DocumentList: FC<IDocumentListProps> = ({ documents = [], datasetId, onUpd
} }
} }
const handleSync = async (workspaceId: string) => {
await syncDataSourceNotion({ url: `/oauth/data-source/notion/${workspaceId}/sync` })
onSync()
}
return ( return (
<> <>
<table className={`w-full border-collapse border-0 text-sm mt-3 ${s.documentTable}`}> <table className={`w-full border-collapse border-0 text-sm mt-3 ${s.documentTable}`}>
...@@ -310,8 +336,9 @@ const DocumentList: FC<IDocumentListProps> = ({ documents = [], datasetId, onUpd ...@@ -310,8 +336,9 @@ const DocumentList: FC<IDocumentListProps> = ({ documents = [], datasetId, onUpd
<td> <td>
<OperationAction <OperationAction
datasetId={datasetId} datasetId={datasetId}
detail={pick(doc, ['enabled', 'archived', 'id'])} detail={pick(doc, ['enabled', 'archived', 'id', 'data_source_type', 'data_source_info'])}
onUpdate={onUpdate} onUpdate={onUpdate}
onSync={handleSync}
/> />
</td> </td>
</tr> </tr>
......
...@@ -20,6 +20,7 @@ const translation = { ...@@ -20,6 +20,7 @@ const translation = {
archive: 'Archive', archive: 'Archive',
delete: 'Delete', delete: 'Delete',
enableWarning: 'Archived file cannot be enabled', enableWarning: 'Archived file cannot be enabled',
sync: 'Sync',
}, },
index: { index: {
enable: 'Enable', enable: 'Enable',
......
...@@ -20,6 +20,7 @@ const translation = { ...@@ -20,6 +20,7 @@ const translation = {
archive: '归档', archive: '归档',
delete: '删除', delete: '删除',
enableWarning: '归档的文件无法启用', enableWarning: '归档的文件无法启用',
sync: '同步',
}, },
index: { index: {
enable: '启用中', enable: '启用中',
......
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