Prevent Duplicate Options in 'Select Guidance' & Refactor #561
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #560
Changes proposed in this PR:
[org, ggs]
to@important_ggs
when it is already included.[org, ggs]
to@important_ggs
. The following is documented in the commit's description:@all_ggs_grouped_by_org.include?(current_user.org)
iterates through@all_ggs_grouped_by_org
to findcurrent_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 loopif (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.