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

Prevent Duplicate Options in 'Select Guidance' & Refactor #561

Closed
wants to merge 3 commits into from

Conversation

aaronskiba
Copy link
Collaborator

Fixes #560

Changes proposed in this PR:

  • This PR addresses the bug where duplicate guidance options were displayed for some plans. The PR consists of two commits:
    • Commit 1 addresses the duplicate guidances bug by preventing the addition of [org, ggs] to @important_ggs when it is already included.
    • Commit 2 refactors the overall assigning of [org, ggs] to @important_ggs. The following is documented in the commit's description:
      • Explanation of re-factor:
        • @all_ggs_grouped_by_org.include?(current_user.org) iterates through @all_ggs_grouped_by_org to find current_user.org. But then the code iterates through @all_ggs_grouped_by_org again at @all_ggs_grouped_by_org.each do |org, ggs|. This refactor adds the (org == current_user.org) check inside @all_ggs_grouped_by_org.each do |org, ggs| and allows us to remove the @all_ggs_grouped_by_org.include?(current_user.org) section.

        • Before this refactor, we had multiple if statements inside the @all_ggs_grouped_by_org.each do |org, ggs| section that each included a !@important_ggs.include?([org, ggs])check. The refactor instead uses a single if statement inside the loop if (org == current_user.org) || @default_orgs.include?(org) || !(ggs & @selected_guidance_groups).empty?. This prevents the addition of duplicate [org, ggs] to @important_ggs, and allows us to remove the !@important_ggs.include?([org, ggs])check.

- Prior to this commit, duplicate guidance options would render when the user's org was also one of the app's default orgs.
Explanation of re-factor:
- `@all_ggs_grouped_by_org.include?(current_user.org)` iterates through `@all_ggs_grouped_by_org` to find `current_user.org`. But then the code iterates through `@all_ggs_grouped_by_org` again at `@all_ggs_grouped_by_org.each do |org, ggs|`.  This refactor adds the `(org == current_user.org)` check inside `@all_ggs_grouped_by_org.each do |org, ggs|` and allows us to remove the `@all_ggs_grouped_by_org.include?(current_user.org)` section.

- Before this refactor, we had multiple if statements inside the `@all_ggs_grouped_by_org.each do |org, ggs|` section that each included a `!@important_ggs.include?([org, ggs])`check. The refactor instead uses a single if statement inside the loop `if (org == current_user.org) || @default_orgs.include?(org) || !(ggs & @selected_guidance_groups).empty?`. This prevents the addition of duplicate `[org, ggs]` to `@important_ggs`, and allows us to remove the `!@important_ggs.include?([org, ggs])`check.
@aaronskiba aaronskiba closed this Jan 5, 2024
@aaronskiba aaronskiba deleted the aaron/issues/560 branch January 31, 2024 23:06
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.

duplicate org name in guidance choices
2 participants