BigW Consortium Gitlab

Commit 868cb430 by Sean McGivern

Fix subgroup issue and MR pages empty states and counts

Previously, these wouldn't count issues or MRs in subgroups - meaning that if _this_ group had no issues or MRs, we'd show the empty state, which was wrong.
parent 58a312f5
...@@ -18,10 +18,6 @@ class Groups::ApplicationController < ApplicationController ...@@ -18,10 +18,6 @@ class Groups::ApplicationController < ApplicationController
@projects ||= GroupProjectsFinder.new(group: group, current_user: current_user).execute @projects ||= GroupProjectsFinder.new(group: group, current_user: current_user).execute
end end
def group_merge_requests
@group_merge_requests = MergeRequestsFinder.new(current_user, group_id: @group.id).execute
end
def authorize_admin_group! def authorize_admin_group!
unless can?(current_user, :admin_group, group) unless can?(current_user, :admin_group, group)
return render_404 return render_404
......
...@@ -14,7 +14,6 @@ class GroupsController < Groups::ApplicationController ...@@ -14,7 +14,6 @@ class GroupsController < Groups::ApplicationController
before_action :authorize_create_group!, only: [:new] before_action :authorize_create_group!, only: [:new]
before_action :group_projects, only: [:projects, :activity, :issues, :merge_requests] before_action :group_projects, only: [:projects, :activity, :issues, :merge_requests]
before_action :group_merge_requests, only: [:merge_requests]
before_action :event_filter, only: [:activity] before_action :event_filter, only: [:activity]
before_action :user_actions, only: [:show, :subgroups] before_action :user_actions, only: [:show, :subgroups]
......
...@@ -19,6 +19,20 @@ module GroupsHelper ...@@ -19,6 +19,20 @@ module GroupsHelper
can?(current_user, :change_share_with_group_lock, group) can?(current_user, :change_share_with_group_lock, group)
end end
def group_issues_count(state:)
IssuesFinder
.new(current_user, group_id: @group.id, state: state, non_archived: true, include_subgroups: true)
.execute
.count
end
def group_merge_requests_count(state:)
MergeRequestsFinder
.new(current_user, group_id: @group.id, state: state, non_archived: true, include_subgroups: true)
.execute
.count
end
def group_icon(group, options = {}) def group_icon(group, options = {})
img_path = group_icon_url(group, options) img_path = group_icon_url(group, options)
image_tag img_path, options image_tag img_path, options
...@@ -77,10 +91,6 @@ module GroupsHelper ...@@ -77,10 +91,6 @@ module GroupsHelper
end end
end end
def group_issues(group)
IssuesFinder.new(current_user, group_id: group.id).execute
end
def remove_group_message(group) def remove_group_message(group)
_("You are going to remove %{group_name}. Removed groups CANNOT be restored! Are you ABSOLUTELY sure?") % _("You are going to remove %{group_name}. Removed groups CANNOT be restored! Are you ABSOLUTELY sure?") %
{ group_name: group.name } { group_name: group.name }
......
- page_title "Issues" - page_title "Issues"
- group_issues_exists = group_issues(@group).exists?
= content_for :meta_tags do = content_for :meta_tags do
= auto_discovery_link_tag(:atom, params.merge(rss_url_options), title: "#{@group.name} issues") = auto_discovery_link_tag(:atom, params.merge(rss_url_options), title: "#{@group.name} issues")
- content_for :page_specific_javascripts do - content_for :page_specific_javascripts do
= webpack_bundle_tag 'common_vue' = webpack_bundle_tag 'common_vue'
- if group_issues_exists - if group_issues_count(state: 'all').zero?
= render 'shared/empty_states/issues', project_select_button: true
- else
.top-area .top-area
= render 'shared/issuable/nav', type: :issues = render 'shared/issuable/nav', type: :issues
.nav-controls .nav-controls
...@@ -19,5 +20,3 @@ ...@@ -19,5 +20,3 @@
= render 'shared/issuable/search_bar', type: :issues = render 'shared/issuable/search_bar', type: :issues
= render 'shared/issues' = render 'shared/issues'
- else
= render 'shared/empty_states/issues', project_select_button: true
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
- content_for :page_specific_javascripts do - content_for :page_specific_javascripts do
= webpack_bundle_tag 'common_vue' = webpack_bundle_tag 'common_vue'
- if @group_merge_requests.empty? - if group_merge_requests_count(state: 'all').zero?
= render 'shared/empty_states/merge_requests', project_select_button: true = render 'shared/empty_states/merge_requests', project_select_button: true
- else - else
.top-area .top-area
......
- issues_count = IssuesFinder.new(current_user, group_id: @group.id, state: 'opened').execute.count - issues_count = group_issues_count(state: 'opened')
- merge_requests_count = MergeRequestsFinder.new(current_user, group_id: @group.id, state: 'opened', non_archived: true).execute.count - merge_requests_count = group_merge_requests_count(state: 'opened')
- issues_sub_menu_items = ['groups#issues', 'labels#index', 'milestones#index'] - issues_sub_menu_items = ['groups#issues', 'labels#index', 'milestones#index']
.nav-sidebar{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) } .nav-sidebar{ class: ("sidebar-collapsed-desktop" if collapsed_sidebar?) }
......
---
title: Ensure group issues and merge requests pages show results from subgroups when
there are no results from the current group
merge_request: 17312
author:
type: fixed
require 'spec_helper' require 'spec_helper'
feature 'Groups Merge Requests Empty States' do feature 'Group empty states' do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:user) { create(:group_member, :developer, user: create(:user), group: group ).user } let(:user) { create(:group_member, :developer, user: create(:user), group: group ).user }
...@@ -8,62 +8,100 @@ feature 'Groups Merge Requests Empty States' do ...@@ -8,62 +8,100 @@ feature 'Groups Merge Requests Empty States' do
sign_in(user) sign_in(user)
end end
context 'group has a project' do [:issue, :merge_request].each do |issuable|
let(:project) { create(:project, namespace: group) } issuable_name = issuable.to_s.humanize.downcase
project_relation = issuable == :issue ? :project : :source_project
before do context "for #{issuable_name}s" do
project.add_master(user) let(:path) { public_send(:"#{issuable}s_group_path", group) }
end
context 'the project has a merge request' do context 'group has a project' do
before do let(:project) { create(:project, namespace: group) }
create(:merge_request, source_project: project)
visit merge_requests_group_path(group) before do
end project.add_master(user)
end
it 'should not display an empty state' do context "the project has #{issuable_name}s" do
expect(page).not_to have_selector('.empty-state') before do
end create(issuable, project_relation => project)
end
context 'the project has no merge requests', :js do visit path
before do end
visit merge_requests_group_path(group)
end
it 'should display an empty state' do it 'does not display an empty state' do
expect(page).to have_selector('.empty-state') expect(page).not_to have_selector('.empty-state')
end end
end
context "the project has no #{issuable_name}s", :js do
before do
visit path
end
it 'displays an empty state' do
expect(page).to have_selector('.empty-state')
end
it "shows a new #{issuable_name} button" do
within '.empty-state' do
expect(page).to have_content("create #{issuable_name}")
end
end
it "the new #{issuable_name} button opens a project dropdown" do
within '.empty-state' do
find('.new-project-item-select-button').click
end
it 'should show a new merge request button' do expect(page).to have_selector('.ajax-project-dropdown')
within '.empty-state' do end
expect(page).to have_content('create merge request')
end end
end end
it 'the new merge request button opens a project dropdown' do context 'group without a project' do
within '.empty-state' do context 'group has a subgroup', :nested_groups do
find('.new-project-item-select-button').click let(:subgroup) { create(:group, parent: group) }
end let(:subgroup_project) { create(:project, namespace: subgroup) }
expect(page).to have_selector('.ajax-project-dropdown') context "the project has #{issuable_name}s" do
end before do
end create(issuable, project_relation => subgroup_project)
end
context 'group without a project' do visit path
before do end
visit merge_requests_group_path(group)
end
it 'should display an empty state' do it 'does not display an empty state' do
expect(page).to have_selector('.empty-state') expect(page).not_to have_selector('.empty-state')
end end
end
it 'should not show a new merge request button' do context "the project has no #{issuable_name}s" do
within '.empty-state' do before do
expect(page).not_to have_link('create merge request') visit path
end
it 'displays an empty state' do
expect(page).to have_selector('.empty-state')
end
end
end
context 'group has no subgroups' do
before do
visit path
end
it 'displays an empty state' do
expect(page).to have_selector('.empty-state')
end
it "shows a new #{issuable_name} button" do
within '.empty-state' do
expect(page).not_to have_link("create #{issuable_name}")
end
end
end
end end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment