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.
Jump to
Jump to file
Failed to load files.
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 @@
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 @@
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

Check warning on line 289 in src/api/app/controllers/webui/request_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/request_controller.rb#L289

Added line #L289 was not covered by tests

@active_tab = 'build_results'
@project = @staging_project || @action[:sprj]
Expand All @@ -296,7 +298,7 @@
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

Check warning on line 301 in src/api/app/controllers/webui/request_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/request_controller.rb#L301

Added line #L301 was not covered by tests

@active_tab = 'rpm_lint'
@ajax_data = {}
Expand All @@ -306,13 +308,13 @@
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

Check warning on line 311 in src/api/app/controllers/webui/request_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/request_controller.rb#L311

Added line #L311 was not covered by tests

@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

Check warning on line 317 in src/api/app/controllers/webui/request_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/request_controller.rb#L317

Added line #L317 was not covered by tests

@active_tab = 'mentioned_issues'
end
Expand Down Expand Up @@ -488,6 +490,10 @@
@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)

Check warning on line 494 in src/api/app/controllers/webui/request_controller.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/controllers/webui/request_controller.rb#L494

Added line #L494 was not covered by tests
end

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

# 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 @@
params
end

def tab_visibility
BsRequestActionTabVisibility.new(self)

Check warning on line 868 in src/api/app/models/bs_request_action.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/models/bs_request_action.rb#L868

Added line #L868 was not covered by tests
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

Check warning on line 5 in src/api/app/models/bs_request_action_tab_visibility.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/models/bs_request_action_tab_visibility.rb#L5

Added line #L5 was not covered by tests
end

def build
source_package && !patchinfo_package

Check warning on line 9 in src/api/app/models/bs_request_action_tab_visibility.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/models/bs_request_action_tab_visibility.rb#L9

Added line #L9 was not covered by tests
end

def rpm_lint
build

Check warning on line 13 in src/api/app/models/bs_request_action_tab_visibility.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/models/bs_request_action_tab_visibility.rb#L13

Added line #L13 was not covered by tests
end

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

Check warning on line 17 in src/api/app/models/bs_request_action_tab_visibility.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/models/bs_request_action_tab_visibility.rb#L17

Added line #L17 was not covered by tests
end

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

Check warning on line 21 in src/api/app/models/bs_request_action_tab_visibility.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/models/bs_request_action_tab_visibility.rb#L21

Added line #L21 was not covered by tests
end

private

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

Check warning on line 27 in src/api/app/models/bs_request_action_tab_visibility.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/models/bs_request_action_tab_visibility.rb#L27

Added line #L27 was not covered by tests
end

def source_package
@action.source_project && @action.source_package

Check warning on line 31 in src/api/app/models/bs_request_action_tab_visibility.rb

View check run for this annotation

Codecov / codecov/patch

src/api/app/models/bs_request_action_tab_visibility.rb#L31

Added line #L31 was not covered by tests
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