From 43f3b8fdfb24e810decb3172d7d1e4ea5ba43031 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Wed, 28 Aug 2024 10:12:14 -0500 Subject: [PATCH] move copy operation to another loop to only copy when no errors --- client/src/composables/historyDragDrop.ts | 34 ++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/client/src/composables/historyDragDrop.ts b/client/src/composables/historyDragDrop.ts index 629343eeefed..0ab2675d43a8 100644 --- a/client/src/composables/historyDragDrop.ts +++ b/client/src/composables/historyDragDrop.ts @@ -7,6 +7,11 @@ import { useEventStore } from "@/stores/eventStore"; import { useHistoryStore } from "@/stores/historyStore"; type DraggableHistoryItem = HistoryItemSummary | DCEDataset; // TODO: DCESummary instead of DCEDataset +interface HistoryItemCopyData { + dataSource: HistoryContentSource; + type: HistoryContentType; + id: string; +} export function useHistoryDragDrop(targetHistoryId?: Ref | string, createNew = false, pinHistories = false) { // convert destinationHistoryId to a ref if it's not already @@ -102,24 +107,33 @@ export function useHistoryDragDrop(targetHistoryId?: Ref | string, creat throw new Error("Destination history not found or created"); } - // iterate over the data array and copy each item to the current history + const copyableItems: HistoryItemCopyData[] = []; + // iterate over the data array and get valid copyable items for (const item of dragItems) { - let dataSource: HistoryContentSource; - let type: HistoryContentType; - let id: string; + let copyableItem: HistoryItemCopyData; if (isHistoryItem(item)) { - dataSource = item.history_content_type === "dataset" ? "hda" : "hdca"; - type = item.history_content_type; - id = item.id; + copyableItem = { + dataSource: item.history_content_type === "dataset" ? "hda" : "hdca", + type: item.history_content_type, + id: item.id, + }; } // For DCEs, only `DCEDataset`s are droppable, `DCEDatasetCollection`s are not else if (isDatasetElement(item) && item.object) { - dataSource = "hda"; - type = "dataset"; - id = item.object.id; + copyableItem = { + dataSource: "hda", + type: "dataset", + id: item.object.id, + }; } else { throw new Error(`Invalid item type${item.element_type ? `: ${item.element_type}` : ""}`); } + copyableItems.push(copyableItem); + } + + // iterate over the data array and copy each item to the current history + for (const item of copyableItems) { + const { dataSource, type, id } = item; await copyDataset(id, historyId, type, dataSource); if (dataSource === "hda") {