Skip to content

Warn delete options multiple branches#2853

Open
thomasiles wants to merge 5 commits into
mainfrom
warn-delete-options-multiple-branches
Open

Warn delete options multiple branches#2853
thomasiles wants to merge 5 commits into
mainfrom
warn-delete-options-multiple-branches

Conversation

@thomasiles

@thomasiles thomasiles commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Delete conditions which reference options which don't exist and add banner to options page about routes

Trello card: https://trello.com/c/vaePaWB5/3141-delete-routes-when-changing-selection-options-makes-it-invalid-when-multiple-branches-is-enabled

This PR adds a banner to the selection options page to warn the user that options are being used in routes. The banner changes the wording based on how many options are involved in routes and whether the "none of the above" is activated for the page.

When options are changed or removed, it removes any conditions which have answer_values which no longer have matching options.

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Do the end to end tests need updating before these changes will pass?
  • Has all relevant documentation been updated?

@thomasiles thomasiles force-pushed the warn-delete-options-multiple-branches branch 2 times, most recently from 315e698 to e2c350d Compare June 19, 2026 09:24
@thomasiles thomasiles marked this pull request as ready for review June 19, 2026 10:24
@thomasiles thomasiles force-pushed the warn-delete-options-multiple-branches branch from e2c350d to fa29e8b Compare June 19, 2026 11:08
Comment thread app/input_objects/pages/question_input.rb Outdated
Comment thread app/input_objects/pages/question_input.rb Outdated
Comment thread app/helpers/pages_helper.rb
Comment thread app/helpers/pages_helper.rb Outdated

# option_indexes is either :number or :answer_value
def selection_options_in_routes_banner(draft_question, selection_options, include_none_of_the_above, option_indexes: :number)
answer_values_from_options = selection_options.pluck(:name) + [Condition::NONE_OF_THE_ABOVE]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
answer_values_from_options = selection_options.pluck(:name) + [Condition::NONE_OF_THE_ABOVE]
answer_values_from_options = selection_options.pluck(:value) + [Condition::NONE_OF_THE_ABOVE]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍 I've changed this to use the selection_options_with_value method and the :value attribute rather than :name

Comment thread app/helpers/pages_helper.rb Outdated
end

if options_in_routes.count == 1 && option_indexes == :number
option_index = selection_options.index { |option| option[:name] == options_in_routes.first.answer_value } + 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
option_index = selection_options.index { |option| option[:name] == options_in_routes.first.answer_value } + 1
option_index = selection_options.index { |option| option[:value] == options_in_routes.first.answer_value } + 1

Comment thread app/helpers/pages_helper.rb Outdated
return { heading: "There is a route from ‘#{option_index}’", text: "If you remove or change this option, the route will be deleted. #{edit_routes_link}" }
end

if selection_options.length == options_in_routes.count + (include_none_of_the_above ? 1 : 0)

@lfdebrux lfdebrux Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I couldn't get the "There are routes fro these options" banner to show with a question which doesn't include a 'none of the above' option, I think this line might need looking at again?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'd mucked up the order of this. I've fixed it and given it a name to hopefully make it clearer.

let(:form) { create :form, :ready_for_routing }
let(:draft_question) { build :selection_draft_question, form_id: form.id, page_id: form.pages.first.id }
let(:selection_options) { (1..3).to_a.map { |i| { name: i.to_s } } }
let(:include_none_of_the_above) { false }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pages::Selection::BaseOptionsInput#selected_none_of_the_above_option returns a string, not a boolean.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good catch, I've changed the value being passed in to is_optional, which is a boolean.

When changing the options in a selection question, we need to remove any
conditions which no longer have a valid answer value.

We add a method which will only be called when the draft question is
saved.
We'll need to check if draft question supports none of the above outside
of the input object.
@thomasiles thomasiles force-pushed the warn-delete-options-multiple-branches branch from f3a3548 to 5c6b767 Compare June 23, 2026 13:16
When changing options, we want to show a banner which tells the user if
they are removing or changing an option which is in a route.

The text for the banner varies depending on how many options are in
routes.

We refer to options in routes as either the option number or the
option's answer value. The bulk options page uses the answer value, the
regular options page uses the option number.
Add the banner to the normal options page.
Add the banner warning users about options in conditions to the bulk
options page.
@thomasiles thomasiles force-pushed the warn-delete-options-multiple-branches branch from 5c6b767 to 3f631ed Compare June 23, 2026 14:53
@github-actions

Copy link
Copy Markdown

🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-2853.admin.review.forms.service.gov.uk/

It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready
after 5 minutes, there may be something wrong with the ECS task. You will need to go to the integration AWS account
to debug, or otherwise ask an infrastructure person.

For the sign in details and more information, see the review apps wiki page.

@thomasiles

Copy link
Copy Markdown
Contributor Author

I've made some changes and checked everything works as designed.

I did look at moving the helper into the input object because they depend on input object methods. It didn't come out much clearer though because it still depended on path helpers and code to generate the link. It might be better as a presenter/service but I'm leaving it here as I'm not confident I'm making things much better by more fiddling.

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