Skip to content

Conversation

@aaronskiba
Copy link
Contributor

Changes proposed in this PR:

  • These changes are intended to refactor app/views/org_admin/conditions/_form.html.erb.
    • Commit 3a11067 creates the files app/views/org_admin/conditions/_new_condition_form.erb and app/views/org_admin/conditions/_existing_condition_display.erb which now handle the logic for new conditions vs existing conditions respectively. This change was largely performed via a simple copy/paste. Commit 4724bc7 further refines this change.
  • Individual descriptions are provided for most of the remaining commits.

Adding a comment to help with maintainability of `app/views/org_admin/conditions/_form.html.erb`
- #3497 introduces `<% condition ||= nil %>` on line 6.
- This refactor replaces the usage of `condition_exists` with `condition.present?`
- `app/views/org_admin/conditions/_container.html.erb` appears to be the only `app/views/org_admin/conditions/_form.html.erb` that passes the `locals : { condition` variable. The `<% condition ||= nil %>` code on line 6 should be sufficient for performing this check.
- Additionally, if `condition == nil` and `condition_exists == true` ever occurred, then we would encounter `NoMethodError` exceptions on lines 13 and 27.
- `<%= select_tag(:action_type, options_for_select(action_type_arr, type_default)` was only being executed when `if condition.nil?` was true (now line 20). Additionally, that was the only line that was using the `type_default` variable.
  - Thus, no conditional is required for the assigning of `type_default` and we can just use `:remove` explicitly on line 30 now.
The modified code was and is only executed when `condition.nil?` is true (line 20). Thus, the ternary operator always evaluated to the else.
- Line 35 is the only that uses the `remove_question_group` variable. However, line 35 is only executed when `condition.nil? == true` (line 18).
This change refactors `app/views/org_admin/conditions/_form.html.erb`. The change moves the logic for new conditions to `app/views/org_admin/conditions/_new_condition_form.erb` and existing conditions to `app/views/org_admin/conditions/_existing_condition_display.erb`.
-  ` action_type_arr` and `remove_question_group` are only needed in `conditions/_new_condition_form.erb`. The assignments have been moved directly to that partial.
- -  ` view_email_content_info` is only needed in `conditions/_new_condition_form.erb`. The assignment has been moved directly to that partial.
@github-actions
Copy link

github-actions bot commented Apr 8, 2025

1 Warning
⚠️ There are code changes, but no corresponding tests. Please include tests if this PR introduces any modifications in behavior. \n
Ignore this warning if the PR ONLY contains translation.io synced updates.

Generated by 🚫 Danger

Copy link
Contributor

@johnpinto1 johnpinto1 left a comment

Choose a reason for hiding this comment

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

0c2e2d2 Approved
97677d4 Approved
c7abc11 Approved
b2eaac4 Approved

e651186 Approved well spotted
dc04625 Approved
3a11067 Approved

@aaronskiba This is brilliant. I can't say I fully understood all the changes. You really have done a good job re-factoring this spaghetti code into smaller chunks. I learnt quite a few Ruby concepts in reviewing.
Further I tested it on n a template with conditional questions.

aaronskiba and others added 2 commits April 9, 2025 08:49
@aaronskiba aaronskiba merged commit 478fdad into johnpinto1-updated-port-of-dmptool-conditional-questions-fix-for-rails7 Apr 9, 2025
8 checks passed
@aaronskiba aaronskiba deleted the aaron/refactor-conditions-form branch April 9, 2025 15:00
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.

3 participants