Merge "Add temporary api for interaction with find-owners plugin"
diff --git a/ui/code-owners-banner.js b/ui/code-owners-banner.js
index a44e258..4e4b07e 100644
--- a/ui/code-owners-banner.js
+++ b/ui/code-owners-banner.js
@@ -133,6 +133,26 @@
banner: {
type: Object,
},
+ /**
+ * This is a temporary property for interop with find-owner plugin.
+ * It stores information about the change and code-owners status for this
+ * change. The possible values for branchState are:
+ * LOADING - branch config are requesting
+ * FAILED - plugin are in failed state (server returned error, etc...)
+ * ENABLED - code-owners is enabled for the change
+ * DISABLED - code-owners is disable for the change
+ *
+ * ENABLED/DISABLED values are different from the pluginStatus.
+ * For merged and abandoned changes the model.pluginStatus value is
+ * always DISABLED, even if code-owners is enabled for a project.
+ */
+ _stateForFindOwnersPlugin: {
+ type: Object,
+ notify: true,
+ computed:
+ '_getStateForFindOwners(model.pluginStatus, model.branchConfig,' +
+ ' change)',
+ },
};
}
@@ -159,6 +179,26 @@
_loadDataAfterStateChanged() {
this.modelLoader.loadPluginStatus();
+ this.modelLoader.loadBranchConfig();
+ }
+
+ _getStateForFindOwners(pluginStatus, branchConfig, change) {
+ if (pluginStatus === undefined || branchConfig === undefined ||
+ change == undefined) {
+ return {
+ branchState: 'LOADING',
+ };
+ }
+ if (pluginStatus.state === PluginState.Failed) {
+ return {
+ change,
+ branchState: 'FAILED',
+ };
+ }
+ return {
+ change,
+ branchState: branchConfig.disabled ? 'DISABLED' : 'ENABLED',
+ };
}
}
diff --git a/ui/plugin.js b/ui/plugin.js
index 40bc4e5..124d986 100644
--- a/ui/plugin.js
+++ b/ui/plugin.js
@@ -21,17 +21,41 @@
import {SuggestOwnersTrigger} from './suggest-owners-trigger.js';
import {CodeOwnersBanner, CodeOwnersPluginStatusNotifier} from './code-owners-banner.js';
+// A temporary property for interop with find-owners plugin.
+// It should be set as earlier as possible, so find-owners plugin can check
+// it in Gerrit.install callback.
+window.__gerrit_code_owners_plugin = {
+ state: {
+ // See CodeOwnersPluginStatusNotifier._stateForFindOwnersPlugin for
+ // a list of possible values.
+ branchState: 'LOADING',
+ },
+ stateChanged: new EventTarget(),
+};
+
Gerrit.install(plugin => {
const restApi = plugin.restApi();
const reporting = plugin.reporting();
plugin.registerCustomComponent('banner', CodeOwnersBanner.is);
+ const stateForFindOwnerPluginChanged = evt => {
+ window.__gerrit_code_owners_plugin.state = evt.detail.value;
+ window.__gerrit_code_owners_plugin.stateChanged
+ .dispatchEvent(new CustomEvent('state-changed'));
+ };
+
plugin.registerCustomComponent(
'change-view-integration', CodeOwnersPluginStatusNotifier.is)
.onAttached(view => {
view.restApi = restApi;
view.reporting = reporting;
+ view.addEventListener('_state-for-find-owners-plugin-changed',
+ stateForFindOwnerPluginChanged);
+ })
+ .onDetached(view => {
+ view.removeEventListener('_state-for-find-owners-plugin-changed',
+ stateForFindOwnerPluginChanged);
});
// owner status column / rows for file list