chore: handle merge problme
This commit is contained in:
parent
55a9898952
commit
00cedc0ca3
@ -1,10 +1,11 @@
|
|||||||
'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 } from 'lodash-es'
|
import { groupBy, omit } from 'lodash-es'
|
||||||
import { PlusIcon } from '@heroicons/react/24/solid'
|
import { PlusIcon } from '@heroicons/react/24/solid'
|
||||||
import { RiDraftLine, RiExternalLinkLine } from '@remixicon/react'
|
import { RiDraftLine, 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'
|
||||||
@ -14,16 +15,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 } from '@/service/datasets'
|
import { createDocument, fetchDocuments } 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, ProcessMode } from '@/models/datasets'
|
import { DataSourceType } 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 { useDocumentList, useInvalidDocumentDetailKey, useInvalidDocumentList } from '@/service/knowledge/use-document'
|
import { useInvalidDocumentDetailKey } 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'
|
||||||
import useEditDocumentMetadata from '../metadata/hooks/use-edit-dataset-metadata'
|
import useEditDocumentMetadata from '../metadata/hooks/use-edit-dataset-metadata'
|
||||||
@ -80,7 +81,7 @@ type IDocumentsProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const fetcher = (url: string) => get(url, {}, {})
|
export const fetcher = (url: string) => get(url, {}, {})
|
||||||
const DEFAULT_LIMIT = 10
|
const DEFAULT_LIMIT = 15
|
||||||
|
|
||||||
const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
@ -101,33 +102,33 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|||||||
|
|
||||||
const debouncedSearchValue = useDebounce(searchValue, { wait: 500 })
|
const debouncedSearchValue = useDebounce(searchValue, { wait: 500 })
|
||||||
|
|
||||||
const { data: documentsRes, isFetching: isListLoading } = useDocumentList({
|
const query = useMemo(() => {
|
||||||
datasetId,
|
return { page: currPage + 1, limit, keyword: debouncedSearchValue, fetch: isDataSourceNotion ? true : '' }
|
||||||
query: {
|
}, [currPage, debouncedSearchValue, isDataSourceNotion, limit])
|
||||||
page: currPage + 1,
|
|
||||||
limit,
|
const { data: documentsRes, mutate, isLoading: isListLoading } = useSWR(
|
||||||
keyword: debouncedSearchValue,
|
{
|
||||||
|
action: 'fetchDocuments',
|
||||||
|
datasetId,
|
||||||
|
params: query,
|
||||||
},
|
},
|
||||||
refetchInterval: (isDataSourceNotion && timerCanRun) ? 2500 : 0,
|
apiParams => fetchDocuments(omit(apiParams, 'action')),
|
||||||
})
|
{ refreshInterval: (isDataSourceNotion && timerCanRun) ? 2500 : 0 },
|
||||||
|
)
|
||||||
const invalidDocumentList = useInvalidDocumentList(datasetId)
|
|
||||||
|
|
||||||
|
const [isMuting, setIsMuting] = useState(false)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (documentsRes) {
|
if (!isListLoading && isMuting)
|
||||||
const totalPages = Math.ceil(documentsRes.total / limit)
|
setIsMuting(false)
|
||||||
if (totalPages < currPage + 1)
|
}, [isListLoading, isMuting])
|
||||||
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(() => {
|
||||||
invalidDocumentList()
|
setIsMuting(true)
|
||||||
|
mutate()
|
||||||
invalidDocumentDetail()
|
invalidDocumentDetail()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
invalidChunkList()
|
invalidChunkList()
|
||||||
@ -177,6 +178,8 @@ 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 +212,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|||||||
indexing_technique: dataset?.indexing_technique,
|
indexing_technique: dataset?.indexing_technique,
|
||||||
process_rule: {
|
process_rule: {
|
||||||
rules: {},
|
rules: {},
|
||||||
mode: ProcessMode.general,
|
mode: 'automatic',
|
||||||
},
|
},
|
||||||
} as CreateDocumentReq
|
} as CreateDocumentReq
|
||||||
|
|
||||||
@ -217,7 +220,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|||||||
datasetId,
|
datasetId,
|
||||||
body: params,
|
body: params,
|
||||||
})
|
})
|
||||||
invalidDocumentList()
|
mutate()
|
||||||
setTimerCanRun(true)
|
setTimerCanRun(true)
|
||||||
// mutateDatasetIndexingStatus(undefined, { revalidate: true })
|
// mutateDatasetIndexingStatus(undefined, { revalidate: true })
|
||||||
setNotionPageSelectorModalVisible(false)
|
setNotionPageSelectorModalVisible(false)
|
||||||
@ -308,7 +311,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{isListLoading
|
{(isLoading && !isMuting)
|
||||||
? <Loading type='app' />
|
? <Loading type='app' />
|
||||||
: total > 0
|
: total > 0
|
||||||
? <List
|
? <List
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user