Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collection copy operation in dataset list #18724

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions client/src/api/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,26 @@ export async function purgeDataset(datasetId: string) {
return data;
}

type CopyDatasetParamsType = GalaxyApiPaths["/api/histories/{history_id}/contents/{type}s"]["post"]["parameters"];
type CopyDatasetBodyType = components["schemas"]["CreateHistoryContentPayload"];
type CopyContentParamsType = GalaxyApiPaths["/api/histories/{history_id}/contents/{type}s"]["post"]["parameters"];
type CopyContentBodyType = components["schemas"]["CreateHistoryContentPayload"];

export async function copyDataset(
datasetId: CopyDatasetBodyType["content"],
historyId: CopyDatasetParamsType["path"]["history_id"],
type: CopyDatasetParamsType["path"]["type"] = "dataset",
source: CopyDatasetBodyType["source"] = "hda"
export async function copyContent(
contentId: CopyContentBodyType["content"],
historyId: CopyContentParamsType["path"]["history_id"],
type: CopyContentParamsType["path"]["type"] = "dataset",
source: CopyContentBodyType["source"] = null
) {
// match source from type unless explicitly provided
if (source === null) {
source = type === "dataset" ? "hda" : "hdca";
}
const { data, error } = await GalaxyApi().POST("/api/histories/{history_id}/contents/{type}s", {
params: {
path: { history_id: historyId, type },
},
body: {
source,
content: datasetId,
content: contentId,
// TODO: Investigate. These should be optional, but the API requires explicit null values?
type,
copy_elements: null,
Expand Down
19 changes: 8 additions & 11 deletions client/src/components/Dataset/DatasetList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { BAlert, BTable } from "bootstrap-vue";
import { storeToRefs } from "pinia";
import { computed, onMounted, ref } from "vue";

import { GalaxyApi, type HDASummary } from "@/api";
import { copyDataset } from "@/api/datasets";
import { GalaxyApi, type HistoryItemSummary } from "@/api";
import { copyContent } from "@/api/datasets";
import { updateTags } from "@/api/tags";
import { useHistoryStore } from "@/stores/historyStore";
import { rethrowSimple } from "@/utils/simple-error";
Expand All @@ -26,7 +26,7 @@ const message = ref("");
const loading = ref(true);
const sortDesc = ref(true);
const sortBy = ref("update_time");
const rows = ref<HDASummary[]>([]);
const rows = ref<HistoryItemSummary[]>([]);
const messageVariant = ref("danger");
const fields = ref([
{
Expand Down Expand Up @@ -86,7 +86,7 @@ async function load(concat = false) {
rethrowSimple(error);
}

const datasets = data as HDASummary[];
const datasets = data as HistoryItemSummary[];

if (concat) {
rows.value = rows.value.concat(datasets);
Expand All @@ -100,23 +100,20 @@ async function load(concat = false) {
}
}

async function onCopyDataset(item: HDASummary) {
async function onCopyContent(item: HistoryItemSummary) {
const dataset_id = item.id;

try {
if (!currentHistoryId.value) {
throw new Error("No current history found.");
}

await copyDataset(dataset_id, currentHistoryId.value);

await copyContent(dataset_id, currentHistoryId.value, item.history_content_type);
historyStore.loadCurrentHistory();
} catch (error: any) {
onError(error);
}
}

async function onShowDataset(item: HDASummary) {
async function onShowDataset(item: HistoryItemSummary) {
const { history_id } = item;
const filters = {
deleted: item.deleted,
Expand Down Expand Up @@ -198,7 +195,7 @@ onMounted(() => {
:items="rows"
@sort-changed="onSort">
<template v-slot:cell(name)="row">
<DatasetName :item="row.item" @showDataset="onShowDataset" @copyDataset="onCopyDataset" />
<DatasetName :item="row.item" @showDataset="onShowDataset" @copyDataset="onCopyContent" />
</template>

<template v-slot:cell(history_id)="row">
Expand Down
5 changes: 2 additions & 3 deletions client/src/components/History/CurrentHistory/HistoryPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { storeToRefs } from "pinia";
import { computed, onMounted, type Ref, ref, set as VueSet, unref, watch } from "vue";

import { type HistoryItemSummary, type HistorySummaryExtended, isHistoryItem, userOwnsHistory } from "@/api";
import { copyDataset } from "@/api/datasets";
import { copyContent } from "@/api/datasets";
import ExpandedItems from "@/components/History/Content/ExpandedItems";
import SelectedItems from "@/components/History/Content/SelectedItems";
import { HistoryFilters } from "@/components/History/HistoryFilters";
Expand Down Expand Up @@ -422,8 +422,7 @@ async function onDrop() {
try {
// iterate over the data array and copy each item to the current history
for (const item of data) {
const dataSource = item.history_content_type === "dataset" ? "hda" : "hdca";
await copyDataset(item.id, props.history.id, item.history_content_type, dataSource);
await copyContent(item.id, props.history.id, item.history_content_type);

if (item.history_content_type === "dataset") {
datasetCount++;
Expand Down
5 changes: 2 additions & 3 deletions client/src/components/History/Multiple/MultipleViewList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { computed, type Ref, ref } from "vue";
import VirtualList from "vue-virtual-scroll-list";

import { type HistoryItemSummary, isHistoryItem } from "@/api";
import { copyDataset } from "@/api/datasets";
import { copyContent } from "@/api/datasets";
import { useAnimationFrameResizeObserver } from "@/composables/sensors/animationFrameResizeObserver";
import { useAnimationFrameScroll } from "@/composables/sensors/animationFrameScroll";
import { Toast } from "@/composables/toast";
Expand Down Expand Up @@ -90,8 +90,7 @@ async function onDrop(evt: any) {
if (currentHistoryId) {
// iterate over the data array and copy each item to the new history
for (const item of historyItems) {
const dataSource = item.history_content_type === "dataset" ? "hda" : "hdca";
await copyDataset(item.id, currentHistoryId, item.history_content_type, dataSource)
await copyContent(item.id, currentHistoryId, item.history_content_type)
.then(() => {
if (item.history_content_type === "dataset") {
datasetCount++;
Expand Down
Loading