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
9df0dced
Unverified
Commit
9df0dced
authored
Sep 22, 2023
by
Joel
Committed by
GitHub
Sep 22, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: dataset eslint error (#1221)
parent
724e0537
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
83 deletions
+93
-83
index.tsx
.../components/datasets/documents/detail/embedding/index.tsx
+2
-2
index.tsx
...p/components/datasets/documents/detail/metadata/index.tsx
+89
-79
hit-detail.tsx
web/app/components/datasets/hit-testing/hit-detail.tsx
+2
-2
No files found.
web/app/components/datasets/documents/detail/embedding/index.tsx
View file @
9df0dced
...
@@ -291,8 +291,8 @@ const EmbeddingDetail: FC<Props> = ({ detail, stopPosition = 'top', datasetId: d
...
@@ -291,8 +291,8 @@ const EmbeddingDetail: FC<Props> = ({ detail, stopPosition = 'top', datasetId: d
<
Divider
/>
<
Divider
/>
<
div
className=
{
s
.
previewTip
}
>
{
t
(
'datasetDocuments.embedding.previewTip'
)
}
</
div
>
<
div
className=
{
s
.
previewTip
}
>
{
t
(
'datasetDocuments.embedding.previewTip'
)
}
</
div
>
<
div
className=
{
style
.
cardWrapper
}
>
<
div
className=
{
style
.
cardWrapper
}
>
{
[
1
,
2
,
3
].
map
(
v
=>
(
{
[
1
,
2
,
3
].
map
(
(
v
,
index
)
=>
(
<
SegmentCard
loading=
{
true
}
detail=
{
{
position
:
v
}
as
any
}
/>
<
SegmentCard
key=
{
index
}
loading=
{
true
}
detail=
{
{
position
:
v
}
as
any
}
/>
))
}
))
}
</
div
>
</
div
>
</>
}
</>
}
...
...
web/app/components/datasets/documents/detail/metadata/index.tsx
View file @
9df0dced
'use client'
'use client'
import
type
{
FC
}
from
'react'
import
type
{
FC
}
from
'react'
import
React
,
{
use
State
,
useEffect
}
from
'react'
import
React
,
{
use
Effect
,
useState
}
from
'react'
import
{
PencilIcon
}
from
'@heroicons/react/24/outline'
import
{
PencilIcon
}
from
'@heroicons/react/24/outline'
import
{
useTranslation
}
from
'react-i18next'
import
{
useTranslation
}
from
'react-i18next'
import
{
useContext
}
from
'use-context-selector'
import
{
useContext
}
from
'use-context-selector'
import
{
get
}
from
'lodash-es'
import
{
get
}
from
'lodash-es'
import
cn
from
'classnames'
import
cn
from
'classnames'
import
{
DocumentContext
}
from
'../index'
import
s
from
'./style.module.css'
import
Input
from
'@/app/components/base/input'
import
Input
from
'@/app/components/base/input'
import
Button
from
'@/app/components/base/button'
import
Button
from
'@/app/components/base/button'
import
Tooltip
from
'@/app/components/base/tooltip'
import
Tooltip
from
'@/app/components/base/tooltip'
...
@@ -18,12 +20,10 @@ import AutoHeightTextarea from '@/app/components/base/auto-height-textarea'
...
@@ -18,12 +20,10 @@ import AutoHeightTextarea from '@/app/components/base/auto-height-textarea'
import
{
asyncRunSafe
,
getTextWidthWithCanvas
}
from
'@/utils'
import
{
asyncRunSafe
,
getTextWidthWithCanvas
}
from
'@/utils'
import
{
modifyDocMetadata
}
from
'@/service/datasets'
import
{
modifyDocMetadata
}
from
'@/service/datasets'
import
type
{
CommonResponse
}
from
'@/models/common'
import
type
{
CommonResponse
}
from
'@/models/common'
import
type
{
FullDocumentDetail
,
DocType
}
from
'@/models/datasets'
import
type
{
DocType
,
FullDocumentDetail
}
from
'@/models/datasets'
import
{
CUSTOMIZABLE_DOC_TYPES
}
from
'@/models/datasets'
import
{
CUSTOMIZABLE_DOC_TYPES
}
from
'@/models/datasets'
import
type
{
metadataType
,
inputType
}
from
'@/hooks/use-metadata'
import
type
{
inputType
,
metadataType
}
from
'@/hooks/use-metadata'
import
{
useMetadataMap
,
useLanguages
,
useBookCategories
,
usePersonalDocCategories
,
useBusinessDocCategories
}
from
'@/hooks/use-metadata'
import
{
useBookCategories
,
useBusinessDocCategories
,
useLanguages
,
useMetadataMap
,
usePersonalDocCategories
}
from
'@/hooks/use-metadata'
import
{
DocumentContext
}
from
'../index'
import
s
from
'./style.module.css'
const
map2Options
=
(
map
:
{
[
key
:
string
]:
string
})
=>
{
const
map2Options
=
(
map
:
{
[
key
:
string
]:
string
})
=>
{
return
Object
.
keys
(
map
).
map
(
key
=>
({
value
:
key
,
name
:
map
[
key
]
}))
return
Object
.
keys
(
map
).
map
(
key
=>
({
value
:
key
,
name
:
map
[
key
]
}))
...
@@ -48,7 +48,7 @@ export const FieldInfo: FC<IFieldInfoProps> = ({
...
@@ -48,7 +48,7 @@ export const FieldInfo: FC<IFieldInfoProps> = ({
showEdit
=
false
,
showEdit
=
false
,
inputType
=
'input'
,
inputType
=
'input'
,
selectOptions
=
[],
selectOptions
=
[],
onUpdate
onUpdate
,
})
=>
{
})
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
textNeedWrap
=
getTextWidthWithCanvas
(
displayedValue
)
>
190
const
textNeedWrap
=
getTextWidthWithCanvas
(
displayedValue
)
>
190
...
@@ -56,7 +56,7 @@ export const FieldInfo: FC<IFieldInfoProps> = ({
...
@@ -56,7 +56,7 @@ export const FieldInfo: FC<IFieldInfoProps> = ({
const
readAlignTop
=
!
showEdit
&&
textNeedWrap
const
readAlignTop
=
!
showEdit
&&
textNeedWrap
return
(
return
(
<
div
className=
{
cn
(
s
.
fieldInfo
,
editAlignTop
&&
`!items-start`
,
readAlignTop
&&
'!items-start pt-1'
)
}
>
<
div
className=
{
cn
(
s
.
fieldInfo
,
editAlignTop
&&
'!items-start'
,
readAlignTop
&&
'!items-start pt-1'
)
}
>
<
div
className=
{
cn
(
s
.
label
,
editAlignTop
&&
'pt-1'
)
}
>
{
label
}
</
div
>
<
div
className=
{
cn
(
s
.
label
,
editAlignTop
&&
'pt-1'
)
}
>
{
label
}
</
div
>
<
div
className=
{
s
.
value
}
>
<
div
className=
{
s
.
value
}
>
{
!
showEdit
{
!
showEdit
...
@@ -132,13 +132,15 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
...
@@ -132,13 +132,15 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
const
[
editStatus
,
setEditStatus
]
=
useState
(
!
doc_type
)
// if no documentType, in editing status by default
const
[
editStatus
,
setEditStatus
]
=
useState
(
!
doc_type
)
// if no documentType, in editing status by default
// the initial values are according to the documentType
// the initial values are according to the documentType
const
[
metadataParams
,
setMetadataParams
]
=
useState
<
{
const
[
metadataParams
,
setMetadataParams
]
=
useState
<
{
documentType
?:
DocType
|
''
;
documentType
?:
DocType
|
''
metadata
:
{
[
key
:
string
]:
string
}
metadata
:
{
[
key
:
string
]:
string
}
}
>
(
}
>
(
doc_type
?
{
doc_type
documentType
:
doc_type
,
?
{
metadata
:
doc_metadata
||
{}
documentType
:
doc_type
,
}
:
{
metadata
:
{}
})
metadata
:
doc_metadata
||
{},
}
:
{
metadata
:
{}
})
const
[
showDocTypes
,
setShowDocTypes
]
=
useState
(
!
doc_type
)
// whether show doc types
const
[
showDocTypes
,
setShowDocTypes
]
=
useState
(
!
doc_type
)
// whether show doc types
const
[
tempDocType
,
setTempDocType
]
=
useState
<
DocType
|
undefined
|
''
>
(
''
)
// for remember icon click
const
[
tempDocType
,
setTempDocType
]
=
useState
<
DocType
|
undefined
|
''
>
(
''
)
// for remember icon click
const
[
saveLoading
,
setSaveLoading
]
=
useState
(
false
)
const
[
saveLoading
,
setSaveLoading
]
=
useState
(
false
)
...
@@ -153,17 +155,18 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
...
@@ -153,17 +155,18 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
setTempDocType
(
docDetail
?.
doc_type
)
setTempDocType
(
docDetail
?.
doc_type
)
setMetadataParams
({
setMetadataParams
({
documentType
:
docDetail
?.
doc_type
,
documentType
:
docDetail
?.
doc_type
,
metadata
:
docDetail
?.
doc_metadata
||
{}
metadata
:
docDetail
?.
doc_metadata
||
{}
,
})
})
}
}
},
[
docDetail
?.
doc_type
])
},
[
docDetail
?.
doc_type
])
// confirm doc type
// confirm doc type
const
confirmDocType
=
()
=>
{
const
confirmDocType
=
()
=>
{
if
(
!
tempDocType
)
return
;
if
(
!
tempDocType
)
return
setMetadataParams
({
setMetadataParams
({
documentType
:
tempDocType
,
documentType
:
tempDocType
,
metadata
:
tempDocType
===
metadataParams
.
documentType
?
metadataParams
.
metadata
:
{}
// change doc type, clear metadata
metadata
:
tempDocType
===
metadataParams
.
documentType
?
metadataParams
.
metadata
:
{}
,
// change doc type, clear metadata
})
})
setEditStatus
(
true
)
setEditStatus
(
true
)
setShowDocTypes
(
false
)
setShowDocTypes
(
false
)
...
@@ -194,9 +197,9 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
...
@@ -194,9 +197,9 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
<
span
className=
{
s
.
changeTip
}
>
{
t
(
'datasetDocuments.metadata.docTypeSelectWarning'
)
}
</
span
>
<
span
className=
{
s
.
changeTip
}
>
{
t
(
'datasetDocuments.metadata.docTypeSelectWarning'
)
}
</
span
>
</>
}
</>
}
<
Radio
.
Group
value=
{
tempDocType
??
documentType
}
onChange=
{
setTempDocType
}
className=
{
s
.
radioGroup
}
>
<
Radio
.
Group
value=
{
tempDocType
??
documentType
}
onChange=
{
setTempDocType
}
className=
{
s
.
radioGroup
}
>
{
CUSTOMIZABLE_DOC_TYPES
.
map
((
type
)
=>
{
{
CUSTOMIZABLE_DOC_TYPES
.
map
((
type
,
index
)
=>
{
const
currValue
=
tempDocType
??
documentType
const
currValue
=
tempDocType
??
documentType
return
<
Radio
value=
{
type
}
className=
{
`${s.radio} ${currValue === type ? 'shadow-none' : ''}`
}
>
return
<
Radio
key=
{
index
}
value=
{
type
}
className=
{
`${s.radio} ${currValue === type ? 'shadow-none' : ''}`
}
>
<
IconButton
<
IconButton
type=
{
type
}
type=
{
type
}
isChecked=
{
currValue
===
type
}
isChecked=
{
currValue
===
type
}
...
@@ -223,25 +226,30 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
...
@@ -223,25 +226,30 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
// show metadata info and edit
// show metadata info and edit
const
renderFieldInfos
=
({
mainField
=
'book'
,
canEdit
}:
{
mainField
?:
metadataType
|
''
;
canEdit
?:
boolean
})
=>
{
const
renderFieldInfos
=
({
mainField
=
'book'
,
canEdit
}:
{
mainField
?:
metadataType
|
''
;
canEdit
?:
boolean
})
=>
{
if
(
!
mainField
)
return
null
if
(
!
mainField
)
return
null
const
fieldMap
=
metadataMap
[
mainField
]?.
subFieldsMap
const
fieldMap
=
metadataMap
[
mainField
]?.
subFieldsMap
const
sourceData
=
[
'originInfo'
,
'technicalParameters'
].
includes
(
mainField
)
?
docDetail
:
metadataParams
.
metadata
const
sourceData
=
[
'originInfo'
,
'technicalParameters'
].
includes
(
mainField
)
?
docDetail
:
metadataParams
.
metadata
const
getTargetMap
=
(
field
:
string
)
=>
{
const
getTargetMap
=
(
field
:
string
)
=>
{
if
(
field
===
'language'
)
return
languageMap
if
(
field
===
'language'
)
if
(
field
===
'category'
&&
mainField
===
'book'
)
{
return
languageMap
if
(
field
===
'category'
&&
mainField
===
'book'
)
return
bookCategoryMap
return
bookCategoryMap
}
if
(
field
===
'document_type'
)
{
if
(
field
===
'document_type'
)
{
if
(
mainField
===
'personal_document'
)
return
personalDocCategoryMap
if
(
mainField
===
'personal_document'
)
if
(
mainField
===
'business_document'
)
return
businessDocCategoryMap
return
personalDocCategoryMap
if
(
mainField
===
'business_document'
)
return
businessDocCategoryMap
}
}
return
{}
as
any
return
{}
as
any
}
}
const
getTargetValue
=
(
field
:
string
)
=>
{
const
getTargetValue
=
(
field
:
string
)
=>
{
const
val
=
get
(
sourceData
,
field
,
''
)
const
val
=
get
(
sourceData
,
field
,
''
)
if
(
!
val
&&
val
!==
0
)
return
'-'
if
(
!
val
&&
val
!==
0
)
return
'-'
if
(
fieldMap
[
field
]?.
inputType
===
'select'
)
if
(
fieldMap
[
field
]?.
inputType
===
'select'
)
return
getTargetMap
(
field
)[
val
]
return
getTargetMap
(
field
)[
val
]
if
(
fieldMap
[
field
]?.
render
)
if
(
fieldMap
[
field
]?.
render
)
...
@@ -286,8 +294,8 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
...
@@ -286,8 +294,8 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
documentId
,
documentId
,
body
:
{
body
:
{
doc_type
:
metadataParams
.
documentType
||
doc_type
||
''
,
doc_type
:
metadataParams
.
documentType
||
doc_type
||
''
,
doc_metadata
:
metadataParams
.
metadata
doc_metadata
:
metadataParams
.
metadata
,
}
}
,
})
as
Promise
<
CommonResponse
>
)
})
as
Promise
<
CommonResponse
>
)
if
(
!
e
)
if
(
!
e
)
notify
({
type
:
'success'
,
message
:
t
(
'common.actionMsg.modifiedSuccessfully'
)
})
notify
({
type
:
'success'
,
message
:
t
(
'common.actionMsg.modifiedSuccessfully'
)
})
...
@@ -300,62 +308,64 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
...
@@ -300,62 +308,64 @@ const Metadata: FC<IMetadataProps> = ({ docDetail, loading, onUpdate }) => {
return
(
return
(
<
div
className=
{
`${s.main} ${editStatus ? 'bg-white' : 'bg-gray-25'}`
}
>
<
div
className=
{
`${s.main} ${editStatus ? 'bg-white' : 'bg-gray-25'}`
}
>
{
loading
?
<
Loading
type=
'app'
/>
:
(
{
loading
<>
?
(<
Loading
type=
'app'
/>)
<
div
className=
{
s
.
titleWrapper
}
>
:
(
<
span
className=
{
s
.
title
}
>
{
t
(
'datasetDocuments.metadata.title'
)
}
</
span
>
<>
<
div
className=
{
s
.
titleWrapper
}
>
<
span
className=
{
s
.
title
}
>
{
t
(
'datasetDocuments.metadata.title'
)
}
</
span
>
{
!
editStatus
?
<
Button
onClick=
{
enabledEdit
}
className=
{
`${s.opBtn} ${s.opEditBtn}`
}
>
<
PencilIcon
className=
{
s
.
opIcon
}
/>
{
t
(
'common.operation.edit'
)
}
</
Button
>
:
showDocTypes
?
null
:
<
div
className=
{
s
.
opBtnWrapper
}
>
<
Button
onClick=
{
onCancel
}
className=
{
`${s.opBtn} ${s.opCancelBtn}`
}
>
{
t
(
'common.operation.cancel'
)
}
</
Button
>
<
Button
onClick=
{
onSave
}
className=
{
`${s.opBtn} ${s.opSaveBtn}`
}
type=
'primary'
loading=
{
saveLoading
}
>
{
t
(
'common.operation.save'
)
}
</
Button
>
</
div
>
}
</
div
>
{
/* show selected doc type and changing entry */
}
{
!
editStatus
{
!
editStatus
?
<
Button
onClick=
{
enabledEdit
}
className=
{
`${s.opBtn} ${s.opEditBtn}`
}
>
?
<
div
className=
{
s
.
documentTypeShow
}
>
<
PencilIcon
className=
{
s
.
opIcon
}
/>
<
TypeIcon
iconName=
{
metadataMap
[
doc_type
||
'book'
]?.
iconName
||
''
}
className=
{
s
.
iconShow
}
/>
{
t
(
'common.operation.edit'
)
}
{
metadataMap
[
doc_type
||
'book'
].
text
}
</
Button
>
</
div
>
:
showDocTypes
:
showDocTypes
?
null
?
null
:
<
div
className=
{
s
.
opBtnWrapper
}
>
:
<
div
className=
{
s
.
documentTypeShow
}
>
<
Button
onClick=
{
onCancel
}
className=
{
`${s.opBtn} ${s.opCancelBtn}`
}
>
{
t
(
'common.operation.cancel'
)
}
</
Button
>
{
metadataParams
.
documentType
&&
<>
<
Button
onClick=
{
onSave
}
<
TypeIcon
iconName=
{
metadataMap
[
metadataParams
.
documentType
||
'book'
].
iconName
||
''
}
className=
{
s
.
iconShow
}
/>
className=
{
`${s.opBtn} ${s.opSaveBtn}`
}
{
metadataMap
[
metadataParams
.
documentType
||
'book'
].
text
}
type=
'primary'
{
editStatus
&&
<
div
className=
'inline-flex items-center gap-1 ml-1'
>
loading=
{
saveLoading
}
>
{
t
(
'common.operation.save'
)
}
</
Button
>
</
div
>
}
</
div
>
{
/* show selected doc type and changing entry */
}
{
!
editStatus
?
<
div
className=
{
s
.
documentTypeShow
}
>
<
TypeIcon
iconName=
{
metadataMap
[
doc_type
||
'book'
]?.
iconName
||
''
}
className=
{
s
.
iconShow
}
/>
{
metadataMap
[
doc_type
||
'book'
].
text
}
</
div
>
:
showDocTypes
?
null
:
<
div
className=
{
s
.
documentTypeShow
}
>
{
metadataParams
.
documentType
&&
<>
<
TypeIcon
iconName=
{
metadataMap
[
metadataParams
.
documentType
||
'book'
].
iconName
||
''
}
className=
{
s
.
iconShow
}
/>
{
metadataMap
[
metadataParams
.
documentType
||
'book'
].
text
}
{
editStatus
&&
<
div
className=
'inline-flex items-center gap-1 ml-1'
>
·
·
<
div
<
div
onClick=
{
()
=>
{
setShowDocTypes
(
true
)
}
}
onClick=
{
()
=>
{
setShowDocTypes
(
true
)
}
}
className=
'cursor-pointer hover:text-[#155EEF]'
className=
'cursor-pointer hover:text-[#155EEF]'
>
>
{
t
(
'common.operation.change'
)
}
{
t
(
'common.operation.change'
)
}
</
div
>
</
div
>
</
div
>
}
</
div
>
}
</>
}
</>
}
</
div
>
</
div
>
}
}
{
(
!
doc_type
&&
showDocTypes
)
?
null
:
<
Divider
/>
}
{
(
!
doc_type
&&
showDocTypes
)
?
null
:
<
Divider
/>
}
{
showDocTypes
?
renderSelectDocType
()
:
renderFieldInfos
({
mainField
:
metadataParams
.
documentType
,
canEdit
:
editStatus
})
}
{
showDocTypes
?
renderSelectDocType
()
:
renderFieldInfos
({
mainField
:
metadataParams
.
documentType
,
canEdit
:
editStatus
})
}
{
/* show fixed fields */
}
{
/* show fixed fields */
}
<
Divider
/>
<
Divider
/>
{
renderFieldInfos
({
mainField
:
'originInfo'
,
canEdit
:
false
})
}
{
renderFieldInfos
({
mainField
:
'originInfo'
,
canEdit
:
false
})
}
<
div
className=
{
`${s.title} mt-8`
}
>
{
metadataMap
.
technicalParameters
.
text
}
</
div
>
<
div
className=
{
`${s.title} mt-8`
}
>
{
metadataMap
.
technicalParameters
.
text
}
</
div
>
<
Divider
/>
<
Divider
/>
{
renderFieldInfos
({
mainField
:
'technicalParameters'
,
canEdit
:
false
})
}
{
renderFieldInfos
({
mainField
:
'technicalParameters'
,
canEdit
:
false
})
}
</>
</>
)
}
)
}
</
div
>
</
div
>
)
)
}
}
...
...
web/app/components/datasets/hit-testing/hit-detail.tsx
View file @
9df0dced
...
@@ -89,8 +89,8 @@ const HitDetail: FC<IHitDetailProps> = ({ segInfo, vectorInfo }) => {
...
@@ -89,8 +89,8 @@ const HitDetail: FC<IHitDetailProps> = ({ segInfo, vectorInfo }) => {
<
div
className=
{
s
.
keywordWrapper
}
>
<
div
className=
{
s
.
keywordWrapper
}
>
{
!
segInfo
?.
keywords
?.
length
{
!
segInfo
?.
keywords
?.
length
?
'-'
?
'-'
:
segInfo
?.
keywords
?.
map
((
word
)
=>
{
:
segInfo
?.
keywords
?.
map
((
word
,
index
)
=>
{
return
<
div
className=
{
s
.
keyword
}
>
{
word
}
</
div
>
return
<
div
key=
{
index
}
className=
{
s
.
keyword
}
>
{
word
}
</
div
>
})
}
})
}
</
div
>
</
div
>
</
div
>
</
div
>
...
...
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