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

View File

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

View File

@@ -1238,14 +1238,16 @@ limitations under the License.
});
test('commitCollapseToggle functions', () => {
element._latestCommitMessage = _.times(31, String).join('\n');
element._latestCommitMessage = _.times(35, String).join('\n');
assert.isTrue(element._commitCollapsed);
assert.isTrue(element._commitCollapsible);
assert.isTrue(
element.$.commitMessage.classList.contains('collapsed'));
element.$.commitMessageEditor.hasAttribute('collapsed'));
MockInteractions.tap(element.$.commitCollapseToggleButton);
assert.isFalse(element._commitCollapsed);
assert.isTrue(element._commitCollapsible);
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);
padding: var(--spacing-m);
}
:host([collapsed]) .viewer {
max-height: 36em;
overflow: hidden;
}
.editor iron-autogrow-textarea {
background-color: var(--view-background-color);
width: 100%;