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]]"
|
commit-num="[[commitNum]]"
|
||||||
on-confirm="_handleCherrypickConfirm"
|
on-confirm="_handleCherrypickConfirm"
|
||||||
on-cancel="_handleConfirmDialogCancel"
|
on-cancel="_handleConfirmDialogCancel"
|
||||||
|
project="[[change.project]]"
|
||||||
hidden></gr-confirm-cherrypick-dialog>
|
hidden></gr-confirm-cherrypick-dialog>
|
||||||
<gr-confirm-revert-dialog id="confirmRevertDialog"
|
<gr-confirm-revert-dialog id="confirmRevertDialog"
|
||||||
class="confirmDialog"
|
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/iron-autogrow-textarea/iron-autogrow-textarea.html">
|
||||||
<link rel="import" href="../../../bower_components/polymer/polymer.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="../../../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">
|
<dom-module id="gr-confirm-cherrypick-dialog">
|
||||||
<template>
|
<template>
|
||||||
@@ -61,11 +63,12 @@ limitations under the License.
|
|||||||
<label for="branchInput">
|
<label for="branchInput">
|
||||||
Cherry Pick to branch
|
Cherry Pick to branch
|
||||||
</label>
|
</label>
|
||||||
<input is="iron-input"
|
<gr-autocomplete
|
||||||
type="text"
|
|
||||||
id="branchInput"
|
id="branchInput"
|
||||||
bind-value="{{branch}}"
|
text="{{branch}}"
|
||||||
|
query="[[_query]]"
|
||||||
placeholder="Destination branch">
|
placeholder="Destination branch">
|
||||||
|
</gr-autocomplete>
|
||||||
<label for="messageInput">
|
<label for="messageInput">
|
||||||
Cherry Pick Commit Message
|
Cherry Pick Commit Message
|
||||||
</label>
|
</label>
|
||||||
@@ -78,6 +81,7 @@ limitations under the License.
|
|||||||
bind-value="{{message}}"></iron-autogrow-textarea>
|
bind-value="{{message}}"></iron-autogrow-textarea>
|
||||||
</div>
|
</div>
|
||||||
</gr-confirm-dialog>
|
</gr-confirm-dialog>
|
||||||
|
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||||
</template>
|
</template>
|
||||||
<script src="gr-confirm-cherrypick-dialog.js"></script>
|
<script src="gr-confirm-cherrypick-dialog.js"></script>
|
||||||
</dom-module>
|
</dom-module>
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const SUGGESTIONS_LIMIT = 15;
|
||||||
|
|
||||||
Polymer({
|
Polymer({
|
||||||
is: 'gr-confirm-cherrypick-dialog',
|
is: 'gr-confirm-cherrypick-dialog',
|
||||||
|
|
||||||
@@ -35,6 +37,13 @@
|
|||||||
commitMessage: String,
|
commitMessage: String,
|
||||||
commitNum: String,
|
commitNum: String,
|
||||||
message: String,
|
message: String,
|
||||||
|
project: String,
|
||||||
|
_query: {
|
||||||
|
type: Function,
|
||||||
|
value() {
|
||||||
|
return this._getProjectBranchesSuggestions.bind(this);
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
observers: [
|
observers: [
|
||||||
@@ -59,5 +68,28 @@
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.fire('cancel', null, {bubbles: false});
|
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;
|
let element;
|
||||||
|
|
||||||
setup(() => {
|
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 = fixture('basic');
|
||||||
|
element.project = 'test-project';
|
||||||
});
|
});
|
||||||
|
|
||||||
test('with merged change', () => {
|
test('with merged change', () => {
|
||||||
@@ -69,5 +85,20 @@ limitations under the License.
|
|||||||
flushAsynchronousOperations();
|
flushAsynchronousOperations();
|
||||||
assert.equal(element.message, myNewMessage);
|
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>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user