Merge "Remove gr-change-requirements"
diff --git a/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.ts b/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.ts
index 95ad376..9df22f1 100644
--- a/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.ts
+++ b/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata.ts
@@ -29,7 +29,6 @@
import '../../shared/gr-linked-chip/gr-linked-chip';
import '../../shared/gr-tooltip-content/gr-tooltip-content';
import '../gr-submit-requirements/gr-submit-requirements';
-import '../gr-change-requirements/gr-change-requirements';
import '../gr-commit-info/gr-commit-info';
import '../gr-reviewer-list/gr-reviewer-list';
import '../../shared/gr-account-list/gr-account-list';
@@ -83,11 +82,7 @@
} from '../../shared/gr-autocomplete/gr-autocomplete';
import {getRevertCreatedChangeIds} from '../../../utils/message-util';
import {Interaction} from '../../../constants/reporting';
-import {
- getApprovalInfo,
- getCodeReviewLabel,
- showNewSubmitRequirements,
-} from '../../../utils/label-util';
+import {getApprovalInfo, getCodeReviewLabel} from '../../../utils/label-util';
import {LitElement, css, html, nothing, PropertyValues} from 'lit';
import {customElement, property, query, state} from 'lit/decorators';
import {sharedStyles} from '../../../styles/shared-styles';
@@ -179,8 +174,6 @@
private readonly reporting = getAppContext().reportingService;
- private readonly flagsService = getAppContext().flagsService;
-
constructor() {
super();
this.queryTopic = (input: string) => this.getTopicSuggestions(input);
@@ -195,7 +188,6 @@
:host {
display: table;
}
- gr-change-requirements,
gr-submit-requirements {
--requirements-horizontal-padding: var(--metadata-horizontal-padding);
}
@@ -702,23 +694,13 @@
}
private renderSubmitRequirements() {
- if (this.showNewSubmitRequirements()) {
- return html`<div class="separatedSection">
- <gr-submit-requirements
- .change=${this.change}
- .account=${this.account}
- .mutable=${this.mutable}
- ></gr-submit-requirements>
- </div>`;
- } else {
- return html` <div class="oldSeparatedSection">
- <gr-change-requirements
- .change=${this.change}
- .account=${this.account}
- .mutable=${this.mutable}
- ></gr-change-requirements>
- </div>`;
- }
+ return html`<div class="separatedSection">
+ <gr-submit-requirements
+ .change=${this.change}
+ .account=${this.account}
+ .mutable=${this.mutable}
+ ></gr-submit-requirements>
+ </div>`;
}
private renderWeblinks() {
@@ -1213,10 +1195,6 @@
);
}
- private showNewSubmitRequirements() {
- return showNewSubmitRequirements(this.flagsService, this.change);
- }
-
private computeVoteForRole(role: ChangeRole) {
const reviewer = this.getNonOwnerRole(role);
if (reviewer && isAccount(reviewer)) {
diff --git a/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata_test.ts b/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata_test.ts
index 2b48697..a383cb1 100644
--- a/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata_test.ts
+++ b/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata_test.ts
@@ -199,8 +199,8 @@
<span class="title"> Hashtags </span>
<span class="value"> </span>
</section>
- <div class="oldSeparatedSection">
- <gr-change-requirements></gr-change-requirements>
+ <div class="separatedSection">
+ <gr-submit-requirements></gr-submit-requirements>
</div>
<gr-endpoint-decorator name="change-metadata-item">
<gr-endpoint-param name="labels"> </gr-endpoint-param>
diff --git a/polygerrit-ui/app/elements/change/gr-change-requirements/gr-change-requirements.ts b/polygerrit-ui/app/elements/change/gr-change-requirements/gr-change-requirements.ts
deleted file mode 100644
index 821e1ce..0000000
--- a/polygerrit-ui/app/elements/change/gr-change-requirements/gr-change-requirements.ts
+++ /dev/null
@@ -1,208 +0,0 @@
-/**
- * @license
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import '../../../styles/shared-styles';
-import '../../../styles/gr-font-styles';
-import '../../shared/gr-button/gr-button';
-import '../../shared/gr-icons/gr-icons';
-import '../../shared/gr-label-info/gr-label-info';
-import '../../shared/gr-limited-text/gr-limited-text';
-import {PolymerElement} from '@polymer/polymer/polymer-element';
-import {htmlTemplate} from './gr-change-requirements_html';
-import {customElement, property, observe} from '@polymer/decorators';
-import {
- ChangeInfo,
- AccountInfo,
- QuickLabelInfo,
- Requirement,
- RequirementType,
- LabelNameToInfoMap,
- LabelInfo,
-} from '../../../types/common';
-import {PolymerDeepPropertyChange} from '@polymer/polymer/interfaces';
-import {getAppContext} from '../../../services/app-context';
-import {labelCompare} from '../../../utils/label-util';
-import {Interaction} from '../../../constants/reporting';
-
-interface ChangeRequirement extends Requirement {
- satisfied: boolean;
- style: string;
-}
-
-interface ChangeWIP {
- type: RequirementType;
- fallback_text: string;
- tooltip: string;
-}
-
-export interface Label {
- labelName: string;
- labelInfo: LabelInfo;
- icon: string;
- style: string;
-}
-
-@customElement('gr-change-requirements')
-export class GrChangeRequirements extends PolymerElement {
- static get template() {
- return htmlTemplate;
- }
-
- @property({type: Object})
- change?: ChangeInfo;
-
- @property({type: Object})
- account?: AccountInfo;
-
- @property({type: Boolean})
- mutable?: boolean;
-
- @property({type: Array, computed: '_computeRequirements(change)'})
- _requirements?: Array<ChangeRequirement | ChangeWIP>;
-
- @property({type: Array})
- _requiredLabels: Label[] = [];
-
- @property({type: Array})
- _optionalLabels: Label[] = [];
-
- @property({type: Boolean, computed: '_computeShowWip(change)'})
- _showWip?: boolean;
-
- @property({type: Boolean})
- _showOptionalLabels = true;
-
- private readonly reporting = getAppContext().reportingService;
-
- _computeShowWip(change: ChangeInfo) {
- return change.work_in_progress;
- }
-
- _computeRequirements(change: ChangeInfo) {
- const _requirements: Array<ChangeRequirement | ChangeWIP> = [];
-
- if (change.requirements) {
- for (const requirement of change.requirements) {
- const satisfied = requirement.status === 'OK';
- const style = this._computeRequirementClass(satisfied);
- _requirements.push({...requirement, satisfied, style});
- }
- }
- if (change.work_in_progress) {
- _requirements.push({
- type: 'wip' as RequirementType,
- fallback_text: 'Work-in-progress',
- tooltip: "Change must not be in 'Work in Progress' state.",
- });
- }
-
- return _requirements;
- }
-
- _computeRequirementClass(requirementStatus: boolean) {
- return requirementStatus ? 'approved' : '';
- }
-
- _computeRequirementIcon(requirementStatus: boolean) {
- return requirementStatus ? 'gr-icons:check' : 'gr-icons:schedule';
- }
-
- @observe('change.labels.*')
- _computeLabels(
- labelsRecord: PolymerDeepPropertyChange<
- LabelNameToInfoMap,
- LabelNameToInfoMap
- >
- ) {
- const labels = labelsRecord.base || {};
- const allLabels: Label[] = [];
-
- for (const label of Object.keys(labels).sort(labelCompare)) {
- allLabels.push({
- labelName: label,
- icon: this._computeLabelIcon(labels[label]),
- style: this._computeLabelClass(labels[label]),
- labelInfo: labels[label],
- });
- }
- this._optionalLabels = allLabels.filter(label => label.labelInfo.optional);
- this._requiredLabels = allLabels.filter(label => !label.labelInfo.optional);
- }
-
- /**
- * @return The icon name, or undefined if no icon should
- * be used.
- */
- _computeLabelIcon(labelInfo: QuickLabelInfo) {
- if (labelInfo.approved) {
- return 'gr-icons:check';
- }
- if (labelInfo.rejected) {
- return 'gr-icons:close';
- }
- return 'gr-icons:schedule';
- }
-
- _computeLabelClass(labelInfo: QuickLabelInfo) {
- if (labelInfo.approved) {
- return 'approved';
- }
- if (labelInfo.rejected) {
- return 'rejected';
- }
- return '';
- }
-
- _computeShowOptional(
- optionalFieldsRecord: PolymerDeepPropertyChange<Label[], Label[]>
- ) {
- return optionalFieldsRecord.base.length ? '' : 'hidden';
- }
-
- _computeLabelValue(value: number) {
- return `${value > 0 ? '+' : ''}${value}`;
- }
-
- _computeSectionClass(show: boolean) {
- return show ? '' : 'hidden';
- }
-
- _handleShowHide() {
- this._showOptionalLabels = !this._showOptionalLabels;
- this.reporting.reportInteraction(Interaction.TOGGLE_SHOW_ALL_BUTTON, {
- sectionName: 'optional labels',
- toState: this._showOptionalLabels ? 'Show all' : 'Show less',
- });
- }
-
- _computeSubmitRequirementEndpoint(item: ChangeRequirement | ChangeWIP) {
- return `submit-requirement-item-${item.type}`;
- }
-
- _computeShowAllLabelText(_showOptionalLabels: boolean) {
- if (_showOptionalLabels) {
- return 'Show less';
- } else {
- return 'Show all';
- }
- }
-}
-
-declare global {
- interface HTMLElementTagNameMap {
- 'gr-change-requirements': GrChangeRequirements;
- }
-}
diff --git a/polygerrit-ui/app/elements/change/gr-change-requirements/gr-change-requirements_html.ts b/polygerrit-ui/app/elements/change/gr-change-requirements/gr-change-requirements_html.ts
deleted file mode 100644
index 0005c90..0000000
--- a/polygerrit-ui/app/elements/change/gr-change-requirements/gr-change-requirements_html.ts
+++ /dev/null
@@ -1,211 +0,0 @@
-/**
- * @license
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import {html} from '@polymer/polymer/lib/utils/html-tag';
-
-export const htmlTemplate = html`
- <style include="gr-font-styles">
- /* Workaround for empty style block - see https://github.com/Polymer/tools/issues/408 */
- </style>
- <style include="shared-styles">
- :host {
- display: table;
- width: 100%;
- }
- .status {
- color: var(--warning-foreground);
- display: inline-block;
- text-align: center;
- vertical-align: top;
- font-family: var(--monospace-font-family);
- font-size: var(--font-size-mono);
- line-height: var(--line-height-mono);
- }
- .approved.status {
- color: var(--positive-green-text-color);
- }
- .rejected.status {
- color: var(--negative-red-text-color);
- }
- iron-icon {
- color: inherit;
- }
- .status iron-icon {
- vertical-align: top;
- }
- gr-endpoint-decorator.submit-requirement-endpoints,
- section {
- display: table-row;
- }
- .show-hide {
- float: right;
- }
- .title {
- min-width: 10em;
- padding: var(--spacing-s) var(--spacing-m) 0
- var(--requirements-horizontal-padding);
- }
- .value {
- padding: var(--spacing-s) 0 0 0;
- }
- .title,
- .value {
- display: table-cell;
- vertical-align: top;
- }
- .hidden {
- display: none;
- }
- .showHide {
- cursor: pointer;
- }
- .showHide .title {
- padding-bottom: var(--spacing-m);
- padding-top: var(--spacing-l);
- }
- .showHide .value {
- padding-top: 0;
- vertical-align: middle;
- }
- .showHide iron-icon {
- color: var(--deemphasized-text-color);
- float: right;
- }
- .show-all-button {
- float: right;
- }
- .show-all-button iron-icon {
- color: inherit;
- --iron-icon-height: 18px;
- --iron-icon-width: 18px;
- }
- .spacer {
- height: var(--spacing-m);
- }
- gr-endpoint-param {
- display: none;
- }
- .metadata-title {
- font-weight: var(--font-weight-bold);
- color: var(--deemphasized-text-color);
- padding-left: var(--metadata-horizontal-padding);
- }
- .title .metadata-title {
- padding-left: 0;
- }
- </style>
- <h3 class="metadata-title heading-3">Submit requirements</h3>
- <template is="dom-repeat" items="[[_requirements]]">
- <gr-endpoint-decorator
- class="submit-requirement-endpoints"
- name$="[[_computeSubmitRequirementEndpoint(item)]]"
- >
- <gr-endpoint-param name="change" value="[[change]]"></gr-endpoint-param>
- <gr-endpoint-param name="requirement" value="[[item]]">
- </gr-endpoint-param>
- <div class="title requirement">
- <span class$="status [[item.style]]">
- <iron-icon
- class="icon"
- icon="[[_computeRequirementIcon(item.satisfied)]]"
- ></iron-icon>
- </span>
- <gr-limited-text
- class="name"
- tooltip="[[item.tooltip]]"
- text="[[item.fallback_text]]"
- ></gr-limited-text>
- </div>
- <div class="value">
- <gr-endpoint-slot name="value"></gr-endpoint-slot>
- </div>
- </gr-endpoint-decorator>
- </template>
- <template is="dom-repeat" items="[[_requiredLabels]]">
- <section>
- <div class="title">
- <span class$="status [[item.style]]">
- <iron-icon class="icon" icon="[[item.icon]]"></iron-icon>
- </span>
- <gr-limited-text
- class="name"
- text="[[item.labelName]]"
- ></gr-limited-text>
- </div>
- <div class="value">
- <gr-label-info
- change="{{change}}"
- account="[[account]]"
- mutable="[[mutable]]"
- label="[[item.labelName]]"
- label-info="[[item.labelInfo]]"
- ></gr-label-info>
- </div>
- </section>
- </template>
- <section class="spacer"></section>
- <section
- class$="spacer [[_computeShowOptional(_optionalLabels.*)]]"
- ></section>
- <section class$="showHide [[_computeShowOptional(_optionalLabels.*)]]">
- <div class="title">
- <h3 class="metadata-title">Other labels</h3>
- </div>
- <div class="value">
- <gr-button link="" class="show-all-button" on-click="_handleShowHide"
- >[[_computeShowAllLabelText(_showOptionalLabels)]]
- <iron-icon
- icon="gr-icons:expand-more"
- hidden$="[[_showOptionalLabels]]"
- ></iron-icon
- ><iron-icon
- icon="gr-icons:expand-less"
- hidden$="[[!_showOptionalLabels]]"
- ></iron-icon>
- </gr-button>
- </div>
- </section>
- <template is="dom-repeat" items="[[_optionalLabels]]">
- <section class$="optional [[_computeSectionClass(_showOptionalLabels)]]">
- <div class="title">
- <span class$="status [[item.style]]">
- <template is="dom-if" if="[[item.icon]]">
- <iron-icon class="icon" icon="[[item.icon]]"></iron-icon>
- </template>
- <template is="dom-if" if="[[!item.icon]]">
- <span>[[_computeLabelValue(item.labelInfo.value)]]</span>
- </template>
- </span>
- <gr-limited-text
- class="name"
- text="[[item.labelName]]"
- ></gr-limited-text>
- </div>
- <div class="value">
- <gr-label-info
- change="{{change}}"
- account="[[account]]"
- mutable="[[mutable]]"
- label="[[item.labelName]]"
- label-info="[[item.labelInfo]]"
- ></gr-label-info>
- </div>
- </section>
- </template>
- <section
- class$="spacer [[_computeShowOptional(_optionalLabels.*)]] [[_computeSectionClass(_showOptionalLabels)]]"
- ></section>
-`;
diff --git a/polygerrit-ui/app/elements/change/gr-change-requirements/gr-change-requirements_test.js b/polygerrit-ui/app/elements/change/gr-change-requirements/gr-change-requirements_test.js
deleted file mode 100644
index 90f9d29..0000000
--- a/polygerrit-ui/app/elements/change/gr-change-requirements/gr-change-requirements_test.js
+++ /dev/null
@@ -1,222 +0,0 @@
-/**
- * @license
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import '../../../test/common-test-setup-karma.js';
-import './gr-change-requirements.js';
-import {isHidden} from '../../../test/test-utils.js';
-
-const basicFixture = fixtureFromElement('gr-change-requirements');
-
-suite('gr-change-metadata tests', () => {
- let element;
-
- setup(() => {
- element = basicFixture.instantiate();
- });
-
- test('requirements computed fields', () => {
- assert.isTrue(element._computeShowWip({work_in_progress: true}));
- assert.isFalse(element._computeShowWip({work_in_progress: false}));
-
- assert.equal(element._computeRequirementClass(true), 'approved');
- assert.equal(element._computeRequirementClass(false), '');
-
- assert.equal(element._computeRequirementIcon(true), 'gr-icons:check');
- assert.equal(element._computeRequirementIcon(false),
- 'gr-icons:schedule');
- });
-
- test('label computed fields', () => {
- assert.equal(element._computeLabelIcon({approved: []}), 'gr-icons:check');
- assert.equal(element._computeLabelIcon({rejected: []}), 'gr-icons:close');
- assert.equal(element._computeLabelIcon({}), 'gr-icons:schedule');
-
- assert.equal(element._computeLabelClass({approved: []}), 'approved');
- assert.equal(element._computeLabelClass({rejected: []}), 'rejected');
- assert.equal(element._computeLabelClass({}), '');
- assert.equal(element._computeLabelClass({value: 0}), '');
-
- assert.equal(element._computeLabelValue(1), '+1');
- assert.equal(element._computeLabelValue(-1), '-1');
- assert.equal(element._computeLabelValue(0), '0');
- });
-
- test('_computeLabels', () => {
- assert.equal(element._optionalLabels.length, 0);
- assert.equal(element._requiredLabels.length, 0);
- element._computeLabels({base: {
- test: {
- all: [{_account_id: 1, name: 'bojack', value: 1}],
- default_value: 0,
- values: [],
- value: 1,
- },
- opt_test: {
- all: [{_account_id: 1, name: 'bojack', value: 1}],
- default_value: 0,
- values: [],
- optional: true,
- },
- }});
- assert.equal(element._optionalLabels.length, 1);
- assert.equal(element._requiredLabels.length, 1);
-
- assert.equal(element._optionalLabels[0].labelName, 'opt_test');
- assert.equal(element._optionalLabels[0].icon, 'gr-icons:schedule');
- assert.equal(element._optionalLabels[0].style, '');
- assert.ok(element._optionalLabels[0].labelInfo);
- });
-
- test('optional show/hide', () => {
- element._optionalLabels = [{label: 'test'}];
- flush();
-
- assert.ok(element.shadowRoot
- .querySelector('section.optional'));
- MockInteractions.tap(element.shadowRoot
- .querySelector('.show-all-button'));
- flush();
-
- assert.isFalse(element._showOptionalLabels);
- assert.isTrue(isHidden(element.shadowRoot
- .querySelector('section.optional')));
- });
-
- test('properly converts satisfied labels', () => {
- element.change = {
- status: 'NEW',
- labels: {
- Verified: {
- approved: [],
- },
- },
- requirements: [],
- };
- flush();
-
- assert.ok(element.shadowRoot
- .querySelector('.approved'));
- assert.ok(element.shadowRoot
- .querySelector('.name'));
- assert.equal(element.shadowRoot
- .querySelector('.name').text, 'Verified');
- });
-
- test('properly converts unsatisfied labels', () => {
- element.change = {
- status: 'NEW',
- labels: {
- Verified: {
- approved: false,
- },
- },
- };
- flush();
-
- const name = element.shadowRoot
- .querySelector('.name');
- assert.ok(name);
- assert.isFalse(name.hasAttribute('hidden'));
- assert.equal(name.text, 'Verified');
- });
-
- test('properly displays Work In Progress', () => {
- element.change = {
- status: 'NEW',
- labels: {},
- requirements: [],
- work_in_progress: true,
- };
- flush();
-
- const changeIsWip = element.shadowRoot
- .querySelector('.title');
- assert.ok(changeIsWip);
- });
-
- test('properly displays a satisfied requirement', () => {
- element.change = {
- status: 'NEW',
- labels: {},
- requirements: [{
- fallback_text: 'Resolve all comments',
- status: 'OK',
- }],
- };
- flush();
-
- const requirement = element.shadowRoot
- .querySelector('.requirement');
- assert.ok(requirement);
- assert.isFalse(requirement.hasAttribute('hidden'));
- assert.ok(requirement.querySelector('.approved'));
- assert.equal(requirement.querySelector('.name').text,
- 'Resolve all comments');
- });
-
- test('satisfied class is applied with OK', () => {
- element.change = {
- status: 'NEW',
- labels: {},
- requirements: [{
- fallback_text: 'Resolve all comments',
- status: 'OK',
- }],
- };
- flush();
-
- const requirement = element.shadowRoot
- .querySelector('.requirement');
- assert.ok(requirement);
- assert.ok(requirement.querySelector('.approved'));
- });
-
- test('satisfied class is not applied with NOT_READY', () => {
- element.change = {
- status: 'NEW',
- labels: {},
- requirements: [{
- fallback_text: 'Resolve all comments',
- status: 'NOT_READY',
- }],
- };
- flush();
-
- const requirement = element.shadowRoot
- .querySelector('.requirement');
- assert.ok(requirement);
- assert.strictEqual(requirement.querySelector('.approved'), null);
- });
-
- test('satisfied class is not applied with RULE_ERROR', () => {
- element.change = {
- status: 'NEW',
- labels: {},
- requirements: [{
- fallback_text: 'Resolve all comments',
- status: 'RULE_ERROR',
- }],
- };
- flush();
-
- const requirement = element.shadowRoot
- .querySelector('.requirement');
- assert.ok(requirement);
- assert.strictEqual(requirement.querySelector('.approved'), null);
- });
-});
-