Skip to content

Commit 55474a1

Browse files
committed
Send back flash messages on section action error. wp/72005
1 parent f5cf000 commit 55474a1

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

app/controllers/admin/settings/project_custom_field_sections_controller.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def destroy
7474
update_header_via_turbo_stream(allow_custom_field_creation: allow_custom_field_creation?)
7575
update_sections_via_turbo_stream(project_custom_field_sections: ProjectCustomFieldSection.all)
7676
else
77-
# TODO: show error message
77+
render_section_error_via_turbo_stream(call)
7878
end
7979

8080
respond_with_turbo_streams
@@ -88,7 +88,7 @@ def move
8888
if call.success?
8989
update_sections_via_turbo_stream(project_custom_field_sections: ProjectCustomFieldSection.all)
9090
else
91-
# TODO: show error message
91+
render_section_error_via_turbo_stream(call)
9292
end
9393

9494
respond_with_turbo_streams
@@ -103,7 +103,7 @@ def drop
103103
update_header_via_turbo_stream(allow_custom_field_creation: allow_custom_field_creation?)
104104
update_sections_via_turbo_stream(project_custom_field_sections: ProjectCustomFieldSection.all)
105105
else
106-
# TODO: show error message
106+
render_section_error_via_turbo_stream(call)
107107
end
108108
respond_with_turbo_streams
109109
end
@@ -114,6 +114,14 @@ def new_link
114114

115115
private
116116

117+
# Show a danger toast with the action's hint (resolved relative to the
118+
# controller/action), appending the service's error detail (e.g. why a
119+
# non-empty section cannot be deleted) when present.
120+
def render_section_error_via_turbo_stream(call)
121+
message = [t(".error"), call.message].compact_blank.join(" ")
122+
render_error_flash_message_via_turbo_stream(message:)
123+
end
124+
117125
def set_project_custom_field_section
118126
@project_custom_field_section = ProjectCustomFieldSection.find(params[:id])
119127
end

app/controllers/admin/settings/user_custom_field_sections_controller.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ def destroy
7272
if call.success?
7373
update_header_via_turbo_stream(allow_custom_field_creation: allow_custom_field_creation?)
7474
update_sections_via_turbo_stream(user_custom_field_sections: UserCustomFieldSection.all)
75-
# TODO: show error message on failure
75+
else
76+
render_section_error_via_turbo_stream(call)
7677
end
7778

7879
respond_with_turbo_streams
@@ -85,7 +86,8 @@ def move
8586

8687
if call.success?
8788
update_sections_via_turbo_stream(user_custom_field_sections: UserCustomFieldSection.all)
88-
# TODO: show error message on failure
89+
else
90+
render_section_error_via_turbo_stream(call)
8991
end
9092

9193
respond_with_turbo_streams
@@ -99,7 +101,8 @@ def drop
99101
if call.success?
100102
update_header_via_turbo_stream(allow_custom_field_creation: allow_custom_field_creation?)
101103
update_sections_via_turbo_stream(user_custom_field_sections: UserCustomFieldSection.all)
102-
# TODO: show error message on failure
104+
else
105+
render_section_error_via_turbo_stream(call)
103106
end
104107

105108
respond_with_turbo_streams
@@ -111,6 +114,14 @@ def new_link
111114

112115
private
113116

117+
# Show a danger toast with the action's hint (resolved relative to the
118+
# controller/action), appending the service's error detail (e.g. why a
119+
# non-empty section cannot be deleted) when present.
120+
def render_section_error_via_turbo_stream(call)
121+
message = [t(".error"), call.message].compact_blank.join(" ")
122+
render_error_flash_message_via_turbo_stream(message:)
123+
end
124+
114125
def set_user_custom_field_section
115126
@user_custom_field_section = UserCustomFieldSection.find(params.expect(:id))
116127
end

config/locales/en.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,20 @@ en:
445445
<p>Hello,</p>
446446
<p>A new project has been created: projectValue:name</p>
447447
<p>Thank you</p>
448+
project_custom_field_sections:
449+
destroy:
450+
error: "The section could not be deleted."
451+
drop:
452+
error: "The section could not be reordered."
453+
move:
454+
error: "The section could not be reordered."
455+
user_custom_field_sections:
456+
destroy:
457+
error: "The section could not be deleted."
458+
drop:
459+
error: "The section could not be reordered."
460+
move:
461+
error: "The section could not be reordered."
448462
work_packages_identifier:
449463
page_header:
450464
description: Choose between classic numerical work package IDs or semantic project-specific ones that prepend the project identifier to the work package ID.

0 commit comments

Comments
 (0)