Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3028 convert csv to excel #5209

Conversation

xeniabarreto
Copy link
Contributor

What github issue is this PR for, if any?

Resolves #3028

What changed, and why?

I implemented data extraction via Excel format with automatic line break correction in the "Case Contact Notes" column.

As instructed by Shen Yang and Linda, I have also added a modal that allows users to choose the desired file format, either CSV or Excel.

How will this affect user permissions?

  • Supervisor permissions:
  • Admin permissions:

How is this tested? (please write tests!) 💖💪

I provide below a video demonstration of the changes.

Screenshots please :)

Gravacao.de.tela.de.14-09-2023.23.01.41.webm

Feelings gif (optional)

What gif best describes your feeling working on this issue? https://giphy.com/
How to embed:
![alt text](https://media.giphy.com/media/1nP7ThJFes5pgXKUNf/giphy.gif)

Feedback please? (optional)

We are very interested in your feedback! Please give us some :) https://forms.gle/1D5ACNgTs2u9gSdh9

@github-actions github-actions bot added ruby Pull requests that update Ruby code erb labels Sep 15, 2023
Copy link
Contributor

@chahmedejaz chahmedejaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work overall 👍
Edit: There are some failing specs. Please review if they are related to your changes. Thanks.

# NOTE: these header labels are for stakeholders and do not match the
# Rails DB names in all cases, e.g. added_to_system_at header is case_contact.created_at
{
internal_contact_number: case_contact&.id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to return an empty hash unless casa_contact present rather than using the safe navigation each time accessing this. i.e.

def self.DATA_COLUMNS(case_contact = nil)
  return {} unless casa_contact

  {
    internal_contact_number: case_contact.id,
    .
    .
    case_contact_notes: case_contact.notes
  }
end 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in the process of learning, I'm very grateful for your review and suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chahmedejaz I'd like to mention that I couldn't use your suggestion to return an empty hash if 'casa_contact' isn't present. The reason is that we're already using the same function with its keys for creating a modal where users select columns to filter before exporting. Thanks for your understanding :)

(string.to_s.size + 3) * font_scale
end

def self.DATA_COLUMNS(case_contact = nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that this function is almost identical to the one we are using in case_contacts_export_csv_service.rb with format changes to added_to_system_at date:

def self.DATA_COLUMNS(case_contact = nil)
# Note: these header labels are for stakeholders and do not match the
# Rails DB names in all cases, e.g. added_to_system_at header is case_contact.created_at
{
internal_contact_number: case_contact&.id,
duration_minutes: case_contact&.report_duration_minutes,
contact_types: case_contact&.report_contact_types,
contact_made: case_contact&.report_contact_made,
contact_medium: case_contact&.medium_type,
occurred_at: I18n.l(case_contact&.occurred_at, format: :full, default: nil),
added_to_system_at: case_contact&.created_at,
miles_driven: case_contact&.miles_driven,
wants_driving_reimbursement: case_contact&.want_driving_reimbursement,
casa_case_number: case_contact&.casa_case&.case_number,
creator_email: case_contact&.creator&.email,
creator_name: case_contact&.creator&.display_name,
supervisor_name: case_contact&.creator&.supervisor&.display_name,
case_contact_notes: case_contact&.notes
}
end

It's better to have consistency (excel version of the hash looks better) across both CSV and Excel reports and extract it out in a common helper module to be included in both services.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chahmedejaz Thank you for your suggestion!
I've implemented the changes as you recommended and pushed the modifications to the code.

@chahmedejaz
Copy link
Contributor

chahmedejaz commented Oct 27, 2023

Thank you so much for working on it, @xeniabarreto. Looks like we are almost there. Great work 👍

P.S. There are some failing checks. Please review if they are related to your changes. Thanks.

@@ -39,6 +39,7 @@ policies/note_policy.rb
presenters/base_presenter.rb
presenters/case_contact_presenter.rb
services/case_contacts_export_csv_service.rb
services/case_contacts_export_excel_service.rb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I am not a fan of skipping tests...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but the methods are hard to test in isolation, and you can test them in the system spec.

@@ -11,6 +11,11 @@ def to_csv
CaseContactsExportCsvService.new(case_contacts_for_csv, columns).perform
end

def to_excel
case_contacts_for_excel = @case_contacts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this extra variable?

Copy link
Collaborator

@compwron compwron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good! Let's get the CI build working

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked how you extracted the same code here so both CSV and Excel services could use it.

But what I don't like (and predates your code) is how this is used for two totally different things:

  1. To get the list of columns for the view
  2. To get a hash for each row of the CSV/Excel file

This is why all the safe operators (&) because in the view it's sending in nil for the case contact. I think a better pattern is to have a list of the columns and use them in the decorator.

</div>
</div>

<script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of putting JS in a view. This should normally be separated into a JS file, but you can achieve the same result by moving the modal inside the form and letting the CSV and Excel buttons be your submit buttons. You just need to put name and value tags on the buttons.

def configure_case_contact_notes_width(sheet)
case_contact_notes_index = filtered_columns.index(:case_contact_notes)

if case_contact_notes_index
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a good catch from the previous code. It was throwing a nil --> Integer error when the notes weren't a selected column.

@github-actions github-actions bot added the dependencies Pull requests that update a dependency file label Oct 29, 2023
skip service tests
Copy link

This PR has been open for a long time without any pushes or comments! What's up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file erb no-pr-activity ruby Pull requests that update Ruby code Tests! 🎉💖👏
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert download case contact notes from CSV to Excel and turn on auto-wrap
4 participants