Add "edit" button to diff view

Bug: Issue 11493
Change-Id: I9825c01ed0c94e29e440be6bbbeabd1fc824c8cd
(cherry picked from commit 90dea338bf)
This commit is contained in:
Paladox none
2020-02-05 14:52:03 +00:00
parent edd57a21d6
commit ce1be9fc07
3 changed files with 33 additions and 3 deletions

View File

@@ -138,11 +138,13 @@ limitations under the License.
align-items: center;
display: flex;
}
.diffModeSelector {
.diffModeSelector,
.editButton {
align-items: center;
display: flex;
}
.diffModeSelector span {
.diffModeSelector span,
.editButton span {
margin-right: .2rem;
}
.diffModeSelector.hide,
@@ -154,6 +156,9 @@ limitations under the License.
text-transform: none;
}
}
.editButtona a {
text-decoration: none;
}
@media screen and (max-width: 50em) {
header {
padding: .5em var(--default-horizontal-margin);
@@ -283,8 +288,15 @@ limitations under the License.
link
disabled="[[_isBlameLoading]]"
on-tap="_toggleBlame">[[_computeBlameToggleLabel(_isBlameLoaded, _isBlameLoading)]]</gr-button>
<span class="separator"></span>
</span>
<template is="dom-if" if="[[_computeIsLoggedIn(_loggedIn)]]">
<span class="editButton">
<a href$="[[_computeEditURL(_change, _patchRange, _path)]]">
<iron-icon icon="gr-icons:edit"></iron-icon>
</a>
<span class="separator"></span>
</span>
</template>
<div class$="diffModeSelector [[_computeModeSelectHideClass(_isImageDiff)]]">
<span>Diff view:</span>
<gr-diff-mode-selector

View File

@@ -526,6 +526,14 @@
return this._getDiffUrl(this._change, this._patchRange, newPath.path);
},
_computeEditURL(change, patchRange, path) {
if ([change, patchRange, path].some(arg => arg === undefined)) {
return '';
}
return Gerrit.Nav.getEditUrlForDiff(
change, path, patchRange.patchNum);
},
/**
* Gives an object representing the target of navigating either left or
* right through the change. The resulting object will have one of the
@@ -1087,5 +1095,9 @@
_handleReloadingDiffPreference() {
this._getDiffPreferences();
},
_computeIsLoggedIn(loggedIn) {
return loggedIn ? true : false;
},
});
})();

View File

@@ -344,6 +344,12 @@ limitations under the License.
PARENT), 'Should navigate to /c/42/1');
});
test('_computeEditURL uses Gerrit.Nav', () => {
const getUrlStub = sandbox.stub(Gerrit.Nav, 'getEditUrlForDiff');
element._computeEditURL(123, {patchNum: undefined}, 'abc/def');
assert.isTrue(getUrlStub.called);
});
test('Diff preferences hidden when no prefs or logged out', () => {
element._loggedIn = false;
flushAsynchronousOperations();