Skip to content

Add delete drafts form#2292

Merged
DavidBiddle merged 6 commits into
mainfrom
add-delete-drafts-form
Oct 27, 2025
Merged

Add delete drafts form#2292
DavidBiddle merged 6 commits into
mainfrom
add-delete-drafts-form

Conversation

@thomasiles
Copy link
Copy Markdown
Contributor

@thomasiles thomasiles commented Oct 21, 2025

Add a delete draft button to live forms with draft

Trello card: https://trello.com/c/tP5Fd96d/2610-add-the-ability-to-delete-a-draft-of-a-live-form-with-a-confirmation-page

This PR replaces #2280 which was reverted in #2288. I reverted it because it prevented live forms being deleted, which the end to end tests rely on, even if it's not exposed to users.

The end-to-end tests delete forms after creating them to keep things tidy.

They manipulate the URL of a live form to directly navigate to the delete form page. At this point the form is a live state. The pages for deleting a form don't have content for deleting live forms so the tests check for the draft content.

def delete_form
    if page.has_link?(form_name)
      click_link(form_name, match: :one)
      live_form_url = page.current_url
      delete_path = live_form_url.gsub("live", "delete")

      visit delete_path
      expect(page.find("h1")).to have_content 'Are you sure you want to delete this draft?'
      choose "Yes", visible: false
      click_button "Continue"

      expect(page.find(".govuk-notification-banner")).to have_content "The draft form, ‘#{form_name}’, has been deleted"
      if page.has_css?('.govuk-table')
        expect(page.find('.govuk-table')).not_to have_content form_name
      end
    end
  end

I think we need to tidy this up. I'm going to raise another card to tackle this as it might need input from design and content or prioritising.

This PR adds a single new commit compared to the previous one. This commit allows live forms to be deleted as before and adds a comment why. Other than than nothing has changed. I've checked locally and the end to end tests pass with this change.

This PR allows users to revert draft forms to their live state. It only extends the current delete button controller to use the RevertDraftService when deleting forms in the live_with_draft_state.

It does a small amount of clean up and refactoring first.

image
  • 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 marked this pull request as ready for review October 22, 2025 08:43
Copy link
Copy Markdown
Contributor

@DavidBiddle DavidBiddle left a comment

Choose a reason for hiding this comment

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

All looks good and I've tested it in the review environment 🎉

When deleting a draft, we check if the form is in a group to decide
where to redirect the user to.

This is left over from before groups were introduced. It's now no longer
possible for a form to be created outside of a group.

Users should always be redirected to the group page when deleting a
draft.
Add a hint_text optional argument to the delete_confirmation_input partial.
Change the delete draft controller so that drafts can be deleted from
forms which are in a live_with_draft state.

We check use a different method to "delete" the draft from a
live form and redirect to the live form page.

We also redirect with a failure if this is called and the form is not a
draft or a live_with_draft form.
Add a hint text to the delete draft live confirmation to help users
understand that deleting a draft will not remove the live form.
When a live form has a draft, show the delete draft form button.
We don't offers users a link to the delete live forms. The end to end
tests navigate directly to the URL to delete forms.

This commit allows live forms to be deleted, preserving the original
behaviour of end point.
@DavidBiddle DavidBiddle force-pushed the add-delete-drafts-form branch from 69378ae to ba1ccd2 Compare October 27, 2025 14:50
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-2292.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.

@DavidBiddle DavidBiddle merged commit 81e8865 into main Oct 27, 2025
6 checks passed
@DavidBiddle DavidBiddle deleted the add-delete-drafts-form branch October 27, 2025 15:07
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