|
@@ -1,11 +1,10 @@
|
|
'use client'
|
|
'use client'
|
|
import type { FC } from 'react'
|
|
import type { FC } from 'react'
|
|
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
-import useSWR from 'swr'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useRouter } from 'next/navigation'
|
|
import { useRouter } from 'next/navigation'
|
|
import { useDebounce, useDebounceFn } from 'ahooks'
|
|
import { useDebounce, useDebounceFn } from 'ahooks'
|
|
-import { groupBy, omit } from 'lodash-es'
|
|
|
|
|
|
+import { groupBy } from 'lodash-es'
|
|
import { PlusIcon } from '@heroicons/react/24/solid'
|
|
import { PlusIcon } from '@heroicons/react/24/solid'
|
|
import { RiExternalLinkLine } from '@remixicon/react'
|
|
import { RiExternalLinkLine } from '@remixicon/react'
|
|
import AutoDisabledDocument from '../common/document-status-with-action/auto-disabled-document'
|
|
import AutoDisabledDocument from '../common/document-status-with-action/auto-disabled-document'
|
|
@@ -15,16 +14,16 @@ import Loading from '@/app/components/base/loading'
|
|
import Button from '@/app/components/base/button'
|
|
import Button from '@/app/components/base/button'
|
|
import Input from '@/app/components/base/input'
|
|
import Input from '@/app/components/base/input'
|
|
import { get } from '@/service/base'
|
|
import { get } from '@/service/base'
|
|
-import { createDocument, fetchDocuments } from '@/service/datasets'
|
|
|
|
|
|
+import { createDocument } from '@/service/datasets'
|
|
import { useDatasetDetailContext } from '@/context/dataset-detail'
|
|
import { useDatasetDetailContext } from '@/context/dataset-detail'
|
|
import { NotionPageSelectorModal } from '@/app/components/base/notion-page-selector'
|
|
import { NotionPageSelectorModal } from '@/app/components/base/notion-page-selector'
|
|
import type { NotionPage } from '@/models/common'
|
|
import type { NotionPage } from '@/models/common'
|
|
import type { CreateDocumentReq } from '@/models/datasets'
|
|
import type { CreateDocumentReq } from '@/models/datasets'
|
|
-import { DataSourceType } from '@/models/datasets'
|
|
|
|
|
|
+import { DataSourceType, ProcessMode } from '@/models/datasets'
|
|
import IndexFailed from '@/app/components/datasets/common/document-status-with-action/index-failed'
|
|
import IndexFailed from '@/app/components/datasets/common/document-status-with-action/index-failed'
|
|
import { useProviderContext } from '@/context/provider-context'
|
|
import { useProviderContext } from '@/context/provider-context'
|
|
import cn from '@/utils/classnames'
|
|
import cn from '@/utils/classnames'
|
|
-import { useInvalidDocumentDetailKey } from '@/service/knowledge/use-document'
|
|
|
|
|
|
+import { useDocumentList, useInvalidDocumentDetailKey, useInvalidDocumentList } from '@/service/knowledge/use-document'
|
|
import { useInvalid } from '@/service/use-base'
|
|
import { useInvalid } from '@/service/use-base'
|
|
import { useChildSegmentListKey, useSegmentListKey } from '@/service/knowledge/use-segment'
|
|
import { useChildSegmentListKey, useSegmentListKey } from '@/service/knowledge/use-segment'
|
|
|
|
|
|
@@ -73,12 +72,12 @@ const EmptyElement: FC<{ canAdd: boolean; onClick: () => void; type?: 'upload' |
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
|
|
|
|
-interface IDocumentsProps {
|
|
|
|
|
|
+type IDocumentsProps = {
|
|
datasetId: string
|
|
datasetId: string
|
|
}
|
|
}
|
|
|
|
|
|
export const fetcher = (url: string) => get(url, {}, {})
|
|
export const fetcher = (url: string) => get(url, {}, {})
|
|
-const DEFAULT_LIMIT = 15
|
|
|
|
|
|
+const DEFAULT_LIMIT = 10
|
|
|
|
|
|
const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|
const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|
const { t } = useTranslation()
|
|
const { t } = useTranslation()
|
|
@@ -99,33 +98,33 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|
|
|
|
|
const debouncedSearchValue = useDebounce(searchValue, { wait: 500 })
|
|
const debouncedSearchValue = useDebounce(searchValue, { wait: 500 })
|
|
|
|
|
|
- const query = useMemo(() => {
|
|
|
|
- return { page: currPage + 1, limit, keyword: debouncedSearchValue, fetch: isDataSourceNotion ? true : '' }
|
|
|
|
- }, [currPage, debouncedSearchValue, isDataSourceNotion, limit])
|
|
|
|
-
|
|
|
|
- const { data: documentsRes, mutate, isLoading: isListLoading } = useSWR(
|
|
|
|
- {
|
|
|
|
- action: 'fetchDocuments',
|
|
|
|
- datasetId,
|
|
|
|
- params: query,
|
|
|
|
|
|
+ const { data: documentsRes, isFetching: isListLoading } = useDocumentList({
|
|
|
|
+ datasetId,
|
|
|
|
+ query: {
|
|
|
|
+ page: currPage + 1,
|
|
|
|
+ limit,
|
|
|
|
+ keyword: debouncedSearchValue,
|
|
},
|
|
},
|
|
- apiParams => fetchDocuments(omit(apiParams, 'action')),
|
|
|
|
- { refreshInterval: (isDataSourceNotion && timerCanRun) ? 2500 : 0 },
|
|
|
|
- )
|
|
|
|
|
|
+ refetchInterval: (isDataSourceNotion && timerCanRun) ? 2500 : 0,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ const invalidDocumentList = useInvalidDocumentList(datasetId)
|
|
|
|
|
|
- const [isMuting, setIsMuting] = useState(false)
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- if (!isListLoading && isMuting)
|
|
|
|
- setIsMuting(false)
|
|
|
|
- }, [isListLoading, isMuting])
|
|
|
|
|
|
+ if (documentsRes) {
|
|
|
|
+ const totalPages = Math.ceil(documentsRes.total / limit)
|
|
|
|
+ if (totalPages < currPage + 1)
|
|
|
|
+ setCurrPage(totalPages === 0 ? 0 : totalPages - 1)
|
|
|
|
+ }
|
|
|
|
+ // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
+ }, [documentsRes])
|
|
|
|
|
|
const invalidDocumentDetail = useInvalidDocumentDetailKey()
|
|
const invalidDocumentDetail = useInvalidDocumentDetailKey()
|
|
const invalidChunkList = useInvalid(useSegmentListKey)
|
|
const invalidChunkList = useInvalid(useSegmentListKey)
|
|
const invalidChildChunkList = useInvalid(useChildSegmentListKey)
|
|
const invalidChildChunkList = useInvalid(useChildSegmentListKey)
|
|
|
|
|
|
const handleUpdate = useCallback(() => {
|
|
const handleUpdate = useCallback(() => {
|
|
- setIsMuting(true)
|
|
|
|
- mutate()
|
|
|
|
|
|
+ invalidDocumentList()
|
|
invalidDocumentDetail()
|
|
invalidDocumentDetail()
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
invalidChunkList()
|
|
invalidChunkList()
|
|
@@ -175,8 +174,6 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|
router.push(`/datasets/${datasetId}/documents/create`)
|
|
router.push(`/datasets/${datasetId}/documents/create`)
|
|
}
|
|
}
|
|
|
|
|
|
- const isLoading = isListLoading // !documentsRes && !error
|
|
|
|
-
|
|
|
|
const handleSaveNotionPageSelected = async (selectedPages: NotionPage[]) => {
|
|
const handleSaveNotionPageSelected = async (selectedPages: NotionPage[]) => {
|
|
const workspacesMap = groupBy(selectedPages, 'workspace_id')
|
|
const workspacesMap = groupBy(selectedPages, 'workspace_id')
|
|
const workspaces = Object.keys(workspacesMap).map((workspaceId) => {
|
|
const workspaces = Object.keys(workspacesMap).map((workspaceId) => {
|
|
@@ -209,7 +206,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|
indexing_technique: dataset?.indexing_technique,
|
|
indexing_technique: dataset?.indexing_technique,
|
|
process_rule: {
|
|
process_rule: {
|
|
rules: {},
|
|
rules: {},
|
|
- mode: 'automatic',
|
|
|
|
|
|
+ mode: ProcessMode.general,
|
|
},
|
|
},
|
|
} as CreateDocumentReq
|
|
} as CreateDocumentReq
|
|
|
|
|
|
@@ -217,7 +214,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|
datasetId,
|
|
datasetId,
|
|
body: params,
|
|
body: params,
|
|
})
|
|
})
|
|
- mutate()
|
|
|
|
|
|
+ invalidDocumentList()
|
|
setTimerCanRun(true)
|
|
setTimerCanRun(true)
|
|
// mutateDatasetIndexingStatus(undefined, { revalidate: true })
|
|
// mutateDatasetIndexingStatus(undefined, { revalidate: true })
|
|
setNotionPageSelectorModalVisible(false)
|
|
setNotionPageSelectorModalVisible(false)
|
|
@@ -272,7 +269,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|
)}
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
- {(isLoading && !isMuting)
|
|
|
|
|
|
+ {isListLoading
|
|
? <Loading type='app' />
|
|
? <Loading type='app' />
|
|
: total > 0
|
|
: total > 0
|
|
? <List
|
|
? <List
|