Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
4643c041
Commit
4643c041
authored
Mar 13, 2024
by
crazywoola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add retry button
parent
3021f025
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
6 deletions
+69
-6
index.tsx
web/app/components/base/retry-button/index.tsx
+62
-3
style.module.css
web/app/components/base/retry-button/style.module.css
+2
-2
datasets.ts
web/models/datasets.ts
+1
-1
datasets.ts
web/service/datasets.ts
+4
-0
No files found.
web/app/components/base/retry-button/index.tsx
View file @
4643c041
'use client'
import
type
{
FC
}
from
'react'
import
React
from
'react'
import
React
,
{
useEffect
,
useReducer
}
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
{
getErrorDocs
}
from
'@/service/datasets'
import
{
getErrorDocs
,
retryErrorDocs
}
from
'@/service/datasets'
import
type
{
IndexingStatusResponse
}
from
'@/models/datasets'
const
WarningIcon
=
()
=>
<
svg
width=
"12"
height=
"12"
viewBox=
"0 0 12 12"
fill=
"none"
xmlns=
"http://www.w3.org/2000 /svg"
>
...
...
@@ -16,17 +17,75 @@ const WarningIcon = () =>
type
Props
=
{
datasetId
:
string
}
type
IIndexState
=
{
value
:
string
}
type
IAction
=
{
type
:
string
}
const
indexStateReducer
=
(
state
:
IIndexState
,
action
:
IAction
)
=>
{
switch
(
action
.
type
)
{
case
'retry'
:
return
{
...
state
,
value
:
'retrying'
,
}
case
'success'
:
return
{
...
state
,
value
:
'success'
,
}
case
'error'
:
return
{
...
state
,
value
:
'error'
,
}
default
:
return
{
...
state
,
value
:
'success'
,
}
}
}
const
RetryButton
:
FC
<
Props
>
=
(
{
datasetId
},
)
=>
{
const
{
t
}
=
useTranslation
()
const
[
indexState
,
dispatch
]
=
useReducer
(
indexStateReducer
,
{
value
:
'success'
})
const
{
data
:
errorDocs
}
=
useSWR
({
datasetId
},
getErrorDocs
)
const
onRetryErrorDocs
=
async
()
=>
{
const
document_ids
=
errorDocs
?.
data
.
map
((
doc
:
IndexingStatusResponse
)
=>
doc
.
id
)
||
[]
const
res
=
await
retryErrorDocs
({
datasetId
,
document_ids
})
if
(
res
.
result
===
'success'
)
dispatch
({
type
:
'success'
})
else
dispatch
({
type
:
'error'
})
}
useEffect
(()
=>
{
if
(
errorDocs
?.
total
===
0
)
dispatch
({
type
:
'success'
})
else
dispatch
({
type
:
'error'
})
},
[
errorDocs
?.
total
])
if
(
indexState
.
value
===
'success'
)
return
null
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'
>
{
errorDocs
?.
total
}
{
t
(
'dataset.docsFailedNotice'
)
}
</
span
>
<
Divider
type=
'vertical'
className=
'!h-4'
/>
<
span
className=
'text-primary-600 font-semibold text-sm'
>
{
t
(
'dataset.retry'
)
}
</
span
>
<
span
className=
{
classNames
(
'text-primary-600 font-semibold text-sm cursor-pointer'
,
indexState
.
value
===
'retrying'
&&
'text-gray-500 cursor-not-allowed'
,
)
}
onClick=
{
indexState
.
value
===
'error'
?
onRetryErrorDocs
:
undefined
}
>
{
t
(
'dataset.retry'
)
}
</
span
>
</
div
>
}
export
default
RetryButton
web/app/components/base/retry-button/style.module.css
View file @
4643c041
.retryBtn
{
@apply
inline-flex
justify-center
items-center
content-center
h-9
leading-5
rounded-lg
px-4
py-2
text-base
cursor-pointer
;
@apply
border-solid
border
border-gray-200
cursor-pointer
text-gray-500
hover
:
bg-white
hover
:
shadow-sm
hover
:
border-gray-300
;
@apply
inline-flex
justify-center
items-center
content-center
h-9
leading-5
rounded-lg
px-4
py-2
text-base;
@apply
border-solid
border
border-gray-200
text-gray-500
hover
:
bg-white
hover
:
shadow-sm
hover
:
border-gray-300
;
}
web/models/datasets.ts
View file @
4643c041
...
...
@@ -413,6 +413,6 @@ export enum DocForm {
}
export
type
ErrorDocsResponse
=
{
data
:
any
[]
data
:
IndexingStatusResponse
[]
total
:
number
}
web/service/datasets.ts
View file @
4643c041
...
...
@@ -232,3 +232,7 @@ export const fetchSupportFileTypes: Fetcher<FileTypesRes, { url: string }> = ({
export
const
getErrorDocs
:
Fetcher
<
ErrorDocsResponse
,
{
datasetId
:
string
}
>
=
({
datasetId
})
=>
{
return
get
<
ErrorDocsResponse
>
(
`/datasets/
${
datasetId
}
/error-docs`
)
}
export
const
retryErrorDocs
:
Fetcher
<
CommonResponse
,
{
datasetId
:
string
;
document_ids
:
string
[]
}
>
=
({
datasetId
,
document_ids
})
=>
{
return
post
<
CommonResponse
>
(
`/datasets/
${
datasetId
}
/retry`
,
{
body
:
{
document_ids
}
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment