From 9c4e9e3f2ffc29bb527413d6773c50bf833568d3 Mon Sep 17 00:00:00 2001
From: Helmi Akermi <70575401+hakermi@users.noreply.github.com>
Date: Fri, 8 Nov 2024 17:18:27 +0100
Subject: [PATCH] Fix: Notes export treeview selection issues - EXO-74698 -
Meeds-io/meeds#2571 (#1204)
Notes export treeview selection issues fixes #1202
---
.../notes/components/NoteTreeviewDrawer.vue | 147 +++++++++++++-----
1 file changed, 109 insertions(+), 38 deletions(-)
diff --git a/notes-webapp/src/main/webapp/vue-app/notes/components/NoteTreeviewDrawer.vue b/notes-webapp/src/main/webapp/vue-app/notes/components/NoteTreeviewDrawer.vue
index 4ff698413..782b157e9 100644
--- a/notes-webapp/src/main/webapp/vue-app/notes/components/NoteTreeviewDrawer.vue
+++ b/notes-webapp/src/main/webapp/vue-app/notes/components/NoteTreeviewDrawer.vue
@@ -294,14 +294,9 @@
-
+ transition>
+
+
+
+
+ {{ item.name }}
+
+
+
{{ $t('notes.button.export') }}
@@ -452,7 +469,8 @@ export default {
tempCleaned: false,
dataCreated: false,
isLoading: false,
- selection: 'independent',
+ selectionType: 'independent',
+ inProgressTreeFetches: []
}),
props: {
selectedTranslation: {
@@ -461,6 +479,12 @@ export default {
}
},
computed: {
+ homeLabel() {
+ return this.home?.name === 'Home' && this.$t('notes.label.noteHome') || this.home.name;
+ },
+ enableExport() {
+ return !this.inProgressTreeFetches?.length;
+ },
confirmCloseLabels() {
return {
title: this.$t('notes.confirmCancelExport.title'),
@@ -490,19 +514,9 @@ export default {
resultSearch() {
return this.showTree;
},
- selectExportLabel() {
- if (this.checkbox === true) {
- return this.$t('notes.label.export.deselectAll');
- } else {
- return this.$t('notes.label.export.selectAll');
- }
- },
openLevel() {
return [this.home.noteId];
},
- selectionType() {
- return this.selection;
- },
isDraftFilter() {
return this.filter === this.$t('notes.filter.label.drafts');
}
@@ -515,6 +529,9 @@ export default {
this.$refs.breadcrumbDrawer.endLoading();
}
},
+ inProgressTreeFetches() {
+ this.isLoading = this.inProgressTreeFetches?.length;
+ },
search() {
this.showTree = true;
if (this.search) {
@@ -527,9 +544,6 @@ export default {
this.retrieveNoteTree(this.note.wikiType, this.note.wikiOwner, this.note.name);
}
},
- checkbox() {
- this.selectAllItems(this.checkbox);
- },
filter() {
if (this.note && this.note.id) {
if (this.note.draftPage) {
@@ -562,9 +576,71 @@ export default {
this.filter = this.filterOptions[0];
},
methods: {
- selectAllItems(select) {
- this.$refs.treeSearch.selectionType = 'leaf';
- this.$refs.treeSearch.updateSelected(this.home.noteId, select);
+ fetchChildrenInParallel(children, level = 0) {
+ if (level >= 2) {
+ return;
+ }
+ children.forEach(item => {
+ if (item.hasChild && !item?.children?.length) {
+ this.inProgressTreeFetches.push(item.noteId);
+ return this.$notesService.getNoteTreeLevel(item.path).then((data) => {
+ item.children = this.mapItems(data?.jsonList);
+ this.fetchChildrenInParallel(item.children, level + 1);
+ const inProgressFetch = this.inProgressTreeFetches.indexOf(item.noteId);
+ this.inProgressTreeFetches.splice(inProgressFetch, 1);
+ });
+ }
+ });
+ },
+ selectChildren(item) {
+ if (item.hasChild && !item?.children?.length) {
+ this.inProgressTreeFetches.push(item.noteId);
+ return this.$notesService.getNoteTreeLevel(item.path).then((data) => {
+ item.children = this.mapItems(data?.jsonList);
+ this.selectionNotes.push(
+ ...item.children.map(item => item.noteId).filter(id => !this.selectionNotes.includes(id)));
+ item.children.forEach(child => this.selectChildren(child));
+ this.openItem(item, this.$refs.treeSearch);
+ this.inProgressTreeFetches.splice(this.inProgressTreeFetches.indexOf(item.noteId), 1);
+ });
+ } else if (item?.children?.length) {
+ this.selectionNotes.push(
+ ...item.children.map(item => item.noteId).filter(id => !this.selectionNotes.includes(id)));
+ this.openItem(item, this.$refs.treeSearch);
+ item.children.forEach(item => this.selectChildren(item));
+ }
+ },
+ deselectChildren(item) {
+ if (item.children) {
+ item.children.forEach((child) => {
+ const index = this.selectionNotes.indexOf(child.noteId);
+ if (index !== -1) {
+ this.selectionNotes.splice(index, 1);
+ }
+ this.deselectChildren(child);
+ });
+ }
+ },
+ updateSelection(item) {
+ this.enableExport = false;
+ const index = this.selectionNotes.findIndex(itemId => itemId === item.noteId);
+ if (index === -1) {
+ if (!this.selectionNotes.includes(item.noteId)) {
+ this.selectionNotes.push(item.noteId);
+ }
+ this.selectChildren(item);
+ } else {
+ this.$refs.treeSearch.selectionType = 'independent';
+ this.$refs.treeSearch.updateSelected(item.noteId, false);
+ this.selectionNotes.splice(index, 1);
+ this.deselectChildren(item);
+ }
+ },
+ isBeingLoaded(item) {
+ return this.inProgressTreeFetches.includes(item.noteId);
+ },
+ isSelected(item) {
+ return this.selectionNotes?.includes(item.noteId);
},
open(note, source, includeDisplay,filter) {
this.render = false;
@@ -575,16 +651,8 @@ export default {
this.filter = filter === 'draft' && this.filterOptions[1] || this.filterOptions[0];
this.getNoteById(note.id);
}
- if (source === 'includePages') {
- this.isIncludePage = true;
- } else {
- this.isIncludePage = false;
- }
- if (includeDisplay) {
- this.displayArrow =false;
- } else {
- this.displayArrow =true;
- }
+ this.isIncludePage = source === 'includePages';
+ this.displayArrow = !includeDisplay;
if (source === 'movePage') {
this.movePage = true;
this.exportNotes = false;
@@ -707,8 +775,7 @@ export default {
}
}
return itemsArray;
- },
-
+ },
filterItemsForMove(item) {
if (item.noteId===this.note.id) {
delete item.children;
@@ -719,7 +786,6 @@ export default {
}
return item;
},
-
naturalSort(items) {
if (items?.length) {
const collator = new Intl.Collator(eXo.env.portal.language, {numeric: true, sensitivity: 'base'});
@@ -737,7 +803,11 @@ export default {
this.$notesService.getNoteTree(noteBookType, noteOwner, noteName, treeType, noteType).then(data => {
if (data?.jsonList?.length) {
this.home = data.jsonList[0];
+ this.home.name = this.homeLabel;
this.items = this.exportNotes && [this.home] || data.jsonList[0].children;
+ if (this.exportNotes) {
+ this.fetchChildrenInParallel(this.home.children);
+ }
if (this.exportNotes) {
if (!this.items[0].hasChild) {
delete this.items[0].children;
@@ -804,12 +874,13 @@ export default {
this.checkbox = false;
$('.spaceButtomNavigation').removeClass('hidden');
this.search = '';
- if (this.exporting){
+ if (this.exporting) {
this.$root.$emit('cancel-export-notes');
this.exportStatus = {};
this.exporting = false;
this.resetImport();
}
+ this.selectionNotes = [];
if (this.closeAll) {
this.$emit('closed');
}