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

View File

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

View File

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