Skip to content

Commit

Permalink
fix for bulk editting wps with hierarchy items
Browse files Browse the repository at this point in the history
  • Loading branch information
brunopagno committed Nov 27, 2024
1 parent a481275 commit f9c9780
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
13 changes: 13 additions & 0 deletions app/helpers/custom_fields_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ def custom_field_tag_for_bulk_edit(name, custom_field, project = nil) # rubocop:
options_for_select(base_options + custom_field.possible_values_options(project)),
id: field_id,
multiple: custom_field.multi_value?)
when "hierarchy"
base_options = [[I18n.t(:label_no_change_option), ""]]
result = CustomFields::Hierarchy::HierarchicalItemService.new
.get_descendants(item: custom_field.hierarchy_root, include_self: false)
.either(
->(items) { items },
->(_) { [] }
)
options = base_options + result.map do |item|
label = item.short.present? ? "#{item.label} (#{item.short})" : item.label
[label, item.id]
end
styled_select_tag(field_name, options_for_select(options), id: field_id, multiple: custom_field.multi_value?)
else
styled_text_field_tag(field_name, "", id: field_id)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ def get_branch(item:)

# Gets all descendant nodes in a tree starting from the item/node.
# @param item [CustomField::Hierarchy::Item] the node
# @param include_self [Boolean] flag
# @return [Success(Array<CustomField::Hierarchy::Item>)]
def get_descendants(item:)
Success(item.self_and_descendants)
def get_descendants(item:, include_self: true)
if include_self
Success(item.self_and_descendants)
else
Success(item.descendants)
end
end

# Move an item/node to a new parent item/node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@
expect(result.value!).to match_array(subitem2)
end
end

context "when does not include self" do
it "returns all descendants not including the item passed" do
result = service.get_descendants(item: mara, include_self: false)
expect(result).to be_success

descendants = result.value!
expect(descendants.size).to eq(2)
expect(descendants).to contain_exactly(subitem, subitem2)
end
end
end

describe "#move_item" do
Expand Down

0 comments on commit f9c9780

Please sign in to comment.