Empty Trash: Visually remove deleted items, refresh icon (#2606)

There were a few problems causing the incorrect behavior:
1. Rows were being removed only if they had no non-deleted children, which
   wasn't the right check. We want to remove all rows with no *deleted*
   children.
2. Children of the removed rows weren't being removed with them.
3. We weren't invalidating the tree (which _removeRows() doesn't do).

Also:

* Erase trashed annotation after getAnnotations() test

Because ItemTree#notify() doesn't yet correctly handle refresh events on
parent items that are themselves children (three-level nesting: item ->
attachment -> annotation), this test was causing a failure in
itemTreeTest.js.
This commit is contained in:
Abe Jellinek 2022-08-18 21:14:34 -04:00 committed by GitHub
parent 6ca854a018
commit 3391f3bc99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 9 deletions

View file

@ -640,11 +640,8 @@ var CollectionTree = class CollectionTree extends LibraryTree {
this.tree.invalidate();
return;
}
if (action == 'refresh') {
// If trash is refreshed, we probably need to update the icon from full to empty
if (type == 'trash') {
this.tree.invalidate();
}
if (action == 'refresh' && type != 'trash') {
// Trash handled below
return;
}
if (type == 'feed' && (action == 'unreadCountUpdated' || action == 'statusChanged')) {
@ -826,6 +823,11 @@ var CollectionTree = class CollectionTree extends LibraryTree {
}
}
}
else if (action == 'refresh' && type == 'trash') {
// We need to update the trash's status (full or empty), and if empty,
// the row might be removed
await this.reload();
}
this.forceUpdate();
var promise = this.waitForSelect();
@ -2307,7 +2309,7 @@ var CollectionTree = class CollectionTree extends LibraryTree {
}
if (showTrash) {
let deletedItems = await Zotero.Items.getDeleted(libraryID);
let deletedItems = await Zotero.Items.getDeleted(libraryID, true);
if (deletedItems.length || Zotero.Prefs.get("showTrashWhenEmpty")) {
var ref = {
libraryID: libraryID

View file

@ -447,11 +447,20 @@ var ItemTree = class ItemTree extends LibraryTree {
let row = this.getRowIndexByID(id);
if (row === false) continue;
let item = Zotero.Items.get(id);
if (!item.deleted && !item.numChildren()) {
// Remove parent row if it isn't deleted and doesn't have any deleted children
// (shown by the numChildren including deleted being the same as numChildren not including deleted)
if (!item.deleted && (!item.isRegularItem() || item.numChildren(true) == item.numChildren(false))) {
rows.push(row);
// And all its children in the tree
for (let child = row + 1; child < this.rowCount && this.getLevel(child) > this.getLevel(row); child++) {
rows.push(child);
}
}
}
this._removeRows(rows);
if (rows.length) {
this._removeRows(rows);
this.tree.invalidate();
}
}
return;

View file

@ -1503,6 +1503,7 @@ Zotero.Items = function() {
);
}
Zotero.debug("Emptied " + deleted.length + " item(s) from trash in " + (new Date() - t) + " ms");
Zotero.Notifier.trigger('refresh', 'trash', libraryID);
}
return deleted.length;

View file

@ -1465,6 +1465,10 @@ describe("Zotero.Item", function () {
await annotation2.saveTx();
});
after(async function () {
await annotation2.eraseTx();
});
it("should return annotations not in trash", async function () {
var items = attachment.getAnnotations();
assert.sameMembers(items, [annotation1]);

View file

@ -684,7 +684,7 @@ describe("Zotero.ItemTree", function() {
});
describe("Trash", function () {
it.skip("should remove untrashed parent item when last trashed child is deleted", function* () {
it("should remove untrashed parent item when last trashed child is deleted", function* () {
var userLibraryID = Zotero.Libraries.userLibraryID;
var item = yield createDataObject('item');
var note = yield createDataObject(