fix: add value problems
This commit is contained in:
parent
4ef2816271
commit
7b144d3ebf
@ -436,7 +436,7 @@ const DocumentList: FC<IDocumentListProps> = ({
|
|||||||
handleSave,
|
handleSave,
|
||||||
} = useBatchEditDocumentMetadata({
|
} = useBatchEditDocumentMetadata({
|
||||||
datasetId,
|
datasetId,
|
||||||
list: documents.filter(item => selectedIds.includes(item.id)),
|
docList: documents.filter(item => selectedIds.includes(item.id)),
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -25,7 +25,7 @@ type Props = {
|
|||||||
datasetId: string,
|
datasetId: string,
|
||||||
documentNum: number
|
documentNum: number
|
||||||
list: MetadataItemInBatchEdit[]
|
list: MetadataItemInBatchEdit[]
|
||||||
onSave: (list: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => void
|
onSave: (editedList: MetadataItemInBatchEdit[], addedList: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => void
|
||||||
onHide: () => void
|
onHide: () => void
|
||||||
onShowManage: () => void
|
onShowManage: () => void
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ const EditMetadataBatchModal: FC<Props> = ({
|
|||||||
const [isApplyToAllSelectDocument, setIsApplyToAllSelectDocument] = useState(false)
|
const [isApplyToAllSelectDocument, setIsApplyToAllSelectDocument] = useState(false)
|
||||||
|
|
||||||
const handleSave = useCallback(() => {
|
const handleSave = useCallback(() => {
|
||||||
onSave([...templeList.filter(item => item.updateType !== UpdateType.delete), ...addedList], isApplyToAllSelectDocument)
|
onSave(templeList.filter(item => item.updateType !== UpdateType.delete), addedList, isApplyToAllSelectDocument)
|
||||||
}, [templeList, addedList, isApplyToAllSelectDocument, onSave])
|
}, [templeList, addedList, isApplyToAllSelectDocument, onSave])
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
|
@ -7,12 +7,12 @@ import { useBatchUpdateDocMetadata } from '@/service/knowledge/use-metadata'
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
datasetId: string
|
datasetId: string
|
||||||
list: SimpleDocumentDetail[]
|
docList: SimpleDocumentDetail[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const useBatchEditDocumentMetadata = ({
|
const useBatchEditDocumentMetadata = ({
|
||||||
datasetId,
|
datasetId,
|
||||||
list,
|
docList,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const [isShowEditModal, {
|
const [isShowEditModal, {
|
||||||
setTrue: showEditModal,
|
setTrue: showEditModal,
|
||||||
@ -21,7 +21,7 @@ const useBatchEditDocumentMetadata = ({
|
|||||||
|
|
||||||
const metaDataList: MetadataItemWithValue[][] = (() => {
|
const metaDataList: MetadataItemWithValue[][] = (() => {
|
||||||
const res: MetadataItemWithValue[][] = []
|
const res: MetadataItemWithValue[][] = []
|
||||||
list.forEach((item) => {
|
docList.forEach((item) => {
|
||||||
if (item.doc_metadata) {
|
if (item.doc_metadata) {
|
||||||
res.push(item.doc_metadata.filter(item => item.id !== 'built-in'))
|
res.push(item.doc_metadata.filter(item => item.id !== 'built-in'))
|
||||||
return
|
return
|
||||||
@ -65,8 +65,7 @@ const useBatchEditDocumentMetadata = ({
|
|||||||
return res
|
return res
|
||||||
}, [metaDataList])
|
}, [metaDataList])
|
||||||
|
|
||||||
const formateToBackendList = (editedList: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => {
|
const formateToBackendList = (editedList: MetadataItemInBatchEdit[], addedList: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => {
|
||||||
// TODO: add list should be not in updateList; and updated not refresh cash
|
|
||||||
const updatedList = editedList.filter((editedItem) => {
|
const updatedList = editedList.filter((editedItem) => {
|
||||||
const originalItem = originalList.find(i => i.id === editedItem.id)
|
const originalItem = originalList.find(i => i.id === editedItem.id)
|
||||||
if (!originalItem) // added item
|
if (!originalItem) // added item
|
||||||
@ -82,14 +81,13 @@ const useBatchEditDocumentMetadata = ({
|
|||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
const res: MetadataBatchEditToServer = list.map((item, i) => {
|
const res: MetadataBatchEditToServer = docList.map((item, i) => {
|
||||||
// the new metadata will override the old one
|
// the new metadata will override the old one
|
||||||
const oldMetadataList = item.doc_metadata || metaDataList[i]
|
const oldMetadataList = metaDataList[i]
|
||||||
let newMetadataList: MetadataItemWithValue[] = oldMetadataList
|
let newMetadataList: MetadataItemWithValue[] = [...oldMetadataList, ...addedList]
|
||||||
.filter((item) => {
|
.filter((item) => {
|
||||||
return item.id !== 'built-in' && !removedList.find(removedItem => removedItem.id === item.id)
|
return !removedList.find(removedItem => removedItem.id === item.id)
|
||||||
})
|
})
|
||||||
|
|
||||||
.map(item => ({
|
.map(item => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
@ -121,8 +119,8 @@ const useBatchEditDocumentMetadata = ({
|
|||||||
|
|
||||||
const { mutate } = useBatchUpdateDocMetadata()
|
const { mutate } = useBatchUpdateDocMetadata()
|
||||||
|
|
||||||
const handleSave = (editedList: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => {
|
const handleSave = (editedList: MetadataItemInBatchEdit[], addedList: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => {
|
||||||
const backendList = formateToBackendList(editedList, isApplyToAllSelectDocument)
|
const backendList = formateToBackendList(editedList, addedList, isApplyToAllSelectDocument)
|
||||||
mutate({
|
mutate({
|
||||||
dataset_id: datasetId,
|
dataset_id: datasetId,
|
||||||
metadata_list: backendList,
|
metadata_list: backendList,
|
||||||
|
Loading…
Reference in New Issue
Block a user