Merge "Handle starring API calls in parent component"
This commit is contained in:
commit
447f649f71
@ -86,7 +86,8 @@ limitations under the License.
|
|||||||
changes="{{_changes}}"
|
changes="{{_changes}}"
|
||||||
preferences="[[preferences]]"
|
preferences="[[preferences]]"
|
||||||
selected-index="{{viewState.selectedChangeIndex}}"
|
selected-index="{{viewState.selectedChangeIndex}}"
|
||||||
show-star="[[_loggedIn]]"></gr-change-list>
|
show-star="[[_loggedIn]]"
|
||||||
|
on-toggle-star="_handleToggleStar"></gr-change-list>
|
||||||
<nav class$="[[_computeNavClass(_loading)]]">
|
<nav class$="[[_computeNavClass(_loading)]]">
|
||||||
Page [[_computePage(_offset, _changesPerPage)]]
|
Page [[_computePage(_offset, _changesPerPage)]]
|
||||||
<a id="prevArrow"
|
<a id="prevArrow"
|
||||||
|
@ -263,5 +263,10 @@
|
|||||||
_computeLoggedIn(account) {
|
_computeLoggedIn(account) {
|
||||||
return !!(account && Object.keys(account).length > 0);
|
return !!(account && Object.keys(account).length > 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_handleToggleStar(e) {
|
||||||
|
this.$.restAPI.saveChangeStarred(e.detail.change._number,
|
||||||
|
e.detail.starred);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
@ -307,10 +307,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const changeEl = changeEls[index];
|
const changeEl = changeEls[index];
|
||||||
const change = changeEl.change;
|
changeEl.$$('gr-change-star').toggleStar();
|
||||||
const newVal = !change.starred;
|
|
||||||
changeEl.set('change.starred', newVal);
|
|
||||||
this.$.restAPI.saveChangeStarred(change._number, newVal);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_changeForIndex(index) {
|
_changeForIndex(index) {
|
||||||
|
@ -60,7 +60,8 @@ limitations under the License.
|
|||||||
account="[[account]]"
|
account="[[account]]"
|
||||||
preferences="[[preferences]]"
|
preferences="[[preferences]]"
|
||||||
selected-index="{{viewState.selectedChangeIndex}}"
|
selected-index="{{viewState.selectedChangeIndex}}"
|
||||||
sections="[[_results]]"></gr-change-list>
|
sections="[[_results]]"
|
||||||
|
on-toggle-star="_handleToggleStar"></gr-change-list>
|
||||||
</div>
|
</div>
|
||||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||||
<gr-reporting id="reporting"></gr-reporting>
|
<gr-reporting id="reporting"></gr-reporting>
|
||||||
|
@ -241,5 +241,10 @@
|
|||||||
_computeUserHeaderClass(userParam) {
|
_computeUserHeaderClass(userParam) {
|
||||||
return userParam === 'self' ? 'hide' : '';
|
return userParam === 'self' ? 'hide' : '';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_handleToggleStar(e) {
|
||||||
|
this.$.restAPI.saveChangeStarred(e.detail.change._number,
|
||||||
|
e.detail.starred);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
|
|
||||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||||
<link rel="import" href="../../shared/gr-icons/gr-icons.html">
|
<link rel="import" href="../../shared/gr-icons/gr-icons.html">
|
||||||
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
|
||||||
<link rel="import" href="../../../styles/shared-styles.html">
|
<link rel="import" href="../../../styles/shared-styles.html">
|
||||||
|
|
||||||
<dom-module id="gr-change-star">
|
<dom-module id="gr-change-star">
|
||||||
@ -36,7 +35,6 @@ limitations under the License.
|
|||||||
class$="[[_computeStarClass(change.starred)]]"
|
class$="[[_computeStarClass(change.starred)]]"
|
||||||
icon$="[[_computeStarIcon(change.starred)]]"></iron-icon>
|
icon$="[[_computeStarIcon(change.starred)]]"></iron-icon>
|
||||||
</button>
|
</button>
|
||||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
|
||||||
</template>
|
</template>
|
||||||
<script src="gr-change-star.js"></script>
|
<script src="gr-change-star.js"></script>
|
||||||
</dom-module>
|
</dom-module>
|
||||||
|
@ -20,14 +20,18 @@
|
|||||||
Polymer({
|
Polymer({
|
||||||
is: 'gr-change-star',
|
is: 'gr-change-star',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired when star state is toggled.
|
||||||
|
*
|
||||||
|
* @event toggle-star
|
||||||
|
*/
|
||||||
|
|
||||||
properties: {
|
properties: {
|
||||||
/** @type {?} */
|
/** @type {?} */
|
||||||
change: {
|
change: {
|
||||||
type: Object,
|
type: Object,
|
||||||
notify: true,
|
notify: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
_xhrPromise: Object, // Used for testing.
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_computeStarClass(starred) {
|
_computeStarClass(starred) {
|
||||||
@ -42,8 +46,10 @@
|
|||||||
toggleStar() {
|
toggleStar() {
|
||||||
const newVal = !this.change.starred;
|
const newVal = !this.change.starred;
|
||||||
this.set('change.starred', newVal);
|
this.set('change.starred', newVal);
|
||||||
this._xhrPromise = this.$.restAPI.saveChangeStarred(this.change._number,
|
this.dispatchEvent(new CustomEvent('toggle-star', {
|
||||||
newVal);
|
bubbles: true,
|
||||||
|
detail: {change: this.change, starred: newVal},
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
@ -37,9 +37,6 @@ limitations under the License.
|
|||||||
let element;
|
let element;
|
||||||
|
|
||||||
setup(() => {
|
setup(() => {
|
||||||
stub('gr-rest-api-interface', {
|
|
||||||
saveChangeStarred() { return Promise.resolve({ok: true}); },
|
|
||||||
});
|
|
||||||
element = fixture('basic');
|
element = fixture('basic');
|
||||||
element.change = {
|
element.change = {
|
||||||
_number: 2,
|
_number: 2,
|
||||||
@ -60,23 +57,21 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('starring', done => {
|
test('starring', done => {
|
||||||
element.set('change.starred', false);
|
element.addEventListener('toggle-star', () => {
|
||||||
MockInteractions.tap(element.$$('button'));
|
|
||||||
|
|
||||||
element._xhrPromise.then(req => {
|
|
||||||
assert.equal(element.change.starred, true);
|
assert.equal(element.change.starred, true);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
element.set('change.starred', false);
|
||||||
|
MockInteractions.tap(element.$$('button'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('unstarring', done => {
|
test('unstarring', done => {
|
||||||
element.set('change.starred', true);
|
element.addEventListener('toggle-star', () => {
|
||||||
MockInteractions.tap(element.$$('button'));
|
|
||||||
|
|
||||||
element._xhrPromise.then(req => {
|
|
||||||
assert.equal(element.change.starred, false);
|
assert.equal(element.change.starred, false);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
element.set('change.starred', true);
|
||||||
|
MockInteractions.tap(element.$$('button'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user