diff options
author | Paladox none <thomasmulhall410@yahoo.com> | 2019-02-21 22:14:43 +0000 |
---|---|---|
committer | Paladox none <thomasmulhall410@yahoo.com> | 2019-03-05 08:55:32 +0000 |
commit | d7765bff4609082560a2753baeef839e645d3724 (patch) | |
tree | 75f04f76d5afadad1e71eb408d26a2f58d0f6aff | |
parent | 002c7931e2265a54c3890348f9f6ee16d7f67765 (diff) |
Do not show "Patch file" if change does not have a parent
Bug: Issue 8495
Change-Id: I4047e600994beedf35562ff4c4f9ea9632808920
3 files changed, 39 insertions, 2 deletions
diff --git a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.html b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.html index 5e82cda980..28d25d27da 100644 --- a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.html +++ b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.html @@ -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 diff --git a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js index 5fc81e80a9..4fe6d8fc3c 100644 --- a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js +++ b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js @@ -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; diff --git a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html index 2915e296d2..ee284b9b24 100644 --- a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html +++ b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html @@ -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> |