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
cae2274f
Commit
cae2274f
authored
May 05, 2017
by
Eric Eastwood
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scope recent searches to project
Fix
https://gitlab.com/gitlab-org/gitlab-ce/issues/31902
parent
1ccf101e
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
25 deletions
+52
-25
app/assets/javascripts/filtered_search/filtered_search_manager.js
...ts/javascripts/filtered_search/filtered_search_manager.js
+7
-3
app/assets/javascripts/filtered_search/stores/recent_searches_store.js
...vascripts/filtered_search/stores/recent_searches_store.js
+1
-0
app/views/shared/issuable/_search_bar.html.haml
app/views/shared/issuable/_search_bar.html.haml
+1
-1
changelogs/unreleased/31902-namespace-recent-searches-to-project.yml
...unreleased/31902-namespace-recent-searches-to-project.yml
+4
-0
spec/features/issues/filtered_search/recent_searches_spec.rb
spec/features/issues/filtered_search/recent_searches_spec.rb
+36
-18
spec/support/filtered_search_helpers.rb
spec/support/filtered_search_helpers.rb
+3
-3
No files found.
app/assets/javascripts/filtered_search/filtered_search_manager.js
View file @
cae2274f
...
@@ -16,10 +16,14 @@ class FilteredSearchManager {
...
@@ -16,10 +16,14 @@ class FilteredSearchManager {
this
.
recentSearchesStore
=
new
RecentSearchesStore
({
this
.
recentSearchesStore
=
new
RecentSearchesStore
({
isLocalStorageAvailable
:
RecentSearchesService
.
isAvailable
(),
isLocalStorageAvailable
:
RecentSearchesService
.
isAvailable
(),
});
});
let
recentSearchesKey
=
'
issue-recent-searches
'
;
const
searchHistoryDropdownElement
=
document
.
querySelector
(
'
.js-filtered-search-history-dropdown
'
);
const
projectPath
=
searchHistoryDropdownElement
?
searchHistoryDropdownElement
.
dataset
.
projectFullPath
:
'
project
'
;
let
recentSearchesPagePrefix
=
'
issue-recent-searches
'
;
if
(
page
===
'
merge_requests
'
)
{
if
(
page
===
'
merge_requests
'
)
{
recentSearches
Key
=
'
merge-request-recent-searches
'
;
recentSearches
PagePrefix
=
'
merge-request-recent-searches
'
;
}
}
const
recentSearchesKey
=
`
${
projectPath
}
-
${
recentSearchesPagePrefix
}
`
;
this
.
recentSearchesService
=
new
RecentSearchesService
(
recentSearchesKey
);
this
.
recentSearchesService
=
new
RecentSearchesService
(
recentSearchesKey
);
// Fetch recent searches from localStorage
// Fetch recent searches from localStorage
...
@@ -47,7 +51,7 @@ class FilteredSearchManager {
...
@@ -47,7 +51,7 @@ class FilteredSearchManager {
this
.
recentSearchesRoot
=
new
RecentSearchesRoot
(
this
.
recentSearchesRoot
=
new
RecentSearchesRoot
(
this
.
recentSearchesStore
,
this
.
recentSearchesStore
,
this
.
recentSearchesService
,
this
.
recentSearchesService
,
document
.
querySelector
(
'
.js-filtered-search-history-dropdown
'
)
,
searchHistoryDropdownElement
,
);
);
this
.
recentSearchesRoot
.
init
();
this
.
recentSearchesRoot
.
init
();
...
...
app/assets/javascripts/filtered_search/stores/recent_searches_store.js
View file @
cae2274f
...
@@ -3,6 +3,7 @@ import _ from 'underscore';
...
@@ -3,6 +3,7 @@ import _ from 'underscore';
class
RecentSearchesStore
{
class
RecentSearchesStore
{
constructor
(
initialState
=
{})
{
constructor
(
initialState
=
{})
{
this
.
state
=
Object
.
assign
({
this
.
state
=
Object
.
assign
({
isLocalStorageAvailable
:
true
,
recentSearches
:
[],
recentSearches
:
[],
},
initialState
);
},
initialState
);
}
}
...
...
app/views/shared/issuable/_search_bar.html.haml
View file @
cae2274f
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
dropdown_class:
"filtered-search-history-dropdown"
,
dropdown_class:
"filtered-search-history-dropdown"
,
content_class:
"filtered-search-history-dropdown-content"
,
content_class:
"filtered-search-history-dropdown-content"
,
title:
"Recent searches"
})
do
title:
"Recent searches"
})
do
.js-filtered-search-history-dropdown
.js-filtered-search-history-dropdown
{
data:
{
project_full_path:
@project
.
full_path
}
}
.filtered-search-box-input-container
.filtered-search-box-input-container
.scroll-container
.scroll-container
%ul
.tokens-container.list-unstyled
%ul
.tokens-container.list-unstyled
...
...
changelogs/unreleased/31902-namespace-recent-searches-to-project.yml
0 → 100644
View file @
cae2274f
---
title
:
Scope issue/merge request recent searches to project
merge_request
:
author
:
spec/features/issues/filtered_search/recent_searches_spec.rb
View file @
cae2274f
...
@@ -3,17 +3,17 @@ require 'spec_helper'
...
@@ -3,17 +3,17 @@ require 'spec_helper'
describe
'Recent searches'
,
js:
true
,
feature:
true
do
describe
'Recent searches'
,
js:
true
,
feature:
true
do
include
FilteredSearchHelpers
include
FilteredSearchHelpers
let
!
(
:group
)
{
create
(
:group
)
}
let
(
:project_1
)
{
create
(
:empty_project
,
:public
)
}
let
!
(
:project
)
{
create
(
:project
,
group:
group
)
}
let
(
:project_2
)
{
create
(
:empty_project
,
:public
)
}
let
!
(
:user
)
{
create
(
:user
)
}
let
(
:project_1_local_storage_key
)
{
"
#{
project_1
.
full_path
}
-issue-recent-searches"
}
before
do
before
do
Capybara
.
ignore_hidden_elements
=
false
Capybara
.
ignore_hidden_elements
=
false
project
.
add_master
(
user
)
create
(
:issue
,
project:
project_1
)
group
.
add_developer
(
user
)
create
(
:issue
,
project:
project_2
)
create
(
:issue
,
project:
project
)
login_as
(
user
)
# Visit any fast-loading page so we can clear local storage without a DOM exception
visit
'/404'
remove_recent_searches
remove_recent_searches
end
end
...
@@ -22,7 +22,7 @@ describe 'Recent searches', js: true, feature: true do
...
@@ -22,7 +22,7 @@ describe 'Recent searches', js: true, feature: true do
end
end
it
'searching adds to recent searches'
do
it
'searching adds to recent searches'
do
visit
namespace_project_issues_path
(
project
.
namespace
,
project
)
visit
namespace_project_issues_path
(
project
_1
.
namespace
,
project_1
)
input_filtered_search
(
'foo'
,
submit:
true
)
input_filtered_search
(
'foo'
,
submit:
true
)
input_filtered_search
(
'bar'
,
submit:
true
)
input_filtered_search
(
'bar'
,
submit:
true
)
...
@@ -35,8 +35,8 @@ describe 'Recent searches', js: true, feature: true do
...
@@ -35,8 +35,8 @@ describe 'Recent searches', js: true, feature: true do
end
end
it
'visiting URL with search params adds to recent searches'
do
it
'visiting URL with search params adds to recent searches'
do
visit
namespace_project_issues_path
(
project
.
namespace
,
project
,
label_name:
'foo'
,
search:
'bar'
)
visit
namespace_project_issues_path
(
project
_1
.
namespace
,
project_1
,
label_name:
'foo'
,
search:
'bar'
)
visit
namespace_project_issues_path
(
project
.
namespace
,
project
,
label_name:
'qux'
,
search:
'garply'
)
visit
namespace_project_issues_path
(
project
_1
.
namespace
,
project_1
,
label_name:
'qux'
,
search:
'garply'
)
items
=
all
(
'.filtered-search-history-dropdown-item'
,
visible:
false
)
items
=
all
(
'.filtered-search-history-dropdown-item'
,
visible:
false
)
...
@@ -46,9 +46,9 @@ describe 'Recent searches', js: true, feature: true do
...
@@ -46,9 +46,9 @@ describe 'Recent searches', js: true, feature: true do
end
end
it
'saved recent searches are restored last on the list'
do
it
'saved recent searches are restored last on the list'
do
set_recent_searches
(
'["saved1", "saved2"]'
)
set_recent_searches
(
project_1_local_storage_key
,
'["saved1", "saved2"]'
)
visit
namespace_project_issues_path
(
project
.
namespace
,
project
,
search:
'foo'
)
visit
namespace_project_issues_path
(
project
_1
.
namespace
,
project_1
,
search:
'foo'
)
items
=
all
(
'.filtered-search-history-dropdown-item'
,
visible:
false
)
items
=
all
(
'.filtered-search-history-dropdown-item'
,
visible:
false
)
...
@@ -58,9 +58,27 @@ describe 'Recent searches', js: true, feature: true do
...
@@ -58,9 +58,27 @@ describe 'Recent searches', js: true, feature: true do
expect
(
items
[
2
].
text
).
to
eq
(
'saved2'
)
expect
(
items
[
2
].
text
).
to
eq
(
'saved2'
)
end
end
it
'searches are scoped to projects'
do
visit
namespace_project_issues_path
(
project_1
.
namespace
,
project_1
)
input_filtered_search
(
'foo'
,
submit:
true
)
input_filtered_search
(
'bar'
,
submit:
true
)
visit
namespace_project_issues_path
(
project_2
.
namespace
,
project_2
)
input_filtered_search
(
'more'
,
submit:
true
)
input_filtered_search
(
'things'
,
submit:
true
)
items
=
all
(
'.filtered-search-history-dropdown-item'
,
visible:
false
)
expect
(
items
.
count
).
to
eq
(
2
)
expect
(
items
[
0
].
text
).
to
eq
(
'things'
)
expect
(
items
[
1
].
text
).
to
eq
(
'more'
)
end
it
'clicking item fills search input'
do
it
'clicking item fills search input'
do
set_recent_searches
(
'["foo", "bar"]'
)
set_recent_searches
(
project_1_local_storage_key
,
'["foo", "bar"]'
)
visit
namespace_project_issues_path
(
project
.
namespace
,
project
)
visit
namespace_project_issues_path
(
project
_1
.
namespace
,
project_1
)
all
(
'.filtered-search-history-dropdown-item'
,
visible:
false
)[
0
].
trigger
(
'click'
)
all
(
'.filtered-search-history-dropdown-item'
,
visible:
false
)[
0
].
trigger
(
'click'
)
wait_for_filtered_search
(
'foo'
)
wait_for_filtered_search
(
'foo'
)
...
@@ -69,8 +87,8 @@ describe 'Recent searches', js: true, feature: true do
...
@@ -69,8 +87,8 @@ describe 'Recent searches', js: true, feature: true do
end
end
it
'clear recent searches button, clears recent searches'
do
it
'clear recent searches button, clears recent searches'
do
set_recent_searches
(
'["foo"]'
)
set_recent_searches
(
project_1_local_storage_key
,
'["foo"]'
)
visit
namespace_project_issues_path
(
project
.
namespace
,
project
)
visit
namespace_project_issues_path
(
project
_1
.
namespace
,
project_1
)
items_before
=
all
(
'.filtered-search-history-dropdown-item'
,
visible:
false
)
items_before
=
all
(
'.filtered-search-history-dropdown-item'
,
visible:
false
)
...
@@ -83,8 +101,8 @@ describe 'Recent searches', js: true, feature: true do
...
@@ -83,8 +101,8 @@ describe 'Recent searches', js: true, feature: true do
end
end
it
'shows flash error when failed to parse saved history'
do
it
'shows flash error when failed to parse saved history'
do
set_recent_searches
(
'fail'
)
set_recent_searches
(
project_1_local_storage_key
,
'fail'
)
visit
namespace_project_issues_path
(
project
.
namespace
,
project
)
visit
namespace_project_issues_path
(
project
_1
.
namespace
,
project_1
)
expect
(
find
(
'.flash-alert'
)).
to
have_text
(
'An error occured while parsing recent searches'
)
expect
(
find
(
'.flash-alert'
)).
to
have_text
(
'An error occured while parsing recent searches'
)
end
end
...
...
spec/support/filtered_search_helpers.rb
View file @
cae2274f
...
@@ -73,11 +73,11 @@ module FilteredSearchHelpers
...
@@ -73,11 +73,11 @@ module FilteredSearchHelpers
end
end
def
remove_recent_searches
def
remove_recent_searches
execute_script
(
'window.localStorage.
removeItem(\'issue-recent-searches\'
);'
)
execute_script
(
'window.localStorage.
clear(
);'
)
end
end
def
set_recent_searches
(
input
)
def
set_recent_searches
(
key
,
input
)
execute_script
(
"window.localStorage.setItem('
issue-recent-searches
', '
#{
input
}
');"
)
execute_script
(
"window.localStorage.setItem('
#{
key
}
', '
#{
input
}
');"
)
end
end
def
wait_for_filtered_search
(
text
)
def
wait_for_filtered_search
(
text
)
...
...
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