Fix search box show/hide logic

The search box should only be shown if there are too many items to
quickly scan on the page. This number is judged to be 7; see the
original PR for more context:
https://github.com/alphagov/notifications-admin/pull/1195

This commit makes that logic work in the world of folders, by explicitly
counting the templates shown on the screen, not all the templates a
service has (which may be spread across multiple folders).
This commit is contained in:
Chris Hill-Scott
2018-11-19 16:26:27 +00:00
parent ad129e92dd
commit 72159ff6e3

View File

@@ -121,14 +121,16 @@ def choose_template(service_id, template_type='all', template_folder_id=None):
)
return redirect(request.url)
templates_on_page = current_service.get_templates(template_type, template_folder_id)
return render_template(
'views/templates/choose.html',
current_template_folder_id=template_folder_id,
can_manage_folders=can_manage_folders(),
template_folder_path=current_service.get_template_folder_path(template_folder_id),
template_folders=current_service.get_template_folders(template_type, template_folder_id),
templates=current_service.get_templates(template_type, template_folder_id),
show_search_box=(len(current_service.get_templates(template_type)) > 7),
templates=templates_on_page,
show_search_box=(len(templates_on_page) > 7),
show_template_nav=(
current_service.has_multiple_template_types
and (len(current_service.all_templates) > 2)