From 3810c5e7c4e5e60721601878a039a90b10fd202c Mon Sep 17 00:00:00 2001 From: Paladox Date: Sat, 17 Mar 2018 16:24:21 +0000 Subject: [PATCH 1/2] PolyGerrit: Add support for "Included In" Bug: Issue 6112 Change-Id: I033e3f248a404813b5bc46eeef6bf25b7153bc1a --- .../change/gr-change-view/gr-change-view.html | 12 +++ .../change/gr-change-view/gr-change-view.js | 13 +++ .../gr-file-list-header.html | 9 ++ .../gr-file-list-header.js | 9 ++ .../gr-included-in-dialog.html | 84 +++++++++++++++++++ .../gr-included-in-dialog.js | 82 ++++++++++++++++++ .../gr-included-in-dialog_test.html | 74 ++++++++++++++++ .../gr-rest-api-interface.js | 7 ++ polygerrit-ui/app/test/index.html | 1 + 9 files changed, 291 insertions(+) create mode 100644 polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.html create mode 100644 polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.js create mode 100644 polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog_test.html diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html index 3ac3a578ae..172795ccd2 100644 --- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html +++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html @@ -36,6 +36,7 @@ limitations under the License. + @@ -203,6 +204,10 @@ limitations under the License. .scrollable { overflow: auto; } + #includedInOverlay { + padding: 2em; + width: 65em; + } @media screen and (min-width: 80em) { .commitMessage { max-width: var(--commit-message-max-width, 100ch); @@ -439,6 +444,7 @@ limitations under the License. revisions="[[_sortedRevisions]]" on-open-diff-prefs="_handleOpenDiffPrefs" on-open-download-dialog="_handleOpenDownloadDialog" + on-open-included-in-dialog="_handleOpenIncludedInDialog" on-expand-diffs="_expandAllDiffs" on-collapse-diffs="_collapseAllDiffs"> @@ -476,6 +482,12 @@ limitations under the License. config="[[_serverConfig.download]]" on-close="_handleDownloadDialogClose"> + + + { + Polymer.dom.flush(); + this.$.includedInOverlay.refit(); + }); + this.$.includedInOverlay.open(); + }, + + _handleIncludedInDialogClose(e) { + this.$.includedInOverlay.close(); + }, + _handleOpenDownloadDialog() { this.$.downloadOverlay.open().then(() => { this.$.downloadOverlay diff --git a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.html b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.html index fd07d4ecf2..fb862603e3 100644 --- a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.html +++ b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.html @@ -131,6 +131,9 @@ limitations under the License. font-family: var(--font-family-bold); margin-right: 1em; } + .container.includedInContainer.hide { + display: none; + } @media screen and (max-width: 50em) { .patchInfo-header .desktop { display: none; @@ -166,6 +169,12 @@ limitations under the License. class="download" on-tap="_handleDownloadTap">Download + + + Included In + + + + + + + + + + diff --git a/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.js b/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.js new file mode 100644 index 0000000000..1079eeca08 --- /dev/null +++ b/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.js @@ -0,0 +1,82 @@ +// 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. +(function() { + 'use strict'; + + Polymer({ + is: 'gr-included-in-dialog', + + /** + * Fired when the user presses the close button. + * + * @event close + */ + + properties: { + /** @type {?} */ + changeNum: { + type: Object, + observer: '_resetData', + }, + /** @type {?} */ + _includedIn: Object, + _loaded: { + type: Boolean, + value: false, + }, + }, + + loadData() { + if (!this.changeNum) { return; } + return this.$.restAPI.getChangeIncludedIn(this.changeNum).then( + configs => { + if (!configs) { return; } + this._includedIn = configs; + this._loaded = true; + }); + }, + + _resetData() { + this._includedIn = null; + this._loaded = false; + }, + + _computeGroups(includedIn) { + if (!includedIn) { return []; } + + const groups = [ + {title: 'Branches', items: includedIn.branches}, + {title: 'Tags', items: includedIn.tags}, + ]; + if (includedIn.external) { + for (const externalKey of Object.keys(includedIn.external)) { + groups.push({ + title: externalKey, + items: includedIn.external[externalKey], + }); + } + } + return groups; + }, + + _handleCloseTap(e) { + e.preventDefault(); + this.fire('close', null, {bubbles: false}); + }, + + _computeLoadingClass(loaded) { + return loaded ? 'loading loaded' : 'loading'; + }, + }); +})(); diff --git a/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog_test.html b/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog_test.html new file mode 100644 index 0000000000..16aa7b21af --- /dev/null +++ b/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog_test.html @@ -0,0 +1,74 @@ + + + + +gr-included-in-dialog + + + + + + + + + + + + + diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js index 763e622754..5e9d913ae3 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js @@ -986,6 +986,13 @@ opt_errFn, null, params); }, + /** + * @param {number|string} changeNum + */ + getChangeIncludedIn(changeNum) { + return this._getChangeURLAndFetch(changeNum, '/in', null); + }, + _computeFilter(filter) { if (filter && filter.startsWith('^')) { filter = '&r=' + encodeURIComponent(filter); diff --git a/polygerrit-ui/app/test/index.html b/polygerrit-ui/app/test/index.html index a06b470922..cbc5cb0846 100644 --- a/polygerrit-ui/app/test/index.html +++ b/polygerrit-ui/app/test/index.html @@ -68,6 +68,7 @@ limitations under the License. 'change/gr-download-dialog/gr-download-dialog_test.html', 'change/gr-file-list-header/gr-file-list-header_test.html', 'change/gr-file-list/gr-file-list_test.html', + 'change/gr-included-in-dialog/gr-included-in-dialog_test.html', 'change/gr-label-score-row/gr-label-score-row_test.html', 'change/gr-label-scores/gr-label-scores_test.html', 'change/gr-message/gr-message_test.html', From 8e32422334e742960e5a987ff1ac5deea8434e3a Mon Sep 17 00:00:00 2001 From: Wyatt Allen Date: Fri, 16 Mar 2018 12:55:58 -0700 Subject: [PATCH 2/2] Included-In dialog polish Add a filter textbox and behavior to the Included-In dialog and align the padding with other dialogs. To accommodate filtering, empty groups are hidden. Change-Id: I481f266ce8cc67de07f1dc8dfb9129b7d36e081b --- .../change/gr-change-view/gr-change-view.html | 1 - .../gr-included-in-dialog.html | 66 ++++++++++++------- .../gr-included-in-dialog.js | 24 +++++-- .../gr-included-in-dialog_test.html | 23 +++++-- 4 files changed, 76 insertions(+), 38 deletions(-) diff --git a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html index 172795ccd2..40db0915b1 100644 --- a/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html +++ b/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.html @@ -205,7 +205,6 @@ limitations under the License. overflow: auto; } #includedInOverlay { - padding: 2em; width: 65em; } @media screen and (min-width: 80em) { diff --git a/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.html b/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.html index a017635252..c3d5808cbf 100644 --- a/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.html +++ b/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.html @@ -23,22 +23,35 @@ limitations under the License.
-

Included In:

+

Included In:

Close +
Loading...
-
- -
+ diff --git a/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.js b/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.js index 1079eeca08..93e644e053 100644 --- a/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.js +++ b/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog.js @@ -35,10 +35,15 @@ type: Boolean, value: false, }, + _filterText: { + type: String, + value: '', + }, }, loadData() { if (!this.changeNum) { return; } + this._filterText = ''; return this.$.restAPI.getChangeIncludedIn(this.changeNum).then( configs => { if (!configs) { return; } @@ -52,22 +57,25 @@ this._loaded = false; }, - _computeGroups(includedIn) { + _computeGroups(includedIn, filterText) { if (!includedIn) { return []; } + const filter = item => !filterText.length || + item.toLowerCase().indexOf(filterText.toLowerCase()) !== -1; + const groups = [ - {title: 'Branches', items: includedIn.branches}, - {title: 'Tags', items: includedIn.tags}, + {title: 'Branches', items: includedIn.branches.filter(filter)}, + {title: 'Tags', items: includedIn.tags.filter(filter)}, ]; if (includedIn.external) { for (const externalKey of Object.keys(includedIn.external)) { groups.push({ title: externalKey, - items: includedIn.external[externalKey], + items: includedIn.external[externalKey].filter(filter), }); } } - return groups; + return groups.filter(g => g.items.length); }, _handleCloseTap(e) { @@ -78,5 +86,11 @@ _computeLoadingClass(loaded) { return loaded ? 'loading loaded' : 'loading'; }, + + _onFilterChanged() { + this.debounce('filter-change', () => { + this._filterText = this.$.filterInput.bindValue; + }, 100); + }, }); })(); diff --git a/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog_test.html b/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog_test.html index 16aa7b21af..1f7af38e8c 100644 --- a/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog_test.html +++ b/polygerrit-ui/app/elements/change/gr-included-in-dialog/gr-included-in-dialog_test.html @@ -45,30 +45,39 @@ limitations under the License. test('_computeGroups', () => { const includedIn = {branches: [], tags: []}; - assert.deepEqual(element._computeGroups(includedIn), [ - {title: 'Branches', items: []}, - {title: 'Tags', items: []}, - ]); + let filterText = ''; + assert.deepEqual(element._computeGroups(includedIn, filterText), []); includedIn.branches.push('master', 'development', 'stable-2.0'); includedIn.tags.push('v1.9', 'v2.0', 'v2.1'); - assert.deepEqual(element._computeGroups(includedIn), [ + assert.deepEqual(element._computeGroups(includedIn, filterText), [ {title: 'Branches', items: ['master', 'development', 'stable-2.0']}, {title: 'Tags', items: ['v1.9', 'v2.0', 'v2.1']}, ]); includedIn.external = {}; - assert.deepEqual(element._computeGroups(includedIn), [ + assert.deepEqual(element._computeGroups(includedIn, filterText), [ {title: 'Branches', items: ['master', 'development', 'stable-2.0']}, {title: 'Tags', items: ['v1.9', 'v2.0', 'v2.1']}, ]); includedIn.external.foo = ['abc', 'def', 'ghi']; - assert.deepEqual(element._computeGroups(includedIn), [ + assert.deepEqual(element._computeGroups(includedIn, filterText), [ {title: 'Branches', items: ['master', 'development', 'stable-2.0']}, {title: 'Tags', items: ['v1.9', 'v2.0', 'v2.1']}, {title: 'foo', items: ['abc', 'def', 'ghi']}, ]); + + filterText = 'v2'; + assert.deepEqual(element._computeGroups(includedIn, filterText), [ + {title: 'Tags', items: ['v2.0', 'v2.1']}, + ]); + + // Filtering is case-insensitive. + filterText = 'V2'; + assert.deepEqual(element._computeGroups(includedIn, filterText), [ + {title: 'Tags', items: ['v2.0', 'v2.1']}, + ]); }); });