Skip to content

Commit

Permalink
use confirmation dialogue to still allow empty collection creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedhamidawan committed Dec 4, 2024
1 parent ae0ff75 commit 1c9e972
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
15 changes: 13 additions & 2 deletions client/src/components/Collections/ListCollectionCreator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { computed, ref, watch } from "vue";
import draggable from "vuedraggable";
import type { HDASummary, HistoryItemSummary } from "@/api";
import { useConfirmDialog } from "@/composables/confirmDialog";
import { Toast } from "@/composables/toast";
import STATES from "@/mvc/dataset/states";
import { useDatatypesMapperStore } from "@/stores/datatypesMapperStore";
Expand Down Expand Up @@ -228,14 +229,24 @@ function clickSelectAll() {
return element.id;
});
}
const { confirm } = useConfirmDialog();
function clickedCreate(collectionName: string) {
async function clickedCreate(collectionName: string) {
checkForDuplicates();
const returnedElements = props.fromSelection ? workingElements.value : inListElements.value;
atLeastOneElement.value = returnedElements.length > 0;
if (state.value !== "error" && atLeastOneElement.value) {
let confirmed = false;
if (!atLeastOneElement.value) {
confirmed = await confirm("Are you sure you want to create a list with no datasets?", {
title: "Create an empty list",
okTitle: "Create",
okVariant: "primary",
});
}
if (state.value !== "error" && (atLeastOneElement.value || confirmed)) {
emit("clicked-create", returnedElements, collectionName, hideSourceItems.value);
}
}
Expand Down
17 changes: 15 additions & 2 deletions client/src/components/Collections/PairedListCollectionCreator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { computed, ref, watch } from "vue";
import draggable from "vuedraggable";
import type { HDASummary, HistoryItemSummary } from "@/api";
import { useConfirmDialog } from "@/composables/confirmDialog";
import { Toast } from "@/composables/toast";
import STATES from "@/mvc/dataset/states";
import { useDatatypesMapperStore } from "@/stores/datatypesMapperStore";
Expand Down Expand Up @@ -724,10 +725,22 @@ function addUploadedFiles(files: HDASummary[]) {
});
}
const { confirm } = useConfirmDialog();
async function clickedCreate(collectionName: string) {
checkForDuplicates();
atLeastOnePair.value = generatedPairs.value.length > 0;
if (state.value == "build" && atLeastOnePair.value) {
let confirmed = false;
if (!atLeastOnePair.value) {
confirmed = await confirm("Are you sure you want to create a list with no pairs?", {
title: "Create an empty list of pairs",
okTitle: "Create",
okVariant: "primary",
});
}
if (state.value == "build" && (atLeastOnePair.value || confirmed)) {
emit("clicked-create", generatedPairs.value, collectionName, hideSourceItems.value);
}
}
Expand Down Expand Up @@ -806,7 +819,7 @@ function _naiveStartingAndEndingLCS(s1: string, s2: string) {

<div v-if="!atLeastOnePair">
<BAlert show variant="warning" dismissible @dismissed="atLeastOnePair = true">
{{ localize("At least one pair is needed for the paired list.") }}
{{ localize("At least one pair is needed for the list of pairs.") }}
<span v-if="fromSelection">
<a class="cancel-text" href="javascript:void(0)" role="button" @click="emit('on-cancel')">
{{ localize("Cancel") }}
Expand Down

0 comments on commit 1c9e972

Please sign in to comment.