Skip to content
Snippets Groups Projects
Commit e5b10a60 authored by Eric Eastwood's avatar Eric Eastwood
Browse files

Scope recent searches to project

parent 561ec48c
No related branches found
No related tags found
No related merge requests found
Pipeline #
Loading
Loading
@@ -16,10 +16,14 @@ class FilteredSearchManager {
this.recentSearchesStore = new RecentSearchesStore({
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') {
recentSearchesKey = 'merge-request-recent-searches';
recentSearchesPagePrefix = 'merge-request-recent-searches';
}
const recentSearchesKey = `${projectPath}-${recentSearchesPagePrefix}`;
this.recentSearchesService = new RecentSearchesService(recentSearchesKey);
 
// Fetch recent searches from localStorage
Loading
Loading
@@ -47,7 +51,7 @@ class FilteredSearchManager {
this.recentSearchesRoot = new RecentSearchesRoot(
this.recentSearchesStore,
this.recentSearchesService,
document.querySelector('.js-filtered-search-history-dropdown'),
searchHistoryDropdownElement,
);
this.recentSearchesRoot.init();
 
Loading
Loading
Loading
Loading
@@ -3,6 +3,7 @@ import _ from 'underscore';
class RecentSearchesStore {
constructor(initialState = {}) {
this.state = Object.assign({
isLocalStorageAvailable: true,
recentSearches: [],
}, initialState);
}
Loading
Loading
Loading
Loading
@@ -19,7 +19,7 @@
dropdown_class: "filtered-search-history-dropdown",
content_class: "filtered-search-history-dropdown-content",
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
.scroll-container
%ul.tokens-container.list-unstyled
Loading
Loading
---
title: Scope issuable recent searches to project
merge_request:
author:
Loading
Loading
@@ -3,15 +3,16 @@ require 'spec_helper'
describe 'Recent searches', js: true, feature: true do
include FilteredSearchHelpers
 
let!(:group) { create(:group) }
let!(:project) { create(:project, group: group) }
let(:project) { create(:project, :public) }
let(:project2) { create(:project, :public) }
let!(:user) { create(:user) }
 
before do
Capybara.ignore_hidden_elements = false
project.add_master(user)
group.add_developer(user)
project2.add_master(user)
create(:issue, project: project)
create(:issue, project: project2)
login_as(user)
 
remove_recent_searches
Loading
Loading
@@ -46,7 +47,7 @@ describe 'Recent searches', js: true, feature: true do
end
 
it 'saved recent searches are restored last on the list' do
set_recent_searches('["saved1", "saved2"]')
set_recent_searches("#{project.full_path}-issue-recent-searches", '["saved1", "saved2"]')
 
visit namespace_project_issues_path(project.namespace, project, search: 'foo')
 
Loading
Loading
@@ -58,8 +59,26 @@ describe 'Recent searches', js: true, feature: true do
expect(items[2].text).to eq('saved2')
end
 
it 'searches are scoped to projects' do
visit namespace_project_issues_path(project.namespace, project)
input_filtered_search('foo', submit: true)
input_filtered_search('bar', submit: true)
visit namespace_project_issues_path(project2.namespace, project2)
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
set_recent_searches('["foo", "bar"]')
set_recent_searches("#{project.full_path}-issue-recent-searches", '["foo", "bar"]')
visit namespace_project_issues_path(project.namespace, project)
 
all('.filtered-search-history-dropdown-item', visible: false)[0].trigger('click')
Loading
Loading
@@ -69,7 +88,7 @@ describe 'Recent searches', js: true, feature: true do
end
 
it 'clear recent searches button, clears recent searches' do
set_recent_searches('["foo"]')
set_recent_searches("#{project.full_path}-issue-recent-searches", '["foo"]')
visit namespace_project_issues_path(project.namespace, project)
 
items_before = all('.filtered-search-history-dropdown-item', visible: false)
Loading
Loading
@@ -83,7 +102,7 @@ describe 'Recent searches', js: true, feature: true do
end
 
it 'shows flash error when failed to parse saved history' do
set_recent_searches('fail')
set_recent_searches("#{project.full_path}-issue-recent-searches", 'fail')
visit namespace_project_issues_path(project.namespace, project)
 
expect(find('.flash-alert')).to have_text('An error occured while parsing recent searches')
Loading
Loading
Loading
Loading
@@ -73,11 +73,11 @@ module FilteredSearchHelpers
end
 
def remove_recent_searches
execute_script('window.localStorage.removeItem(\'issue-recent-searches\');')
execute_script('window.localStorage.clear();')
end
 
def set_recent_searches(input)
execute_script("window.localStorage.setItem('issue-recent-searches', '#{input}');")
def set_recent_searches(key, input)
execute_script("window.localStorage.setItem('#{key}', '#{input}');")
end
 
def wait_for_filtered_search(text)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment