Browse Source
* add placeholder for bulk upload error summary * persist column for bulk upload errors * replace bulk upload summary table placeholderpull/1244/head
Phil Lee
2 years ago
committed by
GitHub
10 changed files with 175 additions and 4 deletions
@ -0,0 +1,25 @@
|
||||
<%= govuk_table do |table| %> |
||||
<% table.caption(size: "m", text: bulk_upload.filename) %> |
||||
|
||||
<% table.head do |head| %> |
||||
<% head.row do |row| %> |
||||
<% row.cell(text: "Column", header: true) %> |
||||
<% row.cell(text: "Number of rows", header: true) %> |
||||
<% row.cell(text: "Question", header: true) %> |
||||
<% row.cell(text: "Error", header: true) %> |
||||
<% row.cell(text: "Specification", header: true) %> |
||||
<% end %> |
||||
<% end %> |
||||
|
||||
<% table.body do |body| %> |
||||
<% sorted_errors.each do |error| %> |
||||
<% body.row do |row| %> |
||||
<% row.cell(text: error[0][0]) %> |
||||
<% row.cell(text: error[1]) %> |
||||
<% row.cell(text: BulkUpload::Lettings::Validator.question_for_field(error[0][1].to_sym)) %> |
||||
<% row.cell(text: error[0][2]) %> |
||||
<% row.cell(text: error[0][1]) %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
||||
<% end %> |
@ -0,0 +1,17 @@
|
||||
class BulkUploadErrorSummaryTableComponent < ViewComponent::Base |
||||
attr_reader :bulk_upload |
||||
|
||||
def initialize(bulk_upload:) |
||||
@bulk_upload = bulk_upload |
||||
|
||||
super |
||||
end |
||||
|
||||
def sorted_errors |
||||
@sorted_errors ||= bulk_upload |
||||
.bulk_upload_errors |
||||
.group(:col, :field, :error) |
||||
.count |
||||
.sort_by { |el| el[0][0].rjust(3, "0") } |
||||
end |
||||
end |
@ -0,0 +1,22 @@
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds"> |
||||
<span class="govuk-caption-l">Bulk upload for lettings (<%= @bulk_upload.year_combo %>)</span> |
||||
<h1 class="govuk-heading-l">Correct data export and reupload</h1> |
||||
|
||||
<p class="govuk-body-l"> |
||||
We noticed that you have a lot of similar errors for some questions. You can download the specification which we reference below to understand how to correct the data. Once you have fixed these errors you can upload again. |
||||
</p> |
||||
</div> |
||||
</div> |
||||
|
||||
<%= render BulkUploadErrorSummaryTableComponent.new(bulk_upload: @bulk_upload) %> |
||||
|
||||
<div class="govuk-grid-row"> |
||||
<div class="govuk-grid-column-two-thirds"> |
||||
<p class="govuk-body"> |
||||
You also have other errors in your file which you can either fix them in the CSV file or you can reupload and fix on CORE. <%= govuk_link_to "View the full report", bulk_upload_lettings_result_path(@bulk_upload) %> |
||||
</p> |
||||
</div> |
||||
</div> |
||||
|
||||
<%= govuk_button_link_to "Upload your file again", start_bulk_upload_lettings_logs_path %> |
@ -0,0 +1,81 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe BulkUploadErrorSummaryTableComponent, type: :component do |
||||
subject(:component) { described_class.new(bulk_upload:) } |
||||
|
||||
let(:bulk_upload) { create(:bulk_upload) } |
||||
|
||||
context "when no errors" do |
||||
it "does not renders any rows" do |
||||
result = render_inline(component) |
||||
expect(result).not_to have_selector("tbody tr") |
||||
end |
||||
end |
||||
|
||||
context "when there are 2 independent errors" do |
||||
let!(:error_2) { create(:bulk_upload_error, bulk_upload:, col: "B", row: 2) } |
||||
let!(:error_1) { create(:bulk_upload_error, bulk_upload:, col: "A", row: 1) } |
||||
|
||||
it "renders rows for each error" do |
||||
result = render_inline(component) |
||||
expect(result).to have_selector("tbody tr", count: 2) |
||||
end |
||||
|
||||
it "renders rows by col order" do |
||||
result = render_inline(component) |
||||
order = result.css("tbody tr td:nth-of-type(1)").map(&:content) |
||||
expect(order).to eql(%w[A B]) |
||||
end |
||||
|
||||
it "render correct data" do |
||||
result = render_inline(component) |
||||
|
||||
row_1 = result.css("tbody tr:nth-of-type(1) td").map(&:content) |
||||
|
||||
expect(row_1).to eql([ |
||||
"A", |
||||
"1", |
||||
BulkUpload::Lettings::Validator.question_for_field(error_1.field.to_sym), |
||||
error_1.error, |
||||
error_1.field, |
||||
]) |
||||
|
||||
row_2 = result.css("tbody tr:nth-of-type(2) td").map(&:content) |
||||
|
||||
expect(row_2).to eql([ |
||||
"B", |
||||
"1", |
||||
BulkUpload::Lettings::Validator.question_for_field(error_2.field.to_sym), |
||||
error_2.error, |
||||
error_2.field, |
||||
]) |
||||
end |
||||
end |
||||
|
||||
context "when there are 2 grouped errors" do |
||||
let!(:error_1) { create(:bulk_upload_error, bulk_upload:, col: "A", row: 1, field: "field_1") } |
||||
|
||||
before do |
||||
create(:bulk_upload_error, bulk_upload:, col: "A", row: 2, field: "field_1") |
||||
end |
||||
|
||||
it "renders 1 row combining the errors" do |
||||
result = render_inline(component) |
||||
expect(result).to have_selector("tbody tr", count: 1) |
||||
end |
||||
|
||||
it "render correct data" do |
||||
result = render_inline(component) |
||||
|
||||
row_1 = result.css("tbody tr:nth-of-type(1) td").map(&:content) |
||||
|
||||
expect(row_1).to eql([ |
||||
"A", |
||||
"2", |
||||
BulkUpload::Lettings::Validator.question_for_field(error_1.field.to_sym), |
||||
error_1.error, |
||||
error_1.field, |
||||
]) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue