Skip to content

Commit

Permalink
Show an error message when submitting a child form without child
Browse files Browse the repository at this point in the history
  • Loading branch information
HDinger committed Jan 31, 2025
1 parent 7f152ea commit 614869a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= component_wrapper do %>
<%= primer_form_with(
id: FORM_ID,
model: WorkPackage.new,
model: @child,
**submit_url_options,
data: {
turbo: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ class WorkPackageRelationsTab::AddWorkPackageChildFormComponent < ApplicationCom
ID_FIELD_TEST_SELECTOR = "work-package-child-form-id"
I18N_NAMESPACE = "work_package_relations_tab"

def initialize(work_package:, base_errors: nil)
def initialize(work_package:, child: nil, base_errors: nil)
super()

@work_package = work_package
@child = child.presence || WorkPackage.new
@base_errors = base_errors
end

Expand Down
19 changes: 17 additions & 2 deletions app/controllers/work_package_children_relations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,23 @@ def new
end

def create
child = WorkPackage.find(params[:work_package][:id])
service_result = set_relation(child:, parent: @work_package)
if params[:work_package][:id].present?
child = WorkPackage.find(params[:work_package][:id])
service_result = set_relation(child:, parent: @work_package)
else
child = WorkPackage.new
child.errors.add(:id, :blank)
service_result = ServiceResult.failure(result: child)
end

if service_result.failure?
update_via_turbo_stream(
component: WorkPackageRelationsTab::AddWorkPackageChildFormComponent.new(work_package: @work_package,
child: service_result.result,
base_errors: service_result.errors[:base]),
status: :bad_request
)
end

respond_with_relations_tab_update(service_result, relation_to_scroll_to: service_result.result)
end

Check notice on line 65 in app/controllers/work_package_children_relations_controller.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] app/controllers/work_package_children_relations_controller.rb#L45-L65 <Metrics/AbcSize>

Assignment Branch Condition size for create is too high. [<4, 21, 3> 21.59/17]
Raw output
app/controllers/work_package_children_relations_controller.rb:45:3: C: Metrics/AbcSize: Assignment Branch Condition size for create is too high. [<4, 21, 3> 21.59/17]
Expand Down

0 comments on commit 614869a

Please sign in to comment.