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

Refactor methods on claims mentor training form #1086

Merged
merged 3 commits into from
Oct 7, 2024

Conversation

ollietreend
Copy link
Member

@ollietreend ollietreend commented Oct 7, 2024

Context

These changes come off the back of a comment thread in a separate PR – see #1062 (comment)

We agreed that the changes I suggested were out of scope for that PR, so I've put them into a new one.

Now that we have a standalone 'training allowance' object, it feels unnecessary for the mentor training form to hide that object from the outside world through abstractions and wrapper methods.

Changes proposed in this pull request

  • Refactor to remove confusingly named method mentor_training_form.max_hours_equals_maximum_claimable_hours?
  • Move the logic from that method into the single place it was being used (i.e. the 'disclaimer' component)
  • Avoid double-memoizing methods, this is not necessary
  • Make methods private where possible

Guidance to review

This PR is based upon #1062 for now, since that branch hasn't been merged in to main yet.

To review this PR, see the commits:

  1. Move logic closer to the code that needs it
  2. Make custom_hours_selected? method private
  3. Stop memoizing max_hours

Link to Trello card

Offshoot of: Refactor the claim form to use Training Allowance

@ollietreend ollietreend requested review from a team as code owners October 7, 2024 11:10
@ollietreend ollietreend changed the base branch from main to ba/refactor_claim_form October 7, 2024 11:12
@ollietreend ollietreend force-pushed the refactor-mentor-training-methods branch from d35742d to 8fe6236 Compare October 7, 2024 13:41
Base automatically changed from ba/refactor_claim_form to main October 7, 2024 13:42
I've relocated the logic that was originally defined as
`Claims::Claim::MentorTrainingForm#max_hours_equals_maximum_claimable_hours?`
because it was only needed and used in the component
`Claims::Claim::MentorTrainingForm::DisclaimerComponent`.

The component spec already covered the required behaviour, so I was able
to simply move the code and cut out an unnecessary layer of abstraction.
This method doesn't need to be part of the form object's public
interface, so I've made it private. It's only used by the validation
rules inside this class.

I've also dropped the memoization of this method. It's a simple and
cheap enough method to run that I don't think it's harmful to run it
twice. It simplifies the code and doesn't add any significant overhead.
This value is already memoized in the training allowance object. There's
no need to double memoize it.
@ollietreend ollietreend force-pushed the refactor-mentor-training-methods branch from 8fe6236 to 0f9fe17 Compare October 7, 2024 13:43
@ollietreend ollietreend enabled auto-merge (rebase) October 7, 2024 13:44
@ollietreend ollietreend merged commit dbc119d into main Oct 7, 2024
8 checks passed
@ollietreend ollietreend deleted the refactor-mentor-training-methods branch October 7, 2024 13:54
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.

2 participants