Skip to content
代码片段 群组 项目
未验证 提交 5e8b892e 编辑于 作者: Joseph Wambua's avatar Joseph Wambua 提交者: GitLab
浏览文件

Add /remove_parent quick action for work items

This quick action removes the parent from the current work item, if
permitted.

Changelog: changed
上级 027c3de8
No related branches found
No related tags found
无相关合并请求
......@@ -16,11 +16,11 @@ def ancestors
end
def self.quick_action_commands
[:set_parent, :add_child]
[:set_parent, :add_child, :remove_parent]
end
def self.quick_action_params
[:set_parent, :add_child]
[:set_parent, :add_child, :remove_parent]
end
def self.sync_params
......@@ -30,9 +30,11 @@ def self.sync_params
def self.process_quick_action_param(param_name, value)
return super unless param_name.in?(quick_action_params) && value.present?
return { parent: value } if param_name == :set_parent
return { children: value } if param_name == :add_child
if [:set_parent, :remove_parent].include?(param_name)
{ parent: value.is_a?(WorkItem) ? value : nil }
else
{ children: value }
end
end
def self.process_sync_params(params)
......
---
key_path: redis_hll_counters.quickactions.i_quickactions_remove_parent_monthly
name: quickactions_remove_parent_monthly
description: Count of MAU using the `/remove_parent` quick action
product_section: dev
product_stage: plan
product_group: product_planning
value_type: number
status: active
milestone: "16.9"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142174
time_frame: 28d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
options:
events:
- i_quickactions_remove_parent
performance_indicator_type: []
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.quickactions.i_quickactions_remove_parent_weekly
name: quickactions_remove_parent_weekly
description: Count of WAU using the `/remove_parent` quick action
product_section: dev
product_stage: plan
product_group: product_planning
value_type: number
status: active
milestone: "16.9"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142174
time_frame: 7d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
options:
events:
- i_quickactions_remove_parent
performance_indicator_type: []
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
......@@ -167,6 +167,7 @@ To auto-format this table, use the VS Code Markdown Table formatter: `https://do
| `/reassign @user1 @user2` | **{check-circle}** Yes | **{check-circle}** Yes | **{check-circle}** Yes | Replace current assignees with those specified. |
| `/relabel ~label1 ~label2` | **{check-circle}** Yes | **{check-circle}** Yes | **{check-circle}** Yes | Replace current labels with those specified. |
| `/remove_due_date` | **{check-circle}** Yes | **{dotted-circle}** No | **{check-circle}** Yes | Remove due date. |
| `/remove_parent` | **{check-circle}** Yes | **{dotted-circle}** No | **{check-circle}** Yes | Removes the parent work item. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/434344) in GitLab 16.9. |
| `/reopen` | **{check-circle}** Yes | **{check-circle}** Yes | **{check-circle}** Yes | Reopen. |
| `/set_parent <work_item>` | **{check-circle}** Yes | **{dotted-circle}** No | **{check-circle}** Yes | Set parent work item to `<work_item>`. The `<work_item>` value should be in the format of `#iid`, `group/project#iid`, or a URL to a work item. [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/420798) in GitLab 16.5. |
| `/shrug <comment>` | **{check-circle}** Yes | **{check-circle}** Yes | **{check-circle}** Yes | Append the comment with `¯\_(ツ)_/¯`. |
......
......@@ -40,6 +40,20 @@ module WorkItemActions
@execution_message[:set_parent] = success_msg[:set_parent]
end
desc { _('Remove work item parent') }
explanation do
format(
_("Remove %{parent_ref} as this work item's parent."),
parent_ref: work_item_parent.to_reference(quick_action_target)
)
end
types WorkItem
condition { work_item_parent.present? && can_admin_link? }
command :remove_parent do
@updates[:remove_parent] = true
@execution_message[:remove_parent] = success_msg[:remove_parent]
end
desc { _('Add children to work item') }
explanation do |child_param|
format(_("Add %{child_ref} to this work item as child(ren)."), child_ref: child_param)
......@@ -126,10 +140,15 @@ def success_msg
type: _('Type changed successfully.'),
promote_to: _("Work item promoted successfully."),
set_parent: _('Work item parent set successfully'),
remove_parent: _('Work item parent removed successfully'),
add_child: _('Child work item(s) added successfully')
}
end
def work_item_parent
quick_action_target.work_item_parent
end
def supports_parent?
::WorkItems::HierarchyRestriction.find_by_child_type_id(quick_action_target.work_item_type_id).present?
end
......
......@@ -40772,6 +40772,9 @@ msgstr ""
msgid "Remove %{displayReference}"
msgstr ""
 
msgid "Remove %{parent_ref} as this work item's parent."
msgstr ""
msgid "Remove %{ruleName}"
msgstr ""
 
......@@ -40937,6 +40940,9 @@ msgstr ""
msgid "Remove weight"
msgstr ""
 
msgid "Remove work item parent"
msgstr ""
msgid "Removed"
msgstr ""
 
......@@ -55758,6 +55764,9 @@ msgstr ""
msgid "Work in progress limit"
msgstr ""
 
msgid "Work item parent removed successfully"
msgstr ""
msgid "Work item parent set successfully"
msgstr ""
 
......@@ -426,6 +426,28 @@
end
end
describe '/remove_parent' do
let_it_be_with_reload(:parent) { create(:work_item, :objective, project: project) }
let_it_be_with_reload(:noteable) { create(:work_item, :objective, project: project) }
let_it_be(:note_text) { "/remove_parent" }
let_it_be(:note) { create(:note, noteable: noteable, project: project, note: note_text) }
before do
create(:parent_link, work_item_parent: parent, work_item: noteable)
end
it 'leaves the note empty' do
expect(execute(note)).to be_empty
end
it 'removes work item parent' do
execute(note)
expect(noteable.valid?).to be_truthy
expect(noteable.work_item_parent).to eq(nil)
end
end
describe '/promote_to' do
shared_examples 'promotes work item' do |from:, to:|
it 'leaves the note empty' do
......
......@@ -2770,6 +2770,42 @@
expect(updates).to eq(set_parent: parent)
end
end
context '/remove_parent command' do
let_it_be_with_reload(:work_item) { create(:work_item, :task, project: project) }
let(:content) { "/remove_parent" }
context 'when a parent is not present' do
it 'is empty' do
_, explanations = service.explain(content, work_item)
expect(explanations).to eq([])
end
end
context 'when a parent is present' do
let_it_be(:parent) { create(:work_item, :issue, project: project) }
before do
create(:parent_link, work_item_parent: parent, work_item: work_item)
end
it 'returns correct explanation' do
_, explanations = service.explain(content, work_item)
expect(explanations)
.to contain_exactly("Remove #{parent.to_reference(work_item)} as this work item's parent.")
end
it 'returns success message' do
_, updates, message = service.execute(content, work_item)
expect(updates).to eq(remove_parent: true)
expect(message).to eq('Work item parent removed successfully')
end
end
end
end
describe '#explain' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册