Skip to content

Commit

Permalink
Update the success view for the new import
Browse files Browse the repository at this point in the history
The new Activity actual, refund and comment import breaks the imported
rows in to meaningful types that we want to show to the user.

Here we add four new tables for showing the imported objects, we choose
to add new ones as the existing shared partials are for a different view
and do not have the appropriate content and we prefer the extra partials
closer to their use than make more complicated shared partials.

We then update the controller to provide the data to the view, this uses
the new Import::Csv::ImportedRow object so that, when required, we can
provide the row number to the user.

Along the way we have to update some specs to account for the new
`Import::Csv::ImportedRow` objects being returned by the `FileService`.
  • Loading branch information
mec committed Jan 19, 2024
1 parent 223e079 commit f2c739d
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Remove the feature flag for ODA bulk upload
- model a simple imported row so that users can see which row in the csv import
were skipped
- the Activity actual, refund and comment upload success view now shows the
imported actuals, refunds, activity comments and skipped rows

## Release 142 - 2024-01-16

Expand Down
15 changes: 9 additions & 6 deletions app/controllers/actuals/uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ def update
@errors = importer.errors

if import_result
# the old import and the UI combine Actuals and Refunds, so we have to do the same
# once we have tested the import, we will come back and make the UI improvements
# to make the most of the new importer
imported_actuals_and_refunds = importer.imported_actuals + importer.imported_refunds
@total_actuals = total_transactions(importer.imported_actuals)
@grouped_actuals = grouped_transactions(importer.imported_actuals)

@total_refunds = total_transactions(importer.imported_refunds)
@grouped_refunds = grouped_transactions(importer.imported_refunds)

@imported_activity_comments = importer.imported_comments

@skipped_rows = importer.skipped_rows

@total_actuals = total_transactions(imported_actuals_and_refunds)
@grouped_actuals = grouped_transactions(imported_actuals_and_refunds)
@success = true

flash.now[:notice] = t("action.actual.upload.success")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def import!

collate_errors_from_row_importer(index, row_importer) if row_importer.errors.any?

imported_row
Import::Csv::ImportedRow.new(index, imported_row)
end

unless @errors.empty?
Expand All @@ -41,26 +41,26 @@ def import!
end

def imported_actuals
@imported_rows.select do |row|
row.is_a?(Actual)
@imported_rows.filter_map do |row|
row.object if row.object.is_a?(Actual)
end
end

def imported_refunds
@imported_rows.select do |row|
row.is_a?(Refund)
@imported_rows.filter_map do |row|
row.object if row.object.is_a?(Refund)
end
end

def imported_comments
@imported_rows.select do |row|
row.is_a?(Comment)
@imported_rows.filter_map do |row|
row.object if row.object.is_a?(Comment)
end
end

def skipped_rows
@imported_rows.select do |row|
row.is_a?(Import::Csv::ActivityActualRefundComment::SkippedRow)
row.object.is_a?(Import::Csv::ActivityActualRefundComment::SkippedRow)
end
end

Expand Down
36 changes: 36 additions & 0 deletions app/views/actuals/uploads/_actuals.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
%table.govuk-table#actuals
%caption.govuk-table__caption.govuk-table__caption--m
Actuals
%thead.govuk-table__head
%tr.govuk-table__row
%th.govuk-table__header{class: "govuk-!-width-one-third", scope: "col"} Activity
%th.govuk-table__header{class: "govuk-!-width-one-third", scope: "col"} RODA Identifier
%th.govuk-table__header{class: "govuk-!-width-one-third", scope: "col"} Value
%tbody.govuk-table__body
- @grouped_actuals.each do |activity, actuals|
%tr.govuk-table__row{ id: "activity_actuals_#{activity.id}" }
%td.govuk-table__cell{class: "govuk-!-width-one-third"}
= activity.title
%td.govuk-table__cell{class: "govuk-!-width-one-third"}
= activity.roda_identifier
%td.govuk-table__cell{class: "govuk-!-width-one-third"}
%table.govuk-table.actuals
- actuals.each do |actual|
%tr.govuk-table__row
%td.govuk-table__cell--numeric{class: "govuk-!-width-one-half", scope: "col"}
= actual.financial_quarter_and_year
%td.govuk-table__cell--numeric{class: "govuk-!-width-one-half", scope: "col"}
= actual.value
- if actual.comment
%tr.govuk-table__row
%td.govuk-table__cell--numeric{class: "govuk-!-width-full", scope: "col", colspan: 2}
= actual.comment.body


%tr.govuk-table__row.totals
%td.govuk-table__cell Total
%td.govuk-table__cell
%td.govuk-table__cell.govuk-table__cell--numeric
= @total_actuals
19 changes: 19 additions & 0 deletions app/views/actuals/uploads/_comments.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
%table.govuk-table#comments
%caption.govuk-table__caption.govuk-table__caption--m
Activity Comments
%thead.govuk-table__head
%tr.govuk-table__row
%th.govuk-table__header{class: "govuk-!-width-one-third", scope: "col"} Activity
%th.govuk-table__header{class: "govuk-!-width-one-third", scope: "col"} RODA Identifier
%th.govuk-table__header{class: "govuk-!-width-one-third", scope: "col"} Comment
%tbody.govuk-table__body
- @imported_activity_comments.each do |comment|
%tr.govuk-table__row{ id: "activity_comment_#{comment.id}" }
%td.govuk-table__cell{class: "govuk-!-width-one-third"}
= comment.associated_activity.title
%td.govuk-table__cell{class: "govuk-!-width-one-third"}
= comment.associated_activity.roda_identifier
%td.govuk-table__cell{class: "govuk-!-width-one-third"}
= comment.body
35 changes: 35 additions & 0 deletions app/views/actuals/uploads/_refunds.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%table.govuk-table#refunds
%caption.govuk-table__caption.govuk-table__caption--m
Refunds
%thead.govuk-table__head
%tr.govuk-table__row
%th.govuk-table__header{class: "govuk-!-width-one-third", scope: "col"} Activity
%th.govuk-table__header{class: "govuk-!-width-one-third", scope: "col"} RODA Identifier
%th.govuk-table__header{class: "govuk-!-width-one-third", scope: "col"} Value
%tbody.govuk-table__body
- @grouped_refunds.each do |activity, refunds|
%tr.govuk-table__row{ id: "activity_actuals_#{activity.id}" }
%td.govuk-table__cell{class: "govuk-!-width-one-third"}
= activity.title
%td.govuk-table__cell{class: "govuk-!-width-one-third"}
= activity.roda_identifier
%td.govuk-table__cell{class: "govuk-!-width-one-third"}
%table.govuk-table.actuals
- refunds.each do |refund|
%tr.govuk-table__row
%td.govuk-table__cell--numeric{class: "govuk-!-width-one-half", scope: "col"}
= refund.financial_quarter_and_year
%td.govuk-table__cell--numeric{class: "govuk-!-width-one-half", scope: "col"}
= refund.value
- if refund.comment
%tr.govuk-table__row
%td.govuk-table__cell--numeric{class: "govuk-!-width-full", scope: "col", colspan: 2}
= refund.comment.body

%tr.govuk-table__row.totals
%td.govuk-table__cell Total
%td.govuk-table__cell
%td.govuk-table__cell.govuk-table__cell--numeric
= @total_refunds
15 changes: 15 additions & 0 deletions app/views/actuals/uploads/_skipped.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%table.govuk-table#skipped
%caption.govuk-table__caption.govuk-table__caption--m
Skipped rows
%thead.govuk-table__head
%tr.govuk-table__row
%th.govuk-table__header{class: "govuk-!-width-one-third", scope: "col"} Row number
%th.govuk-table__header{class: "govuk-!-width-two-thirds", scope: "col"} RODA Identifier
%tbody.govuk-table__body
- @skipped_rows.each do |row|
%tr.govuk-table__row{ id: "skipped-row-#{row.csv_row_number}" }
%td.govuk-table__cell{class: "govuk-!-width-one-third"}
= row.csv_row_number
%td.govuk-table__cell{class: "govuk-!-width-two-thirds"}
= row.object.roda_identifier
24 changes: 21 additions & 3 deletions app/views/actuals/uploads/update.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,27 @@
%h1.govuk-heading-xl
= t("page_title.actual.upload_success")

.govuk-grid-row
.govuk-grid-column-full
= render partial: "shared/actuals/actuals_by_activity"
- if ROLLOUT.active?(:use_new_activity_actual_refund_comment_importer)
.govuk-grid-row
.govuk-grid-column-full
= render partial: "actuals"

.govuk-grid-row
.govuk-grid-column-full
= render partial: "refunds"

.govuk-grid-row
.govuk-grid-column-full
= render partial: "comments"

.govuk-grid-row
.govuk-grid-column-full
= render partial: "skipped"

- else
.govuk-grid-row
.govuk-grid-column-full
= render partial: "shared/actuals/actuals_by_activity"

.govuk-grid-row
.govuk-grid-column-two-thirds
Expand Down
8 changes: 6 additions & 2 deletions spec/controllers/actuals/uploads_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@
allow(fake_import_file).to receive(:valid?).and_return(true)
allow(CsvFileUpload).to receive(:new).and_return(fake_import_file)

importer = instance_double(Actual::Import, import: true)
importer = instance_double(Actual::Import)
allow(importer).to receive(:import).and_return(true)
allow(importer).to receive(:errors).and_return([])
allow(importer).to receive(:imported_actuals).and_return([])
allow(importer).to receive(:invalid_with_comment).and_return(false)
Expand All @@ -152,10 +153,13 @@
allow(fake_import_file).to receive(:valid?).and_return(true)
allow(CsvFileUpload).to receive(:new).and_return(fake_import_file)

importer = instance_double(Import::Csv::ActivityActualRefundComment::FileService, import!: true)
importer = instance_double(Import::Csv::ActivityActualRefundComment::FileService)
allow(importer).to receive(:import!).and_return(true)
allow(importer).to receive(:errors).and_return([])
allow(importer).to receive(:imported_actuals).and_return([])
allow(importer).to receive(:imported_refunds).and_return([])
allow(importer).to receive(:imported_comments).and_return([])
allow(importer).to receive(:skipped_rows).and_return([])
allow(Import::Csv::ActivityActualRefundComment::FileService).to receive(:new).and_return(importer)

allow(Actual::Import).to receive(:new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#{project.roda_identifier} | 1 | 2020 | 20000 | 0 |
#{another_project.roda_identifier} | 1 | 2020 | 0 | 30000 | Refund comment
#{yet_another_project.roda_identifier} | 1 | 2020 | 0 | 0 | Activity comment
#{project.roda_identifier} | 1 | 2020 | 0 | 0 |
CSV
upload_csv(csv_data)
end
Expand All @@ -36,11 +37,25 @@

expect(page).to have_text(t("action.actual.upload.success"))

expect(page).to have_content(project.roda_identifier)
expect(page).to have_content("£20,000.00")

expect(page).to have_content(another_project.roda_identifier)
expect(page).to have_content("-£30,000.00")
within("#actuals") do
expect(page).to have_content(project.roda_identifier)
expect(page).to have_content("£20,000.00")
end

within("#refunds") do
expect(page).to have_content(another_project.roda_identifier)
expect(page).to have_content("-£30,000.00")
end

within("#comments") do
expect(page).to have_content(yet_another_project.roda_identifier)
expect(page).to have_content("Activity comment")
end

within("#skipped") do
expect(page).to have_content("5")
expect(page).to have_content(project.roda_identifier)
end
end

it "allows the user to see the activity comment" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

it "creates the Actual and returns true" do
result = subject.import!
actual = subject.imported_rows.first
actual = subject.imported_rows.first.object

expect(actual.parent_activity).to be activity
expect(actual.value).to eql BigDecimal("10000")
Expand Down Expand Up @@ -73,7 +73,7 @@

it "creates the Refund and returns true" do
result = subject.import!
refund = subject.imported_rows.first
refund = subject.imported_rows.first.object

expect(refund.parent_activity).to eql activity
expect(refund.comment.body).to eql "This is a refund comment."
Expand Down Expand Up @@ -112,7 +112,7 @@

it "creates the Comment and returns true" do
result = subject.import!
imported_comment = subject.imported_rows.first
imported_comment = subject.imported_rows.first.object

expect(result).to be true

Expand Down Expand Up @@ -157,7 +157,7 @@

it "records the details of the skipped row" do
subject.import!
skipped = subject.skipped_rows.first
skipped = subject.skipped_rows.first.object

expect(skipped.roda_identifier).to eql "RODA-ID"
expect(skipped.financial_quarter).to eql "2"
Expand Down

0 comments on commit f2c739d

Please sign in to comment.