Do not show "Patch file" if change does not have a parent

Bug: Issue 8495
Change-Id: I4047e600994beedf35562ff4c4f9ea9632808920
This commit is contained in:
Paladox none
2019-02-21 22:14:43 +00:00
parent 002c7931e2
commit d7765bff46
3 changed files with 39 additions and 2 deletions

View File

@@ -19,8 +19,8 @@ limitations under the License.
<link rel="import" href="../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html">
<link rel="import" href="../../../behaviors/rest-client-behavior/rest-client-behavior.html">
<link rel="import" href="../../shared/gr-download-commands/gr-download-commands.html">
<link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../shared/gr-download-commands/gr-download-commands.html">
<dom-module id="gr-download-dialog">
<template>
@@ -87,7 +87,7 @@ limitations under the License.
selected-scheme="{{_selectedScheme}}"></gr-download-commands>
</section>
<section class="flexContainer">
<div class="patchFiles">
<div class="patchFiles" hidden="[[_computeHidePatchFile(change, patchNum)]]" hidden>
<label>Patch file</label>
<div>
<a

View File

@@ -138,6 +138,17 @@
return shortRev + '.diff.' + (opt_zip ? 'zip' : 'base64');
},
_computeHidePatchFile(change, patchNum) {
for (const rev of Object.values(change.revisions || {})) {
if (this.patchNumEquals(rev._number, patchNum)) {
const parentLength = rev.commit && rev.commit.parents ?
rev.commit.parents.length : 0;
return parentLength == 0;
}
}
return false;
},
_computeArchiveDownloadLink(change, patchNum, format) {
return this.changeBaseURL(change.project, change._number, patchNum) +
'/archive?format=' + format;

View File

@@ -45,6 +45,9 @@ limitations under the License.
revisions: {
'34685798fe548b6d17d1e8e5edc43a26d055cc72': {
_number: 1,
commit: {
parents: [],
},
fetch: {
repo: {
commands: {
@@ -105,6 +108,9 @@ limitations under the License.
revisions: {
'34685798fe548b6d17d1e8e5edc43a26d055cc72': {
_number: 1,
commit: {
parents: [],
},
fetch: {},
},
},
@@ -188,5 +194,25 @@ limitations under the License.
assert.equal(element._computeShowDownloadCommands([]), 'hidden');
assert.equal(element._computeShowDownloadCommands(['test']), '');
});
test('_computeHidePatchFile', () => {
const patchNum = '1';
const change1 = {
revisions: {
r1: {_number: 1, commit: {parents: []}},
},
};
assert.isTrue(element._computeHidePatchFile(change1, patchNum));
const change2 = {
revisions: {
r1: {_number: 1, commit: {parents: [
{commit: 'p1'},
]}},
},
};
assert.isFalse(element._computeHidePatchFile(change2, patchNum));
});
});
</script>