Skip to content

Commit

Permalink
Separate warning and error lists
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Sep 19, 2024
1 parent 9502656 commit c7dd752
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 49 deletions.
8 changes: 6 additions & 2 deletions lib/importer/govuk-prototype-kit.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@
"importFrom": "importer/macros/range_selector.njk"
},
{
"macroName": "importerMappingReview",
"importFrom": "importer/macros/mapping_review.njk"
"macroName": "importerMappingWarningList",
"importFrom": "importer/macros/mapping_warning_list.njk"
},
{
"macroName": "importerMappingErrorList",
"importFrom": "importer/macros/mapping_error_list.njk"
}
]
}
17 changes: 11 additions & 6 deletions lib/importer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,17 @@ exports.Initialise = (config, router, prototypeKit) => {
//--------------------------------------------------------------------
// Returns warnings or errors arising from applying a mapping.
//--------------------------------------------------------------------
prototypeKit.views.addFunction("importerMappingFailures", (data) => {
if (data[MAPPING_ERROR_KEY] || data[MAPPING_WARNING_KEY]) {
return {
warnings: data[MAPPING_WARNING_KEY],
errors: data[MAPPING_ERROR_KEY]
};
prototypeKit.views.addFunction("importerMappingErrors", (data) => {
if (data[MAPPING_ERROR_KEY]) {
return data[MAPPING_ERROR_KEY]
}

return false;
}, {})

prototypeKit.views.addFunction("importerMappingWarnings", (data) => {
if (data[MAPPING_WARNING_KEY]) {
return data[MAPPING_WARNING_KEY]
}

return false;
Expand Down
19 changes: 19 additions & 0 deletions lib/importer/nunjucks/importer/macros/mapping_error_list.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


{#
Shows errors generated when attempting to
perform a mapping
#}
{% macro importerMappingErrorList(data) %}
{% set errors = importerMappingErrors(data) %}
{% if errors %}
<div>
<h2 class="govuk-heading-m">Errors</h2>
<ul>
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
<div>
{% endif %}
{% endmacro %}
32 changes: 0 additions & 32 deletions lib/importer/nunjucks/importer/macros/mapping_review.njk

This file was deleted.

19 changes: 19 additions & 0 deletions lib/importer/nunjucks/importer/macros/mapping_warning_list.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


{#
Shows warnings generated when attempting to
perform a mapping
#}
{% macro importerMappingWarningList(data) %}
{% set warnings = importerMappingWarnings(data) %}
{% if warnings %}
<div>
<h2 class="govuk-heading-m">Warnings</h2>
<ul>
{% for warning in warnings %}
<li>{{ warning }}</li>
{% endfor %}
</ul>
<div>
{% endif %}
{% endmacro %}
7 changes: 5 additions & 2 deletions lib/importer/templates/review.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "layouts/main.html" %}
{% from "importer/macros/mapping_review.njk" import importerMappingReview %}
{% from "importer/macros/mapping_warning_list.njk" import importerMappingWarningList %}
{% from "importer/macros/mapping_error_list.njk" import importerMappingErrorList %}


{% block pageTitle %} {{ serviceName }} – GOV.UK Prototype Kit {% endblock %}
Expand All @@ -12,7 +13,9 @@
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Review your data</h1>

{{ importerMappingReview(data) }}
{{ importerMappingWarningList(data) }}

{{ importerMappingErrorList(data) }}

</div>
</div>
Expand Down
12 changes: 5 additions & 7 deletions prototypes/basic/app/views/review.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "layouts/main.html" %}
{% from "importer/macros/mapping_review.njk" import importerMappingReview %}
{% from "importer/macros/mapping_warning_list.njk" import importerMappingWarningList %}
{% from "importer/macros/mapping_error_list.njk" import importerMappingErrorList %}


{% block pageTitle %} {{ serviceName }} – GOV.UK Prototype Kit {% endblock %}
Expand All @@ -12,13 +13,10 @@
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Review your data</h1>

{{ importerMappingReview(data) }}
{{ importerMappingWarningList(data) }}

{{ importerMappingErrorList(data) }}

<form action="{{ importerReviewDataPath('/success') }}" method="post">
<div class="govuk-button-group">
{{ govukButton({ text: "Submit" }) }}
</div>
</form>
</div>
</div>
{% endblock %}

0 comments on commit c7dd752

Please sign in to comment.