generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor error summary handling and add partial templates for validat…
…ion messages (#847) * Refactor error summary handling and add partial templates for validation messages - Introduced dynamic `errorKey` logic with fallback to a safe default. - Added reusable partial `list-validation-messages.njk` to streamline validation message rendering. - Created specific partial templates for error scenarios: - `error-summary-missing-prison-api-data.njk` - `error-summary-unsupported-offence.njk` - `error-summary-unsupported-sentence.njk` - `error-summary-unsupported-calculation.njk` - `error-summary-suspended-offence.njk` - `error-summary-save-dates.njk` - `error-summary-validation.njk` - `error-summary-default.njk` - Updated `customErrorBanner.njk` to use dynamic titles and include error-specific partials. - Simplified error summary structure for maintainability and extensibility. Warning: I'm not sure there is full test coverage for this * remove debug messages --------- Co-authored-by: Joel Stobart <>
- Loading branch information
1 parent
4e2510a
commit b3397e4
Showing
18 changed files
with
88 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,32 @@ | ||
{% if validationErrors and validationErrors.messages.length > 0 %} | ||
<div class="govuk-error-summary check-information-errors {% if validationErrors.messageType === 'MISSING_PRISON_API_DATA' %}information-summary{% endif %}" aria-labelledby="error-summary-title" role="alert" tabindex="-1" data-module="govuk-error-summary"> | ||
|
||
{% set validErrorKeys = [ | ||
"missing-prison-api-data", | ||
"unsupported-offence", | ||
"suspended-offence", | ||
"unsupported-sentence", | ||
"unsupported-calculation", | ||
"validation", | ||
"save-dates" | ||
] %} | ||
|
||
{% set rawErrorKey = validationErrors.messageType | lower | replace('_', '-') %} | ||
|
||
{% if rawErrorKey in validErrorKeys %} | ||
{% set errorKey = rawErrorKey %} | ||
{% else %} | ||
{% set errorKey = 'default' %} | ||
{% endif %} | ||
|
||
<div class="govuk-error-summary check-information-errors {% if errorKey === 'missing-prison-api-data' %}information-summary{% endif %}" | ||
aria-labelledby="error-summary-title" role="alert" tabindex="-1" data-module="govuk-error-summary"> | ||
<h2 class="govuk-error-summary__title" id="error-summary-title"> | ||
{% if validationErrors.messageType === 'MISSING_PRISON_API_DATA' %} | ||
The calculation breakdown cannot be shown on this page. | ||
{% elif validationErrors.messageType === 'UNSUPPORTED_OFFENCE' %} | ||
One or more offence codes needs updating in NOMIS. | ||
{% elif validationErrors.messageType === 'SUSPENDED_OFFENCE' %} | ||
‘Original offence suspended sentence activated’ is an invalid offence. | ||
{% else %} | ||
There is a problem | ||
{% endif %} | ||
{% include "./errorBanner/error-title-" + errorKey + ".njk" %} | ||
</h2> | ||
<div class="govuk-error-summary__body"> | ||
<ul class="govuk-list govuk-error-summary__list"> | ||
{% if validationErrors.messageType === 'UNSUPPORTED_SENTENCE' %} | ||
<li> | ||
<p class="govuk-body">One or more of the sentence types in this calculation is not currently supported in this service:</p> | ||
</li> | ||
{% elif validationErrors.messageType === 'UNSUPPORTED_CALCULATION' %} | ||
<li> | ||
<p class="govuk-body">This service does not yet support a calculation scenario{% if validationErrors.messages.length > 1 %}s{% endif %} when:</p> | ||
</li> | ||
{% endif %} | ||
{% for error in validationErrors.messages %} | ||
<li> | ||
<p class="govuk-body"> | ||
{% if error.href %} | ||
<a href="{{ error.href }}">{{ error.html | safe if error.html else error.text }}</a> | ||
{% elif error.id %} | ||
<a href="#{{ error.id }}">{{ error.html | safe if error.html else error.text }}</a> | ||
{% else %} | ||
{{ error.html | safe if error.html else error.text | ||
| replace('\n', '<br>') | ||
| replace ('reload this page', '<a href="">reload this page</a>') | safe }} | ||
{% endif %} | ||
</p> | ||
</li> | ||
{% endfor %} | ||
|
||
{% if validationErrors.messageType === 'UNSUPPORTED_SENTENCE' %} | ||
<li> | ||
<p class="govuk-body">If these sentences are correct, you will need to complete this calculation manually in NOMIS.</p> | ||
<p class="govuk-body govuk-!-margin-bottom-0"> | ||
<a href="{{'/supported-sentences/' + prisonerDetail.offenderNo}}">Check supported sentence types</a> | ||
</p> | ||
</li> | ||
{% elif validationErrors.messageType === 'UNSUPPORTED_CALCULATION' %} | ||
<li> | ||
<p class="govuk-body govuk-!-margin-bottom-0">Calculate the release dates manually until {% if validationErrors.messages.length === 1 %}this scenario is{% else %}these scenarios are{% endif %} supported by this service.</p> | ||
</li> | ||
{% elif validationErrors.messageType === 'VALIDATION' %} | ||
<li> | ||
<p class="govuk-body govuk-!-margin-bottom-0">Update these details in NOMIS and then <a href="">reload this page</a>.</p> | ||
</li> | ||
{% elif validationErrors.messageType === 'SAVE_DATES' %} | ||
<li> | ||
<p class="govuk-body govuk-!-margin-bottom-0"> Review the calculation and try again.</p> | ||
</li> | ||
{% endif %} | ||
{% include "./errorBanner/error-summary-" + errorKey + ".njk" %} | ||
</ul> | ||
</div> | ||
</div> | ||
{% endif %} | ||
{% endif %} |
1 change: 1 addition & 0 deletions
1
server/views/pages/partials/errorBanner/error-summary-default.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% include "./list-validation-messages.njk" %} |
1 change: 1 addition & 0 deletions
1
server/views/pages/partials/errorBanner/error-summary-missing-prison-api-data.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% include "./list-validation-messages.njk" %} |
5 changes: 5 additions & 0 deletions
5
server/views/pages/partials/errorBanner/error-summary-save-dates.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% include "./list-validation-messages.njk" %} | ||
|
||
<li> | ||
<p class="govuk-body govuk-!-margin-bottom-0">Review the calculation and try again.</p> | ||
</li> |
3 changes: 3 additions & 0 deletions
3
server/views/pages/partials/errorBanner/error-summary-suspended-offence.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<li> | ||
<p class="govuk-body">‘Original offence suspended sentence activated’ is an invalid offence.</p> | ||
</li> |
10 changes: 10 additions & 0 deletions
10
server/views/pages/partials/errorBanner/error-summary-unsupported-calculation.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<li> | ||
<p class="govuk-body">This service does not yet support a calculation scenario when:</p> | ||
</li> | ||
|
||
{% include "./list-validation-messages.njk" %} | ||
|
||
<li> | ||
<p class="govuk-body govuk-!-margin-bottom-0">Calculate the release dates manually until these scenarios are | ||
supported by this service.</p> | ||
</li> |
5 changes: 5 additions & 0 deletions
5
server/views/pages/partials/errorBanner/error-summary-unsupported-offence.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<li> | ||
<p class="govuk-body">One or more offence codes need updating in NOMIS.</p> | ||
</li> | ||
|
||
{% include "./list-validation-messages.njk" %} |
14 changes: 14 additions & 0 deletions
14
server/views/pages/partials/errorBanner/error-summary-unsupported-sentence.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<li> | ||
<p class="govuk-body">One or more of the sentence types in this calculation is not currently supported in this | ||
service:</p> | ||
</li> | ||
|
||
{% include "./list-validation-messages.njk" %} | ||
|
||
<li> | ||
<p class="govuk-body">If these sentences are correct, you will need to complete this calculation manually in | ||
NOMIS.</p> | ||
<p class="govuk-body govuk-!-margin-bottom-0"> | ||
<a href="{{ '/supported-sentences/' + prisonerDetail.offenderNo }}">Check supported sentence types</a> | ||
</p> | ||
</li> |
6 changes: 6 additions & 0 deletions
6
server/views/pages/partials/errorBanner/error-summary-validation.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% include "./list-validation-messages.njk" %} | ||
|
||
<li> | ||
<p class="govuk-body govuk-!-margin-bottom-0">Update these details in NOMIS and then <a href="">reload this page</a>. | ||
</p> | ||
</li> |
1 change: 1 addition & 0 deletions
1
server/views/pages/partials/errorBanner/error-title-default.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
There is a problem |
1 change: 1 addition & 0 deletions
1
server/views/pages/partials/errorBanner/error-title-missing-prison-api-data.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The calculation breakdown cannot be shown on this page. |
1 change: 1 addition & 0 deletions
1
server/views/pages/partials/errorBanner/error-title-save-dates.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Review the calculation and try again. |
1 change: 1 addition & 0 deletions
1
server/views/pages/partials/errorBanner/error-title-suspended-offence.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
‘Original offence suspended sentence activated’ is an invalid offence. |
1 change: 1 addition & 0 deletions
1
server/views/pages/partials/errorBanner/error-title-unsupported-calculation.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This service does not yet support a calculation scenario. |
1 change: 1 addition & 0 deletions
1
server/views/pages/partials/errorBanner/error-title-unsupported-offence.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
One or more offence codes need updating in NOMIS. |
1 change: 1 addition & 0 deletions
1
server/views/pages/partials/errorBanner/error-title-unsupported-sentence.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
One or more of the sentence types in this calculation is not currently supported. |
1 change: 1 addition & 0 deletions
1
server/views/pages/partials/errorBanner/error-title-validation.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
There is a problem |
11 changes: 11 additions & 0 deletions
11
server/views/pages/partials/errorBanner/list-validation-messages.njk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% for error in validationErrors.messages %} | ||
<li> | ||
<p class="govuk-body"> | ||
{% if error.href %} | ||
<a href="{{ error.href }}">{{ error.html | safe if error.html else error.text }}</a> | ||
{% else %} | ||
{{ error.html | safe if error.html else error.text | replace('\n', '<br>') | safe }} | ||
{% endif %} | ||
</p> | ||
</li> | ||
{% endfor %} |