Use buttons to destroy drafts and questions

As mentioned in commits 5311daadf and bb958daf0, using links combined
with JavaScript to generate POST (or, in this case, DELETE) requests to
the server has a few issues.
This commit is contained in:
Javi Martín
2024-03-06 04:53:15 +01:00
parent 20d3725709
commit ecad046a99
8 changed files with 21 additions and 16 deletions

View File

@@ -15,10 +15,12 @@
<h3 class="inline-block"><%= @draft_version.title %></h3> <h3 class="inline-block"><%= @draft_version.title %></h3>
<div class="float-right"> <div class="float-right">
<%= link_to t("admin.legislation.draft_versions.index.delete"), <%= render Admin::ActionComponent.new(
admin_legislation_process_draft_version_path(@process, @draft_version), :destroy,
method: :delete, @draft_version,
class: "button hollow alert" %> method: :delete,
class: "button hollow alert"
) %>
</div> </div>
</div> </div>

View File

@@ -15,9 +15,12 @@
<h3 class="inline-block"><%= t("admin.legislation.questions.edit.title", question_title: @question.title) %></h3> <h3 class="inline-block"><%= t("admin.legislation.questions.edit.title", question_title: @question.title) %></h3>
<div class="float-right"> <div class="float-right">
<%= link_to t("admin.legislation.questions.index.delete"), admin_legislation_process_question_path(@process, @question), <%= render Admin::ActionComponent.new(
method: :delete, :destroy,
class: "button hollow alert" %> @question,
method: :delete,
class: "button hollow alert"
) %>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -24,9 +24,9 @@ module ActionDispatch::Routing::UrlFor
end end
def namespaced_polymorphic_path(namespace, resource, options = {}) def namespaced_polymorphic_path(namespace, resource, options = {})
if %w[Budget::Group Budget::Heading Poll::Booth Poll::BoothAssignment Poll::Officer if %w[Budget::Group Budget::Heading Legislation::DraftVersion Legislation::Question
Poll::Question Poll::Question::Answer Poll::Question::Answer::Video Poll::Shift Poll::Booth Poll::BoothAssignment Poll::Officer Poll::Question Poll::Question::Answer
SDG::LocalTarget].include?(resource.class.name) Poll::Question::Answer::Video Poll::Shift SDG::LocalTarget].include?(resource.class.name)
resolve = resolve_for(resource) resolve = resolve_for(resource)
resolve_options = resolve.pop resolve_options = resolve.pop

View File

@@ -664,7 +664,6 @@ en:
index: index:
title: Draft versions title: Draft versions
create: Create version create: Create version
delete: Delete
preview: Preview preview: Preview
new: new:
back: Back back: Back
@@ -697,7 +696,6 @@ en:
back: Back back: Back
title: Questions associated to this process title: Questions associated to this process
create: Create question create: Create question
delete: Delete
new: new:
back: Back back: Back
title: Create new question title: Create new question

View File

@@ -664,7 +664,6 @@ es:
index: index:
title: Versiones del borrador title: Versiones del borrador
create: Crear versión create: Crear versión
delete: Borrar
preview: Previsualizar preview: Previsualizar
new: new:
back: Volver back: Volver
@@ -697,7 +696,6 @@ es:
back: Volver back: Volver
title: Preguntas asociadas a este proceso title: Preguntas asociadas a este proceso
create: Crear pregunta create: Crear pregunta
delete: Borrar
new: new:
back: Volver back: Volver
title: Crear nueva pregunta title: Crear nueva pregunta

View File

@@ -346,3 +346,7 @@ end
resolve "Poll::Question::Answer::Video" do |video, options| resolve "Poll::Question::Answer::Video" do |video, options|
[:answer, :video, options.merge(answer_id: video.answer, id: video)] [:answer, :video, options.merge(answer_id: video.answer, id: video)]
end end
resolve "Legislation::DraftVersion" do |version, options|
[version.process, :draft_version, options.merge(id: version)]
end

View File

@@ -78,7 +78,7 @@ describe "Admin legislation draft versions", :admin do
version = create(:legislation_draft_version, body: "Version 1") version = create(:legislation_draft_version, body: "Version 1")
visit edit_admin_legislation_process_draft_version_path(version.process, version) visit edit_admin_legislation_process_draft_version_path(version.process, version)
click_link "Delete" click_button "Delete"
expect(page).to have_content "Draft deleted successfully" expect(page).to have_content "Draft deleted successfully"
end end

View File

@@ -75,7 +75,7 @@ describe "Admin legislation questions", :admin do
visit edit_admin_legislation_process_question_path(process, question) visit edit_admin_legislation_process_question_path(process, question)
click_link "Delete" click_button "Delete"
expect(page).to have_content "Questions" expect(page).to have_content "Questions"
expect(page).to have_content "Question 1" expect(page).to have_content "Question 1"