Skip to content

Commit

Permalink
Show processing label for images that are still uploading
Browse files Browse the repository at this point in the history
If any of the image variants are still uploading, a "Processing" label will
be shown. Similar behaviour already existed for files (will be changed from
saying "Uploading" to also saying "Processing").

The behaviour for files has also been recently changed so that the label shows
when any file versions are still being uploaded/processed rather than it
showing only when the original files is missing. This behaviour is now
consistent between files and images.
  • Loading branch information
lauraghiorghisor-tw committed Oct 4, 2023
1 parent c19ccda commit c1421f8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<% if lead_image %>
<div class="govuk-grid-column-one-third">
<img src="<%= lead_image[:url] %>" alt="<%= lead_image[:preview_alt_text] %>" class="app-view-edition-resource__preview">
<% unless lead_image[:all_image_asset_variants_uploaded] %><span class="govuk-tag govuk-tag--green">Processing</span><% end %>
</div>
<div class="govuk-grid-column-two-thirds">
<p class="govuk-body"><strong>Caption: </strong><%= lead_image[:caption] %></p>
Expand Down Expand Up @@ -66,6 +67,7 @@
<li class="govuk-grid-row">
<div class="govuk-grid-column-one-third">
<img src="<%= image[:url] %>" alt="<%= image[:preview_alt_text] %>" class="app-view-edition-resource__preview">
<% unless image[:all_image_asset_variants_uploaded] %><span class="govuk-tag govuk-tag--green">Processing</span><% end %>
</div>
<div class="govuk-grid-column-two-thirds">
<p class="govuk-body"><strong>Caption: </strong><%= image[:caption] %></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def lead_image_guidance

private

def all_image_asset_variants_uploaded?(image)
image.image_data.all_asset_variants_uploaded? if image.image_data.present?
end

def image_to_hash(image, index)
{
url: image.url,
Expand All @@ -57,6 +61,7 @@ def image_to_hash(image, index)
alt_text: image.alt_text.presence || "None",
markdown: unique_names? ? "[Image: #{image.filename}]" : "!!#{index}",
links: links_for_image(image),
all_image_asset_variants_uploaded: all_image_asset_variants_uploaded?(image),
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,20 @@ class Admin::EditionImages::UploadedImagesComponentTest < ViewComponent::TestCas
assert_selector "input[value='!!1']"
assert_selector "input[value='!!2']"
end

test "shows \"Processing\" label where image assets (variants) are still uploading" do
lead_image_data_with_no_assets = build(:image_data, use_non_legacy_endpoints: true)
regular_image_data_with_no_assets = build(:image_data, use_non_legacy_endpoints: true)
regular_image_data_with_assets = build(:image_data_with_assets)
images = [
build_stubbed(:image, image_data: lead_image_data_with_no_assets),
build_stubbed(:image, image_data: regular_image_data_with_no_assets),
build_stubbed(:image, image_data: regular_image_data_with_assets),
]
edition = build_stubbed(:draft_publication, images:)

render_inline(Admin::EditionImages::UploadedImagesComponent.new(edition:))

assert_text "Processing", count: 2
end
end

0 comments on commit c1421f8

Please sign in to comment.