From 240dfea79ad5241a3365f9645cfb0a4a3bfe5955 Mon Sep 17 00:00:00 2001 From: Patrick Cartlidge Date: Fri, 15 May 2026 13:59:18 +0100 Subject: [PATCH] Add `variant` parameter to `ImageProcessingChecker` To prevent the incorrect variant of an image being used, you can now specify a `variant` in the `ImageProcessingChecker` so that the correct variant of an image will be rendered instead of the previous behaviour (the first non-original image). --- .../admin/modules/image-processing-checker.js | 5 ++-- .../edition_images/image_component.html.erb | 2 +- .../modules/image-processing-checker.spec.js | 23 ++++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/admin/modules/image-processing-checker.js b/app/assets/javascripts/admin/modules/image-processing-checker.js index d6cb68e409d..92c3592e5a8 100644 --- a/app/assets/javascripts/admin/modules/image-processing-checker.js +++ b/app/assets/javascripts/admin/modules/image-processing-checker.js @@ -9,6 +9,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {} constructor($root) { this.$root = $root this.imageLink = this.$root.dataset.imageLink + this.variant = this.$root.dataset.variant || 'original' this.timeoutDuration = parseInt(this.$root.dataset.timeoutDuration, 10) || @@ -95,13 +96,13 @@ window.GOVUK.Modules = window.GOVUK.Modules || {} if (imgElement) { const previewAsset = assets.find( - ({ variant }) => variant !== 'original' + ({ variant }) => variant === this.variant ) // images with multiple assets can have // transformed variants so we should not use // the `original` asset if this is the case - imgElement.src = previewAsset ? previewAsset.url : assets[0].url + imgElement.src = previewAsset.url } this.updateImageStatus(this.imagePreview) diff --git a/app/components/admin/edition_images/image_component.html.erb b/app/components/admin/edition_images/image_component.html.erb index c8fda618341..d1d3595a354 100644 --- a/app/components/admin/edition_images/image_component.html.erb +++ b/app/components/admin/edition_images/image_component.html.erb @@ -1,4 +1,4 @@ -
  • +