Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
955d22cb
Commit
955d22cb
authored
Jan 13, 2021
by
Eugenia Grieff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move template logic to helper
- Modify count format precision - Fix specs
parent
5e93c81a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
24 deletions
+40
-24
app/helpers/groups_helper.rb
app/helpers/groups_helper.rb
+17
-4
app/models/group.rb
app/models/group.rb
+0
-6
app/services/groups/open_issues_count_service.rb
app/services/groups/open_issues_count_service.rb
+2
-0
app/views/layouts/nav/sidebar/_group.html.haml
app/views/layouts/nav/sidebar/_group.html.haml
+2
-4
spec/helpers/groups_helper_spec.rb
spec/helpers/groups_helper_spec.rb
+19
-10
No files found.
app/helpers/groups_helper.rb
View file @
955d22cb
...
...
@@ -61,6 +61,14 @@ module GroupsHelper
can?
(
current_user
,
:set_emails_disabled
,
group
)
&&
!
group
.
parent
&
.
emails_disabled?
end
def
group_open_issues_count
(
group
)
if
Feature
.
enabled?
(
:cached_sidebar_open_issues_count
,
group
)
cached_open_group_issues_count
(
group
)
else
number_with_delimiter
(
group_issues_count
(
state:
'opened'
))
end
end
def
group_issues_count
(
state
:)
IssuesFinder
.
new
(
current_user
,
group_id:
@group
.
id
,
state:
state
,
non_archived:
true
,
include_subgroups:
true
)
...
...
@@ -69,10 +77,15 @@ module GroupsHelper
end
def
cached_open_group_issues_count
(
group
)
issues_count
=
group
.
open_issues_count
(
current_user
)
if
issues_count
>
1000
ActiveSupport
::
NumberHelper
.
number_to_human
(
issues_count
,
units:
{
thousand:
'K'
},
precision:
2
)
count_service
=
Groups
::
OpenIssuesCountService
issues_count
=
count_service
.
new
(
group
,
current_user
).
count
if
issues_count
>
count_service
::
CACHED_COUNT_THRESHOLD
ActiveSupport
::
NumberHelper
.
number_to_human
(
issues_count
,
units:
{
thousand:
'k'
,
million:
'm'
},
precision:
1
,
significant:
false
,
format:
'%n%u'
)
else
number_with_delimiter
(
issues_count
)
end
...
...
app/models/group.rb
View file @
955d22cb
...
...
@@ -620,12 +620,6 @@ class Group < Namespace
Gitlab
::
ServiceDesk
.
supported?
&&
all_projects
.
service_desk_enabled
.
exists?
end
# rubocop: disable CodeReuse/ServiceClass
def
open_issues_count
(
current_user
=
nil
)
Groups
::
OpenIssuesCountService
.
new
(
self
,
current_user
).
count
end
# rubocop: enable CodeReuse/ServiceClass
private
def
update_two_factor_requirement
...
...
app/services/groups/open_issues_count_service.rb
View file @
955d22cb
...
...
@@ -28,6 +28,8 @@ module Groups
end
end
private
def
cache_options
super
.
merge
({
expires_in:
EXPIRATION_TIME
})
end
...
...
app/views/layouts/nav/sidebar/_group.html.haml
View file @
955d22cb
-
issues_count
=
group_open_issues_count
(
@group
)
-
merge_requests_count
=
group_merge_requests_count
(
state:
'opened'
)
-
if
Feature
.
enabled?
(
:cached_sidebar_open_issues_count
,
@group
)
-
issues_count
=
cached_open_group_issues_count
(
@group
)
-
else
-
issues_count
=
number_with_delimiter
(
group_issues_count
(
state:
'opened'
))
.nav-sidebar
{
class:
(
"sidebar-collapsed-desktop"
if
collapsed_sidebar?
),
**
tracking_attrs
(
'groups_side_navigation'
,
'render'
,
'groups_side_navigation'
)
}
.nav-sidebar-inner-scroll
...
...
@@ -58,6 +55,7 @@
%span
.nav-item-name
=
_
(
'Issues'
)
%span
.badge.badge-pill.count
=
issues_count
%ul
.sidebar-sub-level-items
{
data:
{
qa_selector:
'group_issues_sidebar_submenu'
}
}
=
nav_link
(
path:
[
'groups#issues'
,
'labels#index'
,
'milestones#index'
,
'iterations#index'
],
html_options:
{
class:
"fly-out-top-item"
}
)
do
=
link_to
issues_group_path
(
@group
)
do
...
...
spec/helpers/groups_helper_spec.rb
View file @
955d22cb
...
...
@@ -445,36 +445,45 @@ RSpec.describe GroupsHelper do
end
end
describe
`#cached_open_group_issues_count`
do
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
,
name:
'group'
)
}
describe
'#cached_open_group_issues_count'
do
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:group
)
{
create
(
:group
,
name:
'group'
)
}
let_it_be
(
:count_service
)
{
Groups
::
OpenIssuesCountService
}
before
do
allow
(
helper
).
to
receive
(
:current_user
)
{
current_user
}
end
it
'returns all digits for count value under 1000'
do
allow
(
group
).
to
receive
(
:open_issues_count
).
with
(
current_user
)
{
999
}
allow_next_instance_of
(
count_service
)
do
|
service
|
allow
(
service
).
to
receive
(
:count
).
and_return
(
999
)
end
expect
(
helper
.
cached_open_group_issues_count
(
group
)).
to
eq
(
'999'
)
end
it
'returns truncated digits for count value over 1000'
do
allow
(
group
).
to
receive
(
:open_issues_count
).
with
(
current_user
)
{
2300
}
allow_next_instance_of
(
count_service
)
do
|
service
|
allow
(
service
).
to
receive
(
:count
).
and_return
(
2300
)
end
expect
(
helper
.
cached_open_group_issues_count
(
group
)).
to
eq
(
'2.3
K
'
)
expect
(
helper
.
cached_open_group_issues_count
(
group
)).
to
eq
(
'2.3
k
'
)
end
it
'returns truncated digits for count value over 10000'
do
allow
(
group
).
to
receive
(
:open_issues_count
).
with
(
current_user
)
{
12560
}
allow_next_instance_of
(
count_service
)
do
|
service
|
allow
(
service
).
to
receive
(
:count
).
and_return
(
12560
)
end
expect
(
helper
.
cached_open_group_issues_count
(
group
)).
to
eq
(
'1
3 K
'
)
expect
(
helper
.
cached_open_group_issues_count
(
group
)).
to
eq
(
'1
2.6k
'
)
end
it
'returns truncated digits for count value over 100000'
do
allow
(
group
).
to
receive
(
:open_issues_count
).
with
(
current_user
)
{
112560
}
allow_next_instance_of
(
count_service
)
do
|
service
|
allow
(
service
).
to
receive
(
:count
).
and_return
(
112560
)
end
expect
(
helper
.
cached_open_group_issues_count
(
group
)).
to
eq
(
'11
0 K
'
)
expect
(
helper
.
cached_open_group_issues_count
(
group
)).
to
eq
(
'11
2.6k
'
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment