Commit a1094e23 authored by Alexis Reigel's avatar Alexis Reigel

add type filter to admin runners page

parent dc1e0f6b
...@@ -7,6 +7,13 @@ const tokenKeys = [{ ...@@ -7,6 +7,13 @@ const tokenKeys = [{
symbol: '', symbol: '',
icon: 'signal', icon: 'signal',
tag: 'status', tag: 'status',
}, {
key: 'type',
type: 'string',
param: 'type',
symbol: '',
icon: 'cube',
tag: 'type',
}]; }];
const AdminRunnersFilteredSearchTokenKeys = new FilteredSearchTokenKeys(tokenKeys); const AdminRunnersFilteredSearchTokenKeys = new FilteredSearchTokenKeys(tokenKeys);
......
...@@ -96,6 +96,11 @@ export default class FilteredSearchDropdownManager { ...@@ -96,6 +96,11 @@ export default class FilteredSearchDropdownManager {
gl: NullDropdown, gl: NullDropdown,
element: this.container.querySelector('#js-dropdown-admin-runner-status'), element: this.container.querySelector('#js-dropdown-admin-runner-status'),
}, },
type: {
reference: null,
gl: NullDropdown,
element: this.container.querySelector('#js-dropdown-admin-runner-type'),
},
}; };
supportedTokens.forEach((type) => { supportedTokens.forEach((type) => {
......
...@@ -10,6 +10,7 @@ class Admin::RunnersFinder < UnionFinder ...@@ -10,6 +10,7 @@ class Admin::RunnersFinder < UnionFinder
def execute def execute
search! search!
filter_by_status! filter_by_status!
filter_by_runner_type!
sort! sort!
paginate! paginate!
...@@ -36,10 +37,11 @@ class Admin::RunnersFinder < UnionFinder ...@@ -36,10 +37,11 @@ class Admin::RunnersFinder < UnionFinder
end end
def filter_by_status! def filter_by_status!
status = @params[:status_status] filter_by!(:status_status, Ci::Runner::AVAILABLE_STATUSES)
if status.present? && Ci::Runner::AVAILABLE_STATUSES.include?(status)
@runners = @runners.public_send(status) # rubocop:disable GitlabSecurity/PublicSend
end end
def filter_by_runner_type!
filter_by!(:type_type, Ci::Runner::AVAILABLE_TYPES)
end end
def sort! def sort!
...@@ -49,4 +51,12 @@ class Admin::RunnersFinder < UnionFinder ...@@ -49,4 +51,12 @@ class Admin::RunnersFinder < UnionFinder
def paginate! def paginate!
@runners = @runners.page(@params[:page]).per(NUMBER_OF_RUNNERS_PER_PAGE) @runners = @runners.page(@params[:page]).per(NUMBER_OF_RUNNERS_PER_PAGE)
end end
def filter_by!(scope_name, available_scopes)
scope = @params[scope_name]
if scope.present? && available_scopes.include?(scope)
@runners = @runners.public_send(scope) # rubocop:disable GitlabSecurity/PublicSend
end
end
end end
...@@ -82,12 +82,21 @@ ...@@ -82,12 +82,21 @@
{{hint}} {{hint}}
%span.js-filter-tag.dropdown-light-content %span.js-filter-tag.dropdown-light-content
{{tag}} {{tag}}
#js-dropdown-admin-runner-status.filtered-search-input-dropdown-menu.dropdown-menu #js-dropdown-admin-runner-status.filtered-search-input-dropdown-menu.dropdown-menu
%ul{ data: { dropdown: true } } %ul{ data: { dropdown: true } }
- Ci::Runner::AVAILABLE_STATUSES.each do |status| - Ci::Runner::AVAILABLE_STATUSES.each do |status|
%li.filter-dropdown-item{ data: { value: status } } %li.filter-dropdown-item{ data: { value: status } }
= button_tag class: %w[btn btn-link] do = button_tag class: %w[btn btn-link] do
= status.titleize = status.titleize
#js-dropdown-admin-runner-type.filtered-search-input-dropdown-menu.dropdown-menu
%ul{ data: { dropdown: true } }
- Ci::Runner::AVAILABLE_TYPES.each do |runner_type|
%li.filter-dropdown-item{ data: { value: runner_type } }
= button_tag class: %w[btn btn-link] do
= runner_type.titleize
= button_tag class: %w[clear-search hidden] do = button_tag class: %w[clear-search hidden] do
= icon('times') = icon('times')
.filter-dropdown-container .filter-dropdown-container
......
...@@ -73,9 +73,8 @@ describe "Admin Runners" do ...@@ -73,9 +73,8 @@ describe "Admin Runners" do
expect(page).to have_text 'No runners found' expect(page).to have_text 'No runners found'
end end
end
it 'shows correct runner when status is selected and search term is entered', :js do it 'shows correct runner when status is selected and search term is entered' do
create(:ci_runner, description: 'runner-a-1', active: true) create(:ci_runner, description: 'runner-a-1', active: true)
create(:ci_runner, description: 'runner-a-2', active: false) create(:ci_runner, description: 'runner-a-2', active: false)
create(:ci_runner, description: 'runner-b-1', active: true) create(:ci_runner, description: 'runner-b-1', active: true)
...@@ -92,6 +91,55 @@ describe "Admin Runners" do ...@@ -92,6 +91,55 @@ describe "Admin Runners" do
expect(page).not_to have_content 'runner-b-1' expect(page).not_to have_content 'runner-b-1'
expect(page).not_to have_content 'runner-a-2' expect(page).not_to have_content 'runner-a-2'
end end
end
describe 'filter by type', :js do
it 'shows correct runner when type matches' do
create :ci_runner, :project, description: 'runner-project'
create :ci_runner, :group, description: 'runner-group'
visit admin_runners_path
expect(page).to have_content 'runner-project'
expect(page).to have_content 'runner-group'
input_filtered_search_keys('type:project_type')
expect(page).to have_content 'runner-project'
expect(page).not_to have_content 'runner-group'
end
it 'shows no runner when type does not match' do
create :ci_runner, :project, description: 'runner-project'
create :ci_runner, :group, description: 'runner-group'
visit admin_runners_path
input_filtered_search_keys('type:instance_type')
expect(page).not_to have_content 'runner-project'
expect(page).not_to have_content 'runner-group'
expect(page).to have_text 'No runners found'
end
it 'shows correct runner when type is selected and search term is entered' do
create :ci_runner, :project, description: 'runner-a-1'
create :ci_runner, :instance, description: 'runner-a-2'
create :ci_runner, :project, description: 'runner-b-1'
visit admin_runners_path
input_filtered_search_keys('type:project_type')
expect(page).to have_content 'runner-a-1'
expect(page).to have_content 'runner-b-1'
expect(page).not_to have_content 'runner-a-2'
input_filtered_search_keys('type:project_type runner-a')
expect(page).to have_content 'runner-a-1'
expect(page).not_to have_content 'runner-b-1'
expect(page).not_to have_content 'runner-a-2'
end
end
it 'sorts by last contact date', :js do it 'sorts by last contact date', :js do
create(:ci_runner, description: 'runner-1', created_at: '2018-07-12 15:37', contacted_at: '2018-07-12 15:37') create(:ci_runner, description: 'runner-1', created_at: '2018-07-12 15:37', contacted_at: '2018-07-12 15:37')
......
...@@ -29,6 +29,14 @@ describe Admin::RunnersFinder do ...@@ -29,6 +29,14 @@ describe Admin::RunnersFinder do
end end
end end
context 'filter by runner type' do
it 'calls the corresponding scope on Ci::Runner' do
expect(Ci::Runner).to receive(:project_type).and_call_original
described_class.new(params: { type_type: 'project_type' }).execute
end
end
context 'sort' do context 'sort' do
context 'without sort param' do context 'without sort param' do
it 'sorts by created_at' do it 'sorts by created_at' do
......
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