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

3351 add family archive #3623

Merged
merged 28 commits into from
Sep 14, 2023
Merged

Conversation

grantmca
Copy link
Contributor

Checklist:

  • I have performed a self-review of my own code,
  • I have added tests that prove my fix is effective or that my feature works,
  • New and existing unit tests pass locally with my changes ("bundle exec rake"),
  • Title include "WIP" if work is in progress.

Resolves #3351

Description

Guide questions:

  • What motivated this change (if not already described in an issue)?
    --The ability to archive families no longer use to help users not have to scroll through large list
    --Increases usability for the user, provides additional info on reports

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

You can validate the change by switching some families to archived in the dev env and ensuring they do not show up by default, additionally check that any children associated with the families are also archived. Also validate that when "Include Archived" is checked that all families are shown on the index screen

Screenshots

  • To make things look good I centered both the checkbox on families and on children filters so they match
Screenshot 2023-05-26 at 1 43 11 PM Screenshot 2023-05-26 at 1 43 03 PM

* Updated the view, controller and test to use the new column
* Added auto archive of children on families archive
* Added scope to Families with unit tests
* Added default filter to families controller
* Updated the CSV output on the families controller
* Added `Include Archived?` option on the families view
* Added request test to ensure default only returns the non-archived
* Added test for `Include Archived?` check on index
@grantmca grantmca changed the title WIP: 3351 add family archive 3351 add family archive May 27, 2023
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Added some comments and suggestions.

app/models/partners/family.rb Outdated Show resolved Hide resolved
app/models/partners/family.rb Outdated Show resolved Hide resolved
db/migrate/20230430025441_add_archive_to_families.rb Outdated Show resolved Hide resolved
spec/models/partners/family_spec.rb Outdated Show resolved Hide resolved
* Extracted archiving the children of a family to a service object that
  is called in the family controller and took the funciton and callback
  off of the family model
* Updated and added unit test
* Updated the migration to remove backfill migration
@grantmca
Copy link
Contributor Author

I think I have addressed all of the changes, I might need to rebase but should be set

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Getting closer! Had some more comments.

app/controllers/partners/families_controller.rb Outdated Show resolved Hide resolved
app/models/partners/family.rb Outdated Show resolved Hide resolved
app/services/partners/archive_family_children.rb Outdated Show resolved Hide resolved
db/migrate/20230430025441_add_archive_to_families.rb Outdated Show resolved Hide resolved
@grantmca
Copy link
Contributor Author

Getting closer! Had some more comments.

Thank you! I'll get on it

updated it to module level function. I also updated the migration table
to creat the column and set nill and default all on one line
@grantmca
Copy link
Contributor Author

I moved forward with all of the changes to the service class and the migration. I played around with updating the family controller for a while to make it work with bools but I did some investigation into filterrific and it when you pass in 'false' as a query parameter to filteriffic it translates that false to '0' and when you pass in true it is passed through as true. 0 is truthy in ruby and the True object does not have the method zero? on it so there is not good concise way to write the scope. I think the way it is now it the best option and the it follows the pattern of the children model as well.

@dorner
Copy link
Collaborator

dorner commented Jul 16, 2023

@grantmca I'm not sure I understand this. Filterrific parameters get sent to the controller. The controller can make whatever changes it has to do to those parameters rather than passing them blindly to the service object or the model. I'd rather see those changes happen in the controller than downstream.

@grantmca
Copy link
Contributor Author

@grantmca I'm not sure I understand this. Filterrific parameters get sent to the controller. The controller can make whatever changes it has to do to those parameters rather than passing them blindly to the service object or the model. I'd rather see those changes happen in the controller than downstream.

I apologize for any confusion caused by my previous explanation. Here's a more detailed breakdown: the view sends either '0' or '1' as the params for the checkbox to the controller. Within the controller, I implemented and tested logic that cast this '0' or '1' to a boolean value and then pass this boolean to the 'filterrific' initializer. The gem 'filterrific' provides us with the service object @filterrific, and its method @filterrific.find receives the filterrific parameters from the controller. Using these parameters and a scope defined on the model, the method returns the desired results. However, there's is a catch: the "filterrific" service object performs some parameter data cleanup before passing the parameters to the model's scope. One such cleanup action is converting 'false' to 0 before passing it to the model's scope. Since the model's scope might expect a boolean value, this can lead to converting the scope just for it to be converted back to 0. I am open to any suggestions on how to best handle this case! Let me know if you need any further adjustments!

@dorner
Copy link
Collaborator

dorner commented Jul 18, 2023

I think the issue might be because it's using the string "false" instead of a Boolean false. Can you try casting the string to a boolean and see what happens?

@grantmca
Copy link
Contributor Author

I think the issue might be because it's using the string "false" instead of a Boolean false. Can you try casting the string to a boolean and see what happens?

I am sorry I should of used backticks instead of single quotes, I am passing the bool false into the params when I was getting that response. I am struggling to figure out why this is happening. I have unpacked the gem and I am digging into it to try and see if I can come up with any reason, I will keep you updated with what I find

@dorner
Copy link
Collaborator

dorner commented Jul 21, 2023

Please do, thanks. This behavior really doesn't make any sense.

@grantmca
Copy link
Contributor Author

grantmca commented Aug 6, 2023

Please do, thanks. This behavior really doesn't make any sense.

This seems to maybe be a bug on Filterfific's end. On this line you can see that in the define_and_assign_attr_accessors_for_each_filter goes through each of the params for each filter and before assigning them as attr_accessor it checks each of them to see if they are present? and if not it will not assign them. In our case false.present? is false because false is treated as a non-present value so the parameter is not being passed into the scope. This does not seem like the intended behavior for the service obj so I am going to reach out on the filterrific gem and maybe create a PR to fix this issue. Given this info what would you recommend on this PR? @dorner

@dorner
Copy link
Collaborator

dorner commented Aug 10, 2023

So it looks like this is the suggested approach: jhund/filterrific#9

In general I'd try to keep the 0/1 check to a single place. If you have to massage the parameters to turn the 0/1 into true/false, I'd do it in a method or callback before any other methods are called.

@grantmca
Copy link
Contributor Author

So it looks like this is the suggested approach: jhund/filterrific#9

In general I'd try to keep the 0/1 check to a single place. If you have to massage the parameters to turn the 0/1 into true/false, I'd do it in a method or callback before any other methods are called.

I went ahead and opened a PR for this on filterrific jhund/filterrific#224 @dorner let me know how we should proceed form here.

@dorner
Copy link
Collaborator

dorner commented Aug 27, 2023

@grantmca did you try this approach? jhund/filterrific#9 (comment) We could use that while we wait :)

* Updated the view, controller and test to use the new column
* Added auto archive of children on families archive
* Added scope to Families with unit tests
* Added default filter to families controller
* Updated the CSV output on the families controller
* Added `Include Archived?` option on the families view
* Added request test to ensure default only returns the non-archived
* Added test for `Include Archived?` check on index
* Extracted archiving the children of a family to a service object that
  is called in the family controller and took the funciton and callback
  off of the family model
* Updated and added unit test
* Updated the migration to remove backfill migration
updated it to module level function. I also updated the migration table
to creat the column and set nill and default all on one line
@grantmca
Copy link
Contributor Author

grantmca commented Sep 6, 2023

I think that we are all set now! @dorner, I updated the scope to follow the example on the issue you linked. Let me know what you think!

@grantmca grantmca requested a review from dorner September 8, 2023 03:16
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Probably as good as it's going to get - but I think there's a typo in the migration file?

db/migrate/20230430025441_add_archive_to_families.rb Outdated Show resolved Hide resolved
@grantmca grantmca requested a review from dorner September 9, 2023 03:18
@dorner
Copy link
Collaborator

dorner commented Sep 14, 2023

Thanks for all your patience with this! In it goes!

@dorner dorner merged commit 4ff7b49 into rubyforgood:main Sep 14, 2023
11 checks passed
scooter-dangle added a commit that referenced this pull request Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add ability to archive family
2 participants