8000 Fix issues with Conditional question serialization (offered by @briri from DMPTool) in PR https://github.com/CDLUC3/dmptool/pull/667 by johnpinto1 · Pull Request #3497 · DMPRoadmap/roadmap · GitHub
[go: up one dir, main page]

Skip to content

Fix issues with Conditional question serialization (offered by @briri from DMPTool) in PR https://github.com/CDLUC3/dmptool/pull/667 #3497

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

Conversation

johnpinto1
Copy link
Contributor
@johnpinto1 johnpinto1 commented Mar 27, 2025

Previous PR closed as it was easier to add code to a new pull of development. Old PR #3476 closed

Fix issues with Conditional question serialization (offered by @briri from DMPTool) in PR CDLUC3#667

Changes proposed in this PR (text from cited PR):

  • There is a migration file with code for MySQL and Postgres to update the Conditions table to convert JSON Arrays in string format records in the conditions table so that they are JSON Arrays.
  • Updated the form partials in app/views/org_admin/conditions/_form.erb.rb to properly send condition data to the controller.
  • Removed all JSON.parse calls in the app/helpers/conditions.rb helper
  • The user can no longer edit a condition. They need to remove it and create a new condition. This applies to the email for 'add notifications' too.

Made the following changes to simplify this patch and to make it a little more user friendly:

  • The "Add Conditions" button will now say "Edit Conditions" if there are any conditions for a given question.
  • Updated the column heading over the "thing that happens when the condition is met" from "Remove" to "Target" since the content of the column can either be questions being removed or an email notification being sent.
  • Conditions of any action type can be added or removed (not updated anymore).
  • Hovering over the email of an existing condition displays a tooltip that shows the email message, subject, etc. The email content can no longer be edited once saved. It will need to be removed and re-created.
  • We allow only one question option to be selected when adding a Condition unlike inthe DMPTool version because experience with multiple options chosen has been problematic and buggy when used by users in DMPOnline.
  • To add a condition you must have selected an Option and Action together with:
    -- If Action is 'remove', you need to select one or more choices in Target.
    -- If Action is 'add notification', you need to fill in all the fields in the 'Send email' popup.
    Otherwise, the condition will not be saved.

Some screenshots:
Selection_073
Selection_075
Selection_076
Selection_077

        from DMPTool).nBased on DMPtool commit CDLUC3#667.

        Changes proposed in this PR (text from cited PR):
           - There is a migration file with code for MySQL and Postgres to update the Conditions table to convert JSON Arrays in string format records in the conditions table so that they are JSON Arrays.
           - Updated the form partials in app/views/org_admin/conditions/_form.erb.rb to properly send condition data to the controller.
           - Removed all JSON.parse calls in the app/helpers/conditions.rb helper
           - The user canno longer edit a condition. They need to remove it
             and create a new condition. This applies to the email for 'add
    notifications' too.

        Made the following changes to simplify this patch and to make it a little more user friendly:

           - The "Add Conditions" button will now say "Edit Conditions" if there are any conditions for a given question.
           - Updated the column heading over the "thing that happens when the condition is met" from "Remove" to "Target" since the content of the column can either be questions being removed or an email notification being sent.
           - Conditions of any action type can be added or removed (not updated anymore).
           - Hovering over the email of an existing condition displays a tooltip that shows the email message, subject, etc. The email content can no longer be edited once saved. It will need to be removed and re-created.
           - We allow only one question option to be selected when adding a Condition unlike inthe DMPTool version because experience with multiple options chosen has been problematic and buggy when used by users in DMPOnline.
           - To add a condition you must have selected an Option and Action together with:
              o if Action is 'remove', you need to select one or more choices in Target.
              o if Action is 'add notification', you need to fill in all the fields in the 'Send email' popup.
             Otherwise, the condition will not be saved.
@johnpinto1 johnpinto1 requested review from briri and aaronskiba March 27, 2025 14:27
Copy link
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

@johnpinto1
Copy link
Contributor Author

This was added as Rails 7 update was breaking for editing template and adding conditional question
Selection_007
Selection_006

@aaronskiba
Copy link
Contributor
aaronskiba commented Apr 1, 2025

(UPDATE: I have verified that this same behaviour currently exists on main. Rather than requesting changes in this PR, I will create an issue describing what I've found here.)

I will have to look at code behaviour prior to this PR, but I'm noticing the following:

  1. Save checkbox with question options and conditions:
    Screenshot from 2025-04-01 15-02-24
  2. Update answer format from checkbox to date:
    Screenshot from 2025-04-01 15-02-47
  3. The conditions remain visible:
    Screenshot from 2025-04-01 15-03-14
  4. The question options remain visible in Template Overview:
    Screenshot from 2025-04-01 16-12-00

sanitize_hash in QuestionsController to reflect the change structure. It
is now a hash of a  hash.
@johnpinto1 johnpinto1 force-pushed the johnpinto1-updated-port-of-dmptool-conditional-questions-fix-for-rails7 branch from 6f543cc to dba3999 Compare April 3, 2025 09:52
from
<% cond_lbl = (!conditions.nil? && conditions.any?) ? 'Edit Conditions' : 'Add Conditions' %>
to concise version
 <% cond_lbl = conditions&.any? ? 'Edit Conditions' : 'Add Conditions' %>.
John Pinto and others added 6 commits April 4, 2025 10:29
    <% condition = condition ||= nil %>
    with concise expression as in
    <% condition ||= nil %>.
This change uses `.map` to refactor/simplify the mapping of `option_list` and `remove_data`. It also removes the needed for temporary arrays.
Refactored `save_condition` method via new `handle_webhook_data` helper method.
  - Helper method returns nil if any of the required webhook_data fields are absent. Else, it constructs and returns the webhook_data hash
  - Returning nil when any fields are absent enables us to simplify the if check that immediately follows (now line 240) to `if c.option_list.empty? || c.webhook_data.nil?`
- Overall, these changes simplify the `save_condition` method and even remove a previous rubocop offense.
- Moved `c.option_list.empty?` immediately after `c.option_list` assignment to streamline logic.
- This change reduces unnecessary processing of `c.remove_data` and `c.webhook_data`.
- Isolating the `c.option_list.empty?` check also simplifies subsequent checks for `c.remove_data.empty?` and c.webhook_data.nil?` later in the code.
- Moved logic for handling option_list and remove_data into separate helper methods (handle_option_list and handle_remove_data).
- This simplifies our `save_condition` method and resolves some previously disabled rubocop offenses.
aaronskiba and others added 4 commits April 7, 2025 09:50
Adding a comment to help with maintainability of `app/views/org_admin/conditions/_form.html.erb`
…-condition

Refactor `Question.save_condition`
aaronskiba and others added 9 commits April 7, 2025 14:59
- #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.
…s-fix-for-rails7' into aaron/refactor-conditions-form
Refactor `org_admin/conditions/_form.html.erb`
NOTE: For app/views/org_admin/conditions/_existing_condition_display.erb, `hook_tip` refers to the pop up message that is rendered when hovering over the email address in the "Target" section of an "Email" type action. We are only enabling for the titles here ('Name', 'Email', 'Subject', and 'Message'), not the actual corresponding values.
Copy link
Contributor
@aaronskiba aaronskiba left a comment

Choose a reason for hiding this comment

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

My last commit enables a few more translations. I am approving this PR.

@aaronskiba aaronskiba merged commit 9572e01 into development Apr 9, 2025
8 checks passed
@aaronskiba aaronskiba deleted the johnpinto1-updated-port-of-dmptool-conditional-questions-fix-for-rails7 branch April 15, 2025 16:01
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
0