Merge "Fix box-shadow of collapsed commit message"

This commit is contained in:
Ben Rohlfs
2020-01-23 09:56:21 +00:00
committed by Gerrit Code Review
4 changed files with 32 additions and 23 deletions

View File

@@ -190,10 +190,6 @@ limitations under the License.
height: 0; height: 0;
margin-bottom: var(--spacing-l); margin-bottom: var(--spacing-l);
} }
#commitMessage.collapsed {
max-height: 36em;
overflow: hidden;
}
#relatedChanges.collapsed { #relatedChanges.collapsed {
margin-bottom: var(--spacing-l); margin-bottom: var(--spacing-l);
max-height: var(--relation-chain-max-height, 2em); max-height: var(--relation-chain-max-height, 2em);
@@ -449,12 +445,13 @@ limitations under the License.
</div> </div>
<div <div
id="commitMessage" id="commitMessage"
class$="commitMessage [[_computeCommitClass(_commitCollapsed, _latestCommitMessage)]]"> class="commitMessage">
<gr-editable-content id="commitMessageEditor" <gr-editable-content id="commitMessageEditor"
editing="[[_editingCommitMessage]]" editing="[[_editingCommitMessage]]"
content="{{_latestCommitMessage}}" content="{{_latestCommitMessage}}"
storage-key="[[_computeCommitMessageKey(_change._number, _change.current_revision)]]" storage-key="[[_computeCommitMessageKey(_change._number, _change.current_revision)]]"
remove-zero-width-space> remove-zero-width-space
collapsed$="[[_computeCommitMessageCollapsed(_commitCollapsed, _commitCollapsible)]]">
<gr-linked-text pre <gr-linked-text pre
content="[[_latestCommitMessage]]" content="[[_latestCommitMessage]]"
config="[[_projectConfig.commentlinks]]" config="[[_projectConfig.commentlinks]]"
@@ -477,7 +474,7 @@ limitations under the License.
<div <div
id="commitCollapseToggle" id="commitCollapseToggle"
class="collapseToggleContainer" class="collapseToggleContainer"
hidden$="[[_computeCommitToggleHidden(_latestCommitMessage)]]"> hidden$="[[!_commitCollapsible]]">
<gr-button <gr-button
link link
id="commitCollapseToggleButton" id="commitCollapseToggleButton"

View File

@@ -184,7 +184,8 @@
_hideEditCommitMessage: { _hideEditCommitMessage: {
type: Boolean, type: Boolean,
computed: '_computeHideEditCommitMessage(_loggedIn, ' + computed: '_computeHideEditCommitMessage(_loggedIn, ' +
'_editingCommitMessage, _change, _editMode)', '_editingCommitMessage, _change, _editMode, _commitCollapsed, ' +
'_commitCollapsible)',
}, },
_diffAgainst: String, _diffAgainst: String,
/** @type {?string} */ /** @type {?string} */
@@ -243,10 +244,16 @@
computed: computed:
'_computeChangeStatusChips(_change, _mergeable, _submitEnabled)', '_computeChangeStatusChips(_change, _mergeable, _submitEnabled)',
}, },
/** If false, then the "Show more" button was used to expand. */
_commitCollapsed: { _commitCollapsed: {
type: Boolean, type: Boolean,
value: true, value: true,
}, },
/** Is the "Show more/less" button visible? */
_commitCollapsible: {
type: Boolean,
computed: '_computeCommitCollapsible(_latestCommitMessage)',
},
_relatedChangesCollapsed: { _relatedChangesCollapsed: {
type: Boolean, type: Boolean,
value: true, value: true,
@@ -543,10 +550,12 @@
return this.changeStatuses(change, options); return this.changeStatuses(change, options);
} }
_computeHideEditCommitMessage(loggedIn, editing, change, editMode) { _computeHideEditCommitMessage(
loggedIn, editing, change, editMode, collapsed, collapsible) {
if (!loggedIn || editing || if (!loggedIn || editing ||
(change && change.status === this.ChangeStatus.MERGED) || (change && change.status === this.ChangeStatus.MERGED) ||
editMode) { editMode ||
(collapsed && collapsible)) {
return true; return true;
} }
@@ -1589,9 +1598,8 @@
return 'Change ' + changeNum; return 'Change ' + changeNum;
} }
_computeCommitClass(collapsed, commitMessage) { _computeCommitMessageCollapsed(collapsed, collapsible) {
if (this._computeCommitToggleHidden(commitMessage)) { return ''; } return collapsible && collapsed;
return collapsed ? 'collapsed' : '';
} }
_computeRelatedChangesClass(collapsed) { _computeRelatedChangesClass(collapsed) {
@@ -1628,9 +1636,9 @@
} }
} }
_computeCommitToggleHidden(commitMessage) { _computeCommitCollapsible(commitMessage) {
if (!commitMessage) { return true; } if (!commitMessage) { return false; }
return commitMessage.split('\n').length < MIN_LINES_FOR_COMMIT_COLLAPSE; return commitMessage.split('\n').length >= MIN_LINES_FOR_COMMIT_COLLAPSE;
} }
_getOffsetHeight(element) { _getOffsetHeight(element) {
@@ -1658,8 +1666,6 @@
// bottom margin. // bottom margin.
const EXTRA_HEIGHT = 30; const EXTRA_HEIGHT = 30;
let newHeight; let newHeight;
const hasCommitToggle =
!this._computeCommitToggleHidden(this._latestCommitMessage);
if (window.matchMedia(`(max-width: ${BREAKPOINT_RELATED_SMALL})`) if (window.matchMedia(`(max-width: ${BREAKPOINT_RELATED_SMALL})`)
.matches) { .matches) {
@@ -1678,7 +1684,7 @@
MINIMUM_RELATED_MAX_HEIGHT); MINIMUM_RELATED_MAX_HEIGHT);
newHeight = medRelatedHeight; newHeight = medRelatedHeight;
} else { } else {
if (hasCommitToggle) { if (this._commitCollapsible) {
// Make sure the content is lined up if both areas have buttons. If // Make sure the content is lined up if both areas have buttons. If
// the commit message is not collapsed, instead use the change info // the commit message is not collapsed, instead use the change info
// height. // height.
@@ -1701,7 +1707,7 @@
stylesToUpdate['--relation-chain-max-height'] = newHeight + 'px'; stylesToUpdate['--relation-chain-max-height'] = newHeight + 'px';
// Update the max-height of the relation chain to this new height. // Update the max-height of the relation chain to this new height.
if (hasCommitToggle) { if (this._commitCollapsible) {
stylesToUpdate['--related-change-btn-top-padding'] = remainder + 'px'; stylesToUpdate['--related-change-btn-top-padding'] = remainder + 'px';
} }

View File

@@ -1238,14 +1238,16 @@ limitations under the License.
}); });
test('commitCollapseToggle functions', () => { test('commitCollapseToggle functions', () => {
element._latestCommitMessage = _.times(31, String).join('\n'); element._latestCommitMessage = _.times(35, String).join('\n');
assert.isTrue(element._commitCollapsed); assert.isTrue(element._commitCollapsed);
assert.isTrue(element._commitCollapsible);
assert.isTrue( assert.isTrue(
element.$.commitMessage.classList.contains('collapsed')); element.$.commitMessageEditor.hasAttribute('collapsed'));
MockInteractions.tap(element.$.commitCollapseToggleButton); MockInteractions.tap(element.$.commitCollapseToggleButton);
assert.isFalse(element._commitCollapsed); assert.isFalse(element._commitCollapsed);
assert.isTrue(element._commitCollapsible);
assert.isFalse( assert.isFalse(
element.$.commitMessage.classList.contains('collapsed')); element.$.commitMessageEditor.hasAttribute('collapsed'));
}); });
}); });

View File

@@ -38,6 +38,10 @@ limitations under the License.
box-shadow: var(--elevation-level-1); box-shadow: var(--elevation-level-1);
padding: var(--spacing-m); padding: var(--spacing-m);
} }
:host([collapsed]) .viewer {
max-height: 36em;
overflow: hidden;
}
.editor iron-autogrow-textarea { .editor iron-autogrow-textarea {
background-color: var(--view-background-color); background-color: var(--view-background-color);
width: 100%; width: 100%;