Commit 3021f025 authored by crazywoola's avatar crazywoola

feat: add fetch

parent f8e3ad69
'use client'
import type { FC } from 'react'
import React, { useEffect } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import classNames from 'classnames'
import useSWR from 'swr'
import s from './style.module.css'
import Divider from '@/app/components/base/divider'
import { get } from '@/service/base'
import { getErrorDocs } from '@/service/datasets'
const WarningIcon = () =>
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000 /svg">
......@@ -18,16 +20,13 @@ type Props = {
const RetryButton: FC<Props> = (
{ datasetId },
) => {
useEffect(() => {
get(`/datasets/${datasetId}/error-docs`).then((res) => {
console.log(res)
})
}, [])
const { t } = useTranslation()
const { data: errorDocs } = useSWR({ datasetId }, getErrorDocs)
return <div className={classNames('inline-flex justify-center items-center gap-2', s.retryBtn)}>
<WarningIcon />
<span className='flex shrink-0 text-sm text-gray-500'>3 docs embeddings failed</span>
<span className='flex shrink-0 text-sm text-gray-500'>{errorDocs?.total} {t('dataset.docsFailedNotice')}</span>
<Divider type='vertical' className='!h-4' />
<span className='text-primary-600 font-semibold text-sm'>RETRY</span>
<span className='text-primary-600 font-semibold text-sm'>{t('dataset.retry')}</span>
</div>
}
export default RetryButton
......@@ -42,6 +42,8 @@ const translation = {
change: 'Change',
changeRetrievalMethod: 'Change retrieval method',
},
docsFailedNotice: 'documents failed to be indexed',
retry: 'Retry',
}
export default translation
......@@ -42,6 +42,8 @@ const translation = {
change: '変更',
changeRetrievalMethod: '検索方法の変更',
},
docsFailedNotice: 'ドキュメントのインデックスに失敗しました',
retry: '再試行',
}
export default translation
......@@ -41,6 +41,8 @@ const translation = {
change: 'Alterar',
changeRetrievalMethod: 'Alterar método de recuperação',
},
docsFailedNotice: 'documentos falharam ao serem indexados',
retry: 'Tentar novamente',
}
export default translation
......@@ -42,6 +42,8 @@ const translation = {
change: 'Змінити',
changeRetrievalMethod: 'Змінити метод пошуку',
},
docsFailedNotice: 'документи не вдалося проіндексувати',
retry: 'Повторити спробу',
}
export default translation
......@@ -42,6 +42,8 @@ const translation = {
change: '更改',
changeRetrievalMethod: '更改检索方法',
},
docsFailedNotice: '文档无法被索引',
retry: '重试',
}
export default translation
......@@ -411,3 +411,8 @@ export enum DocForm {
TEXT = 'text_model',
QA = 'qa_model',
}
export type ErrorDocsResponse = {
data: any[]
total: number
}
......@@ -7,6 +7,7 @@ import type {
DataSetListResponse,
DocumentDetailResponse,
DocumentListResponse,
ErrorDocsResponse,
FileIndexingEstimateResponse,
HitTestingRecordsResponse,
HitTestingResponse,
......@@ -227,3 +228,7 @@ type FileTypesRes = {
export const fetchSupportFileTypes: Fetcher<FileTypesRes, { url: string }> = ({ url }) => {
return get<FileTypesRes>(url)
}
export const getErrorDocs: Fetcher<ErrorDocsResponse, { datasetId: string }> = ({ datasetId }) => {
return get<ErrorDocsResponse>(`/datasets/${datasetId}/error-docs`)
}
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