chore: original list
This commit is contained in:
parent
a8c9201c4a
commit
a46d4afa75
@ -426,7 +426,9 @@ const DocumentList: FC<IDocumentListProps> = ({
|
||||
const isQAMode = chunkingMode === ChunkingMode.qa
|
||||
const [localDocs, setLocalDocs] = useState<LocalDoc[]>(documents)
|
||||
const [enableSort, setEnableSort] = useState(true)
|
||||
const { isShowEditModal, showEditModal, hideEditModal } = useBatchEditDocumentMetadata()
|
||||
const { isShowEditModal, showEditModal, hideEditModal } = useBatchEditDocumentMetadata({
|
||||
list: documents,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
setLocalDocs(documents)
|
||||
|
||||
@ -1,15 +1,84 @@
|
||||
import { useBoolean } from 'ahooks'
|
||||
import type { MetadataItemInBatchEdit, MetadataItemWithValue } from '../types'
|
||||
import { DataType } from '../types'
|
||||
import type { SimpleDocumentDetail } from '@/models/datasets'
|
||||
import { useMemo } from 'react'
|
||||
|
||||
const useBatchEditDocumentMetadata = () => {
|
||||
// compare
|
||||
// original and edited list.
|
||||
// Use the edited list, except the original and edited value is both multiple value.
|
||||
const testMetadataList: MetadataItemWithValue[][] = [
|
||||
[
|
||||
{ id: 'str-same-value', name: 'name', type: DataType.string, value: 'Joel' },
|
||||
{ id: 'num', name: 'age', type: DataType.number, value: 10 },
|
||||
{ id: 'str-with-different-value', name: 'hobby', type: DataType.string, value: 'bbb' },
|
||||
],
|
||||
[
|
||||
{ id: 'str-same-value', name: 'name', type: DataType.string, value: 'Joel' },
|
||||
{ id: 'str-with-different-value', name: 'hobby', type: DataType.string, value: 'ccc' },
|
||||
],
|
||||
]
|
||||
|
||||
type Props = {
|
||||
list: SimpleDocumentDetail[]
|
||||
}
|
||||
|
||||
const useBatchEditDocumentMetadata = ({
|
||||
list,
|
||||
}: Props) => {
|
||||
const [isShowEditModal, {
|
||||
setTrue: showEditModal,
|
||||
setFalse: hideEditModal,
|
||||
}] = useBoolean(false)
|
||||
|
||||
const originalList = useMemo(() => {
|
||||
const idNameValue: Record<string, { value: string | number | null, isMultipleValue: boolean }> = {}
|
||||
// TODO: mock backend data struct
|
||||
// const metaDataList: MetadataItemWithValue[][] = list.map((item, i) => {
|
||||
// if (item.doc_metadata)
|
||||
// return item.doc_metadata
|
||||
|
||||
// return testMetadataList[i] || []
|
||||
// })
|
||||
const metaDataList = testMetadataList
|
||||
const res: MetadataItemInBatchEdit[] = []
|
||||
metaDataList.forEach((metaData) => {
|
||||
metaData.forEach((item) => {
|
||||
// if (item.value === 'ccc') {
|
||||
// debugger
|
||||
// }
|
||||
if (idNameValue[item.id]?.isMultipleValue)
|
||||
return
|
||||
const itemInRes = res.find(i => i.id === item.id)
|
||||
if (!idNameValue[item.id]) {
|
||||
idNameValue[item.id] = {
|
||||
value: item.value,
|
||||
isMultipleValue: false,
|
||||
}
|
||||
}
|
||||
|
||||
if (itemInRes && itemInRes.value !== item.value) {
|
||||
idNameValue[item.id].isMultipleValue = true
|
||||
itemInRes.isMultipleValue = true
|
||||
itemInRes.value = null
|
||||
return
|
||||
}
|
||||
if (!itemInRes) {
|
||||
res.push({
|
||||
...item,
|
||||
isMultipleValue: false,
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
return res
|
||||
}, [list])
|
||||
|
||||
return {
|
||||
isShowEditModal,
|
||||
showEditModal,
|
||||
hideEditModal,
|
||||
originalList,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -14,17 +14,22 @@ export type MetadataItem = BuiltInMetadataItem & {
|
||||
}
|
||||
|
||||
export type MetadataItemWithValue = MetadataItem & {
|
||||
value: string | number
|
||||
value: string | number | null
|
||||
}
|
||||
|
||||
export type MetadataItemWithValueLength = MetadataItem & {
|
||||
use_count: number
|
||||
}
|
||||
|
||||
export type MetadataItemInBatchEdit = MetadataItemWithValue & {
|
||||
isMultipleValue?: boolean
|
||||
}
|
||||
|
||||
export enum UpdateType {
|
||||
changeValue = 'changeValue',
|
||||
delete = 'delete',
|
||||
}
|
||||
|
||||
export type MetadataItemWithEdit = MetadataItemWithValue & {
|
||||
isMultipleValue?: boolean
|
||||
isUpdated?: boolean
|
||||
|
||||
@ -3,6 +3,7 @@ import type { AppIconType, AppMode, RetrievalConfig } from '@/types/app'
|
||||
import type { Tag } from '@/app/components/base/tag-management/constant'
|
||||
import type { IndexingType } from '@/app/components/datasets/create/step-two'
|
||||
import type { MetadataFilteringVariableType } from '@/app/components/workflow/nodes/knowledge-retrieval/types'
|
||||
import type { MetadataItemWithValue } from '@/app/components/datasets/metadata/types'
|
||||
|
||||
export enum DataSourceType {
|
||||
FILE = 'upload_file',
|
||||
@ -324,6 +325,7 @@ export type SimpleDocumentDetail = InitialDocumentDetail & {
|
||||
extension: string
|
||||
}
|
||||
}
|
||||
doc_metadata?: MetadataItemWithValue[]
|
||||
}
|
||||
|
||||
export type DocumentListResponse = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user