Skip to content

Commit

Permalink
Introduce a more detailed description of multi action requests
Browse files Browse the repository at this point in the history
  • Loading branch information
hellcp-work authored and hennevogel committed Jan 31, 2025
1 parent 434c4b5 commit bbaeefe
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 5 deletions.
96 changes: 96 additions & 0 deletions src/api/app/components/bs_request_description_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# This component renders the request description based on the type of the actions

class BsRequestDescriptionComponent < ApplicationComponent
attr_reader :bs_request

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(bs_request:)
super
@bs_request = bs_request

Check warning on line 13 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L12-L13

Added lines #L12 - L13 were not covered by tests
end

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/BlockLength
# rubocop:disable Style/FormatString
def call
# creator = action.bs_request.creator
types = bs_request.bs_request_actions.group_by(&:type)
description = []

Check warning on line 23 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L22-L23

Added lines #L22 - L23 were not covered by tests

types.each do |type, actions|
source_packages = actions.map(&:source_package).uniq.map { |a| tag.b(a) }
source_packages = shorten_list(source_packages)
source_projects = actions.map(&:source_project).uniq.map { |a| tag.b(a) }
source_projects = shorten_list(source_projects)
source_container = if actions.length == 1 && source_packages.length == 1
"package #{source_projects.first} / #{source_packages.first}"
elsif source_packages
"#{'package'.pluralize(source_packages.count)} #{source_packages.to_sentence} from #{'project'.pluralize(source_projects.count)} #{source_projects.to_sentence}"

Check warning on line 33 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L25-L33

Added lines #L25 - L33 were not covered by tests
else
"#{'project'.pluralize(source_projects.count)} #{source_projects.to_sentence}"

Check warning on line 35 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L35

Added line #L35 was not covered by tests
end
source_container = tag.span(sanitize(source_container), data: { bs_toggle: 'popover', bs_content: actions.map { |a| tag.b("#{a.source_project} / #{a.source_package}") }.uniq.to_sentence })

Check warning on line 37 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L37

Added line #L37 was not covered by tests

target_projects = actions.map(&:target_project).uniq.map { |a| tag.b(a) }
target_projects = shorten_list(target_projects)
target_container = "#{'project'.pluralize(target_projects.count)} #{target_projects.to_sentence}"
target_container = tag.span(sanitize(target_container), data: { bs_toggle: 'popover', bs_content: actions.map { |a| tag.b("#{a.target_project} / #{a.target_package}") }.uniq.to_sentence })

Check warning on line 42 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L39-L42

Added lines #L39 - L42 were not covered by tests

source_and_target_container = [source_container, target_container].join(tag.i(nil, class: 'fas fa-long-arrow-alt-right text-info mx-2'))

Check warning on line 44 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L44

Added line #L44 was not covered by tests

description << case type

Check warning on line 46 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L46

Added line #L46 was not covered by tests
when 'submit'
'Submit %{source_and_target_container}' % { source_and_target_container: source_and_target_container }

Check warning on line 48 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L48

Added line #L48 was not covered by tests
when 'delete'
target = actions.map do |a|
string = ''
string += "repository #{tag.b(a.target_repository)} for " if a.target_repository
string += a.target_package ? 'package ' : 'project '
string += "#{tag.b(a.target_project)} "
string += "/ #{tag.b(a.target_package)}"
string

Check warning on line 56 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L50-L56

Added lines #L50 - L56 were not covered by tests
end.to_sentence
'Delete %{target}' %

Check warning on line 58 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L58

Added line #L58 was not covered by tests
{ target: target }
when 'add_role', 'set_bugowner'
'Change role for %{target_container}' % { target_container: target_container }

Check warning on line 61 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L61

Added line #L61 was not covered by tests
when 'change_devel'
'Set %{source_container} to be devel project/package of %{target_container}' %

Check warning on line 63 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L63

Added line #L63 was not covered by tests
{ source_container: source_container, target_container: target_container }
when 'maintenance_incident'
'Submit update from %{source_and_target_container}' %

Check warning on line 66 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L66

Added line #L66 was not covered by tests
{ source_and_target_container: source_and_target_container }
when 'maintenance_release'
'Maintenance release %{source_and_target_container}' %

Check warning on line 69 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L69

Added line #L69 was not covered by tests
{ source_and_target_container: source_and_target_container }
when 'release'
'Release %{source_and_target_container}' %

Check warning on line 72 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L72

Added line #L72 was not covered by tests
{ source_and_target_container: source_and_target_container }
end
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
sanitize(description.to_sentence)

Check warning on line 79 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L79

Added line #L79 was not covered by tests
end

private

def shorten_list(array, limit = 3)
if array.count > limit
total = array.count - (limit - 1)
array = array.take((limit - 1))
array << "#{total} #{'other'.pluralize(total)}"

Check warning on line 88 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L85-L88

Added lines #L85 - L88 were not covered by tests
end
array

Check warning on line 90 in src/api/app/components/bs_request_description_component.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/components/bs_request_description_component.rb#L90

Added line #L90 was not covered by tests
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/BlockLength
# rubocop:enable Style/FormatString
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
.mb-1
= render partial: 'webui/shared/label', collection: bs_request.labels, as: :label
.mb-1
- if bs_request_actions_count != 1
= render BsRequestActionSourceAndTargetComponent.new(bs_request)
- else
.mb-2.request-index-description.text-truncate
= render BsRequestActionDescriptionComponent.new(action: bs_request.bs_request_actions.first, text_only: true)
= render BsRequestDescriptionComponent.new(bs_request:)
.mb-2.request-index-description.text-truncate
= bs_request.description
.text-end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class BsRequestDescriptionComponentPreview < ViewComponent::Preview
# Preview at http://HOST:PORT/rails/view_components/bs_request_description_component/submit_preview
def submit_preview
bs_request = BsRequestAction.where(type: :submit).last.bs_request
render(BsRequestDescriptionComponent.new(bs_request: bs_request))
end

def submit_preview_text_only
bs_request = BsRequestAction.where(type: :submit).last
render(BsRequestDescriptionComponent.new(bs_request: bs_request))
end

def delete_preview
bs_request = BsRequestAction.where(type: :delete).last
render(BsRequestDescriptionComponent.new(bs_request: bs_request))
end

def delete_preview_text_only
bs_request = BsRequestAction.where(type: :delete).last
render(BsRequestDescriptionComponent.new(bs_request: bs_request))
end

def add_role_preview
bs_request = BsRequestAction.where(type: :add_role).first
render(BsRequestDescriptionComponent.new(bs_request: bs_request))
end

def change_devel_preview
bs_request = BsRequestAction.where(type: :change_devel).first
render(BsRequestDescriptionComponent.new(bs_request: bs_request))
end

def change_devel_preview_text_only
bs_request = BsRequestAction.where(type: :change_devel).first
render(BsRequestDescriptionComponent.new(bs_request: bs_request))
end
end

0 comments on commit bbaeefe

Please sign in to comment.