Allow item pane sections to declare dependencies for rerender, fix Libraries and Collections not updating (#4155)

This commit is contained in:
Abe Jellinek 2024-05-30 01:44:11 -04:00 committed by GitHub
parent 5ebd6c4141
commit 6b4cac1fb5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 6 deletions

View file

@ -99,6 +99,10 @@
`, ['chrome://zotero/locale/zotero.dtd']);
}
get _renderDependencies() {
return [...super._renderDependencies, this.collectionTreeRow?.id];
}
init() {
this.initCollapsibleSection();
this._creatorTypeMenu.addEventListener('command', async (event) => {

View file

@ -115,6 +115,14 @@
set tabType(tabType) {
this._tabType = tabType;
}
get collectionTreeRow() {
return this._collectionTreeRow;
}
set collectionTreeRow(collectionTreeRow) {
this._collectionTreeRow = collectionTreeRow;
}
get pinnedPane() {
return this.getAttribute('pinnedPane');
@ -262,6 +270,7 @@
box.tabID = this.tabID;
box.tabType = this.tabType;
box.item = item;
box.collectionTreeRow = this.collectionTreeRow;
// Execute sync render immediately
if (!box.hidden && box.render) {
if (box.render) {

View file

@ -154,6 +154,7 @@
this._itemDetails.tabID = "zotero-pane";
this._itemDetails.tabType = "library";
this._itemDetails.item = item;
this._itemDetails.collectionTreeRow = this.collectionTreeRow;
if (this.hasAttribute("collapsed")) {
return true;

View file

@ -59,6 +59,14 @@ class ItemPaneSectionElementBase extends XULElementBase {
this._tabType = tabType;
this.setAttribute('tabType', tabType);
}
get collectionTreeRow() {
return this._collectionTreeRow;
}
set collectionTreeRow(collectionTreeRow) {
this._collectionTreeRow = collectionTreeRow;
}
_syncRenderPending = false;
@ -106,18 +114,24 @@ class ItemPaneSectionElementBase extends XULElementBase {
await this._forceRenderAll();
};
get _renderDependencies() {
return [this._tabID, this._item?.id];
}
/**
* @param {"sync" | "async"} [type]
* @returns {boolean}
*/
_isAlreadyRendered(type = "sync") {
let key = `_${type}RenderItemID`;
let key = `_${type}RenderDependencies`;
let pendingKey = `_${type}RenderPending`;
let itemIDKey = `_${type}RenderItemID`;
let renderFlag = this[key];
let pendingFlag = this[pendingKey];
let oldDependencies = this[key];
let newDependencies = this._renderDependencies;
let isRendered = renderFlag && this.item?.id == renderFlag;
let isPending = this[pendingKey];
let isRendered = Zotero.Utilities.arrayEquals(oldDependencies, newDependencies);
if (this.skipRender) {
if (!isRendered) {
this[pendingKey] = true;
@ -126,17 +140,20 @@ class ItemPaneSectionElementBase extends XULElementBase {
return true;
}
if (!pendingFlag && renderFlag && this.item?.id == renderFlag) {
if (!isPending && isRendered) {
return true;
}
this[key] = this.item.id;
this[key] = newDependencies;
this[pendingKey] = false;
this[itemIDKey] = this.item?.id;
return false;
}
_resetRenderedFlags() {
// Clear cached flags to allow re-rendering
delete this._syncRenderDependencies;
delete this._syncRenderItemID;
delete this._asyncRenderDependencies;
delete this._asyncRenderItemID;
}

View file

@ -60,6 +60,10 @@ import { getCSSIcon } from 'components/icons';
this._linkedItems = [];
}
get _renderDependencies() {
return [...super._renderDependencies, this.collectionTreeRow?.id];
}
init() {
this._notifierID = Zotero.Notifier.registerObserver(this, ['item'], 'librariesCollectionsBox');
this._body = this.querySelector('.body');