Merge pull request #3436 from alphagov/limit-search-50

Don’t show pagination links when searching
This commit is contained in:
Chris Hill-Scott
2020-05-07 10:09:58 +01:00
committed by GitHub
3 changed files with 39 additions and 2 deletions

View File

@@ -211,6 +211,7 @@ def get_notifications(service_id, message_type, status_override=None):
filter_args = parse_filter_args(request.args)
filter_args['status'] = set_status_filters(filter_args)
service_data_retention_days = None
search_term = request.form.get('to', '')
if message_type is not None:
service_data_retention_days = current_service.get_days_of_retention(message_type)
@@ -235,7 +236,7 @@ def get_notifications(service_id, message_type, status_override=None):
template_type=[message_type] if message_type else [],
status=filter_args.get('status'),
limit_days=service_data_retention_days,
to=request.form.get('to', ''),
to=search_term,
)
url_args = {
'message_type': message_type,
@@ -284,6 +285,7 @@ def get_notifications(service_id, message_type, status_override=None):
limit_days=service_data_retention_days,
prev_page=prev_page,
next_page=next_page,
show_pagination=(not search_term),
status=request.args.get('status'),
message_type=message_type,
download_link=download_link,

View File

@@ -33,6 +33,12 @@
</div>
{% endif %}
{{ previous_next_navigation(prev_page, next_page) }}
{% if show_pagination %}
{{ previous_next_navigation(prev_page, next_page) }}
{% elif next_page %}
<p class="table-show-more-link">
Only showing the first 50 messages
</p>
{% endif %}
</div>

View File

@@ -527,6 +527,35 @@ def test_should_show_notifications_for_a_service_with_next_previous(
assert 'page 1' in prev_page_link.text.strip()
def test_doesnt_show_pagination_with_search_term(
client_request,
service_one,
active_user_with_permissions,
mock_get_notifications_with_previous_next,
mock_get_service_statistics,
mock_get_service_data_retention,
mock_get_no_api_keys,
mocker,
):
page = client_request.post(
'main.view_notifications',
service_id=service_one['id'],
message_type='sms',
_data={
'to': 'test@example.com',
},
_expected_status=200,
)
assert len(page.select('tbody tr')) == 50
assert not page.find('a', {'rel': 'next'})
assert not page.find('a', {'rel': 'previous'})
assert normalize_spaces(
page.select_one('.table-show-more-link').text
) == (
'Only showing the first 50 messages'
)
@pytest.mark.parametrize(
"job_created_at, expected_message", [
("2016-01-10 11:09:00.000000+00:00", "Data available for 7 days"),