Skip to content

Commit

Permalink
remove actionable pagination for single page (#478)
Browse files Browse the repository at this point in the history
* remove 'registered by' from search results

* remove page range if only single page of search results

* update test
  • Loading branch information
tom-webber authored Jun 21, 2024
1 parent 0361250 commit 0c12c22
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 47 deletions.
8 changes: 5 additions & 3 deletions home/service/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, form: SearchForm, page: str, items_per_page: int = 20):
self.results = self._get_search_results(page, items_per_page)
self.highlighted_results = self._highlight_results()
self.paginator = self._get_paginator(items_per_page)
self.context = self._get_context()
self.context = self._get_context(items_per_page)

@staticmethod
def _build_custom_property_filter(
Expand Down Expand Up @@ -165,7 +165,7 @@ def _generate_domain_clear_href(
)
}

def _get_context(self) -> dict[str, Any]:
def _get_context(self, items_per_page: int) -> dict[str, Any]:
if self.results.total_results >= settings.MAX_RESULTS:
total_results = f"{settings.MAX_RESULTS}+"
else:
Expand All @@ -182,7 +182,9 @@ def _get_context(self) -> dict[str, Any]:
),
"number_of_words": len(self.form_data.get("query", "").split()),
"paginator": self.paginator,
"total_results": total_results,
"results_per_page": items_per_page,
"total_results_str": total_results,
"total_results": self.results.total_results,
"label_clear_href": self._generate_label_clear_ref(),
"readable_match_reasons": self._get_match_reason_display_names(),
}
Expand Down
72 changes: 37 additions & 35 deletions templates/partial/pagination.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
{% load future %}
{% if results %}
<nav class="govuk-pagination" role="navigation" aria-label="Pagination">
{% if page_obj.has_previous %}
<div class="govuk-pagination__prev">
<a class="govuk-link govuk-pagination__link" href="{% url 'home:pagination' page=page_obj.previous_page_number %}{% query_string clear_label=None clear_filter=None %}" rel="prev">
<svg class="govuk-pagination__icon govuk-pagination__icon--prev" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
<path d="m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z"></path>
</svg>
<span class="govuk-pagination__link-title">Previous<span class="govuk-visually-hidden"> page</span></span></a>
</div>
{% endif %}
<ul class="govuk-pagination__list">
{% for p in page_range %}
{% if paginator.ELLIPSIS != p %}
{% if page_obj.number == p %}
<li class="govuk-pagination__item govuk-pagination__item--current">
{% else %}
<li class="govuk-pagination__item">
{% endif %}
<a class="govuk-link govuk-pagination__link" href="{% url 'home:pagination' page=p %}{% query_string clear_label=None clear_filter=None new=None %}" aria-label="Page {{ p }}">
{{ p }}
</a>
</li>
{% else %}
<li class="govuk-pagination__item govuk-pagination__item--ellipses">&ctdot;</li>
<nav class="govuk-pagination" role="navigation" aria-label="Pagination">
{% if page_obj.has_previous %}
<div class="govuk-pagination__prev">
<a class="govuk-link govuk-pagination__link" href="{% url 'home:pagination' page=page_obj.previous_page_number %}{% query_string clear_label=None clear_filter=None %}" rel="prev">
<svg class="govuk-pagination__icon govuk-pagination__icon--prev" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
<path d="m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z"></path>
</svg>
<span class="govuk-pagination__link-title">Previous<span class="govuk-visually-hidden"> page</span></span></a>
</div>
{% endif %}
<ul class="govuk-pagination__list">
{% if total_results > results_per_page %}
{% for p in page_range %}
{% if paginator.ELLIPSIS != p %}
{% if page_obj.number == p %}
<li class="govuk-pagination__item govuk-pagination__item--current">
{% else %}
<li class="govuk-pagination__item">
{% endif %}
<a class="govuk-link govuk-pagination__link" href="{% url 'home:pagination' page=p %}{% query_string clear_label=None clear_filter=None new=None %}" aria-label="Page {{ p }}">
{{ p }}
</a>
</li>
{% else %}
<li class="govuk-pagination__item govuk-pagination__item--ellipses">&ctdot;</li>
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
</ul>
{% if page_obj.has_next %}
<div class="govuk-pagination__next">
<a class="govuk-link govuk-pagination__link" href="{% url 'home:pagination' page=page_obj.next_page_number %}{% query_string clear_label=None clear_filter=None value=None new=None %}" rel="next"> <span class="govuk-pagination__link-title">Next<span class="govuk-visually-hidden"> page</span></span> <svg class="govuk-pagination__icon govuk-pagination__icon--next" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
<path d="m8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z"></path>
</svg></a>
</div>
{% endif %}
</nav>
{% endif %}
</ul>
{% if page_obj.has_next %}
<div class="govuk-pagination__next">
<a class="govuk-link govuk-pagination__link" href="{% url 'home:pagination' page=page_obj.next_page_number %}{% query_string clear_label=None clear_filter=None value=None new=None %}" rel="next"> <span class="govuk-pagination__link-title">Next<span class="govuk-visually-hidden"> page</span></span> <svg class="govuk-pagination__icon govuk-pagination__icon--next" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
<path d="m8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z"></path>
</svg></a>
</div>
{% endif %}
</nav>
{% endif %}
6 changes: 0 additions & 6 deletions templates/partial/search_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ <h3 class="govuk-heading-m govuk-!-margin-bottom-2">
</div>
{% endif %}
<dl class="govuk-summary-list govuk-summary-list--no-border">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Registered by:</dt>
<dd class="govuk-summary-list__value">
TBC
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Refresh period:</dt>
<dd class="govuk-summary-list__value">
Expand Down
4 changes: 2 additions & 2 deletions templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ <h1 class="govuk-heading-l">{{h1_value}}</h1>
{% include "partial/filter.html" %}
<div class="govuk-grid-column-two-thirds">
{% if results %}
<h2 class="govuk-heading-l govuk-!-display-inline-block" id="result-count">{{total_results|intcomma}} results</h2>
<h2 class="govuk-heading-l govuk-!-display-inline-block" id="result-count">{{total_results_str|intcomma}} results</h2>
{% else %}
{% include "partial/no_results.html" %}
{% include "partial/no_results.html" %}
{% endif %}
{% include "partial/sort.html" %}
{% include "partial/search_result.html" %}
Expand Down
3 changes: 2 additions & 1 deletion tests/home/service/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def test_get_context_form(self, valid_form, search_context):

def test_get_context_search_result(self, mock_catalogue, search_context):
assert search_context["results"] == mock_catalogue.search().page_results
assert search_context["total_results"] == "100"
assert search_context["total_results_str"] == "100"
assert search_context["total_results"] == 100

def test_get_context_paginator(self, search_context):
assert search_context["page_obj"].number == 1
Expand Down

0 comments on commit 0c12c22

Please sign in to comment.