Skip to content

Commit 814c381

Browse files
Matthew Brewergregbell
authored andcommitted
activeadmin#293 - Scopes shouldn't show up when no filter results
1 parent de6d7fb commit 814c381

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

features/index/index_scopes.feature

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ Feature: Index Scoping
2626
And I should see the scope "All" with the count 10
2727
And I should see 10 posts in the table
2828

29+
Scenario: Viewing resources with one scope and no results
30+
Given 10 posts exist
31+
And an index configuration of:
32+
"""
33+
ActiveAdmin.register Post do
34+
scope :all, :default => true
35+
filter :title
36+
end
37+
"""
38+
39+
When I fill in "Search Title" with "Hello World 17"
40+
And I press "Filter"
41+
And I should not see the scope "All"
42+
43+
When I am on the index page for posts
44+
Then I should see the scope "All" selected
45+
2946
Scenario: Viewing resources when scoping
3047
Given 6 posts exist
3148
And 4 published posts exist
@@ -46,8 +63,8 @@ Feature: Index Scoping
4663
And I should see 4 posts in the table
4764

4865
Scenario: Viewing resources with optional scopes
49-
Given 10 posts exist
50-
And an index configuration of:
66+
Given 10 posts exist
67+
And an index configuration of:
5168
"""
5269
ActiveAdmin.register Post do
5370
scope :all, :if => proc { false }
@@ -62,11 +79,11 @@ Feature: Index Scoping
6279
end
6380
end
6481
"""
65-
Then I should see the scope "Default" selected
66-
And I should not see the scope "All"
67-
And I should not see the scope "Today"
68-
And I should see the scope "Shown"
69-
And I should see the scope "Default" with the count 10
82+
Then I should see the scope "Default" selected
83+
And I should not see the scope "All"
84+
And I should not see the scope "Today"
85+
And I should see the scope "Shown"
86+
And I should see the scope "Default" with the count 10
7087

7188
Scenario: Viewing resources with mulitple scopes as blocks
7289
Given 10 posts exist

lib/active_admin/views/components/scopes.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ module Views
66
class Scopes < ActiveAdmin::Component
77
builder_method :scopes_renderer
88

9+
include ActiveAdmin::ScopeChain
10+
911
def default_class_name
1012
"scopes table_tools_segmented_control"
1113
end
12-
14+
1315
def tag_name
1416
'ul'
1517
end
1618

1719
def build(scopes)
18-
scopes.each do |scope|
19-
build_scope(scope) if call_method_or_proc_on(self, scope.display_if_block)
20+
unless current_filter_search_empty?
21+
scopes.each do |scope|
22+
build_scope(scope) if call_method_or_proc_on(self, scope.display_if_block)
23+
end
2024
end
2125
end
2226

@@ -53,7 +57,9 @@ def current_scope?(scope)
5357
end
5458
end
5559

56-
include ActiveAdmin::ScopeChain
60+
def current_filter_search_empty?
61+
collection.empty? && params.include?(:q)
62+
end
5763

5864
# Return the count for the scope passed in.
5965
def get_scope_count(scope)

0 commit comments

Comments
 (0)