Skip to content

Commit b950d52

Browse files
authored
Merge pull request #17302 from ncounter/request-list-with-description
Unify request description of list page and detail page
2 parents 9975abf + 2a77325 commit b950d52

File tree

4 files changed

+67
-25
lines changed

4 files changed

+67
-25
lines changed

src/api/app/components/bs_request_action_description_component.rb

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
11
# This component renders the request action description based on the type of the action
22

33
class BsRequestActionDescriptionComponent < ApplicationComponent
4-
attr_reader :action
4+
attr_reader :action, :text_only
55

66
delegate :project_or_package_link, to: :helpers
77
delegate :user_with_realname_and_icon, to: :helpers
88
delegate :requester_str, to: :helpers
99
delegate :creator_intentions, to: :helpers
1010

11-
def initialize(action:)
11+
def initialize(action:, text_only: false)
1212
super
1313
@action = action
14+
@text_only = text_only
1415
end
1516

1617
# rubocop:disable Metrics/CyclomaticComplexity
1718
# rubocop:disable Rails/OutputSafety
1819
# rubocop:disable Style/FormatString
1920
def description
2021
creator = action.bs_request.creator
22+
2123
source_project_hash = { project: action.source_project, package: action.source_package, trim_to: nil }
2224
target_project_hash = { project: action.target_project, package: action.target_package, trim_to: nil }
2325

24-
source_container = project_or_package_link(source_project_hash)
25-
target_container = project_or_package_link(target_project_hash)
26+
source_and_target_component = BsRequestActionSourceAndTargetComponent.new(action.bs_request)
27+
28+
if text_only
29+
source_container = source_and_target_component.source
30+
target_container = source_and_target_component.target
31+
else
32+
source_container = project_or_package_link(source_project_hash)
33+
target_container = project_or_package_link(target_project_hash)
34+
end
35+
36+
source_and_target_container = source_and_target_component.combine(source_container, target_container)
2637

2738
description = case action.type
2839
when 'submit'
29-
'Submit %{source_container} to %{target_container}' %
30-
{ source_container: source_container, target_container: target_container }
40+
'Submit %{source_and_target_container}' % { source_and_target_container: source_and_target_container }
3141
when 'delete'
32-
target_repository = "repository #{link_to(action.target_repository, repositories_path(target_project_hash))} for " if action.target_repository
42+
repository_content = text_only ? action.target_repository : link_to(action.target_repository, repositories_path(target_project_hash))
43+
target_repository = "repository #{repository_content} for " if action.target_repository
3344

3445
'Delete %{target_repository}%{target_container}' %
3546
{ target_repository: target_repository, target_container: target_container }
@@ -44,14 +55,14 @@ def description
4455
'Set %{source_container} to be devel project/package of %{target_container}' %
4556
{ source_container: source_container, target_container: target_container }
4657
when 'maintenance_incident'
47-
'Submit update from %{source_container} to %{target_container}' %
48-
{ source_container: source_container, target_container: target_container }
58+
'Submit update from %{source_and_target_container}' %
59+
{ source_and_target_container: source_and_target_container }
4960
when 'maintenance_release'
50-
'Maintenance release %{source_container} to %{target_container}' %
51-
{ source_container: source_container, target_container: target_container }
61+
'Maintenance release %{source_and_target_container}' %
62+
{ source_and_target_container: source_and_target_container }
5263
when 'release'
53-
'Release %{source_container} to %{target_container}' %
54-
{ source_container: source_container, target_container: target_container }
64+
'Release %{source_and_target_container}' %
65+
{ source_and_target_container: source_and_target_container }
5566
end
5667

5768
# HACK: this is just a porting of the already existing way of passing the string to the view

src/api/app/components/bs_request_action_source_and_target_component.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,9 @@ def initialize(bs_request)
99
end
1010

1111
def call
12-
capture do
13-
if source.present?
14-
concat(tag.span(source))
15-
concat(tag.i(nil, class: 'fas fa-long-arrow-alt-right text-info mx-2'))
16-
end
17-
concat(tag.span(target))
18-
end
12+
combine(source, target)
1913
end
2014

21-
private
22-
2315
def source
2416
@source ||= if number_of_bs_request_actions > 1
2517
''
@@ -33,4 +25,14 @@ def target
3325

3426
[bs_request_action.target_project, bs_request_action.target_package].compact.join(' / ')
3527
end
28+
29+
def combine(source, target)
30+
capture do
31+
if source.present?
32+
concat(tag.span(source))
33+
concat(tag.i(nil, class: 'fas fa-long-arrow-alt-right text-info mx-2'))
34+
end
35+
concat(tag.span(target))
36+
end
37+
end
3638
end

src/api/app/views/webui/shared/bs_requests/_request_item.html.haml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
.mb-1
2121
= render partial: 'webui/shared/label', collection: bs_request.labels, as: :label
2222
.mb-1
23-
= render BsRequestActionSourceAndTargetComponent.new(bs_request)
24-
.mb-2.request-index-description.text-truncate
25-
= bs_request.description
23+
- if bs_request_actions_count != 1
24+
= render BsRequestActionSourceAndTargetComponent.new(bs_request)
25+
- else
26+
.mb-2.request-index-description.text-truncate
27+
= render BsRequestActionDescriptionComponent.new(action: bs_request.bs_request_actions.first, text_only: true)
28+
.mb-2.request-index-description.text-truncate
29+
= bs_request.description
2630
.text-end
2731
%span
2832
= render AvatarComponent.new(name: bs_request.creator, email: User.find_by_login(bs_request.creator).email, custom_css: 'align-text-bottom')

src/api/spec/components/previews/bs_request_action_description_component_preview.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,33 @@ def submit_preview
55
render(BsRequestActionDescriptionComponent.new(action: action))
66
end
77

8+
def submit_preview_text_only
9+
action = BsRequestAction.where(type: :submit).last
10+
render(BsRequestActionDescriptionComponent.new(action: action, text_only: true))
11+
end
12+
13+
def delete_preview
14+
action = BsRequestAction.where(type: :delete).last
15+
render(BsRequestActionDescriptionComponent.new(action: action))
16+
end
17+
18+
def delete_preview_text_only
19+
action = BsRequestAction.where(type: :delete).last
20+
render(BsRequestActionDescriptionComponent.new(action: action, text_only: true))
21+
end
22+
823
def add_role_preview
924
action = BsRequestAction.where(type: :add_role).first
1025
render(BsRequestActionDescriptionComponent.new(action: action))
1126
end
27+
28+
def change_devel_preview
29+
action = BsRequestAction.where(type: :change_devel).first
30+
render(BsRequestActionDescriptionComponent.new(action: action))
31+
end
32+
33+
def change_devel_preview_text_only
34+
action = BsRequestAction.where(type: :change_devel).first
35+
render(BsRequestActionDescriptionComponent.new(action: action, text_only: true))
36+
end
1237
end

0 commit comments

Comments
 (0)