Skip to content

Warn delete options multiple branches#2853

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

Warn delete options multiple branches#2853
thomasiles wants to merge 6 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 from a1516ef to 315e698 Compare June 19, 2026 08:53
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.
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.
@thomasiles thomasiles force-pushed the warn-delete-options-multiple-branches branch 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
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 e2c350d to fa29e8b Compare June 19, 2026 11:08
def remove_conditions_without_valid_answer_values(page)
return unless answer_type == "selection"

valid_answer_values = answer_settings[:selection_options].map { it[:name] }

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.

Shouldn't we be using the :value rather than the :name here?

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! good point


valid_answer_values = answer_settings[:selection_options].map { it[:name] }

if answer_settings[:none_of_the_above_question].present?

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.

What if the selection option allows "none of the above" as an answer but doesn't ask for a different answer?

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 don't know how I didn't trigger that when testing. I've also added a guard clause to only change it when it's being treated as a selection option as the other cases are handled elsewhere or in other tickets.

end

# 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)

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 wonder if it would be easier to use this method if if was on the input object rather than a standalone helper... did you consider that?

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 did consider this and it's how I started off. I didn't want to bloat the input object with something so dedicated to the presentation. I'm not super keen on helper methods but it seemed the right place.

I'll happily change it back to the input object if you think thats a better place for it. It would make it easier to call and possibly easier to test too.

@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.

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