diff --git a/assets/src/bundles/browse/browse-utils.js b/assets/src/bundles/browse/browse-utils.js --- a/assets/src/bundles/browse/browse-utils.js +++ b/assets/src/bundles/browse/browse-utils.js @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 The Software Heritage developers + * Copyright (C) 2018-2021 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information @@ -65,8 +65,8 @@ $('#swh-branch-search-form').submit(function(e) { var searchParams = new URLSearchParams(window.location.search); - const searchString = $('#swh-branch-search-string').val().trim(); - searchParams.set('branch_name_include', searchString); + searchParams.set('name_include', + $('#swh-branch-search-string').val().trim()); window.location.search = searchParams.toString(); e.preventDefault(); }); diff --git a/cypress/integration/origin-browse.spec.js b/cypress/integration/origin-browse.spec.js --- a/cypress/integration/origin-browse.spec.js +++ b/cypress/integration/origin-browse.spec.js @@ -1,5 +1,5 @@ /** - * Copyright (C) 2020 The Software Heritage developers + * Copyright (C) 2020-2021 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information @@ -100,19 +100,19 @@ cy.get('#swh-branch-serach-button').click(); cy.location('search') - .should('include', 'branch_name_include=mas'); + .should('include', 'name_include=mas'); cy.get('table').contains('td', 'master').should('be.visible'); cy.get('#swh-branch-search-string').should('have.value', 'mas'); }); - it('should empty search show all branches', function() { + it('should show all the branches for empty search', function() { cy.get('#swh-branch-search-string').clear(); cy.get('#swh-branch-serach-button').click(); cy.location('search') - .should('include', 'branch_name_include='); + .should('include', 'name_include='); cy.get('table').contains('td', 'master').should('be.visible'); @@ -125,3 +125,44 @@ cy.get('table').contains('td', 'No branch names containing random have been found!').should('be.visible'); }); }); + +describe('Test browse releases', function() { + beforeEach(function() { + const url = `${this.Urls.browse_origin_releases()}?origin_url=${this.origin[1].url}`; + cy.visit(url); + }); + + it('should have the v2 release in the list', function() { + cy.get('table').contains('td', 'v2.0').should('be.visible'); + }); + + it('should search inside the releases', function() { + cy.get('#swh-branch-search-string').type('v2.4'); + cy.get('#swh-branch-serach-button').click(); + + cy.location('search') + .should('include', 'name_include=v2.4'); + + cy.get('table').contains('td', 'v2.4').should('be.visible'); + + cy.get('#swh-branch-search-string').should('have.value', 'v2.4'); + }); + + it('should show all the releases for empty search', function() { + cy.get('#swh-branch-search-string').clear(); + cy.get('#swh-branch-serach-button').click(); + + cy.location('search') + .should('include', 'name_include='); + + cy.get('table').contains('td', 'v2.0').should('be.visible'); + + cy.get('#swh-branch-search-string').should('have.value', ''); + }); + + it('should show no release exists message on failed search', function() { + cy.get('#swh-branch-search-string').type('random{enter}'); + + cy.get('table').contains('td', 'No release names containing random have been found!').should('be.visible'); + }); +}); diff --git a/swh/web/browse/snapshot_context.py b/swh/web/browse/snapshot_context.py --- a/swh/web/browse/snapshot_context.py +++ b/swh/web/browse/snapshot_context.py @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2020 The Software Heritage developers +# Copyright (C) 2018-2021 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -1326,7 +1326,11 @@ def browse_snapshot_releases( - request, snapshot_id=None, origin_url=None, timestamp=None + request, + snapshot_id=None, + origin_url=None, + timestamp=None, + release_name_include=None, ): """ Django view implementation for browsing a list of releases in a snapshot @@ -1354,8 +1358,11 @@ rel_from, PER_PAGE + 1, target_types=["release", "alias"], + branch_name_include_substring=release_name_include, ) - _, displayed_releases, _ = process_snapshot_branches(snapshot) + displayed_releases = [] + if snapshot: + _, displayed_releases, _ = process_snapshot_branches(snapshot) for release in displayed_releases: query_params_tgt = {"snapshot": snapshot_id} @@ -1426,7 +1433,7 @@ browse_view_name, url_args=url_args, query_params=query_params ) - if snapshot["next_branch"] is not None: + if snapshot and snapshot["next_branch"] is not None: query_params_next = dict(query_params) next_rel = displayed_releases[-1]["branch_name"] del displayed_releases[-1] @@ -1458,5 +1465,6 @@ "snapshot_context": snapshot_context, "vault_cooking": None, "show_actions": False, + "search_string": release_name_include or "", }, ) diff --git a/swh/web/browse/views/origin.py b/swh/web/browse/views/origin.py --- a/swh/web/browse/views/origin.py +++ b/swh/web/browse/views/origin.py @@ -161,7 +161,7 @@ origin_url=request.GET.get("origin_url"), snapshot_id=request.GET.get("snapshot"), timestamp=request.GET.get("timestamp"), - branch_name_include=request.GET.get("branch_name_include"), + branch_name_include=request.GET.get("name_include"), ) @@ -202,6 +202,7 @@ origin_url=request.GET.get("origin_url"), snapshot_id=request.GET.get("snapshot"), timestamp=request.GET.get("timestamp"), + release_name_include=request.GET.get("name_include"), ) diff --git a/swh/web/templates/browse/branches.html b/swh/web/templates/browse/branches.html --- a/swh/web/templates/browse/branches.html +++ b/swh/web/templates/browse/branches.html @@ -13,15 +13,7 @@ {% block swh-browse-content %}
-
- -
- -
-
+ {% include "includes/branch-search.html" %}
diff --git a/swh/web/templates/browse/releases.html b/swh/web/templates/browse/releases.html --- a/swh/web/templates/browse/releases.html +++ b/swh/web/templates/browse/releases.html @@ -1,7 +1,7 @@ {% extends "./browse.html" %} {% comment %} -Copyright (C) 2017-2019 The Software Heritage developers +Copyright (C) 2017-2021 The Software Heritage developers See the AUTHORS file at the top-level directory of this distribution License: GNU Affero General Public License version 3, or any later version See top-level LICENSE file for more information @@ -10,8 +10,10 @@ {% load swh_templatetags %} {% block swh-browse-content %} -{% if displayed_releases|length > 0 %}
+
+ {% include "includes/branch-search.html" %} +
@@ -22,53 +24,62 @@ - {% for release in displayed_releases %} - - - - - + + + + + + {% endfor %} + {% else %} + + - {% endfor %} + {% endif %}
- - {% if release.alias %} - - {% else %} - - {% endif %} - {{ release.name }} - - - - {{ release.target|slice:":7" }} - - - {{ release.message }} - - {{ release.date }} + {% if displayed_releases|length > 0 %} + {% for release in displayed_releases %} +
+ + {% if release.alias %} + + {% else %} + + {% endif %} + {{ release.name }} + + + + {{ release.target|slice:":7" }} + + + {{ release.message }} + + {{ release.date }} +
+ {% if search_string %} + No release names containing {{search_string}} have been found! + {% else %} + The list of releases is empty! + {% endif %}
-{% else %} - The list of releases is empty ! -{% endif %} {% endblock %} {% block swh-browse-after-content %} -{% if prev_releases_url or next_releases_url %} - + {% endif %} {% endblock %} diff --git a/swh/web/templates/includes/branch-search.html b/swh/web/templates/includes/branch-search.html new file mode 100644 --- /dev/null +++ b/swh/web/templates/includes/branch-search.html @@ -0,0 +1,16 @@ +{% comment %} +Copyright (C) 2021 The Software Heritage developers +See the AUTHORS file at the top-level directory of this distribution +License: GNU Affero General Public License version 3, or any later version +See top-level LICENSE file for more information +{% endcomment %} + +
+ +
+ +
+