Commit 483536a2 authored by crazywoola's avatar crazywoola

chore: update code

parent b161faec
...@@ -20,37 +20,25 @@ type Props = { ...@@ -20,37 +20,25 @@ type Props = {
type IIndexState = { type IIndexState = {
value: string value: string
} }
type ActionType = 'retry' | 'success' | 'error'
type IAction = { type IAction = {
type: string type: ActionType
} }
const indexStateReducer = (state: IIndexState, action: IAction) => { const indexStateReducer = (state: IIndexState, action: IAction) => {
switch (action.type) { const actionMap = {
case 'retry': retry: 'retry',
return { success: 'success',
...state, error: 'error',
value: 'retry',
}
case 'success':
return {
...state,
value: 'success',
} }
case 'error':
return {
...state,
value: 'error',
}
default:
return { return {
...state, ...state,
value: 'success', value: actionMap[action.type] || state.value,
}
} }
} }
const RetryButton: FC<Props> = ( const RetryButton: FC<Props> = ({ datasetId }) => {
{ datasetId },
) => {
const { t } = useTranslation() const { t } = useTranslation()
const [indexState, dispatch] = useReducer(indexStateReducer, { value: 'success' }) const [indexState, dispatch] = useReducer(indexStateReducer, { value: 'success' })
const { data: errorDocs } = useSWR({ datasetId }, getErrorDocs) const { data: errorDocs } = useSWR({ datasetId }, getErrorDocs)
...@@ -74,19 +62,24 @@ const RetryButton: FC<Props> = ( ...@@ -74,19 +62,24 @@ const RetryButton: FC<Props> = (
if (indexState.value === 'success') if (indexState.value === 'success')
return null return null
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'>{errorDocs?.total} {t('dataset.docsFailedNotice')}</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 <span
className={ className={classNames(
classNames(
'text-primary-600 font-semibold text-sm cursor-pointer', 'text-primary-600 font-semibold text-sm cursor-pointer',
indexState.value === 'retry' && '!text-gray-500 !cursor-not-allowed', indexState.value === 'retry' && '!text-gray-500 !cursor-not-allowed',
) )}
}
onClick={indexState.value === 'error' ? onRetryErrorDocs : undefined} onClick={indexState.value === 'error' ? onRetryErrorDocs : undefined}
>{t('dataset.retry')}</span> >
{t('dataset.retry')}
</span>
</div> </div>
)
} }
export default RetryButton export default RetryButton
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