Commit 3021f025 authored by crazywoola's avatar crazywoola

feat: add fetch

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