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