#1718 Fix request_diff showing instead of commit_list in new tab
Merged 7 years ago by pingou. Opened 7 years ago by cep.
cep/pagure master  into  master

@@ -26,7 +26,7 @@ 

  {% endblock %}

  

  {% block repo %}

- <div class="row">

+ <div class="row" id="pr-wrapper">

    <div class="col-md-12">

  {% if pull_request %}

  <h3><span class="label label-default">PR#{{requestid}}</span>
@@ -1244,10 +1244,27 @@ 

      highlight_comment();

    } else {

      if (onload) {

-         $('#request_diff').addClass('active');

-         $('#comments').removeClass('active');

+       // Hide all tabs, and then show the one pointed to by the hash.

+       // This is neccessary to handle 'Back' button presses in the browser,

+       // which otherwise break the tabs view .

+       $('#pr-tabs .nav-item a.nav-link').removeClass('active');

+       $('#pr-wrapper .tab-pane').removeClass('active');

+       // When the hash points to 'Files Changed' tab, or a highlight.

+       if (location.hash.indexOf("request_diff") > -1 ||

+           location.hash.indexOf("_") === 1) {

          $('[href="#request_diff"]').addClass('active');

-         $('[href="#comments"]').removeClass('active');

+         $('#request_diff').addClass('active');

+       }

+       // When the hash points to 'Commits' tab.

+       else if (location.hash.indexOf("commit_list") > -1) {

+         $('[href="#commit_list"]').addClass('active');

+         $('#commit_list').addClass('active');

+       }

+       // If neither, then show the 'Comments' tab by default.

+       else {

+         $('#comments').addClass('active');

+         $('[href="#comments"]').addClass('active');

+       }

      }

      var file = parseInt(location.hash.substr(2).split(',')[0], 10);

      var lines = location.hash.split(',')[1].split('-').map(function (x) { return parseInt(x, 10) });
@@ -1370,6 +1387,12 @@ 

    window.location.hash = hash;

    return false;

  });

+ 

+ // Update hash links in the addressbar according to which tab is clicked

+ // on the PR page.

+ $(document).on('click', '#pr-tabs a', function() {

+   window.location.hash = $(this).attr('href');

+ });

  </script>

  

  

Fixed the issue where opening the 'Commits' tab in a new browser
tab showed the 'Files Changed' tab instead.

Fixes https://pagure.io/pagure/issue/787

1 new commit added

  • Proper links for PR tabs
7 years ago

The subsequent commit fixes https://pagure.io/pagure/issue/1698.
Issues #787 and #1698 are closely related.

Looking good, I'll have to test it locally but the code makes sense to me, thanks ! :)

neat and clean :thumbsup: :)

It almost works :)

Basically it works for the classic use-case of clicking on the tabs, then sharing that link works but it doesn't work when highlighting some part of the PR and sharing that link, for example: https://pagure.io/pagure/pull-request/1718#_1,8-10

So we're close but there is one more use-case to consider :)

1 new commit added

  • Handle URL hashes for highlights.
7 years ago

@pingou I think that fixes it :)

I also wrapped the entire thing in #pr-wrapper, just to make sure we only hide .tab-panes local to the PR page.

rebased

7 years ago

Pull-Request has been merged by pingou

7 years ago