-
Notifications
You must be signed in to change notification settings - Fork 10
Refactor feature report to make it easier to add new feature reports (part 2) #1970
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
base: main
Are you sure you want to change the base?
Conversation
664b564 to
33d7a62
Compare
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 was following this quite well until the point CsvReportService was added, and then it started getting a bit confusing.
Up to this point, I think all the changes made sense and there were some really nice improvements in here.
Could you potentially make the PR stop at that point and then raise another PR that combines all the routes into one so we can look at that in isolation? I'd fear that although you've made it potentially simpler to add a report, it might be a bit confusing to understand the magic behind it.
| return NilCsvService if record_type.nil? | ||
|
|
||
| "Reports::#{record_type.capitalize}CsvReportService".constantize | ||
| 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 fear this is might make it more difficult to understand than it makes it easier to maintain.
Instead of having a controller action for each feature report, use a single action which gets the report to generate from a dynamic segment in the path. This should mean that in future adding a new feature report should require only adding a new method to FeatureReportService.
Rather than allowing any method on FeatureReportService to be called (and potentially opening up a security hole), this commit adds some metaprogramming machinery to manage a list of methods which are feature reports and adds methods to allow that to be used safely, both to constrain the parameters in the routes and to prevent arbitrary methods from being called from the controller.
33d7a62 to
1d6cda5
Compare
|
|
🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-1970.admin.review.forms.service.gov.uk/ It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready For the sign in details and more information, see the review apps wiki page. |



What problem does this pull request solve?
I wanted to add a new feature report, but I found the feature report code was very repetitive and I had to add a lot of files to do that, and I felt like this situation could be improved. So in this PR, I try to make the feature report code more DRY.
The aim was to get it to the point where (in the simplest case) adding a new feature report required only adding a new method to
Reports::FeatureReportService, and all the related routes, controller actions, views should automatically be generated, including for the CSV downloads.A big part of this is making the responsibilities for each class involved in making a feature report more clearly deliniated and less overlapping, with the controller creating the pipeline to get the final result. It is now expected that FormDocumentsService will be called first, and that passed to FeatureReportService with is responsible just for filtering form documents and optionally converting it into a list of questions. There are helpers that turn this array of form documents or question page documents into a GOV.UK styles table; if a CSV is wanted for the end result, CsvReportService generates the CSV for either an array of form documents or an array of question page documents.
There is a little bit of metaprogramming magic required for this, to make the FeatureReportService aware of what methods the other things should be generated for there is a new class method
.define_report:For a more realistic example, see #1971.
The changes in this PR also increase the reusability to the point where it's feasible for us to add feature reports for draft forms, see #1972 for this in action.
Things to consider when reviewing