Recompute patchset dropdown items if change is updated
Change-Id: I3be3c6367f252ef5e447f099acbfbff8a9f0ec19
diff --git a/gr-checks/gr-checks-view.js b/gr-checks/gr-checks-view.js
index 25c6100..8d4e3f8 100644
--- a/gr-checks/gr-checks-view.js
+++ b/gr-checks/gr-checks-view.js
@@ -41,7 +41,7 @@
properties: {
revision: {
type: Object,
- observer: '_computeCurrentPatchSet',
+ observer: '_handleRevisionUpdate',
},
change: Object,
/** @type {function(number, number): !Promise<!Object>} */
@@ -67,6 +67,7 @@
_patchSetDropdownItems: {
type: Array,
value() { return []; },
+ computed: '_computePatchSetDropdownItems(change)',
},
_currentPatchSet: {
type: Number,
@@ -80,7 +81,15 @@
attached() {
this.pluginRestApi = this.plugin.restApi();
this._initCreateCheckerCapability();
- this._patchSetDropdownItems = Object.values(this.change.revisions)
+ },
+
+ detached() {
+ clearInterval(this.pollChecksInterval);
+ this.unlisten(document, 'visibilitychange', '_onVisibililityChange');
+ },
+
+ _computePatchSetDropdownItems(change) {
+ return Object.values(change.revisions)
.filter(patch => patch._number !== 'edit')
.map(patch => {
return {
@@ -89,20 +98,15 @@
};
})
.sort((a, b) => b.value - a.value);
- this._currentPatchSet = this.revision._number;
},
- detached() {
- clearInterval(this.pollChecksInterval);
- this.unlisten(document, 'visibilitychange', '_onVisibililityChange');
- },
-
- _computeCurrentPatchSet(revision) {
+ _handleRevisionUpdate(revision) {
this._currentPatchSet = revision._number;
},
_handlePatchSetChanged(e) {
- const patchSet = e.detail.value;
+ // gr-dropdown-list returns value of type "String"
+ const patchSet = parseInt(e.detail.value);
if (patchSet === this._currentPatchSet) return;
this._currentPatchSet = patchSet;
},
diff --git a/gr-checks/gr-checks-view_test.html b/gr-checks/gr-checks-view_test.html
index 51765b1..16fa6c4 100644
--- a/gr-checks/gr-checks-view_test.html
+++ b/gr-checks/gr-checks-view_test.html
@@ -377,19 +377,21 @@
const fetchChecksStub = sandbox.stub(element,
'_fetchChecks');
assert.equal(element._currentPatchSet, 3);
- element._currentPatchSet = 2;
- const firstCallArgs = fetchChecksStub.args[0];
- assert.equal(firstCallArgs[1], element._currentPatchSet);
- clock.tick(CHECKS_POLL_INTERVAL_MS + 1000);
+ element.revision = REVISION2;
flush(() => {
- assert(fetchChecksStub.callCount === 2);
- const secondCallArgs = fetchChecksStub.args[1];
- assert.equal(secondCallArgs[1], element._currentPatchSet);
- done();
+ const firstCallArgs = fetchChecksStub.args[0];
+ assert.equal(firstCallArgs[1], element._currentPatchSet);
+ clock.tick(CHECKS_POLL_INTERVAL_MS + 1000);
+ flush(() => {
+ assert(fetchChecksStub.callCount === 2);
+ const secondCallArgs = fetchChecksStub.args[1];
+ assert.equal(secondCallArgs[1], element._currentPatchSet);
+ done();
+ });
});
});
- test('update to revision updatesd currentPatchset', done => {
+ test('update to revision updates currentPatchset', done => {
assert.equal(element._currentPatchSet, 3);
element.revision = REVISION2;
flush(() => {