From 72159ff6e33d4d87fc57ce3cf5e79dc33b63c0f5 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 19 Nov 2018 16:26:27 +0000 Subject: [PATCH] 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). --- app/main/views/templates.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 70a854143..c11231006 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -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)