Fix loading _dynamicTabHeaderEndpoints in time under Polymer 2

We use an observer to make sure '_change' and '_selectedRevision'
are defined. This ensures that when we load the dynamic plugins, these
variables are defined. This also allows us to call _performPostLoadTasks
after the plugins are loaded to ensure the primary tab is selected.

Bug: Issue 11173
Change-Id: I0701f028f14bda23f0e017f0cbb1c82a58fab45e
This commit is contained in:
Paladox none
2019-08-07 16:34:53 +00:00
parent 7f2450f9ea
commit 027aaa76fe

View File

@@ -303,6 +303,7 @@
'_labelsChanged(_change.labels.*)',
'_paramsAndChangeChanged(params, _change)',
'_patchNumChanged(_patchRange.patchNum)',
'_loadDynamicTabHeaderAndContent(_change, _selectedRevision)',
],
keyboardShortcuts() {
@@ -337,17 +338,6 @@
this._setDiffViewMode();
});
Gerrit.awaitPluginsLoaded().then(() => {
this._dynamicTabHeaderEndpoints =
Gerrit._endpoints.getDynamicEndpoints('change-view-tab-header');
this._dynamicTabContentEndpoints =
Gerrit._endpoints.getDynamicEndpoints('change-view-tab-content');
if (this._dynamicTabContentEndpoints.length
!== this._dynamicTabHeaderEndpoints.length) {
console.warn('Different number of tab headers and tab content.');
}
});
this.addEventListener('comment-save', this._handleCommentSave.bind(this));
this.addEventListener('comment-refresh', this._reloadDrafts.bind(this));
this.addEventListener('comment-discard',
@@ -770,6 +760,41 @@
});
},
/**
* We use an observer to observe 'change' and 'selectedRevision'
* variables. This fixes an issue under Polymer 2 so that the dynamic
* plugins loads when these variables load.
*/
_loadDynamicTabHeaderAndContent(change, selectedRevision) {
// These vars are unused, but because primaryTabs extension point
// uses it, we makes sure we doin't load the plugin until these vars
// exist.
if (!change || !selectedRevision) return;
// We cache the _dynamicTabHeaderEndpoints and _dynamicTabContentEndpoints
// var so that we doin't keep loading the same dynamic plugin
// over and over when 'change' or 'selectedRevision' change.
if (this._dynamicTabHeaderEndpoints || this._dynamicTabContentEndpoints) {
return;
}
Gerrit.awaitPluginsLoaded().then(() => {
this._dynamicTabHeaderEndpoints =
Gerrit._endpoints.getDynamicEndpoints('change-view-tab-header');
this._dynamicTabContentEndpoints =
Gerrit._endpoints.getDynamicEndpoints('change-view-tab-content');
if (this._dynamicTabContentEndpoints.length
!== this._dynamicTabHeaderEndpoints.length) {
console.warn('Different number of tab headers and tab content.');
}
}).then(() => {
// We need a second then(..) to ensure that the dynamic endpoints
// are created before we call _performPostLoadTasks(). This ensures it has
// enough time before the primary tab gets selected.
this._performPostLoadTasks();
});
},
_paramsAndChangeChanged(value) {
// If the change number or patch range is different, then reset the
// selected file index.