Use imported ChangeTableBehavior
This change removes usage of global Gerrit.ChangeTableBehavior and
replace it with direct import. Also, the ChangeTableMixin is removed,
because it was introduced as a workaround for polylint tests and is no
longer needed.
Change-Id: I831d7ba8ea680fe7d4f076e5bed47addd3406946
diff --git a/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior.js b/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior.js
index 0a3da6e..6c469a5 100644
--- a/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior.js
+++ b/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior.js
@@ -14,124 +14,100 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-(function(window) {
- 'use strict';
- window.Gerrit = window.Gerrit || {};
-
- /** @polymerBehavior Gerrit.ChangeTableBehavior */
- Gerrit.ChangeTableBehavior = {
- properties: {
- columnNames: {
- type: Array,
- value: [
- 'Subject',
- 'Status',
- 'Owner',
- 'Assignee',
- 'Reviewers',
- 'Comments',
- 'Repo',
- 'Branch',
- 'Updated',
- 'Size',
- ],
- readOnly: true,
- },
+/** @polymerBehavior Gerrit.ChangeTableBehavior */
+export const ChangeTableBehavior = {
+ properties: {
+ columnNames: {
+ type: Array,
+ value: [
+ 'Subject',
+ 'Status',
+ 'Owner',
+ 'Assignee',
+ 'Reviewers',
+ 'Comments',
+ 'Repo',
+ 'Branch',
+ 'Updated',
+ 'Size',
+ ],
+ readOnly: true,
},
+ },
- /**
- * Returns the complement to the given column array
- *
- * @param {Array} columns
- * @return {!Array}
- */
- getComplementColumns(columns) {
- return this.columnNames.filter(column => !columns.includes(column));
- },
+ /**
+ * Returns the complement to the given column array
+ *
+ * @param {Array} columns
+ * @return {!Array}
+ */
+ getComplementColumns(columns) {
+ return this.columnNames.filter(column => !columns.includes(column));
+ },
- /**
- * @param {string} columnToCheck
- * @param {!Array} columnsToDisplay
- * @return {boolean}
- */
- isColumnHidden(columnToCheck, columnsToDisplay) {
- if ([columnsToDisplay, columnToCheck].some(arg => arg === undefined)) {
- return false;
- }
- return !columnsToDisplay.includes(columnToCheck);
- },
+ /**
+ * @param {string} columnToCheck
+ * @param {!Array} columnsToDisplay
+ * @return {boolean}
+ */
+ isColumnHidden(columnToCheck, columnsToDisplay) {
+ if ([columnsToDisplay, columnToCheck].some(arg => arg === undefined)) {
+ return false;
+ }
+ return !columnsToDisplay.includes(columnToCheck);
+ },
- /**
- * Is the column disabled by a server config or experiment? For example the
- * assignee feature might be disabled and thus the corresponding column is
- * also disabled.
- *
- * @param {string} column
- * @param {Object} config
- * @param {!Array<string>} experiments
- * @return {boolean}
- */
- isColumnEnabled(column, config, experiments) {
- if (!config || !config.change) return true;
- if (column === 'Assignee') return !!config.change.enable_assignee;
- if (column === 'Comments') return experiments.includes('comments-column');
- if (column === 'Reviewers') return !!config.change.enable_attention_set;
- return true;
- },
+ /**
+ * Is the column disabled by a server config or experiment? For example the
+ * assignee feature might be disabled and thus the corresponding column is
+ * also disabled.
+ *
+ * @param {string} column
+ * @param {Object} config
+ * @param {!Array<string>} experiments
+ * @return {boolean}
+ */
+ isColumnEnabled(column, config, experiments) {
+ if (!config || !config.change) return true;
+ if (column === 'Assignee') return !!config.change.enable_assignee;
+ if (column === 'Comments') return experiments.includes('comments-column');
+ if (column === 'Reviewers') return !!config.change.enable_attention_set;
+ return true;
+ },
- /**
- * @param {!Array<string>} columns
- * @param {Object} config
- * @param {!Array<string>} experiments
- * @return {!Array<string>} enabled columns, see isColumnEnabled().
- */
- getEnabledColumns(columns, config, experiments) {
- return columns.filter(
- col => this.isColumnEnabled(col, config, experiments));
- },
+ /**
+ * @param {!Array<string>} columns
+ * @param {Object} config
+ * @param {!Array<string>} experiments
+ * @return {!Array<string>} enabled columns, see isColumnEnabled().
+ */
+ getEnabledColumns(columns, config, experiments) {
+ return columns.filter(
+ col => this.isColumnEnabled(col, config, experiments));
+ },
- /**
- * The Project column was renamed to Repo, but some users may have
- * preferences that use its old name. If that column is found, rename it
- * before use.
- *
- * @param {!Array<string>} columns
- * @return {!Array<string>} If the column was renamed, returns a new array
- * with the corrected name. Otherwise, it returns the original param.
- */
- getVisibleColumns(columns) {
- const projectIndex = columns.indexOf('Project');
- if (projectIndex === -1) { return columns; }
- const newColumns = columns.slice(0);
- newColumns[projectIndex] = 'Repo';
- return newColumns;
- },
- };
+ /**
+ * The Project column was renamed to Repo, but some users may have
+ * preferences that use its old name. If that column is found, rename it
+ * before use.
+ *
+ * @param {!Array<string>} columns
+ * @return {!Array<string>} If the column was renamed, returns a new array
+ * with the corrected name. Otherwise, it returns the original param.
+ */
+ getVisibleColumns(columns) {
+ const projectIndex = columns.indexOf('Project');
+ if (projectIndex === -1) { return columns; }
+ const newColumns = columns.slice(0);
+ newColumns[projectIndex] = 'Repo';
+ return newColumns;
+ },
+};
- // eslint-disable-next-line no-unused-vars
- function defineEmptyMixin() {
- // This is a temporary function.
- // Polymer linter doesn't process correctly the following code:
- // class MyElement extends Polymer.mixinBehaviors([legacyBehaviors], ...) {...}
- // To workaround this issue, the mock mixin is declared in this method.
- // In the following changes, legacy behaviors will be converted to mixins.
-
- /**
- * @polymer
- * @mixinFunction
- */
- Gerrit.ChangeTableMixin = base =>
- class extends base {
- static get properties() {
- return {
- columnNames: {
- type: Array,
- },
- };
- }
-
- isColumnHidden(columnToCheck, columnsToDisplay) {}
- };
- }
-})(window);
+// TODO(dmfilippov) Remove the following lines with assignments
+// Plugins can use the behavior because it was accessible with
+// the global Gerrit... variable. To avoid breaking changes in plugins
+// temporary assign global variables.
+window.Gerrit = window.Gerrit || {};
+window.Gerrit.ChangeTableBehavior = ChangeTableBehavior;
diff --git a/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior_test.html b/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior_test.html
index 8036ff0..39a4ea5 100644
--- a/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior_test.html
+++ b/polygerrit-ui/app/behaviors/gr-change-table-behavior/gr-change-table-behavior_test.html
@@ -39,8 +39,8 @@
<script type="module">
import '../../test/common-test-setup.js';
-import './gr-change-table-behavior.js';
import {Polymer} from '@polymer/polymer/lib/legacy/polymer-fn.js';
+import {ChangeTableBehavior} from './gr-change-table-behavior.js';
suite('gr-change-table-behavior tests', () => {
let element;
// eslint-disable-next-line no-unused-vars
@@ -50,7 +50,7 @@
// Define a Polymer element that uses this behavior.
Polymer({
is: 'test-element',
- behaviors: [Gerrit.ChangeTableBehavior],
+ behaviors: [ChangeTableBehavior],
});
});
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item.js b/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item.js
index 69f2a44..dfe10a6 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item.js
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list-item/gr-change-list-item.js
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-import '../../../behaviors/gr-change-table-behavior/gr-change-table-behavior.js';
import '../../../behaviors/gr-path-list-behavior/gr-path-list-behavior.js';
import '../../../behaviors/gr-url-encoding-behavior/gr-url-encoding-behavior.js';
import '../../../behaviors/rest-client-behavior/rest-client-behavior.js';
@@ -38,6 +37,7 @@
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-change-list-item_html.js';
import {BaseUrlBehavior} from '../../../behaviors/base-url-behavior/base-url-behavior.js';
+import {ChangeTableBehavior} from '../../../behaviors/gr-change-table-behavior/gr-change-table-behavior.js';
const CHANGE_SIZE = {
XS: 10,
@@ -47,7 +47,6 @@
};
/**
- * @appliesMixin Gerrit.ChangeTableMixin
* @appliesMixin Gerrit.PathListMixin
* @appliesMixin Gerrit.RESTClientMixin
* @appliesMixin Gerrit.URLEncodingMixin
@@ -55,7 +54,7 @@
*/
class GrChangeListItem extends mixinBehaviors( [
BaseUrlBehavior,
- Gerrit.ChangeTableBehavior,
+ ChangeTableBehavior,
Gerrit.PathListBehavior,
Gerrit.RESTClientBehavior,
Gerrit.URLEncodingBehavior,
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js
index 5f7467b..78ebc19 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-import '../../../behaviors/gr-change-table-behavior/gr-change-table-behavior.js';
import '../../../behaviors/gr-url-encoding-behavior/gr-url-encoding-behavior.js';
import '../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.js';
import '../../../behaviors/rest-client-behavior/rest-client-behavior.js';
@@ -36,6 +35,7 @@
import {htmlTemplate} from './gr-change-list_html.js';
import {flags} from '../../../services/flags';
import {BaseUrlBehavior} from '../../../behaviors/base-url-behavior/base-url-behavior.js';
+import {ChangeTableBehavior} from '../../../behaviors/gr-change-table-behavior/gr-change-table-behavior.js';
const NUMBER_FIXED_COLUMNS = 3;
const CLOSED_STATUS = ['MERGED', 'ABANDONED'];
@@ -43,7 +43,6 @@
const MAX_SHORTCUT_CHARS = 5;
/**
- * @appliesMixin Gerrit.ChangeTableMixin
* @appliesMixin Gerrit.KeyboardShortcutMixin
* @appliesMixin Gerrit.RESTClientMixin
* @appliesMixin Gerrit.URLEncodingMixin
@@ -51,7 +50,7 @@
*/
class GrChangeList extends mixinBehaviors( [
BaseUrlBehavior,
- Gerrit.ChangeTableBehavior,
+ ChangeTableBehavior,
Gerrit.KeyboardShortcutBehavior,
Gerrit.RESTClientBehavior,
Gerrit.URLEncodingBehavior,
diff --git a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.js b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.js
index 85c34a4..61e8e93 100644
--- a/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.js
+++ b/polygerrit-ui/app/elements/settings/gr-change-table-editor/gr-change-table-editor.js
@@ -14,8 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-import '../../../behaviors/gr-change-table-behavior/gr-change-table-behavior.js';
-
import '../../../scripts/bundled-polymer.js';
import '../../shared/gr-button/gr-button.js';
import '../../shared/gr-date-formatter/gr-date-formatter.js';
@@ -28,13 +26,13 @@
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-change-table-editor_html.js';
+import {ChangeTableBehavior} from '../../../behaviors/gr-change-table-behavior/gr-change-table-behavior.js';
/**
- * @appliesMixin Gerrit.ChangeTableMixin
* @extends Polymer.Element
*/
class GrChangeTableEditor extends mixinBehaviors( [
- Gerrit.ChangeTableBehavior,
+ ChangeTableBehavior,
], GestureEventListeners(
LegacyElementMixin(
PolymerElement))) {
diff --git a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js
index 9a5c6a6..161fa3c 100644
--- a/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js
+++ b/polygerrit-ui/app/elements/settings/gr-settings-view/gr-settings-view.js
@@ -48,6 +48,7 @@
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-settings-view_html.js';
import {DocsUrlBehavior} from '../../../behaviors/docs-url-behavior/docs-url-behavior.js';
+import {ChangeTableBehavior} from '../../../behaviors/gr-change-table-behavior/gr-change-table-behavior.js';
const PREFS_SECTION_FIELDS = [
'changes_per_page',
@@ -78,12 +79,11 @@
];
/**
- * @appliesMixin Gerrit.ChangeTableMixin
* @extends Polymer.Element
*/
class GrSettingsView extends mixinBehaviors( [
DocsUrlBehavior,
- Gerrit.ChangeTableBehavior,
+ ChangeTableBehavior,
], GestureEventListeners(
LegacyElementMixin(
PolymerElement))) {