Commit fad10ed9 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Save epics state filter in user preference

parent f6289d49
......@@ -2835,6 +2835,7 @@ ActiveRecord::Schema.define(version: 20181204135932) do
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.string "epics_sort"
t.integer "roadmap_epics_state"
t.index ["user_id"], name: "index_user_preferences_on_user_id", unique: true, using: :btree
end
......
......@@ -54,7 +54,7 @@ export default () => {
filterQueryString,
presetType,
timeframe,
state: dataset.epicsState
state: dataset.epicsState,
});
const store = new RoadmapStore(parseInt(dataset.groupId, 0), timeframe, presetType);
......
......@@ -13,9 +13,8 @@ module Groups
def show
# Used to persist the order and show the correct sorting dropdown on UI.
@sort = set_sort_order
@epics_state = epics_state_in_user_preference || 'all'
@epics_count = EpicsFinder.new(current_user, group_id: @group.id).execute.count
@epics_state = params[:state] || 'all'
end
private
......@@ -34,5 +33,18 @@ module Groups
Users::UpdateService.new(current_user, user: current_user, roadmap_layout: roadmap_layout).execute
end
def epics_state_in_user_preference
return unless current_user
preference = current_user.user_preference
state_id = Epic.states[params[:state]]
if params[:state].present? && state_id != preference.roadmap_epics_state
preference.update(roadmap_epics_state: state_id)
end
Epic.states.key(preference.roadmap_epics_state)
end
end
end
.dropdown.inline
.dropdown.inline.dropdown-epics-state
%button.dropdown-toggle{ type: 'button', data: { toggle: 'dropdown' } }
= epic_state_title(@epics_state)
= icon('chevron-down')
......
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddEpicsStateToUserPreferences < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :user_preferences, :roadmap_epics_state, :integer
end
end
......@@ -8,6 +8,7 @@ describe 'group epic roadmap', :js do
let(:filtered_search) { find('.filtered-search') }
let(:js_dropdown_label) { '#js-dropdown-label' }
let(:filter_dropdown) { find("#{js_dropdown_label} .filter-dropdown") }
let(:state_dropdown) { find('.dropdown-epics-state') }
let(:bug_label) { create(:group_label, group: group, title: 'Bug') }
let(:critical_label) { create(:group_label, group: group, title: 'Critical') }
......@@ -50,7 +51,7 @@ describe 'group epic roadmap', :js do
end
it 'renders the sort dropdown correctly' do
page.within('.content-wrapper .content .epics-filters') do
page.within('.content-wrapper .content .epics-other-filters') do
expect(page).to have_css('.filter-dropdown-container')
find('.dropdown-toggle').click
page.within('.dropdown-menu') do
......@@ -76,6 +77,40 @@ describe 'group epic roadmap', :js do
end
end
describe 'roadmap page with epics state filter' do
before do
state_dropdown.find('.dropdown-toggle').click
end
it 'renders open epics only' do
state_dropdown.find('a', text: 'Open epics').click
page.within('.roadmap-container .epics-list-section') do
expect(page).to have_selector('.epics-list-item .epic-title', count: 2)
end
end
it 'renders closed epics only' do
state_dropdown.find('a', text: 'Closed epics').click
page.within('.roadmap-container .epics-list-section') do
expect(page).to have_selector('.epics-list-item .epic-title', count: 1)
end
end
it 'saves last selected epic state' do
state_dropdown.find('a', text: 'Open epics').click
visit group_roadmap_path(group)
wait_for_requests
expect(state_dropdown.find('.dropdown-toggle')).to have_text("Open epics")
page.within('.roadmap-container .epics-list-section') do
expect(page).to have_selector('.epics-list-item .epic-title', count: 2)
end
end
end
describe 'roadmap page with filter applied' do
before do
search_for_label(bug_label)
......
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