Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring tab visibility - use decorator instead of helper #14349

Merged
merged 4 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/api/app/controllers/webui/request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Webui::RequestController < Webui::WebuiController
if: -> { Flipper.enabled?(:request_show_redesign, User.session) }
before_action :set_action_id, only: [:inline_comment, :show, :build_results, :rpm_lint, :changes, :mentioned_issues],
if: -> { Flipper.enabled?(:request_show_redesign, User.session) }
before_action :set_bs_request_action, only: [:show, :build_results, :rpm_lint, :changes, :mentioned_issues],
if: -> { Flipper.enabled?(:request_show_redesign, User.session) }
before_action :set_active_action, only: [:inline_comment, :show, :build_results, :rpm_lint, :changes, :mentioned_issues],
if: -> { Flipper.enabled?(:request_show_redesign, User.session) }
before_action :set_superseded_request, only: [:show, :request_action, :request_action_changes, :build_results, :rpm_lint, :changes, :mentioned_issues]
Expand Down Expand Up @@ -284,7 +286,7 @@ def inline_comment
end

def build_results
redirect_to request_show_path(params[:number], params[:request_action_id]) unless @action[:sprj] || @action[:spkg]
redirect_to request_show_path(params[:number], params[:request_action_id]) unless @bs_request_action.tab_visibility.build

@active_tab = 'build_results'
@project = @staging_project || @action[:sprj]
Expand All @@ -296,7 +298,7 @@ def build_results
end

def rpm_lint
redirect_to request_show_path(params[:number], params[:request_action_id]) unless @action[:sprj] || @action[:spkg]
redirect_to request_show_path(params[:number], params[:request_action_id]) unless @bs_request_action.tab_visibility.rpm_lint

@active_tab = 'rpm_lint'
@ajax_data = {}
Expand All @@ -306,13 +308,13 @@ def rpm_lint
end

def changes
redirect_to request_show_path(params[:number], params[:request_action_id]) unless @action[:type].in?(@actions_for_diff)
redirect_to request_show_path(params[:number], params[:request_action_id]) unless @bs_request_action.tab_visibility.changes

@active_tab = 'changes'
end

def mentioned_issues
redirect_to request_show_path(params[:number], params[:request_action_id]) unless @action[:type].in?(@actions_for_diff)
redirect_to request_show_path(params[:number], params[:request_action_id]) unless @bs_request_action.tab_visibility.issues

@active_tab = 'mentioned_issues'
end
Expand Down Expand Up @@ -488,6 +490,10 @@ def set_action_id
@action_id = params[:request_action_id] || @supported_actions.first&.id || @actions.first.id
end

def set_bs_request_action
@bs_request_action = @bs_request.bs_request_actions.find(@action_id)
end

def set_active_action
@active_action = @actions.find(@action_id)
end
Expand Down Expand Up @@ -560,7 +566,6 @@ def prepare_request_data

# Handling build results
@staging_project = @bs_request.staging_project.name unless @bs_request.staging_project_id.nil?
@actions_for_diff = [:submit, :delete, :maintenance_incident, :maintenance_release]

handle_notification
end
Expand Down
4 changes: 4 additions & 0 deletions src/api/app/models/bs_request_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,10 @@ def event_parameters
params
end

def tab_visibility
BsRequestActionTabVisibility.new(self)
end

private

def cache_diffs
Expand Down
33 changes: 33 additions & 0 deletions src/api/app/models/bs_request_action_tab_visibility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class BsRequestActionTabVisibility
CHANGES_TABS = [:submit, :maintenance_incident, :maintenance_release].freeze

def initialize(bs_request_action)
@action = bs_request_action
end

def build
source_package && !patchinfo_package
end

def rpm_lint
build
end

def changes
(@action.type == :delete && @action.source_package) || @action.type.in?(CHANGES_TABS)
end

def issues
@action.type.in?(CHANGES_TABS)
end

private

def patchinfo_package
@action.type.in?([:maintenance_incident, :maintenance_release]) && @action.source_package == 'patchinfo'
end

def source_package
@action.source_project && @action.source_package
end
end
7 changes: 4 additions & 3 deletions src/api/app/views/webui/request/_request_tabs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
%li.nav-item.scrollable-tab-link
= link_to('Conversation', request_show_path(bs_request.number, actions_count > 1 ? active_action : nil),
class: "nav-link text-nowrap #{active_tab == 'conversation' ? 'active' : ''}")
- if (action[:sprj] || action[:spkg]) && !(action[:type].in?([:maintenance_incident, :maintenance_release]) && action[:spkg] == 'patchinfo')
- if bs_request_action.tab_visibility.build
%li.nav-item.scrollable-tab-link.active
= link_to('Build Results', request_build_results_path(bs_request.number, actions_count > 1 ? active_action : nil),
class: "nav-link text-nowrap #{active_tab == 'build_results' ? 'active' : ''}")
- if bs_request_action.tab_visibility.rpm_lint
%li.nav-item.scrollable-tab-link
= link_to('RPM Lint', request_rpm_lint_path(bs_request.number, actions_count > 1 ? active_action : nil),
class: "nav-link text-nowrap #{active_tab == 'rpm_lint' ? 'active' : ''}")
- if action[:type].in?(actions_for_diff)
- if bs_request_action.tab_visibility.changes
%li.nav-item.scrollable-tab-link
= link_to('Changes', request_changes_path(bs_request.number, actions_count > 1 ? active_action : nil),
class: "nav-link text-nowrap #{active_tab == 'changes' ? 'active' : ''}")
- if action[:type].in?(actions_for_diff)
- if bs_request_action.tab_visibility.issues
%li.nav-item.scrollable-tab-link
= link_to(request_mentioned_issues_path(bs_request.number, actions_count > 1 ? active_action : nil),
class: "nav-link text-nowrap #{active_tab == 'mentioned_issues' ? 'active' : ''}") do
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/views/webui/request/beta_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
prev_action: @prev_action, next_action: @next_action, supported_actions: @supported_actions,
diff_to_superseded_id: @diff_to_superseded_id, diff_limit: @diff_limit, page_name: '' }
= render partial: 'request_tabs',
locals: { actions_for_diff: @actions_for_diff, bs_request: @bs_request, action: @action, issues: @issues,
active_action: @active_action, actions_count: @supported_actions.count, active_tab: @active_tab }
locals: { bs_request: @bs_request, bs_request_action: @bs_request_action, issues: @issues, active_action: @active_action,
actions_count: @supported_actions.count, active_tab: @active_tab }
.container.p-4
.row
.col-md-12
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/views/webui/request/build_results.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
prev_action: @prev_action, next_action: @next_action, supported_actions: @supported_actions,
diff_to_superseded_id: @diff_to_superseded_id, diff_limit: @diff_limit, page_name: 'request_build_results' }
= render partial: 'request_tabs',
locals: { actions_for_diff: @actions_for_diff, bs_request: @bs_request, action: @action, issues: @issues,
active_action: @active_action, actions_count: @supported_actions.count, active_tab: @active_tab }
locals: { bs_request: @bs_request, bs_request_action: @bs_request_action, issues: @issues, active_action: @active_action,
actions_count: @supported_actions.count, active_tab: @active_tab }
.container.p-4
- if @buildable
.build-results-content{ data: @ajax_data }
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/views/webui/request/changes.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
prev_action: @prev_action, next_action: @next_action, supported_actions: @supported_actions,
diff_to_superseded_id: @diff_to_superseded_id, diff_limit: @diff_limit, page_name: 'request_changes' }
= render partial: 'request_tabs',
locals: { actions_for_diff: @actions_for_diff, bs_request: @bs_request, action: @action, issues: @issues,
active_action: @active_action, actions_count: @supported_actions.count, active_tab: @active_tab }
locals: { bs_request: @bs_request, bs_request_action: @bs_request_action, issues: @issues, active_action: @active_action,
actions_count: @supported_actions.count, active_tab: @active_tab }
.container.p-4
.tab-content.sourcediff
= render SourcediffComponent.new(bs_request: @bs_request, action: @action, index: 0)
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/views/webui/request/mentioned_issues.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
prev_action: @prev_action, next_action: @next_action, supported_actions: @supported_actions,
diff_to_superseded_id: @diff_to_superseded_id, diff_limit: @diff_limit, page_name: 'request_mentioned_issues' }
= render partial: 'request_tabs',
locals: { actions_for_diff: @actions_for_diff, bs_request: @bs_request, action: @action, issues: @issues,
active_action: @active_action, actions_count: @supported_actions.count, active_tab: @active_tab }
locals: { bs_request: @bs_request, bs_request_action: @bs_request_action, issues: @issues, active_action: @active_action,
actions_count: @supported_actions.count, active_tab: @active_tab }
.container.p-4
- if @issues.empty?
%p No issues are mentioned for this request action.
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/views/webui/request/rpm_lint.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
prev_action: @prev_action, next_action: @next_action, supported_actions: @supported_actions,
diff_to_superseded_id: @diff_to_superseded_id, diff_limit: @diff_limit, page_name: 'request_rpm_lint' }
= render partial: 'request_tabs',
locals: { actions_for_diff: @actions_for_diff, bs_request: @bs_request, action: @action, issues: @issues,
active_action: @active_action, actions_count: @supported_actions.count, active_tab: @active_tab }
locals: { bs_request: @bs_request, bs_request_action: @bs_request_action, issues: @issues, active_action: @active_action,
actions_count: @supported_actions.count, active_tab: @active_tab }
.container.p-4
- if @action[:spkg]
.rpm-lint-content{ data: @ajax_data }
Expand Down
10 changes: 10 additions & 0 deletions src/api/spec/features/webui/requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@
visit request_show_path(delete_bs_request)
expect(page).to have_text('Project Maintainers')
end

it 'a delete request does not show the Changes Tab' do
visit request_show_path(delete_bs_request)
expect(page).not_to have_text('Changes')
end

it 'a delete request does not show the Issues Tab' do
visit request_show_path(delete_bs_request)
expect(page).not_to have_text('Issues')
end
end

describe 'for a request with a deleted target project' do
Expand Down