-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move request action info to a component
In more than one place in the application, we need to know the source and target packages related to the request action, if any. So we extract the code from NotificationActionDescriptionComponent and create an independent component for the source and target information.
- Loading branch information
Showing
2 changed files
with
38 additions
and
33 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/api/app/components/bs_request_action_source_and_target_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class BsRequestActionSourceAndTargetComponent < ApplicationComponent | ||
attr_reader :bs_request_action, :number_of_bs_request_actions | ||
|
||
def initialize(bs_request) | ||
super | ||
|
||
@bs_request = bs_request | ||
@bs_request_action = @bs_request.bs_request_actions.first | ||
@number_of_bs_request_actions = @bs_request.bs_request_actions.size | ||
end | ||
|
||
def call | ||
capture do | ||
if source.present? | ||
concat(tag.span(source)) | ||
concat(tag.i(nil, class: 'fas fa-long-arrow-alt-right text-info mx-2')) | ||
end | ||
concat(tag.span(target)) | ||
end | ||
end | ||
|
||
private | ||
|
||
def source | ||
@source ||= if number_of_bs_request_actions > 1 | ||
'' | ||
else | ||
[bs_request_action.source_project, bs_request_action.source_package].compact.join(' / ') | ||
end | ||
end | ||
|
||
def target | ||
return bs_request_action.target_project if number_of_bs_request_actions > 1 | ||
|
||
[bs_request_action.target_project, bs_request_action.target_package].compact.join(' / ') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters