BigW Consortium Gitlab

Commit bb447383 by Oxan van Leeuwen

Add issue events filter and make sure "All" really shows everything

Currently, the EventFilter whitelists event types for the "All" filter. This has gotten outdated, which causes the confusing behaviour of the "All" tab not really showing all events. To make matters worse, by default no tab at all is selected, which does show all events, so selecting the "All" tab actually hides some events. Fix this by: - Making sure All always includes all activity, by abolishing the whitelist and just returning all events instead. - Make the All tab selected by default. - Add Issue events tab to include the specific events around opening and closing issues, since there was no specific filter to see them yet. Fixes #24826
parent ef6a91af
...@@ -5,5 +5,7 @@ ...@@ -5,5 +5,7 @@
- if event_filter_visible(:merge_requests) - if event_filter_visible(:merge_requests)
= event_filter_link EventFilter.merged, 'Merge events' = event_filter_link EventFilter.merged, 'Merge events'
- if event_filter_visible(:issues) - if event_filter_visible(:issues)
= event_filter_link EventFilter.issue, 'Issue events'
- if event_filter_visible(:issues)
= event_filter_link EventFilter.comments, 'Comments' = event_filter_link EventFilter.comments, 'Comments'
= event_filter_link EventFilter.team, 'Team' = event_filter_link EventFilter.team, 'Team'
---
title: Add issue events filter and make all really show all events
merge_request: 7673
author: Oxan van Leeuwen
...@@ -14,6 +14,10 @@ class EventFilter ...@@ -14,6 +14,10 @@ class EventFilter
'merged' 'merged'
end end
def issue
'issue'
end
def comments def comments
'comments' 'comments'
end end
...@@ -32,32 +36,20 @@ class EventFilter ...@@ -32,32 +36,20 @@ class EventFilter
end end
def apply_filter(events) def apply_filter(events)
return events unless params.present? return events if params.blank? || params == EventFilter.all
filter = params.dup
actions = []
case filter case params
when EventFilter.push when EventFilter.push
actions = [Event::PUSHED] events.where(action: Event::PUSHED)
when EventFilter.merged when EventFilter.merged
actions = [Event::MERGED] events.where(action: Event::MERGED)
when EventFilter.comments when EventFilter.comments
actions = [Event::COMMENTED] events.where(action: Event::COMMENTED)
when EventFilter.team when EventFilter.team
actions = [Event::JOINED, Event::LEFT, Event::EXPIRED] events.where(action: [Event::JOINED, Event::LEFT, Event::EXPIRED])
when EventFilter.all when EventFilter.issue
actions = [ events.where(action: [Event::CREATED, Event::UPDATED, Event::CLOSED, Event::REOPENED])
Event::PUSHED,
Event::MERGED,
Event::COMMENTED,
Event::JOINED,
Event::LEFT,
Event::EXPIRED
]
end end
events.where(action: actions)
end end
def options(key) def options(key)
...@@ -73,6 +65,10 @@ class EventFilter ...@@ -73,6 +65,10 @@ class EventFilter
end end
def active?(key) def active?(key)
params.include? key if params.present?
params.include? key
else
key == EventFilter.all
end
end end
end end
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
%span %span
Merge events Merge events
%li %li
%a.event-filter-link{ id: "issue_event_filter", title: "Filter by issue events", href: "/dashboard/activity"}
%span
Issue events
%li
%a.event-filter-link{ id: "comments_event_filter", title: "Filter by comments", href: "/dashboard/activity"} %a.event-filter-link{ id: "comments_event_filter", title: "Filter by comments", href: "/dashboard/activity"}
%span %span
Comments Comments
......
...@@ -7,6 +7,10 @@ describe EventFilter, lib: true do ...@@ -7,6 +7,10 @@ describe EventFilter, lib: true do
let!(:push_event) { create(:event, action: Event::PUSHED, project: public_project, target: public_project, author: source_user) } let!(:push_event) { create(:event, action: Event::PUSHED, project: public_project, target: public_project, author: source_user) }
let!(:merged_event) { create(:event, action: Event::MERGED, project: public_project, target: public_project, author: source_user) } let!(:merged_event) { create(:event, action: Event::MERGED, project: public_project, target: public_project, author: source_user) }
let!(:created_event) { create(:event, action: Event::CREATED, project: public_project, target: public_project, author: source_user) }
let!(:updated_event) { create(:event, action: Event::UPDATED, project: public_project, target: public_project, author: source_user) }
let!(:closed_event) { create(:event, action: Event::CLOSED, project: public_project, target: public_project, author: source_user) }
let!(:reopened_event) { create(:event, action: Event::REOPENED, project: public_project, target: public_project, author: source_user) }
let!(:comments_event) { create(:event, action: Event::COMMENTED, project: public_project, target: public_project, author: source_user) } let!(:comments_event) { create(:event, action: Event::COMMENTED, project: public_project, target: public_project, author: source_user) }
let!(:joined_event) { create(:event, action: Event::JOINED, project: public_project, target: public_project, author: source_user) } let!(:joined_event) { create(:event, action: Event::JOINED, project: public_project, target: public_project, author: source_user) }
let!(:left_event) { create(:event, action: Event::LEFT, project: public_project, target: public_project, author: source_user) } let!(:left_event) { create(:event, action: Event::LEFT, project: public_project, target: public_project, author: source_user) }
...@@ -21,6 +25,11 @@ describe EventFilter, lib: true do ...@@ -21,6 +25,11 @@ describe EventFilter, lib: true do
expect(events).to contain_exactly(merged_event) expect(events).to contain_exactly(merged_event)
end end
it 'applies issue filter' do
events = EventFilter.new(EventFilter.issue).apply_filter(Event.all)
expect(events).to contain_exactly(created_event, updated_event, closed_event, reopened_event)
end
it 'applies comments filter' do it 'applies comments filter' do
events = EventFilter.new(EventFilter.comments).apply_filter(Event.all) events = EventFilter.new(EventFilter.comments).apply_filter(Event.all)
expect(events).to contain_exactly(comments_event) expect(events).to contain_exactly(comments_event)
...@@ -33,17 +42,17 @@ describe EventFilter, lib: true do ...@@ -33,17 +42,17 @@ describe EventFilter, lib: true do
it 'applies all filter' do it 'applies all filter' do
events = EventFilter.new(EventFilter.all).apply_filter(Event.all) events = EventFilter.new(EventFilter.all).apply_filter(Event.all)
expect(events).to contain_exactly(push_event, merged_event, comments_event, joined_event, left_event) expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event)
end end
it 'applies no filter' do it 'applies no filter' do
events = EventFilter.new(nil).apply_filter(Event.all) events = EventFilter.new(nil).apply_filter(Event.all)
expect(events).to contain_exactly(push_event, merged_event, comments_event, joined_event, left_event) expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event)
end end
it 'applies unknown filter' do it 'applies unknown filter' do
events = EventFilter.new('').apply_filter(Event.all) events = EventFilter.new('').apply_filter(Event.all)
expect(events).to contain_exactly(push_event, merged_event, comments_event, joined_event, left_event) expect(events).to contain_exactly(push_event, merged_event, created_event, updated_event, closed_event, reopened_event, comments_event, joined_event, left_event)
end end
end end
end end
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