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
1d860cd8
Commit
1d860cd8
authored
Jun 16, 2023
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: dataset document list
parent
d658ea8a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
41 deletions
+43
-41
base.tsx
web/app/components/base/notion-page-selector/base.tsx
+1
-1
index.tsx
web/app/components/datasets/documents/index.tsx
+36
-37
list.tsx
web/app/components/datasets/documents/list.tsx
+4
-3
datasets.ts
web/models/datasets.ts
+2
-0
No files found.
web/app/components/base/notion-page-selector/base.tsx
View file @
1d860cd8
...
@@ -96,7 +96,7 @@ const NotionPageSelector = ({
...
@@ -96,7 +96,7 @@ const NotionPageSelector = ({
<>
<>
<
div
className=
'flex items-center pl-[10px] pr-2 h-11 bg-white border-b border-b-gray-200 rounded-t-xl'
>
<
div
className=
'flex items-center pl-[10px] pr-2 h-11 bg-white border-b border-b-gray-200 rounded-t-xl'
>
<
WorkspaceSelector
<
WorkspaceSelector
value=
{
currentWorkspaceId
}
value=
{
currentWorkspaceId
||
firstWorkspaceId
}
items=
{
notionWorkspaces
}
items=
{
notionWorkspaces
}
onSelect=
{
handleSelectWorkspace
}
onSelect=
{
handleSelectWorkspace
}
/>
/>
...
...
web/app/components/datasets/documents/index.tsx
View file @
1d860cd8
...
@@ -14,11 +14,11 @@ import Button from '@/app/components/base/button'
...
@@ -14,11 +14,11 @@ import Button from '@/app/components/base/button'
import
Input
from
'@/app/components/base/input'
import
Input
from
'@/app/components/base/input'
import
Pagination
from
'@/app/components/base/pagination'
import
Pagination
from
'@/app/components/base/pagination'
import
{
get
}
from
'@/service/base'
import
{
get
}
from
'@/service/base'
import
{
createDocument
,
fetchDocuments
,
getDatasetIndexingStatus
}
from
'@/service/datasets'
import
{
createDocument
,
fetchDocuments
}
from
'@/service/datasets'
import
{
useDatasetDetailContext
}
from
'@/context/dataset-detail'
import
{
useDatasetDetailContext
}
from
'@/context/dataset-detail'
import
{
NotionPageSelectorModal
}
from
'@/app/components/base/notion-page-selector'
import
{
NotionPageSelectorModal
}
from
'@/app/components/base/notion-page-selector'
import
type
{
DataSourceNotionPage
}
from
'@/models/common'
import
type
{
DataSourceNotionPage
}
from
'@/models/common'
import
type
{
CreateDocumentReq
,
IndexingStatusResponse
}
from
'@/models/datasets'
import
type
{
CreateDocumentReq
}
from
'@/models/datasets'
import
{
DataSourceType
}
from
'@/models/datasets'
import
{
DataSourceType
}
from
'@/models/datasets'
// Custom page count is not currently supported.
// Custom page count is not currently supported.
...
@@ -83,60 +83,57 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
...
@@ -83,60 +83,57 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
const
{
dataset
}
=
useDatasetDetailContext
()
const
{
dataset
}
=
useDatasetDetailContext
()
const
[
notionPageSelectorModalVisible
,
setNotionPageSelectorModalVisible
]
=
useState
(
false
)
const
[
notionPageSelectorModalVisible
,
setNotionPageSelectorModalVisible
]
=
useState
(
false
)
const
[
timerCanRun
,
setTimerCanRun
]
=
useState
(
true
)
const
[
timerCanRun
,
setTimerCanRun
]
=
useState
(
true
)
const
isDataSourceNotion
=
dataset
?.
data_source_type
===
DataSourceType
.
NOTION
const
query
=
useMemo
(()
=>
{
const
query
=
useMemo
(()
=>
{
return
{
page
:
currPage
+
1
,
limit
,
keyword
:
searchValue
}
return
{
page
:
currPage
+
1
,
limit
,
keyword
:
searchValue
,
fetch
:
isDataSourceNotion
?
true
:
''
}
},
[
searchValue
,
currPage
])
},
[
searchValue
,
currPage
,
isDataSourceNotion
])
const
{
data
:
documentsRes
,
error
,
mutate
}
=
useSWR
({
const
{
data
:
documentsRes
,
error
,
mutate
}
=
useSWR
(
{
action
:
'fetchDocuments'
,
action
:
'fetchDocuments'
,
datasetId
,
datasetId
,
params
:
query
,
params
:
query
,
},
apiParams
=>
fetchDocuments
(
omit
(
apiParams
,
'action'
)))
},
const
{
data
:
datasetIndexingStatus
,
mutate
:
mutateDatasetIndexingStatus
}
=
useSWR
(
timerCanRun
?
datasetId
:
null
,
getDatasetIndexingStatus
,
{
refreshInterval
:
2500
})
apiParams
=>
fetchDocuments
(
omit
(
apiParams
,
'action'
)),
{
refreshInterval
:
(
isDataSourceNotion
&&
timerCanRun
)
?
2500
:
0
},
)
const
d
atasetDocumentProgress
:
[
Record
<
string
,
number
>
,
boolean
]
=
useMemo
(()
=>
{
const
d
ocumentsWithProgress
=
useMemo
(()
=>
{
let
completedNum
=
0
let
completedNum
=
0
const
progressPercentMap
=
datasetIndexingStatus
?.
data
?.
reduce
((
prev
:
Record
<
string
,
number
>
,
next
:
IndexingStatusResponse
)
=>
{
let
percent
=
0
const
{
id
,
completed_segments
,
total_segments
,
indexing_status
}
=
next
const
documentsData
=
documentsRes
?.
data
.
map
((
documentItem
)
=>
{
const
{
indexing_status
,
completed_segments
,
total_segments
}
=
documentItem
const
isEmbeddinged
=
indexing_status
===
'completed'
||
indexing_status
===
'paused'
||
indexing_status
===
'error'
const
isEmbeddinged
=
indexing_status
===
'completed'
||
indexing_status
===
'paused'
||
indexing_status
===
'error'
if
(
isEmbeddinged
)
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
)
{
p
rev
[
id
]
=
isEmbeddinged
?
100
:
0
p
ercent
=
isEmbeddinged
?
100
:
0
}
}
else
{
else
{
const
per
cent
=
Math
.
round
(
completedCount
*
100
/
totalCount
)
const
per
=
Math
.
round
(
completedCount
*
100
/
totalCount
)
p
rev
[
id
]
=
percent
>
100
?
100
:
percent
p
ercent
=
per
>
100
?
100
:
per
}
}
return
prev
},
{})
||
{}
if
(
completedNum
===
datasetIndexingStatus
?.
data
?.
length
)
setTimerCanRun
(
false
)
return
[
progressPercentMap
,
completedNum
===
datasetIndexingStatus
?.
data
?.
length
]
},
[
datasetIndexingStatus
])
const
documentsWithProgress
=
useMemo
(()
=>
{
return
{
...
documentsRes
,
data
:
documentsRes
?.
data
.
map
((
documentItem
)
=>
{
return
{
return
{
...
documentItem
,
...
documentItem
,
percent
:
datasetDocumentProgress
[
0
][
documentItem
.
id
]
,
percent
,
}
}
}),
})
if
(
completedNum
===
documentsRes
?.
data
.
length
)
setTimerCanRun
(
false
)
return
{
...
documentsRes
,
data
:
documentsData
,
}
}
},
[
documentsRes
,
datasetDocumentProgress
])
},
[
documentsRes
])
const
total
=
documentsRes
?.
total
||
0
const
total
=
documentsRes
?.
total
||
0
const
routeToDocCreate
=
()
=>
{
const
routeToDocCreate
=
()
=>
{
if
(
dataset
?.
data_source_type
===
DataSourceType
.
NOTION
)
{
if
(
isDataSourceNotion
)
{
setNotionPageSelectorModalVisible
(
true
)
setNotionPageSelectorModalVisible
(
true
)
return
return
}
}
...
@@ -189,10 +186,12 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
...
@@ -189,10 +186,12 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
})
})
mutate
()
mutate
()
setTimerCanRun
(
true
)
setTimerCanRun
(
true
)
mutateDatasetIndexingStatus
(
undefined
,
{
revalidate
:
true
})
//
mutateDatasetIndexingStatus(undefined, { revalidate: true })
setNotionPageSelectorModalVisible
(
false
)
setNotionPageSelectorModalVisible
(
false
)
}
}
const
documentsList
=
isDataSourceNotion
?
documentsWithProgress
?.
data
:
documentsRes
?.
data
return
(
return
(
<
div
className=
'flex flex-col h-full overflow-y-auto'
>
<
div
className=
'flex flex-col h-full overflow-y-auto'
>
<
div
className=
'flex flex-col justify-center gap-1 px-6 pt-4'
>
<
div
className=
'flex flex-col justify-center gap-1 px-6 pt-4'
>
...
@@ -211,7 +210,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
...
@@ -211,7 +210,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
<
Button
type=
'primary'
onClick=
{
routeToDocCreate
}
className=
'!h-8 !text-[13px]'
>
<
Button
type=
'primary'
onClick=
{
routeToDocCreate
}
className=
'!h-8 !text-[13px]'
>
<
PlusIcon
className=
'h-4 w-4 mr-2 stroke-current'
/>
<
PlusIcon
className=
'h-4 w-4 mr-2 stroke-current'
/>
{
{
dataset
?.
data_source_type
===
DataSourceType
.
NOTION
isDataSourceNotion
?
t
(
'datasetDocuments.list.addPages'
)
?
t
(
'datasetDocuments.list.addPages'
)
:
t
(
'datasetDocuments.list.addFile'
)
:
t
(
'datasetDocuments.list.addFile'
)
}
}
...
@@ -220,7 +219,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
...
@@ -220,7 +219,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
{
isLoading
{
isLoading
?
<
Loading
type=
'app'
/>
?
<
Loading
type=
'app'
/>
:
total
>
0
:
total
>
0
?
<
List
documents=
{
documents
WithProgress
?.
data
||
[]
}
datasetId=
{
datasetId
}
onUpdate=
{
mutate
}
/>
?
<
List
documents=
{
documents
List
||
[]
}
datasetId=
{
datasetId
}
onUpdate=
{
mutate
}
/>
:
<
EmptyElement
onClick=
{
routeToDocCreate
}
/>
:
<
EmptyElement
onClick=
{
routeToDocCreate
}
/>
}
}
{
/* Show Pagination only if the total is more than the limit */
}
{
/* Show Pagination only if the total is more than the limit */
}
...
...
web/app/components/datasets/documents/list.tsx
View file @
1d860cd8
...
@@ -252,8 +252,9 @@ const renderCount = (count: number | undefined) => {
...
@@ -252,8 +252,9 @@ const renderCount = (count: number | undefined) => {
return
`
${
formatNumber
((
count
/
1000
).
toFixed
(
1
))}
k`
return
`
${
formatNumber
((
count
/
1000
).
toFixed
(
1
))}
k`
}
}
type
LocalDoc
=
SimpleDocumentDetail
&
{
percent
?:
number
}
type
IDocumentListProps
=
{
type
IDocumentListProps
=
{
documents
:
(
SimpleDocumentDetail
&
{
percent
:
number
})
[]
documents
:
LocalDoc
[]
datasetId
:
string
datasetId
:
string
onUpdate
:
()
=>
void
onUpdate
:
()
=>
void
}
}
...
@@ -264,7 +265,7 @@ type IDocumentListProps = {
...
@@ -264,7 +265,7 @@ type IDocumentListProps = {
const
DocumentList
:
FC
<
IDocumentListProps
>
=
({
documents
=
[],
datasetId
,
onUpdate
})
=>
{
const
DocumentList
:
FC
<
IDocumentListProps
>
=
({
documents
=
[],
datasetId
,
onUpdate
})
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
router
=
useRouter
()
const
router
=
useRouter
()
const
[
localDocs
,
setLocalDocs
]
=
useState
<
(
SimpleDocumentDetail
&
{
percent
:
number
})
[]
>
(
documents
)
const
[
localDocs
,
setLocalDocs
]
=
useState
<
LocalDoc
[]
>
(
documents
)
const
[
enableSort
,
setEnableSort
]
=
useState
(
false
)
const
[
enableSort
,
setEnableSort
]
=
useState
(
false
)
useEffect
(()
=>
{
useEffect
(()
=>
{
...
@@ -331,7 +332,7 @@ const DocumentList: FC<IDocumentListProps> = ({ documents = [], datasetId, onUpd
...
@@ -331,7 +332,7 @@ const DocumentList: FC<IDocumentListProps> = ({ documents = [], datasetId, onUpd
<
td
>
<
td
>
{
{
[
'indexing'
,
'splitting'
,
'parsing'
,
'cleaning'
].
includes
(
doc
.
indexing_status
)
[
'indexing'
,
'splitting'
,
'parsing'
,
'cleaning'
].
includes
(
doc
.
indexing_status
)
?
<
ProgressBar
percent=
{
doc
.
percent
}
/>
?
<
ProgressBar
percent=
{
doc
.
percent
||
0
}
/>
:
<
StatusItem
status=
{
doc
.
display_status
}
/>
:
<
StatusItem
status=
{
doc
.
display_status
}
/>
}
}
</
td
>
</
td
>
...
...
web/models/datasets.ts
View file @
1d860cd8
...
@@ -146,6 +146,8 @@ export type InitialDocumentDetail = {
...
@@ -146,6 +146,8 @@ export type InitialDocumentDetail = {
created_at
:
number
created_at
:
number
indexing_status
:
DocumentIndexingStatus
indexing_status
:
DocumentIndexingStatus
display_status
:
DocumentDisplayStatus
display_status
:
DocumentDisplayStatus
completed_segments
?:
number
total_segments
?:
number
}
}
export
type
SimpleDocumentDetail
=
InitialDocumentDetail
&
{
export
type
SimpleDocumentDetail
=
InitialDocumentDetail
&
{
...
...
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