PolyGerrit: Add support for suggesting branches in cherry-pick dialog
Mimics gwtui and makes it easier if you type a letter in, it should give you the results. Change-Id: I46a1192a565351389895599f1b1589bbb9e3d338
This commit is contained in:
@@ -122,6 +122,7 @@ limitations under the License.
|
||||
commit-num="[[commitNum]]"
|
||||
on-confirm="_handleCherrypickConfirm"
|
||||
on-cancel="_handleConfirmDialogCancel"
|
||||
project="[[change.project]]"
|
||||
hidden></gr-confirm-cherrypick-dialog>
|
||||
<gr-confirm-revert-dialog id="confirmRevertDialog"
|
||||
class="confirmDialog"
|
||||
|
||||
@@ -16,8 +16,10 @@ limitations under the License.
|
||||
|
||||
<link rel="import" href="../../../bower_components/iron-autogrow-textarea/iron-autogrow-textarea.html">
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../../shared/gr-confirm-dialog/gr-confirm-dialog.html">
|
||||
<link rel="import" href="../../../styles/shared-styles.html">
|
||||
<link rel="import" href="../../shared/gr-autocomplete/gr-autocomplete.html">
|
||||
<link rel="import" href="../../shared/gr-confirm-dialog/gr-confirm-dialog.html">
|
||||
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
||||
|
||||
<dom-module id="gr-confirm-cherrypick-dialog">
|
||||
<template>
|
||||
@@ -61,11 +63,12 @@ limitations under the License.
|
||||
<label for="branchInput">
|
||||
Cherry Pick to branch
|
||||
</label>
|
||||
<input is="iron-input"
|
||||
type="text"
|
||||
<gr-autocomplete
|
||||
id="branchInput"
|
||||
bind-value="{{branch}}"
|
||||
text="{{branch}}"
|
||||
query="[[_query]]"
|
||||
placeholder="Destination branch">
|
||||
</gr-autocomplete>
|
||||
<label for="messageInput">
|
||||
Cherry Pick Commit Message
|
||||
</label>
|
||||
@@ -78,6 +81,7 @@ limitations under the License.
|
||||
bind-value="{{message}}"></iron-autogrow-textarea>
|
||||
</div>
|
||||
</gr-confirm-dialog>
|
||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||
</template>
|
||||
<script src="gr-confirm-cherrypick-dialog.js"></script>
|
||||
</dom-module>
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const SUGGESTIONS_LIMIT = 15;
|
||||
|
||||
Polymer({
|
||||
is: 'gr-confirm-cherrypick-dialog',
|
||||
|
||||
@@ -35,6 +37,13 @@
|
||||
commitMessage: String,
|
||||
commitNum: String,
|
||||
message: String,
|
||||
project: String,
|
||||
_query: {
|
||||
type: Function,
|
||||
value() {
|
||||
return this._getProjectBranchesSuggestions.bind(this);
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
observers: [
|
||||
@@ -59,5 +68,28 @@
|
||||
e.preventDefault();
|
||||
this.fire('cancel', null, {bubbles: false});
|
||||
},
|
||||
|
||||
_getProjectBranchesSuggestions(input) {
|
||||
if (input.startsWith('refs/heads/')) {
|
||||
input = input.substring('refs/heads/'.length);
|
||||
}
|
||||
return this.$.restAPI.getProjectBranches(
|
||||
input, this.project, SUGGESTIONS_LIMIT).then(response => {
|
||||
const branches = [];
|
||||
let branch;
|
||||
for (const key in response) {
|
||||
if (!response.hasOwnProperty(key)) { continue; }
|
||||
if (response[key].ref.startsWith('refs/heads/')) {
|
||||
branch = response[key].ref.substring('refs/heads/'.length);
|
||||
} else {
|
||||
branch = response[key].ref;
|
||||
}
|
||||
branches.push({
|
||||
name: branch,
|
||||
});
|
||||
}
|
||||
return branches;
|
||||
});
|
||||
},
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -36,7 +36,23 @@ limitations under the License.
|
||||
let element;
|
||||
|
||||
setup(() => {
|
||||
stub('gr-rest-api-interface', {
|
||||
getProjectBranches(input) {
|
||||
if (input.startsWith('test')) {
|
||||
return Promise.resolve([
|
||||
{
|
||||
ref: 'refs/heads/test-branch',
|
||||
revision: '67ebf73496383c6777035e374d2d664009e2aa5c',
|
||||
can_delete: true,
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
return Promise.resolve({});
|
||||
}
|
||||
},
|
||||
});
|
||||
element = fixture('basic');
|
||||
element.project = 'test-project';
|
||||
});
|
||||
|
||||
test('with merged change', () => {
|
||||
@@ -69,5 +85,20 @@ limitations under the License.
|
||||
flushAsynchronousOperations();
|
||||
assert.equal(element.message, myNewMessage);
|
||||
});
|
||||
|
||||
test('_getProjectBranchesSuggestions empty', done => {
|
||||
element._getProjectBranchesSuggestions('nonexistent').then(branches => {
|
||||
assert.equal(branches.length, 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('_getProjectBranchesSuggestions non-empty', done => {
|
||||
element._getProjectBranchesSuggestions('test-branch').then(branches => {
|
||||
assert.equal(branches.length, 1);
|
||||
assert.equal(branches[0].name, 'test-branch');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user