Commit ea36f95c authored by StyleZhang's avatar StyleZhang

fix: dataset document list timer

parent 47703033
......@@ -77,9 +77,10 @@ const Item = memo(({ index, style, data }: ListChildComponentProps<{
listMapWithChildrenAndDescendants: NotionPageTreeMap
searchValue: string
previewPageId: string
pagesMap: DataSourceNotionPageMap
}>) => {
const { t } = useTranslation()
const { dataList, handleToggle, checkedIds, handleCheck, canPreview, handlePreview, listMapWithChildrenAndDescendants, searchValue, previewPageId } = data
const { dataList, handleToggle, checkedIds, handleCheck, canPreview, handlePreview, listMapWithChildrenAndDescendants, searchValue, previewPageId, pagesMap } = data
const current = dataList[index]
const currentWithChildrenAndDescendants = listMapWithChildrenAndDescendants[current.page_id]
const hasChild = currentWithChildrenAndDescendants.descendants.size > 0
......@@ -96,7 +97,7 @@ const Item = memo(({ index, style, data }: ListChildComponentProps<{
/>
)
}
if (current.parent_id === 'root') {
if (current.parent_id === 'root' || !pagesMap[current.parent_id]) {
return (
<div></div>
)
......@@ -287,6 +288,7 @@ const PageSelector = ({
listMapWithChildrenAndDescendants,
searchValue,
previewPageId: currentPreviewPageId,
pagesMap,
}}
>
{Item}
......
......@@ -93,19 +93,20 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
datasetId,
params: query,
}, apiParams => fetchDocuments(omit(apiParams, 'action')))
const { data: datasetIndexingStatus } = useSWR(timerCanRun ? datasetId : null, getDatasetIndexingStatus, { refreshInterval: 2500 })
const { data: datasetIndexingStatus, mutate: mutateDatasetIndexingStatus } = useSWR(timerCanRun ? datasetId : null, getDatasetIndexingStatus, { refreshInterval: 2500 })
const datasetDocumentProgress: [Record<string, number>, boolean] = useMemo(() => {
let completedNum = 0
const progressPercentMap = datasetIndexingStatus?.data.reduce((prev: Record<string, number>, next: IndexingStatusResponse) => {
const progressPercentMap = datasetIndexingStatus?.data?.reduce((prev: Record<string, number>, next: IndexingStatusResponse) => {
const { id, completed_segments, total_segments, indexing_status } = next
const isEmbeddinged = indexing_status === 'completed' || indexing_status === 'paused' || indexing_status === 'error'
if (indexing_status === 'completed' || indexing_status === 'paused' || indexing_status === 'error')
if (isEmbeddinged)
completedNum++
const completedCount = completed_segments || 0
const totalCount = total_segments || 0
if (totalCount === 0 && completedCount === 0) {
prev[id] = indexing_status === 'completed' ? 100 : 0
prev[id] = isEmbeddinged ? 100 : 0
}
else {
const percent = Math.round(completedCount * 100 / totalCount)
......@@ -115,12 +116,12 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
return prev
}, {}) || {}
return [progressPercentMap, completedNum === datasetIndexingStatus?.data.length]
}, [datasetIndexingStatus?.data])
if (datasetDocumentProgress[1])
if (completedNum === datasetIndexingStatus?.data?.length)
setTimerCanRun(false)
return [progressPercentMap, completedNum === datasetIndexingStatus?.data?.length]
}, [datasetIndexingStatus])
const documentsWithProgress = useMemo(() => {
return {
...documentsRes,
......@@ -187,8 +188,9 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
body: params,
})
mutate()
setNotionPageSelectorModalVisible(false)
setTimerCanRun(true)
mutateDatasetIndexingStatus(undefined, { revalidate: true })
setNotionPageSelectorModalVisible(false)
}
const handleSync = async () => {
......
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