Use imported DisplayNameBehavior

This change removes usage of global Gerrit.DisplayNameBehavior and
replace it with direct import. Also, the DisplayNameMixin is removed,
because it was introduced as a workaround for polylint tests and is no
longer needed.

Change-Id: I7b350f9b5daf1ad234b35287c6899341a2cbf024
This commit is contained in:
Dmitrii Filippov
2020-04-03 17:01:47 +02:00
parent f8038490eb
commit f5f2578eed
5 changed files with 27 additions and 47 deletions

View File

@@ -16,42 +16,26 @@
*/
import '../../scripts/gr-display-name-utils/gr-display-name-utils.js';
(function(window) {
'use strict';
/** @polymerBehavior Gerrit.DisplayNameBehavior */
export const DisplayNameBehavior = {
// TODO(dmfilippov) replace DisplayNameBehavior with GrDisplayNameUtils
window.Gerrit = window.Gerrit || {};
getUserName(config, account) {
return GrDisplayNameUtils.getUserName(config, account);
},
/** @polymerBehavior Gerrit.DisplayNameBehavior */
Gerrit.DisplayNameBehavior = {
// TODO(dmfilippov) replace DisplayNameBehavior with GrDisplayNameUtils
getDisplayName(config, account) {
return GrDisplayNameUtils.getDisplayName(config, account);
},
getUserName(config, account) {
return GrDisplayNameUtils.getUserName(config, account);
},
getGroupDisplayName(group) {
return GrDisplayNameUtils.getGroupDisplayName(group);
},
};
getDisplayName(config, account) {
return GrDisplayNameUtils.getDisplayName(config, account);
},
getGroupDisplayName(group) {
return GrDisplayNameUtils.getGroupDisplayName(group);
},
};
// 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.DisplayNameMixin = base =>
class extends base {
};
}
})(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.DisplayNameBehavior = DisplayNameBehavior;

View File

@@ -31,8 +31,8 @@ limitations under the License.
<script type="module">
import '../../test/common-test-setup.js';
import './gr-display-name-behavior.js';
import {Polymer} from '@polymer/polymer/lib/legacy/polymer-fn.js';
import {DisplayNameBehavior} from './gr-display-name-behavior.js';
suite('gr-display-name-behavior tests', () => {
let element;
// eslint-disable-next-line no-unused-vars
@@ -47,7 +47,7 @@ suite('gr-display-name-behavior tests', () => {
Polymer({
is: 'test-element-anon',
behaviors: [
Gerrit.DisplayNameBehavior,
DisplayNameBehavior,
],
});
});

View File

@@ -14,8 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import '../../../behaviors/gr-display-name-behavior/gr-display-name-behavior.js';
import '../../../scripts/bundled-polymer.js';
import '../../shared/gr-button/gr-button.js';
import '../../shared/gr-dropdown/gr-dropdown.js';
@@ -27,15 +25,15 @@ import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-l
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-account-dropdown_html.js';
import {DisplayNameBehavior} from '../../../behaviors/gr-display-name-behavior/gr-display-name-behavior.js';
const INTERPOLATE_URL_PATTERN = /\$\{([\w]+)\}/g;
/**
* @appliesMixin Gerrit.DisplayNameMixin
* @extends Polymer.Element
*/
class GrAccountDropdown extends mixinBehaviors( [
Gerrit.DisplayNameBehavior,
DisplayNameBehavior,
], GestureEventListeners(
LegacyElementMixin(
PolymerElement))) {

View File

@@ -16,7 +16,6 @@
*/
import '../../../scripts/bundled-polymer.js';
import '../../../behaviors/gr-display-name-behavior/gr-display-name-behavior.js';
import '../gr-navigation/gr-navigation.js';
import '../../shared/gr-rest-api-interface/gr-rest-api-interface.js';
import '../gr-search-bar/gr-search-bar.js';
@@ -25,17 +24,17 @@ import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-l
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-smart-search_html.js';
import {DisplayNameBehavior} from '../../../behaviors/gr-display-name-behavior/gr-display-name-behavior.js';
const MAX_AUTOCOMPLETE_RESULTS = 10;
const SELF_EXPRESSION = 'self';
const ME_EXPRESSION = 'me';
/**
* @appliesMixin Gerrit.DisplayNameMixin
* @extends Polymer.Element
*/
class GrSmartSearch extends mixinBehaviors( [
Gerrit.DisplayNameBehavior,
DisplayNameBehavior,
], GestureEventListeners(
LegacyElementMixin(
PolymerElement))) {

View File

@@ -17,7 +17,6 @@
import '../../../scripts/bundled-polymer.js';
import '@polymer/iron-icon/iron-icon.js';
import '../../../behaviors/gr-display-name-behavior/gr-display-name-behavior.js';
import '../../../behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js';
import '../../../styles/shared-styles.js';
import '../gr-avatar/gr-avatar.js';
@@ -29,13 +28,13 @@ import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-l
import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
import {PolymerElement} from '@polymer/polymer/polymer-element.js';
import {htmlTemplate} from './gr-account-label_html.js';
import {DisplayNameBehavior} from '../../../behaviors/gr-display-name-behavior/gr-display-name-behavior.js';
/**
* @appliesMixin Gerrit.DisplayNameMixin
* @extends Polymer.Element
*/
class GrAccountLabel extends mixinBehaviors( [
Gerrit.DisplayNameBehavior,
DisplayNameBehavior,
], GestureEventListeners(
LegacyElementMixin(
PolymerElement))) {