Skip to content

Commit 1cf34de

Browse files
authored
Merge pull request #231 from opf/fix/danger-preview
Fix the dangerDialog form previews
2 parents 3cf8fe4 + 10cf9d2 commit 1cf34de

File tree

7 files changed

+46
-4
lines changed

7 files changed

+46
-4
lines changed

.changeset/young-doors-explode.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openproject/primer-view-components': patch
3+
---
4+
5+
Fix form preview of DangerConfirmationDialog

previews/primer/open_project/danger_confirmation_dialog_preview.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ def custom_icon
7272
dialog.with_confirmation_check_box_content("I understand that this deletion cannot be reversed")
7373
end
7474
end
75+
76+
# @label With form using FormBuilder for testing puposes
77+
# @hidden
78+
def with_form_builder_form_test(route_format: :html)
79+
render_with_template(locals: { route_format: route_format })
80+
end
81+
82+
# @label With form for testing purposes
83+
# @hidden
84+
def with_form_test(route_format: :html)
85+
render_with_template(locals: { route_format: route_format })
86+
end
7587
end
7688
end
7789
end

previews/primer/open_project/danger_confirmation_dialog_preview/with_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%= render(Primer::OpenProject::DangerConfirmationDialog.new(
22
title: "Delete dialog",
3-
form_arguments: { action: generic_form_submission_path(format: route_format) }
3+
form_arguments: { action: "" } # Use the correct form action here.
44
)) do |dialog| %>
55
<% dialog.with_show_button { "Click me" } %>
66
<% dialog.with_confirmation_message do |message|

previews/primer/open_project/danger_confirmation_dialog_preview/with_form_builder_form.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<%= form_with(url: generic_form_submission_path(format: route_format)) do |f| %>
1+
<!-- Use the correct form URL here. -->
2+
<%= form_with(url: "") do |f| %>
23
<%= render(Primer::OpenProject::DangerConfirmationDialog.new(
34
title: "Delete dialog",
45
form_arguments: { builder: f, name: "confirm_very_dangerous_action" }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<%= form_with(url: generic_form_submission_path(route_format)) do |f| %>
2+
<%= render(Primer::OpenProject::DangerConfirmationDialog.new(
3+
title: "Delete dialog",
4+
form_arguments: { builder: f, name: "confirm_very_dangerous_action" }
5+
)) do |dialog| %>
6+
<% dialog.with_show_button { "Click me" } %>
7+
<% dialog.with_confirmation_message do |message|
8+
message.with_heading(tag: :h2).with_content("Permanently delete?")
9+
message.with_description_content("This action is not reversible. Please proceed with caution.")
10+
end %>
11+
<% dialog.with_confirmation_check_box_content("I understand that this deletion cannot be reversed") %>
12+
<% end %>
13+
<% end %>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<%= render(Primer::OpenProject::DangerConfirmationDialog.new(
2+
title: "Delete dialog",
3+
form_arguments: { action: generic_form_submission_path(route_format) }
4+
)) do |dialog| %>
5+
<% dialog.with_show_button { "Click me" } %>
6+
<% dialog.with_confirmation_message do |message|
7+
message.with_heading(tag: :h2).with_content("Permanently delete?")
8+
message.with_description_content("This action is not reversible. Please proceed with caution.")
9+
end %>
10+
<% dialog.with_confirmation_check_box_content("I understand that this deletion cannot be reversed") %>
11+
<% end %>

test/system/open_project/danger_confirmation_dialog_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_submit_button_enabled_when_confirmation_check_box_checked
3434
end
3535

3636
def test_submit_button_submits_form
37-
visit_preview(:with_form, route_format: :json)
37+
visit_preview(:with_form_test, route_format: :json)
3838

3939
click_button("Click me")
4040

@@ -49,7 +49,7 @@ def test_submit_button_submits_form
4949
end
5050

5151
def test_submit_button_submits_form_builder_form
52-
visit_preview(:with_form_builder_form, route_format: :json)
52+
visit_preview(:with_form_builder_form_test, route_format: :json)
5353

5454
click_button("Click me")
5555

0 commit comments

Comments
 (0)