diff --git a/client/src/api/index.ts b/client/src/api/index.ts index db8f67c3d53d..bd17dc514d52 100644 --- a/client/src/api/index.ts +++ b/client/src/api/index.ts @@ -232,7 +232,7 @@ export function isHistoryItem(item: object): item is HistoryItemSummary { return item && "history_content_type" in item; } -export function isCollectionItem(item: object): item is DCESummary { +export function isDCE(item: object): item is DCESummary { return item && "element_type" in item; } diff --git a/client/src/components/History/CurrentHistory/HistoryPanel.vue b/client/src/components/History/CurrentHistory/HistoryPanel.vue index deb96c456c88..432665fa6d4f 100644 --- a/client/src/components/History/CurrentHistory/HistoryPanel.vue +++ b/client/src/components/History/CurrentHistory/HistoryPanel.vue @@ -4,10 +4,11 @@ import { storeToRefs } from "pinia"; import { computed, onMounted, type Ref, ref, set as VueSet, unref, watch } from "vue"; import { - type HDAObject, + type DCESummary, type HistoryItemSummary, type HistorySummaryExtended, isDatasetElement, + isDCE, isHistoryItem, userOwnsHistory, } from "@/api"; @@ -61,7 +62,7 @@ interface Props { isMultiViewItem?: boolean; } -type DraggableHistoryItem = HistoryItemSummary | HDAObject; +type DraggableHistoryItem = HistoryItemSummary | (DCESummary & { history_id: string }); type ContentItemRef = Record | null>>; @@ -237,10 +238,8 @@ function getDragData() { const dragItems = eventStore.getDragItems(); // Filter out any non-history items const historyItems = dragItems?.map((item: any) => { - if (isHistoryItem(item)) { + if (isHistoryItem(item) || isDCE(item)) { return item; - } else if (isDatasetElement(item)) { - return item.object; } }) as DraggableHistoryItem[]; const historyId = historyItems?.[0]?.history_id; @@ -397,15 +396,32 @@ async function onDrop() { // iterate over the data array and copy each item to the current history for (const item of data) { let dataSource: HistoryContentsArgs["source"]; - const type = item.history_content_type as "dataset" | "dataset_collection" | undefined; - if (type) { - // it's a `HistoryItemSummary` - dataSource = type === "dataset" ? "hda" : "hdca"; - } else { - // it's a `HDAObject` from a collection + let type: HistoryContentsArgs["type"]; + let id: string; + if (isHistoryItem(item)) { + dataSource = item.history_content_type === "dataset" ? "hda" : "hdca"; + type = item.history_content_type; + id = item.id; + } + // TEMPORARY: fix this when DCEs are handled correctly, unify like commented out code below + else if (isDatasetElement(item) && item.object) { dataSource = "hda"; + type = "dataset"; + id = item.object.id; + } + /** TODO: Handle DCE, `DCEDataset`s work fine as they are HDAs, + * `DCECollection`s are `dataset_collection`s and need to be HDCAs... + */ + // else if (isDCE(item) && (item as DCESummary).object) { + // const collectionElement = item as DCESummary; + // dataSource = collectionElement.element_type === "dataset_collection" ? "hdca" : "hda"; // incorrect... + // type = collectionElement.element_type === "dataset_collection" ? "dataset_collection" : "dataset"; + // id = collectionElement.object.id as string; + // } + else { + throw new Error(`Invalid item type${item.element_type ? `: ${item.element_type}` : ""}`); } - await copyDataset(item.id, props.history.id, type, dataSource); + await copyDataset(id, props.history.id, type, dataSource); if (dataSource === "hda") { datasetCount++; diff --git a/client/src/utils/setDrag.ts b/client/src/utils/setDrag.ts index ef4c4e87df49..f6d1023c9241 100644 --- a/client/src/utils/setDrag.ts +++ b/client/src/utils/setDrag.ts @@ -1,7 +1,7 @@ /** * Helper to configure datatransfer for drag & drop operations */ -import { type DCESummary, isCollectionItem } from "@/api"; +import { type DCESummary, isDCE } from "@/api"; import { type EventData, useEventStore } from "@/stores/eventStore"; type NamedDCESummary = DCESummary & { name: string }; @@ -50,7 +50,7 @@ export function setItemDragstart( } function setCollectionElementName(obj: T) { - if (isCollectionItem(obj as object)) { + if (isDCE(obj as object)) { obj["name"] = obj.element_identifier; } }