From 31b424885d5d2c88e06be9d83355440e084a63b6 Mon Sep 17 00:00:00 2001 From: tim-s-ccs Date: Wed, 23 Oct 2024 14:56:49 +0100 Subject: [PATCH] Upgrade Digital Marketplace Frontend to v1.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update CCS GOV.UK Frontend Jinja to v1.3.0 (GOV.UK Frontend 5.7.1) 🆕 New features: Add macros for the following components: | Component name | Macro name | |-----------------|-------------------------------------| | Question select | `digitalmarketplaceQuestionSelect` | --- CHANGELOG.md | 17 ++ README.md | 4 +- digitalmarketplace_frontend_jinja/__init__.py | 2 +- .../components/question-pricing/macro.html | 267 ++++++++++-------- .../components/question-select/macro.html | 53 ++++ .../templates/components/question/macro.html | 3 + package-lock.json | 18 +- package.json | 2 +- 8 files changed, 237 insertions(+), 129 deletions(-) create mode 100644 digitalmarketplace_frontend_jinja/templates/components/question-select/macro.html diff --git a/CHANGELOG.md b/CHANGELOG.md index 51c3c53..10b1d2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,18 +4,35 @@ Records breaking changes from major version bumps. ## Unreleased +## 2.10.0 + +Upgrade Digital Marketplace Frontend to v1.3.1 + +Update CCS GOV.UK Frontend Jinja to v1.3.0 (GOV.UK Frontend 5.7.1) + +🆕 New features: + + Add macros for the following components: + + | Component name | Macro name | + |-----------------|-------------------------------------| + | Question select | `digitalmarketplaceQuestionSelect` | + + ## 2.9.0 Upgrade Digital Marketplace Frontend to v1.2.0 Update CCS GOV.UK Frontend Jinja to v1.2.1 (GOV.UK Frontend 5.4.1) + ## 2.8.0 Update ccs-digitalmarketplace-utils to v67 which, in turn, updates flask to v3.0 Upgrade Digital Marketplace Frontend to v1.1 + ## 2.7.0 Make updates for change from Digital Marketplace GOV.UK Frontend to Digital Marketplace Frontend diff --git a/README.md b/README.md index ce8fc60..3eaa980 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,9 @@ This project was inspired by the [GOV.UK Frontend Jinja Macros](https://github.c The following table shows the version of Digital Marketplace Frontend Jinja that you should use for your targeted version of CCS Digital Marketplace GOV.UK Frontend: | Digital Marketplace Frontend Jinja Version | Target CCS Digital Marketplace GOV.UK Frontend Version | -| ----------------------------- | ------------------------------ | +| ------------------------------------------ | ------------------------------------------------------ | +| [2.10.0](https://github.com/tim-s-ccs/ccs-digitalmarketplace-frontend-jinja/releases/tag/2.10.0) | [1.3.1](https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-govuk-frontend/releases/tag/v1.3.1) | +| [2.9.0](https://github.com/tim-s-ccs/ccs-digitalmarketplace-frontend-jinja/releases/tag/2.9.0) | [1.2.0](https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-govuk-frontend/releases/tag/v1.2.0) | | [2.8.0](https://github.com/tim-s-ccs/ccs-digitalmarketplace-frontend-jinja/releases/tag/2.8.0) | [1.1.0](https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-govuk-frontend/releases/tag/v1.1.0) | | [2.7.0](https://github.com/tim-s-ccs/ccs-digitalmarketplace-frontend-jinja/releases/tag/2.7.0) | [1.0.0](https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-govuk-frontend/releases/tag/v1.0.0) | | [2.6.0](https://github.com/tim-s-ccs/ccs-digitalmarketplace-frontend-jinja/releases/tag/2.6.0) | [6.4.0](https://github.com/Crown-Commercial-Service/ccs-digitalmarketplace-govuk-frontend/releases/tag/6.4.0) | diff --git a/digitalmarketplace_frontend_jinja/__init__.py b/digitalmarketplace_frontend_jinja/__init__.py index 387cfac..e2e6e4b 100644 --- a/digitalmarketplace_frontend_jinja/__init__.py +++ b/digitalmarketplace_frontend_jinja/__init__.py @@ -1 +1 @@ -__version__ = '2.9.0' +__version__ = '2.10.0' diff --git a/digitalmarketplace_frontend_jinja/templates/components/question-pricing/macro.html b/digitalmarketplace_frontend_jinja/templates/components/question-pricing/macro.html index adbb290..cbaf7a3 100644 --- a/digitalmarketplace_frontend_jinja/templates/components/question-pricing/macro.html +++ b/digitalmarketplace_frontend_jinja/templates/components/question-pricing/macro.html @@ -6,10 +6,12 @@ {% set name = params.question.id %} {% set errorMessage = params.errors[name] if params.errors %} +{% set price = params.question.fields.price %} {% set minimumPrice = params.question.fields.minimum_price %} {% set maximumPrice = params.question.fields.maximum_price %} {% set priceUnit = params.question.fields.price_unit %} {% set priceInterval = params.question.fields.price_interval %} +{% set optional_fields = params.question.optional_fields or [] %} {% call govukFieldset({ "legend": { @@ -33,147 +35,176 @@ {% endif %} {% if priceUnit %} - {% set questionText = "Unit (optional)" if 'price_unit' in (params.question.optional_fields or []) else "Unit" %} + {% set questionText = "Unit (optional)" if 'price_unit' in optional_fields else "Unit" %} {% set value = params.data[priceUnit] if params.data %} + {% set units = params.question.units or [ + { + "label": "a unit", + "value": "Unit" + }, + { + "label": "a licence", + "value": "Licence" + }, + { + "label": "a user", + "value": "User" + }, + { + "label": "a device", + "value": "Device" + }, + { + "label": "a instance", + "value": "Instance" + }, + { + "label": "a server", + "value": "Server" + }, + { + "label": "a virtual machine", + "value": "Virtual machine" + }, + { + "label": "a transaction", + "value": "Transaction" + }, + { + "label": "a megabyte", + "value": "Megabyte" + }, + { + "label": "a gigabyte", + "value": "Gigabyte" + }, + { + "label": "a terabyte", + "value": "Terabyte" + } + ] %} + + {% set items = [] %} + + {% set _items = items.append({ + "text": "", + "value": "", + "selected": "" == value + }) %} + + {% for unit in units %} + {% set unit_value = unit.value if unit.value else unit.label %} + {% set _items = items.append({ + "text": unit.label, + "value": unit_value, + "selected": unit_value == value + }) %} + {% endfor %} + {{ govukSelect({ "id": "input-" + priceUnit, 'name': priceUnit, "label": { "html": questionText }, - "items": [ - { - 'text': "", - "value": "", - "selected": "" == value - }, - { - "text": "a unit", - "value": "Unit", - "selected": "Unit" == value - }, - { - "text": "a licence", - "value": "Licence", - "selected": "Licence" == value - }, - { - "text": "a user", - "value": "User", - "selected": "User" == value - }, - { - "text": "a device", - "value": "Device", - "selected": "Device" == value - }, - { - "text": "a instance", - "value": "Instance", - "selected": "Instance" == value - }, - { - "text": "a server", - "value": "Server", - "selected": "Server" == value - }, - { - "text": "a virtual machine", - "value": "Virtual machine", - "selected": "Virtual machine" == value - }, - { - "text": "a transaction", - "value": "Transaction", - "selected": "Transaction" == value - }, - { - "text": "a megabyte", - "value": "Megabyte", - "selected": "Megabyte" == value - }, - { - "text": "a gigabyte", - "value": "Gigabyte", - "selected": "Gigabyte" == value - }, - { - "text": "a terabyte", - "value": "Terabyte", - "selected": "Terabyte" == value - } - ] + "items": items }) }} {% endif %} {% if priceInterval %} - {% set questionText = "Time (optional)" if 'price_interval' in (params.question.optional_fields or []) else "Time" %} + {% set questionText = "Time (optional)" if 'price_interval' in optional_fields else "Time" %} {% set value = params.data[priceInterval] if params.data %} + {% set intervals = params.question.intervals or [ + { + "label": "a second", + "value": "Second" + }, + { + "label": "a minute", + "value": "Minute" + }, + { + "label": "a hour", + "value": "Hour" + }, + { + "label": "a day", + "value": "Day" + }, + { + "label": "a week", + "value": "Week" + }, + { + "label": "a month", + "value": "Month" + }, + { + "label": "a quarter", + "value": "Quarter" + }, + { + "label": "a 6 months", + "value": "6 months" + }, + { + "label": "a year", + "value": "Year" + } + ] %} + + {% set items = [] %} + + {% set _items = items.append({ + "text": "", + "value": "", + "selected": "" == value + }) %} + + {% for interval in intervals %} + {% set interval_value = interval.value if interval.value else interval.label %} + {% set _items = items.append({ + "text": interval.label, + "value": interval_value, + "selected": interval_value == value + }) %} + {% endfor %} + {{ govukSelect({ "id": "input-" + priceInterval, "name": priceInterval, "label": { "text": questionText }, - "items": [ - { - "text": "", - "value": "", - "selected": "" == value - }, - { - "text": "a second", - "value": "Second", - "selected": "Second" == value - }, - { - "text": "a minute", - "value": "Minute", - "selected": "Minute" == value - }, - { - "text": "a hour", - "value": "Hour", - "selected": "Hour" == value - }, - { - "text": "a day", - "value": "Day", - "selected": "Day" == value - }, - { - "text": "a week", - "value": "Week", - "selected": "Week" == value - }, - { - "text": "a month", - "value": "Month", - "selected": "Month" == value - }, - { - "text": "a quarter", - "value": "Quarter", - "selected": "Quarter" == value - }, - { - "text": "a 6 months", - "value": "6 months", - "selected": "6 months" == value - }, - { - "text": "a year", - "value": "Year", - "selected": "Year" == value - } - ] + "items": items + }) }} + {% endif %} + + {% if price %} + {% set questionText = "Price (optional)" if 'price' in optional_fields else "Price" %} + {% set value = params.data[price] if params.data %} + + {{ govukInput({ + "id": "input-" + price, + "name": price, + "classes": "govuk-input--width-10", + "label": { + "text": questionText + }, + 'hint': { + "text": 'For example, £199.99' + }, + "value": value, + "prefix": { + "text": "£" + } }) }} {% endif %} {% if minimumPrice %} - {% set questionText = "Minimum price (optional)" if 'minimum_price' in (params.question.optional_fields or []) else "Minimum price" %} + {% set questionText = "Minimum price (optional)" if 'minimum_price' in optional_fields else "Minimum price" %} {% set value = params.data[minimumPrice] if params.data %} {{ govukInput({ @@ -194,7 +225,7 @@ {% endif %} {% if maximumPrice %} - {% set questionText = "Maximum price (optional)" if 'maximum_price' in (params.question.optional_fields or []) else "Maximum price" %} + {% set questionText = "Maximum price (optional)" if 'maximum_price' in optional_fields else "Maximum price" %} {% set value = params.data[maximumPrice] if params.data %} {{ govukInput({ diff --git a/digitalmarketplace_frontend_jinja/templates/components/question-select/macro.html b/digitalmarketplace_frontend_jinja/templates/components/question-select/macro.html new file mode 100644 index 0000000..e401af5 --- /dev/null +++ b/digitalmarketplace_frontend_jinja/templates/components/question-select/macro.html @@ -0,0 +1,53 @@ +{% macro digitalmarketplaceQuestionSelect(params) %} +{%- from "govuk_frontend_jinja/components/select/macro.html" import govukSelect -%} +{%- from "digitalmarketplace_frontend_jinja/components/question-format-hint/macro.html" import digitalmarketplaceQuestionFormatHint -%} + +{% set name = params.question.id %} +{% set items = [] %} +{% set default_option = params.question.default_option | default({})%} +{% set questionText = params.question.question + " (optional)" if params.question.optional else params.question.question %} + +{% if params.errors and params.errors[name] %} + {% set errorMessage = { "text": params.errors[name]["message"] } %} +{% elif params.frameworkReusedFrom and params.data and params.data[name] %} + {% set errorMessage = { + "text": "This answer is from your " + params.frameworkReusedFrom + " declaration", + "visuallyHiddenText": "Notice" + } %} + {% set formGroupClasses = "dm-form-group--declaration-reuse" %} +{% endif %} + +{% set default_value = default_option.value if default_option.value else default_option.label | default("") %} +{% set default_item = { + "text": default_option.label, + "value": default_value, + "selected": default_value == params.data[name] if params.data +} %} +{% set _items = items.append(default_item) %} + +{% for option in params.question.options %} + {% set value = option.value if option.value else option.label %} + {% set _items = items.append({ + "text": option.label, + "value": value, + "selected": value == params.data[name] if params.data + }) %} +{% endfor %} + +{{ govukSelect({ + "name": name, + "id": "input-" + name, + "label": { + "html": questionText, + "classes": "govuk-label--m" + }, + "formGroup": { + "classes": formGroupClasses + }, + "items": items, + "hint": { + "html": digitalmarketplaceQuestionFormatHint(params.question) + } if params.question.hint or params.question.question_advice, + "errorMessage": errorMessage if errorMessage +}) }} +{% endmacro %} diff --git a/digitalmarketplace_frontend_jinja/templates/components/question/macro.html b/digitalmarketplace_frontend_jinja/templates/components/question/macro.html index 8fab634..d69443f 100644 --- a/digitalmarketplace_frontend_jinja/templates/components/question/macro.html +++ b/digitalmarketplace_frontend_jinja/templates/components/question/macro.html @@ -10,6 +10,7 @@ {%- from "digitalmarketplace_frontend_jinja/components/question-checkboxes/macro.html" import digitalmarketplaceQuestionCheckboxes -%} {%- from "digitalmarketplace_frontend_jinja/components/question-checkbox-tree/macro.html" import digitalmarketplaceQuestionCheckboxTree -%} {%- from "digitalmarketplace_frontend_jinja/components/question-list/macro.html" import digitalmarketplaceQuestionList -%} +{%- from "digitalmarketplace_frontend_jinja/components/question-select/macro.html" import digitalmarketplaceQuestionSelect -%} {%- from "digitalmarketplace_frontend_jinja/components/question-multiquestion/macro.html" import digitalmarketplaceQuestionMultiquestion -%}
= 4.2.0" }, "peerDependencies": { "accessible-autocomplete": "^3.0.x", - "govuk-frontend": "^5.5.0", + "govuk-frontend": "^5.7.1", "jquery": "^3.x", "js-cookie": "^3.0.x" } }, "node_modules/govuk-frontend": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/govuk-frontend/-/govuk-frontend-5.5.0.tgz", - "integrity": "sha512-lNSHCOzgk6LfgelcdtJxTLK1BX/cpjCUyEB3LnzliD9o9YQckNMsbj5+jSOs2RFy6XBJ/DJqxj2TKfjBCuzpyA==", + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/govuk-frontend/-/govuk-frontend-5.7.1.tgz", + "integrity": "sha512-jF1cq5rn57kxZmJRprUZhTQ31zaBBK4b5AyeJaPX3Yhg22lk90Mx/dQLvOk/ycV3wM7e0y+s4IPvb2fFaPlCGg==", "dev": true, + "license": "MIT", "peer": true, "engines": { "node": ">= 4.2.0" diff --git a/package.json b/package.json index 0b51419..89e05bf 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,6 @@ "author": "CCS", "license": "MIT", "devDependencies": { - "digitalmarketplace-frontend": "^1.2.0" + "digitalmarketplace-frontend": "^1.3.1" } }