Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for bulk editting work packages with hierarchy items #17287

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading