Fix duplicate attachment row from attachments-box notify()
(#4250)
This commit is contained in:
parent
fad3e25278
commit
310e741a01
2 changed files with 11 additions and 24 deletions
|
@ -104,40 +104,24 @@
|
|||
}
|
||||
|
||||
notify(action, type, ids) {
|
||||
if (!(action === 'add' || action === 'modify' || action === 'refresh' || action === 'delete')) {
|
||||
return;
|
||||
}
|
||||
if (!this._item?.isRegularItem()) return;
|
||||
|
||||
this._updateAttachmentIDs().then(() => {
|
||||
this.updatePreview();
|
||||
|
||||
let attachments = Zotero.Items.get((this._attachmentIDs).filter(id => ids.includes(id)));
|
||||
if (attachments.length === 0 && action !== "delete") {
|
||||
return;
|
||||
for (let id of ids) {
|
||||
this.querySelector(`attachment-row[attachment-id="${id}"]`)
|
||||
?.remove();
|
||||
}
|
||||
if (action == 'add') {
|
||||
if (action !== 'delete') {
|
||||
let attachments = Zotero.Items.get(this._attachmentIDs.filter(id => ids.includes(id)));
|
||||
for (let attachment of attachments) {
|
||||
this.addRow(attachment);
|
||||
}
|
||||
}
|
||||
// When annotation added to attachment, action=modify
|
||||
// When annotation deleted from attachment, action=refresh
|
||||
else if (action == 'modify' || action == 'refresh') {
|
||||
for (let attachment of attachments) {
|
||||
let row = this.querySelector(`attachment-row[attachment-id="${attachment.id}"]`);
|
||||
if (row) {
|
||||
row.remove();
|
||||
}
|
||||
this.addRow(attachment);
|
||||
}
|
||||
}
|
||||
else if (action == 'delete') {
|
||||
for (let id of ids) {
|
||||
let row = this.querySelector(`attachment-row[attachment-id="${id}"]`);
|
||||
if (row) {
|
||||
row.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.updateCount();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -597,6 +597,9 @@ describe("Item pane", function () {
|
|||
assert.equal(preview.previewType, "pdf");
|
||||
// 2 rows
|
||||
assert.equal(attachmentsBox.querySelectorAll("attachment-row").length, 2);
|
||||
// Simulate an extra 'add' event on the attachment - still 2 rows
|
||||
attachmentsBox.notify('add', 'item', [attachment2.id]);
|
||||
assert.equal(attachmentsBox.querySelectorAll("attachment-row").length, 2);
|
||||
|
||||
// Created annotations should be update in preview and attachment row
|
||||
let annotation = await createAnnotation('highlight', attachment2);
|
||||
|
|
Loading…
Reference in a new issue