Refactor and add CommentTab Enum to add more tabs

* Add CommentTab Enum type instead of a single variable denoting
if messages tab is selected or not
* Refactor for adding Robot Comments CommentTab

Change-Id: I677f5ad98e6d0684a498ee28690d4dc00ac1709f
This commit is contained in:
Dhruv Srivastava
2020-01-27 17:04:14 +01:00
parent 70d5a68b96
commit 97fb2347fd
3 changed files with 31 additions and 12 deletions

View File

@@ -613,7 +613,8 @@ limitations under the License.
<span>Comment Threads</span></gr-tooltip-content>
</paper-tab>
</paper-tabs>
<template is="dom-if" if="[[_showMessagesView]]">
<template is="dom-if" if="[[_isSelectedView(_currentView,
_commentTabs.CHANGE_LOG)]]">
<gr-messages-list
class="hideOnMobileOverlay"
change-num="[[_changeNum]]"
@@ -626,7 +627,8 @@ limitations under the License.
on-message-anchor-tap="_handleMessageAnchorTap"
on-reply="_handleMessageReply"></gr-messages-list>
</template>
<template is="dom-if" if="[[!_showMessagesView]]">
<template is="dom-if" if="[[_isSelectedView(_currentView,
_commentTabs.COMMENT_THREADS)]]">
<gr-thread-list
threads="[[_commentThreads]]"
change="[[_change]]"

View File

@@ -59,6 +59,11 @@
UNIFIED: 'UNIFIED_DIFF',
};
const CommentTabs = {
CHANGE_LOG: 0,
COMMENT_THREADS: 1,
};
const CHANGE_DATA_TIMING_LABEL = 'ChangeDataLoaded';
const CHANGE_RELOAD_TIMING_LABEL = 'ChangeReloaded';
const SEND_REPLY_TIMING_LABEL = 'SendReply';
@@ -193,6 +198,10 @@
type: String,
value: '',
},
_commentTabs: {
type: Object,
value: CommentTabs,
},
_lineHeight: Number,
_changeIdCommitMessageError: {
type: String,
@@ -280,9 +289,9 @@
type: Boolean,
value: undefined,
},
_showMessagesView: {
type: Boolean,
value: true,
_currentView: {
type: Number,
value: CommentTabs.CHANGE_LOG,
},
_showFileTabContent: {
type: Boolean,
@@ -460,7 +469,11 @@
}
_handleCommentTabChange() {
this._showMessagesView = this.$.commentTabs.selected === 0;
this._currentView = this.$.commentTabs.selected;
}
_isSelectedView(currentView, view) {
return currentView === view;
}
_handleFileTabChange(e) {
@@ -773,8 +786,7 @@
// get messed up if changed here, because it requires the tabs to be on
// the streen, and they are hidden shortly after this. The tab switching
// animation will happen in post render tasks.
this._showMessagesView = true;
this._currentView = CommentTabs.CHANGE_LOG;
if (value.view !== Gerrit.Nav.View.CHANGE) {
this._initialLoadComplete = false;
return;

View File

@@ -63,6 +63,11 @@ limitations under the License.
let navigateToChangeStub;
const TEST_SCROLL_TOP_PX = 100;
const CommentTabs = {
CHANGE_LOG: 0,
COMMENT_THREADS: 1,
};
setup(() => {
sandbox = sinon.sandbox.create();
stub('gr-endpoint-decorator', {
@@ -375,7 +380,7 @@ limitations under the License.
test('thread list modified', () => {
sandbox.spy(element, '_handleReloadDiffComments');
element._showMessagesView = false;
element._currentView = CommentTabs.COMMENT_THREADS;
flushAsynchronousOperations();
return element._reloadComments().then(() => {
@@ -442,18 +447,18 @@ limitations under the License.
// Wait for tab to get selected
flush(() => {
assert.equal(element.$.commentTabs.selected, 0);
assert.isTrue(element._showMessagesView);
assert.equal(element._currentView, CommentTabs.CHANGE_LOG);
// Switch to comment thread tab
MockInteractions.tap(element.$$('paper-tab.commentThreads'));
assert.equal(element.$.commentTabs.selected, 1);
assert.isFalse(element._showMessagesView);
assert.equal(element._currentView, CommentTabs.COMMENT_THREADS);
// When the change is partially reloaded (ex: Shift+R), the content
// is swapped out before the tab, so messages list will display even
// though the tab for comment threads is still temporarily selected.
element._paramsChanged(element.params);
assert.equal(element.$.commentTabs.selected, 1);
assert.isTrue(element._showMessagesView);
assert.equal(element._currentView, CommentTabs.CHANGE_LOG);
done();
});
});