Load GWT-compiled plugins in PolyGerrit
Also install "stepping stone" API to simplify migration. Feature: Issue 7800 Change-Id: Ib22d2ef4bc2e485228e35e7ca9183a8a984dbbe1
This commit is contained in:
parent
17c02269fc
commit
250bf09f5c
@ -346,19 +346,15 @@ limitations under the License.
|
|||||||
|
|
||||||
test('installGwt calls _pluginInstalled', () => {
|
test('installGwt calls _pluginInstalled', () => {
|
||||||
sandbox.stub(Gerrit, '_pluginInstalled');
|
sandbox.stub(Gerrit, '_pluginInstalled');
|
||||||
Gerrit.installGwt();
|
Gerrit.installGwt('http://test.com/plugins/testplugin/static/test.js');
|
||||||
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
|
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('installGwt returns a stub object', () => {
|
test('installGwt returns a plugin', () => {
|
||||||
const plugin = Gerrit.installGwt();
|
const plugin = Gerrit.installGwt(
|
||||||
sandbox.stub(console, 'warn');
|
'http://test.com/plugins/testplugin/static/test.js');
|
||||||
assert.isAbove(Object.keys(plugin).length, 0);
|
assert.isOk(plugin);
|
||||||
for (const name of Object.keys(plugin)) {
|
assert.isOk(plugin._loadedGwt);
|
||||||
console.warn.reset();
|
|
||||||
plugin[name]();
|
|
||||||
assert.isTrue(console.warn.calledOnce);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('attributeHelper', () => {
|
test('attributeHelper', () => {
|
||||||
@ -391,9 +387,8 @@ limitations under the License.
|
|||||||
|
|
||||||
suite('popup', () => {
|
suite('popup', () => {
|
||||||
test('popup(element) is deprecated', () => {
|
test('popup(element) is deprecated', () => {
|
||||||
assert.throws(() => {
|
plugin.popup(document.createElement('div'));
|
||||||
plugin.popup(document.createElement('div'));
|
assert.isTrue(console.error.calledOnce);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('popup(moduleName) creates popup with component', () => {
|
test('popup(moduleName) creates popup with component', () => {
|
||||||
|
@ -14,21 +14,11 @@
|
|||||||
(function(window) {
|
(function(window) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const warnNotSupported = function(opt_name) {
|
|
||||||
console.warn('Plugin API method ' + (opt_name || '') + ' is not supported');
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hash of loaded and installed plugins, name to Plugin object.
|
* Hash of loaded and installed plugins, name to Plugin object.
|
||||||
*/
|
*/
|
||||||
const plugins = {};
|
const plugins = {};
|
||||||
|
|
||||||
const stubbedMethods = ['_loadedGwt'];
|
|
||||||
const GWT_PLUGIN_STUB = {};
|
|
||||||
for (const name of stubbedMethods) {
|
|
||||||
GWT_PLUGIN_STUB[name] = warnNotSupported.bind(null, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
const PANEL_ENDPOINTS_MAPPING = {
|
const PANEL_ENDPOINTS_MAPPING = {
|
||||||
CHANGE_SCREEN_BELOW_COMMIT_INFO_BLOCK: 'change-view-integration',
|
CHANGE_SCREEN_BELOW_COMMIT_INFO_BLOCK: 'change-view-integration',
|
||||||
CHANGE_SCREEN_BELOW_CHANGE_INFO_BLOCK: 'change-metadata-item',
|
CHANGE_SCREEN_BELOW_CHANGE_INFO_BLOCK: 'change-metadata-item',
|
||||||
@ -113,6 +103,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.deprecated = {
|
this.deprecated = {
|
||||||
|
_loadedGwt: deprecatedAPI._loadedGwt.bind(this),
|
||||||
install: deprecatedAPI.install.bind(this),
|
install: deprecatedAPI.install.bind(this),
|
||||||
onAction: deprecatedAPI.onAction.bind(this),
|
onAction: deprecatedAPI.onAction.bind(this),
|
||||||
panel: deprecatedAPI.panel.bind(this),
|
panel: deprecatedAPI.panel.bind(this),
|
||||||
@ -254,7 +245,8 @@
|
|||||||
|
|
||||||
Plugin.prototype.popup = function(moduleName) {
|
Plugin.prototype.popup = function(moduleName) {
|
||||||
if (typeof moduleName !== 'string') {
|
if (typeof moduleName !== 'string') {
|
||||||
throw new Error('deprecated, use deprecated.popup');
|
console.error('.popup(element) deprecated, use .popup(moduleName)!');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const api = new GrPopupInterface(this, moduleName);
|
const api = new GrPopupInterface(this, moduleName);
|
||||||
return api.open();
|
return api.open();
|
||||||
@ -272,7 +264,9 @@
|
|||||||
|
|
||||||
Plugin.prototype.screen = function(screenName, opt_moduleName) {
|
Plugin.prototype.screen = function(screenName, opt_moduleName) {
|
||||||
if (opt_moduleName && typeof opt_moduleName !== 'string') {
|
if (opt_moduleName && typeof opt_moduleName !== 'string') {
|
||||||
throw new Error('deprecated, use deprecated.screen');
|
console.error('.screen(pattern, callback) deprecated, use ' +
|
||||||
|
'.screen(screenName, opt_moduleName)!');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return this.registerCustomComponent(
|
return this.registerCustomComponent(
|
||||||
Gerrit._getPluginScreenName(this.getPluginName(), screenName),
|
Gerrit._getPluginScreenName(this.getPluginName(), screenName),
|
||||||
@ -280,6 +274,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const deprecatedAPI = {
|
const deprecatedAPI = {
|
||||||
|
_loadedGwt: ()=> {},
|
||||||
|
|
||||||
install() {
|
install() {
|
||||||
console.log('Installing deprecated APIs is deprecated!');
|
console.log('Installing deprecated APIs is deprecated!');
|
||||||
for (const method in this.deprecated) {
|
for (const method in this.deprecated) {
|
||||||
@ -379,6 +375,7 @@
|
|||||||
CHANGE_INFO: el.change,
|
CHANGE_INFO: el.change,
|
||||||
REVISION_INFO: el.revision,
|
REVISION_INFO: el.revision,
|
||||||
},
|
},
|
||||||
|
onUnload: () => {},
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -481,13 +478,20 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Polyfill GWT API dependencies to avoid runtime exceptions when loading
|
* Install "stepping stones" API for GWT-compiled plugins by default.
|
||||||
* GWT-compiled plugins.
|
* @deprecated best effort support, will be removed with GWT UI.
|
||||||
* @deprecated Not supported in PolyGerrit.
|
|
||||||
*/
|
*/
|
||||||
Gerrit.installGwt = function() {
|
Gerrit.installGwt = function(url) {
|
||||||
Gerrit._pluginInstalled();
|
Gerrit._pluginInstalled();
|
||||||
return GWT_PLUGIN_STUB;
|
const name = getPluginNameFromUrl(new URL(url));
|
||||||
|
let plugin;
|
||||||
|
try {
|
||||||
|
plugin = plugins[name] || new Plugin(url);
|
||||||
|
plugin.deprecated.install();
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(`${name} install failed: ${e.name}: ${e.message}`);
|
||||||
|
}
|
||||||
|
return plugin;
|
||||||
};
|
};
|
||||||
|
|
||||||
Gerrit._allPluginsPromise = null;
|
Gerrit._allPluginsPromise = null;
|
||||||
|
Loading…
Reference in New Issue
Block a user