From 45b60e955588aa8d103aeddae17dfa78c02234b2 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 12 May 2020 17:52:13 +0100 Subject: [PATCH] Show usage count on uploads page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because we’re be grouping jobs under their parent contact lists it’s good to have some information ‘scent’ to help people find their jobs, ie by clicking into a contact list. It also lets you see which list have been used more than others, maybe because the update hasn’t been sent to that group of people yet. The hint text under uploads always says when they were used. For contact lists this is a bit more complicated, since they can: - never have been used - been used multiple times This commit makes use of the new fields being returned by the API to say determine when these messages are relevant. They also let us differentiate between a contact list that’s never been used, and one that has been used, but not recently enough to show any jobs against it. --- app/models/contact_list.py | 2 ++ app/templates/views/dashboard/_jobs.html | 18 +++++++++++++----- tests/app/main/views/test_send.py | 17 +++++++++-------- .../views/uploads/test_upload_contact_list.py | 2 +- .../app/main/views/uploads/test_upload_hub.py | 10 ++++++++-- tests/conftest.py | 16 ++++++++++++++++ 6 files changed, 49 insertions(+), 16 deletions(-) diff --git a/app/models/contact_list.py b/app/models/contact_list.py index e1bbebbca..294c53165 100644 --- a/app/models/contact_list.py +++ b/app/models/contact_list.py @@ -24,6 +24,8 @@ class ContactList(JSONModel): ALLOWED_PROPERTIES = { 'id', 'created_by', + 'has_jobs', + 'recent_job_count', 'service_id', 'original_file_name', 'row_count', diff --git a/app/templates/views/dashboard/_jobs.html b/app/templates/views/dashboard/_jobs.html index d65e3573f..7a8e0f9a2 100644 --- a/app/templates/views/dashboard/_jobs.html +++ b/app/templates/views/dashboard/_jobs.html @@ -1,6 +1,6 @@ {% from "components/table.html" import list_table, field, right_aligned_field_heading, row_heading %} {% from "components/big-number.html" import big_number -%} -{% from "components/message-count-label.html" import message_count_label, recipient_count_label -%} +{% from "components/message-count-label.html" import message_count_label, recipient_count_label, iteration_count -%}
{% call(item, row_number) list_table( @@ -35,10 +35,18 @@ {% elif item.upload_type == 'contact_list' %} - Uploaded {{ - item.created_at|format_datetime_relative - }} - + {% if item.recent_job_count %} + Used {{ iteration_count(item.recent_job_count) }} + in the last + {{ current_service.get_days_of_retention(item.template_type) }} + days + {% elif item.has_jobs %} + Not used in the last + {{ current_service.get_days_of_retention(item.template_type) }} + days + {% else %} + Not used yet + {% endif %} {% elif item.upload_type == 'letter_day' %} {{ item.letter_printing_statement }} diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index 875c9206f..cc906312f 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -4174,21 +4174,21 @@ def test_redirects_to_template_if_job_exists_already( @pytest.mark.parametrize(( 'template_type, ' 'expected_list_id, ' - 'expected_filename, ' + 'expected_filenames, ' 'expected_time, ' 'expected_count' ), ( ( 'email', '6ce466d0-fd6a-11e5-82f5-e0accb9d11a6', - 'EmergencyContactList.xls', + ['EmergencyContactList.xls'], 'Uploaded today at 10:59am', '100 email addresses', ), ( 'sms', 'd7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad', - 'phone number list.csv', + ['phone number list.csv', 'UnusedList.tsv'], 'Uploaded today at 1:00pm', '123 phone numbers', ), @@ -4201,7 +4201,7 @@ def test_choose_from_contact_list( fake_uuid, template_type, expected_list_id, - expected_filename, + expected_filenames, expected_time, expected_count, ): @@ -4215,10 +4215,11 @@ def test_choose_from_contact_list( service_id=SERVICE_ONE_ID, template_id=fake_uuid, ) - assert len(page.select('.file-list-filename-large')) == 1 - assert normalize_spaces(page.select_one('.file-list-filename-large').text) == ( - expected_filename - ) + assert [ + normalize_spaces(filename.text) + for filename in page.select('.file-list-filename-large') + ] == expected_filenames + assert page.select_one('a.file-list-filename-large')['href'] == url_for( 'main.send_from_contact_list', service_id=SERVICE_ONE_ID, diff --git a/tests/app/main/views/uploads/test_upload_contact_list.py b/tests/app/main/views/uploads/test_upload_contact_list.py index 364db9f20..6f932e854 100644 --- a/tests/app/main/views/uploads/test_upload_contact_list.py +++ b/tests/app/main/views/uploads/test_upload_contact_list.py @@ -478,7 +478,7 @@ def test_view_contact_list( 'Uploaded by Test User today at 10:59am.' ) assert normalize_spaces(page.select('main p')[1].text) == ( - 'Not used yet.' + 'Not used in the last 7 days.' ) assert normalize_spaces(page.select_one('main h2').text) == ( '51 saved email addresses' diff --git a/tests/app/main/views/uploads/test_upload_hub.py b/tests/app/main/views/uploads/test_upload_hub.py index fae8de5d8..f9e44fafe 100644 --- a/tests/app/main/views/uploads/test_upload_hub.py +++ b/tests/app/main/views/uploads/test_upload_hub.py @@ -338,6 +338,7 @@ def test_uploads_page_shows_contact_lists_first( mock_get_no_uploads, mock_get_jobs, mock_get_contact_lists, + mock_get_service_data_retention, ): page = client_request.get('main.uploads', service_id=SERVICE_ONE_ID) @@ -349,14 +350,19 @@ def test_uploads_page_shows_contact_lists_first( ), ( 'phone number list.csv ' - 'Uploaded 13 March at 1:00pm ' + 'Used twice in the last 7 days ' '123 saved phone numbers' ), ( 'EmergencyContactList.xls ' - 'Uploaded 13 March at 10:59am ' + 'Not used in the last 7 days ' '100 saved email addresses' ), + ( + 'UnusedList.tsv ' + 'Not used yet ' + '1 saved phone number' + ), ( 'even_later.csv ' 'Sending 1 January 2016 at 11:09pm ' diff --git a/tests/conftest.py b/tests/conftest.py index f4ce31281..a283d3b82 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2075,6 +2075,8 @@ def mock_get_contact_lists(mocker, api_user_active, fake_uuid): 'id': fake_uuid, 'original_file_name': 'EmergencyContactList.xls', 'row_count': 100, + 'recent_job_count': 0, + 'has_jobs': True, 'service_id': service_id, 'template_type': 'email', }, { @@ -2083,6 +2085,18 @@ def mock_get_contact_lists(mocker, api_user_active, fake_uuid): 'id': 'd7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad', 'original_file_name': 'phone number list.csv', 'row_count': 123, + 'recent_job_count': 2, + 'has_jobs': True, + 'service_id': service_id, + 'template_type': 'sms', + }, { + 'created_at': '2020-02-02 02:00:00', + 'created_by': 'Test User', + 'id': fake_uuid, + 'original_file_name': 'UnusedList.tsv', + 'row_count': 1, + 'recent_job_count': 0, + 'has_jobs': False, 'service_id': service_id, 'template_type': 'sms', }] @@ -2102,6 +2116,8 @@ def mock_get_contact_list(mocker, api_user_active, fake_uuid): 'id': fake_uuid, 'original_file_name': 'EmergencyContactList.xls', 'row_count': 100, + 'recent_job_count': 0, + 'has_jobs': True, 'service_id': service_id, 'template_type': 'email', }