Skip to content

Commit 3e226ae

Browse files
use text only collection element; fix rename bug; add rename modal
This aims to fix all of the issues here: Fixes #20441 Using the default text-only value for the slot in `FormSelectMany` works best as it prevents layout shifting on hover/focused states. This commit also fixes a bug with the `renameElement` function, which would create a duplicate of the renamed element (1 in `inListElements`, 1 in `workingElements` upon rename). This adds a modal where the user can choose to rename elements if they'd like, instead of renaming the elements inside the multi select; which is not intuitive and can also interfere with clicking an element to select it.
1 parent 70891f6 commit 3e226ae

File tree

5 files changed

+95
-16
lines changed

5 files changed

+95
-16
lines changed

client/src/components/Collections/ListCollectionCreator.vue

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { type Mode, useCollectionCreator } from "./common/useCollectionCreator";
1818
1919
import GButton from "../BaseComponents/GButton.vue";
2020
import GButtonGroup from "../BaseComponents/GButtonGroup.vue";
21+
import GModal from "../BaseComponents/GModal.vue";
2122
import FormSelectMany from "../Form/Elements/FormSelectMany/FormSelectMany.vue";
2223
import HelpText from "../Help/HelpText.vue";
2324
import CollectionCreator from "@/components/Collections/common/CollectionCreator.vue";
@@ -343,12 +344,39 @@ function addUploadedFiles(files: HDASummary[]) {
343344
});
344345
}
345346
347+
/** If we are creating a collection from a history (not a pre-selection of elements),
348+
* once we have some selected elements, we provide an option to rename them in a modal.
349+
*/
350+
const canRenameElements = computed(() => {
351+
return !props.fromSelection && inListElements.value.length > 0;
352+
});
353+
/** A toggle for the modal that allows renaming elements in the selected list */
354+
const renamingElements = ref(false);
346355
/** find the element in the workingElements array and update its name */
347356
function renameElement(element: any, name: string) {
357+
// We do this whole process of removing and readding because inListElements
358+
// might be reacting to changes in workingElements, and we want to
359+
// prevent that from causing issues with producing duplicate elements in either list:
360+
361+
// first check at what index of inlistElements the element is
362+
const index = inListElements.value.findIndex((e) => e.id === element.id);
363+
if (index < 0) {
364+
return;
365+
}
366+
367+
// remove from inListElements
368+
inListElements.value = inListElements.value.filter((e) => e.id !== element.id);
369+
370+
// then find the element in workingElements, and rename it
348371
element = workingElements.value.find((e) => e.id === element.id);
349372
if (element) {
350373
element.name = name;
351374
}
375+
376+
// now add again to inListElements at same index
377+
if (index >= 0) {
378+
inListElements.value.splice(index, 0, element);
379+
}
352380
}
353381
354382
function selectionAsHdaSummary(value: any): HDASummary {
@@ -413,11 +441,13 @@ function selectionAsHdaSummary(value: any): HDASummary {
413441
:show-buttons="showButtonsForModal"
414442
:collection-name="collectionName"
415443
:mode="mode"
444+
:can-rename-elements="canRenameElements"
416445
@on-update-collection-name="onUpdateCollectionName"
417446
@add-uploaded-files="addUploadedFiles"
418447
@on-update-datatype-toggle="changeDatatypeFilter"
419448
@onUpdateHideSourceItems="onUpdateHideSourceItems"
420449
@remove-extensions-toggle="removeExtensionsToggle"
450+
@clicked-rename="renamingElements = true"
421451
@clicked-create="attemptCreate">
422452
<template v-slot:help-content>
423453
<p>
@@ -443,7 +473,7 @@ function selectionAsHdaSummary(value: any): HDASummary {
443473
<li v-if="!fromSelection">
444474
The filter textbox can be used to rapidly find the datasets of interest by name.
445475
</li>
446-
<li>
476+
<li v-if="fromSelection">
447477
{{ localize("Change the identifier of elements in the list by clicking on") }}
448478
<i data-target=".collection-element .name">
449479
{{ localize("the existing name") }}
@@ -520,6 +550,21 @@ function selectionAsHdaSummary(value: any): HDASummary {
520550
</i>
521551
{{ localize(".") }}
522552
</p>
553+
554+
<p v-if="!fromSelection">
555+
<strong>
556+
{{ localize("Optional:") }}
557+
</strong>
558+
{{
559+
localize(
560+
"Once you have made your selection, if you wish to rename the elements in the list, click"
561+
)
562+
}}
563+
<i data-target=".rename-elements">
564+
{{ localize("Rename list elements") }}
565+
</i>
566+
{{ localize(". This opens a modal where you can rename the elements individually.") }}
567+
</p>
523568
</template>
524569

525570
<template v-slot:middle-content>
@@ -669,14 +714,28 @@ function selectionAsHdaSummary(value: any): HDASummary {
669714
:options="workingElements.map((e) => ({ label: e.name || '', value: e }))">
670715
<template v-slot:label-area="{ value }">
671716
<DatasetCollectionElementView
672-
class="w-100"
717+
text-only
718+
not-editable
673719
:element="selectionAsHdaSummary(value)"
674-
:hide-extension="!showElementExtension"
675-
@onRename="(name) => renameElement(value, name)" />
720+
:hide-extension="!showElementExtension" />
676721
</template>
677722
</FormSelectMany>
678723
</template>
679724
</CollectionCreator>
725+
726+
<GModal
727+
class="rename-elements-modal"
728+
:show.sync="renamingElements"
729+
size="small"
730+
title="Click on dataset names to rename them">
731+
<DatasetCollectionElementView
732+
v-for="value in inListElements"
733+
:key="value.id"
734+
class="w-100"
735+
:element="selectionAsHdaSummary(value)"
736+
:hide-extension="!showElementExtension"
737+
@onRename="(name) => renameElement(value, name)" />
738+
</GModal>
680739
</div>
681740
</div>
682741
</template>
@@ -686,6 +745,12 @@ function selectionAsHdaSummary(value: any): HDASummary {
686745
@import "theme/blue.scss";
687746
688747
.list-collection-creator {
748+
.rename-elements-modal {
749+
.collection-element {
750+
cursor: unset;
751+
}
752+
}
753+
689754
.footer {
690755
margin-top: 8px;
691756
}
@@ -732,11 +797,6 @@ function selectionAsHdaSummary(value: any): HDASummary {
732797
border-color: black;
733798
}
734799
}
735-
&:not(.with-actions) {
736-
&:hover {
737-
border: none;
738-
}
739-
}
740800
741801
&:last-of-type {
742802
margin-bottom: 2px;

client/src/components/Collections/ListDatasetCollectionElementView.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface Props {
1515
notEditable?: boolean;
1616
hideExtension?: boolean;
1717
showHid?: boolean;
18+
textOnly?: boolean;
1819
}
1920
2021
const props = defineProps<Props>();
@@ -45,10 +46,11 @@ watch(
4546

4647
<template>
4748
<div
48-
class="collection-element d-flex justify-content-between"
49+
class="d-flex justify-content-between"
4950
:data-hid="element.hid"
50-
:class="{ 'with-actions': hasActions }"
51+
:class="{ 'collection-element': !textOnly, 'with-actions': hasActions }"
5152
role="button"
53+
data-description="list dataset collection element"
5254
tabindex="0"
5355
@keyup.enter="emit('element-is-selected', element)"
5456
@click="emit('element-is-selected', element)">

client/src/components/Collections/common/CollectionCreator.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interface Props {
3636
showButtons?: boolean;
3737
collectionName: string;
3838
mode: "wizard" | "modal";
39+
canRenameElements?: boolean;
3940
}
4041
4142
const props = withDefaults(defineProps<Props>(), {
@@ -46,12 +47,14 @@ const props = withDefaults(defineProps<Props>(), {
4647
collectionType: undefined,
4748
showButtons: true,
4849
mode: "modal",
50+
canRenameElements: false,
4951
});
5052
5153
const emit = defineEmits<{
5254
(e: "on-update-collection-name", name: string): void;
5355
(e: "remove-extensions-toggle"): void;
5456
(e: "clicked-create", value: string): void;
57+
(e: "clicked-rename"): void;
5558
(e: "onUpdateHideSourceItems", value: boolean): void;
5659
(e: "on-update-datatype-toggle", value: "all" | "datatype" | "ext"): void;
5760
(e: "add-uploaded-files", value: HDASummary[]): void;
@@ -196,9 +199,11 @@ watch(
196199
<CollectionCreatorFooterButtons
197200
v-if="showButtons"
198201
:short-what-is-being-created="shortWhatIsBeingCreated"
202+
:can-rename-elements="props.canRenameElements"
199203
:valid-input="validInput"
200204
@clicked-cancel="cancelCreate"
201-
@clicked-create="emit('clicked-create', collectionName)" />
205+
@clicked-create="emit('clicked-create', collectionName)"
206+
@clicked-rename="emit('clicked-rename')" />
202207
</div>
203208
</div>
204209
</BTab>

client/src/components/Collections/common/CollectionCreatorFooterButtons.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import GButton from "@/components/BaseComponents/GButton.vue";
66
interface Props {
77
validInput: boolean;
88
shortWhatIsBeingCreated: string;
9+
canRenameElements?: boolean;
910
}
1011
1112
defineProps<Props>();
1213
1314
const emit = defineEmits<{
1415
(e: "clicked-create"): void;
16+
(e: "clicked-rename"): void;
1517
(e: "clicked-cancel"): void;
1618
}>();
1719
</script>
@@ -22,8 +24,18 @@ const emit = defineEmits<{
2224
{{ localize("Cancel") }}
2325
</GButton>
2426

25-
<GButton class="create-collection" color="blue" :disabled="!validInput" @click="emit('clicked-create')">
26-
{{ localize("Create " + shortWhatIsBeingCreated) }}
27-
</GButton>
27+
<span>
28+
<GButton
29+
v-if="canRenameElements"
30+
class="rename-elements"
31+
size="small"
32+
:disabled="!validInput"
33+
@click="emit('clicked-rename')">
34+
{{ localize("Rename " + shortWhatIsBeingCreated) + " elements" }}
35+
</GButton>
36+
<GButton class="create-collection" color="blue" :disabled="!validInput" @click="emit('clicked-create')">
37+
{{ localize("Create " + shortWhatIsBeingCreated) }}
38+
</GButton>
39+
</span>
2840
</div>
2941
</template>

client/src/utils/navigation/navigation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ workflow_run:
729729
_: '[data-label="${label}"] .tabs'
730730
create: '${_} .create-collection'
731731
select_all: "${_} [data-description='select many select all']"
732-
element_by_hid: "${_} .collection-element[data-hid='${hid}']"
732+
element_by_hid: "${_} [data-description='list dataset collection element'][data-hid='${hid}']"
733733
<<: *upload_mixin
734734

735735
form_element:

0 commit comments

Comments
 (0)