Browse Source

bulk upload error summary min limit

- the errors summary table only show errors for column where there
  at least 16 errors for that column
- if there are fewer than 16 errors that can see detailed report to pin
  point and fix those specific issues
pull/1347/head
Phil Lee 3 years ago
parent
commit
87131a63c3
  1. 9
      app/components/bulk_upload_error_summary_table_component.rb
  2. 17
      spec/components/bulk_upload_error_summary_table_component_spec.rb

9
app/components/bulk_upload_error_summary_table_component.rb

@ -1,4 +1,6 @@
class BulkUploadErrorSummaryTableComponent < ViewComponent::Base class BulkUploadErrorSummaryTableComponent < ViewComponent::Base
DISPLAY_THRESHOLD = 16
attr_reader :bulk_upload attr_reader :bulk_upload
def initialize(bulk_upload:) def initialize(bulk_upload:)
@ -11,7 +13,14 @@ class BulkUploadErrorSummaryTableComponent < ViewComponent::Base
@sorted_errors ||= bulk_upload @sorted_errors ||= bulk_upload
.bulk_upload_errors .bulk_upload_errors
.group(:col, :field, :error) .group(:col, :field, :error)
.having("count(*) > ?", display_threshold)
.count .count
.sort_by { |el| el[0][0].rjust(3, "0") } .sort_by { |el| el[0][0].rjust(3, "0") }
end end
private
def display_threshold
DISPLAY_THRESHOLD
end
end end

17
spec/components/bulk_upload_error_summary_table_component_spec.rb

@ -5,6 +5,10 @@ RSpec.describe BulkUploadErrorSummaryTableComponent, type: :component do
let(:bulk_upload) { create(:bulk_upload) } let(:bulk_upload) { create(:bulk_upload) }
before do
stub_const("BulkUploadErrorSummaryTableComponent::DISPLAY_THRESHOLD", 0)
end
context "when no errors" do context "when no errors" do
it "does not renders any rows" do it "does not renders any rows" do
result = render_inline(component) result = render_inline(component)
@ -12,6 +16,19 @@ RSpec.describe BulkUploadErrorSummaryTableComponent, type: :component do
end end
end end
context "when below threshold" do
before do
stub_const("BulkUploadErrorSummaryTableComponent::DISPLAY_THRESHOLD", 16)
create(:bulk_upload_error, bulk_upload:, col: "A", row: 1)
end
it "does not render rows" do
result = render_inline(component)
expect(result).to have_selector("tbody tr", count: 0)
end
end
context "when there are 2 independent errors" do context "when there are 2 independent errors" do
let!(:error_2) { create(:bulk_upload_error, bulk_upload:, col: "B", row: 2) } 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) } let!(:error_1) { create(:bulk_upload_error, bulk_upload:, col: "A", row: 1) }

Loading…
Cancel
Save