From 789e576ddb670602c59f7d7d28db4f970efc84bf Mon Sep 17 00:00:00 2001 From: Ross Jones Date: Tue, 12 Nov 2024 11:57:00 +0000 Subject: [PATCH] Show upload preview without error Adds a new macro which will show the upload form without relying on any macros that are not installed because we are showing the preview by just showing the template on the page. As a result the preview.show() macro needs to import all of the govuk components (which are not installed in the importer, but will be when showing the preview) for any govuk components. Unfortunately, when installing this template, it will keep the block that decides to show the preview and will likely generate support questions around its presence. --- lib/importer/templates/previews/upload.html | 24 +++++++++++ lib/importer/templates/upload.html | 47 ++++++++++++--------- 2 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 lib/importer/templates/previews/upload.html diff --git a/lib/importer/templates/previews/upload.html b/lib/importer/templates/previews/upload.html new file mode 100644 index 00000000..3ca24bd9 --- /dev/null +++ b/lib/importer/templates/previews/upload.html @@ -0,0 +1,24 @@ +{% from "govuk/components/button/macro.njk" import govukButton %} +{% from "govuk/components/file-upload/macro.njk" import govukFileUpload %} + +{% macro show() %} +
+

Upload your data

+ +
+
+ {{ govukFileUpload({ + id: "file-upload", + name: "file", + label: { text: "Upload an XLSX, ODS, or CSV file"}, + attributes: { "accept": + ".xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,.csv,text/csv,application/vnd.oasis.opendocument.spreadsheet,.ods"}, + errorMessage: false }) + }} +
+
+ {{ govukButton({ text: "Upload" }) }} +
+
+
+{% endmacro %} diff --git a/lib/importer/templates/upload.html b/lib/importer/templates/upload.html index b442b36c..c981602e 100644 --- a/lib/importer/templates/upload.html +++ b/lib/importer/templates/upload.html @@ -4,31 +4,36 @@ {% block pageTitle %} {{ serviceName }} – GOV.UK Prototype Kit {% endblock %} {% block beforeContent %} -{{ govukBackLink({ text: "Back", href: "javascript:window.history.back()" }) }} + {{ govukBackLink({ text: "Back", href: "javascript:window.history.back()" }) }} {% endblock %} {% block content %}
-
-

Upload your data

+ {% if importerUploadPath %} +
+

Upload your data

-
-
- {{ govukFileUpload({ - id: "file-upload", - name: "file", - label: { text: "Upload an XLSX, ODS, or CSV file"}, - attributes: { "accept": ".xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,.csv,text/csv,application/vnd.oasis.opendocument.spreadsheet,.ods"}, - errorMessage: importerError(data) - }) - }} -
-
- {{ govukButton({ text: "Upload" }) }} -
-
-
+
+
+ {{ + govukFileUpload({ + id: "file-upload", + name: "file", + label: { text: "Upload an XLSX, ODS, or CSV file"}, + attributes: { "accept": + ".xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,.csv,text/csv,application/vnd.oasis.opendocument.spreadsheet,.ods"}, + errorMessage: importerError(data) + }) + }} +
+
+ {{ govukButton({ text: "Upload" }) }} +
+
+
+ {% else %} + {% import "./previews/upload.html" as preview %} + {{ preview.show() }} + {% endif %}
- - {% endblock %}