From 7b144d3ebffbde2cc346ec4cc13c295e4e4a2471 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 6 Mar 2025 11:49:27 +0800 Subject: [PATCH] fix: add value problems --- .../components/datasets/documents/list.tsx | 2 +- .../metadata/edit-metadata-batch/modal.tsx | 4 ++-- .../hooks/use-batch-edit-document-metadata.ts | 22 +++++++++---------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/web/app/components/datasets/documents/list.tsx b/web/app/components/datasets/documents/list.tsx index ed286cfcf9..218cdb73b7 100644 --- a/web/app/components/datasets/documents/list.tsx +++ b/web/app/components/datasets/documents/list.tsx @@ -436,7 +436,7 @@ const DocumentList: FC = ({ handleSave, } = useBatchEditDocumentMetadata({ datasetId, - list: documents.filter(item => selectedIds.includes(item.id)), + docList: documents.filter(item => selectedIds.includes(item.id)), }) useEffect(() => { diff --git a/web/app/components/datasets/metadata/edit-metadata-batch/modal.tsx b/web/app/components/datasets/metadata/edit-metadata-batch/modal.tsx index dd4afcaca0..7afbc90b1a 100644 --- a/web/app/components/datasets/metadata/edit-metadata-batch/modal.tsx +++ b/web/app/components/datasets/metadata/edit-metadata-batch/modal.tsx @@ -25,7 +25,7 @@ type Props = { datasetId: string, documentNum: number list: MetadataItemInBatchEdit[] - onSave: (list: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => void + onSave: (editedList: MetadataItemInBatchEdit[], addedList: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => void onHide: () => void onShowManage: () => void } @@ -109,7 +109,7 @@ const EditMetadataBatchModal: FC = ({ const [isApplyToAllSelectDocument, setIsApplyToAllSelectDocument] = useState(false) 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]) return ( { const [isShowEditModal, { setTrue: showEditModal, @@ -21,7 +21,7 @@ const useBatchEditDocumentMetadata = ({ const metaDataList: MetadataItemWithValue[][] = (() => { const res: MetadataItemWithValue[][] = [] - list.forEach((item) => { + docList.forEach((item) => { if (item.doc_metadata) { res.push(item.doc_metadata.filter(item => item.id !== 'built-in')) return @@ -65,8 +65,7 @@ const useBatchEditDocumentMetadata = ({ return res }, [metaDataList]) - const formateToBackendList = (editedList: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => { - // TODO: add list should be not in updateList; and updated not refresh cash + const formateToBackendList = (editedList: MetadataItemInBatchEdit[], addedList: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => { const updatedList = editedList.filter((editedItem) => { const originalItem = originalList.find(i => i.id === editedItem.id) if (!originalItem) // added item @@ -82,14 +81,13 @@ const useBatchEditDocumentMetadata = ({ return false }) - const res: MetadataBatchEditToServer = list.map((item, i) => { + const res: MetadataBatchEditToServer = docList.map((item, i) => { // the new metadata will override the old one - const oldMetadataList = item.doc_metadata || metaDataList[i] - let newMetadataList: MetadataItemWithValue[] = oldMetadataList + const oldMetadataList = metaDataList[i] + let newMetadataList: MetadataItemWithValue[] = [...oldMetadataList, ...addedList] .filter((item) => { - return item.id !== 'built-in' && !removedList.find(removedItem => removedItem.id === item.id) + return !removedList.find(removedItem => removedItem.id === item.id) }) - .map(item => ({ id: item.id, name: item.name, @@ -121,8 +119,8 @@ const useBatchEditDocumentMetadata = ({ const { mutate } = useBatchUpdateDocMetadata() - const handleSave = (editedList: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => { - const backendList = formateToBackendList(editedList, isApplyToAllSelectDocument) + const handleSave = (editedList: MetadataItemInBatchEdit[], addedList: MetadataItemInBatchEdit[], isApplyToAllSelectDocument: boolean) => { + const backendList = formateToBackendList(editedList, addedList, isApplyToAllSelectDocument) mutate({ dataset_id: datasetId, metadata_list: backendList,