-
-
Notifications
You must be signed in to change notification settings - Fork 484
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
Issue 3028 convert csv to excel #5209
Conversation
There was a problem hiding this 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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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:
casa/app/services/case_contacts_export_csv_service.rb
Lines 23 to 42 in 8f08a6a
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.
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
app/models/case_contact_report.rb
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this 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
There was a problem hiding this comment.
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:
- To get the list of columns for the view
- 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.
app/views/reports/index.html.erb
Outdated
</div> | ||
</div> | ||
|
||
<script> |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
some changes
skip service tests
This PR has been open for a long time without any pushes or comments! What's up? |
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?
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