Add some summaries of letter validation errors

We show letter validation errors in two places:

1. In response to a user uploading a PDF
   Here we use the error banner pattern because the problem is as a
   direct consequence of a user’s action, and is blocking them from
   continuing.

2. Once a PDF provided through the API has been validated
   We use a less prominent pattern of red text with no border because
   the message is reporting on something that’s already happened, and
   which wasn’t a direct consequence of the user clicking something

Because the context and patterns used are different we need slightly
different content in each of these situations. Previously we tried to
reuse the same content to make the code cleaner and less repetitive. But
ultimately a clear interface trumps clear code.
This commit is contained in:
Chris Hill-Scott
2020-01-10 17:29:58 +00:00
parent a186d0eeff
commit 540945539b
4 changed files with 75 additions and 14 deletions

View File

@@ -579,6 +579,10 @@ LETTER_VALIDATION_MESSAGES = {
'You need to change the size or orientation of {invalid_pages}. <br>'
f'Files must meet our <a href="{LETTER_SPECIFICATION_URL}" target="_blank">letter specification</a>.'
),
'summary': (
'Validation failed because {invalid_pages} {invalid_pages_are_or_is} not A4 portrait size.<br>'
f'Files must meet our <a href="{LETTER_SPECIFICATION_URL}" target="_blank">letter specification</a>.'
),
},
'content-outside-printable-area': {
'title': 'Your content is outside the printable area',
@@ -586,6 +590,10 @@ LETTER_VALIDATION_MESSAGES = {
'You need to edit {invalid_pages}.<br>'
f'Files must meet our <a href="{LETTER_SPECIFICATION_URL}" target="_blank">letter specification</a>.'
),
'summary': (
'Validation failed because content is outside the printable area on {invalid_pages}.<br>'
f'Files must meet our <a href="{LETTER_SPECIFICATION_URL}" target="_blank">letter specification</a>.'
),
},
'letter-too-long': {
'title': 'Your letter is too long',
@@ -593,6 +601,10 @@ LETTER_VALIDATION_MESSAGES = {
'Letters must be 10 pages or less. <br>'
'Your letter is {page_count} pages long.'
),
'summary': (
'Validation failed because this letter is {page_count} pages long.<br>'
'Letters must be 10 pages or less.'
),
},
'no-encoded-string': {
'title': 'Sanitise failed - No encoded string'
@@ -603,6 +615,10 @@ LETTER_VALIDATION_MESSAGES = {
'Notify cannot read this PDF.'
'<br>Save a new copy of your file and try again.'
),
'summary': (
'Letters must be 10 pages or less. <br>'
'This letter is {page_count} pages long.'
),
},
'address-is-empty': {
'title': 'The address block is empty',
@@ -610,6 +626,10 @@ LETTER_VALIDATION_MESSAGES = {
'You need to add a recipient address.<br>'
f'Files must meet our <a href="{LETTER_SPECIFICATION_URL}" target="_blank">letter specification</a>.'
),
'summary': (
'Validation failed because the address block is empty.<br>'
f'Files must meet our <a href="{LETTER_SPECIFICATION_URL}" target="_blank">letter specification</a>.'
),
}
}
@@ -618,6 +638,8 @@ def get_letter_validation_error(validation_message, invalid_pages=None, page_cou
if validation_message not in LETTER_VALIDATION_MESSAGES:
return {'title': 'Validation failed'}
invalid_pages_are_or_is = 'is' if len(invalid_pages) == 1 else 'are'
invalid_pages = unescaped_formatted_list(
invalid_pages or [],
before_each='',
@@ -630,8 +652,14 @@ def get_letter_validation_error(validation_message, invalid_pages=None, page_cou
'title': LETTER_VALIDATION_MESSAGES[validation_message]['title'],
'detail': LETTER_VALIDATION_MESSAGES[validation_message]['detail'].format(
invalid_pages=invalid_pages,
invalid_pages_are_or_is=invalid_pages_are_or_is,
page_count=page_count,
)
),
'summary': LETTER_VALIDATION_MESSAGES[validation_message]['summary'].format(
invalid_pages=invalid_pages,
invalid_pages_are_or_is=invalid_pages_are_or_is,
page_count=page_count,
),
}