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..eb2017ef1947 100644 --- a/client/src/components/History/CurrentHistory/HistoryPanel.vue +++ b/client/src/components/History/CurrentHistory/HistoryPanel.vue @@ -4,7 +4,7 @@ import { storeToRefs } from "pinia"; import { computed, onMounted, type Ref, ref, set as VueSet, unref, watch } from "vue"; import { - type HDAObject, + type DCEDataset, type HistoryItemSummary, type HistorySummaryExtended, isDatasetElement, @@ -61,7 +61,7 @@ interface Props { isMultiViewItem?: boolean; } -type DraggableHistoryItem = HistoryItemSummary | HDAObject; +type DraggableHistoryItem = HistoryItemSummary | DCEDataset; // TODO: DCESummary instead of DCEDataset type ContentItemRef = Record | null>>; @@ -236,14 +236,17 @@ function getDragData() { const eventStore = useEventStore(); const dragItems = eventStore.getDragItems(); // Filter out any non-history items - const historyItems = dragItems?.map((item: any) => { - if (isHistoryItem(item)) { - return item; - } else if (isDatasetElement(item)) { - return item.object; - } - }) as DraggableHistoryItem[]; - const historyId = historyItems?.[0]?.history_id; + // TODO: `isDCE` instead of `isDatasetElement` + const historyItems = dragItems?.filter( + (item: any) => isHistoryItem(item) || isDatasetElement(item) + ) as DraggableHistoryItem[]; + + // TODO: handle historyId === null || historyItems.length === 0 + const historyId = historyItems[0] + ? isHistoryItem(historyItems[0]) + ? historyItems[0].history_id + : historyItems[0].object?.history_id + : null; return { data: historyItems, sameHistory: historyId === props.history.id, multiple: historyItems?.length > 1 }; } @@ -397,15 +400,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; } }