Skip to content

Commit

Permalink
Reuse request action description in a text mode too
Browse files Browse the repository at this point in the history
  • Loading branch information
ncounter committed Jan 27, 2025
1 parent 09f7c57 commit ab22bc0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
43 changes: 30 additions & 13 deletions src/api/app/components/bs_request_action_description_component.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
# This component renders the request action description based on the type of the action

class BsRequestActionDescriptionComponent < ApplicationComponent
attr_reader :action
attr_reader :action, :text_only

delegate :project_or_package_link, to: :helpers
delegate :user_with_realname_and_icon, to: :helpers
delegate :requester_str, to: :helpers
delegate :creator_intentions, to: :helpers

def initialize(action:)
def initialize(action:, text_only: false)
super
@action = action
@text_only = text_only
end

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Rails/OutputSafety
# rubocop:disable Style/FormatString
def description
creator = action.bs_request.creator

source_project_hash = { project: action.source_project, package: action.source_package, trim_to: nil }
target_project_hash = { project: action.target_project, package: action.target_package, trim_to: nil }

source_container = project_or_package_link(source_project_hash)
target_container = project_or_package_link(target_project_hash)
source_and_target_component = BsRequestActionSourceAndTargetComponent.new(action.bs_request)

source_text = source_and_target_component.source
target_text = source_and_target_component.target
source_and_target_text = source_and_target_component.call

source_container = text_only ? source_text : project_or_package_link(source_project_hash)
target_container = text_only ? target_text : project_or_package_link(target_project_hash)
source_and_target_container = if text_only
source_and_target_text
else
tag.span(source_container)
.concat(tag.i(nil, class: 'fas fa-long-arrow-alt-right text-info mx-2'))
.concat(tag.span(target_container))
end

description = case action.type
when 'submit'
'Submit %{source_container} to %{target_container}' %
{ source_container: source_container, target_container: target_container }
'Submit %{source_and_target_container}' % { source_and_target_container: source_and_target_container }
when 'delete'
target_repository = "repository #{link_to(action.target_repository, repositories_path(target_project_hash))} for " if action.target_repository
repository_content = text_only ? action.target_repository : link_to(action.target_repository, repositories_path(target_project_hash))
target_repository = "repository #{repository_content} for " if action.target_repository

'Delete %{target_repository}%{target_container}' %
{ target_repository: target_repository, target_container: target_container }
Expand All @@ -44,21 +60,22 @@ def description
'Set %{source_container} to be devel project/package of %{target_container}' %
{ source_container: source_container, target_container: target_container }
when 'maintenance_incident'
'Submit update from %{source_container} to %{target_container}' %
{ source_container: source_container, target_container: target_container }
'Submit update from %{source_and_target_container}' %
{ source_and_target_container: source_and_target_container }
when 'maintenance_release'
'Maintenance release %{source_container} to %{target_container}' %
{ source_container: source_container, target_container: target_container }
'Maintenance release %{source_and_target_container}' %
{ source_and_target_container: source_and_target_container }
when 'release'
'Release %{source_container} to %{target_container}' %
{ source_container: source_container, target_container: target_container }
'Release %{source_and_target_container}' %
{ source_and_target_container: source_and_target_container }
end

# HACK: this is just a porting of the already existing way of passing the string to the view
# TODO: refactor in order to get rid of the `html_safe` tagging
description.html_safe
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Rails/OutputSafety
# rubocop:enable Style/FormatString
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def call
end
end

private

def source
@source ||= if number_of_bs_request_actions > 1
''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
.mb-1
= render partial: 'webui/shared/label', collection: bs_request.labels, as: :label
.mb-1
= render BsRequestActionSourceAndTargetComponent.new(bs_request)
.mb-2.request-index-description.text-truncate
= bs_request.description
- if bs_request_actions_count != 1
= render BsRequestActionSourceAndTargetComponent.new(bs_request)
.mb-2.request-index-description.text-truncate
= bs_request.description
- else
.mb-2.request-index-description.text-truncate
= render BsRequestActionDescriptionComponent.new(action: bs_request.bs_request_actions.first, text_only: true)
.text-end
%span
= render AvatarComponent.new(name: bs_request.creator, email: User.find_by_login(bs_request.creator).email, custom_css: 'align-text-bottom')
Expand Down

0 comments on commit ab22bc0

Please sign in to comment.