Commit 1b7464ed authored by Sarah Yasonik's avatar Sarah Yasonik Committed by Mayra Cabrera

Specify a dropdown name for dashboards

parent ae853dba
......@@ -13,12 +13,23 @@ module Gitlab
def all_dashboard_paths(project)
file_finder(project)
.list_files_for(DASHBOARD_ROOT)
.map { |filepath| { path: filepath, default: false } }
.map do |filepath|
{
path: filepath,
display_name: name_for_path(filepath),
default: false
}
end
end
def file_finder(project)
Gitlab::Template::Finders::RepoTemplateFinder.new(project, DASHBOARD_ROOT, '.yml')
end
# Grabs the filepath after the base directory.
def name_for_path(filepath)
filepath.delete_prefix("#{DASHBOARD_ROOT}/")
end
end
private
......
......@@ -7,11 +7,13 @@ module Gitlab
module Dashboard
class SystemDashboardService < Gitlab::Metrics::Dashboard::BaseService
SYSTEM_DASHBOARD_PATH = 'config/prometheus/common_metrics.yml'
SYSTEM_DASHBOARD_NAME = 'Default'
class << self
def all_dashboard_paths(_project)
[{
path: SYSTEM_DASHBOARD_PATH,
display_name: SYSTEM_DASHBOARD_NAME,
default: true
}]
end
......
......@@ -49,7 +49,7 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi
describe '.find_all_paths' do
let(:all_dashboard_paths) { described_class.find_all_paths(project) }
let(:system_dashboard) { { path: system_dashboard_path, default: true } }
let(:system_dashboard) { { path: system_dashboard_path, display_name: 'Default', default: true } }
it 'includes only the system dashboard by default' do
expect(all_dashboard_paths).to eq([system_dashboard])
......@@ -60,7 +60,7 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi
let(:project) { project_with_dashboard(dashboard_path) }
it 'includes system and project dashboards' do
project_dashboard = { path: dashboard_path, default: false }
project_dashboard = { path: dashboard_path, display_name: 'test.yml', default: false }
expect(all_dashboard_paths).to contain_exactly(system_dashboard, project_dashboard)
end
......
......@@ -59,4 +59,29 @@ describe Gitlab::Metrics::Dashboard::ProjectDashboardService, :use_clean_rails_m
it_behaves_like 'misconfigured dashboard service response', :unprocessable_entity
end
end
describe '::all_dashboard_paths' do
let(:all_dashboards) { described_class.all_dashboard_paths(project) }
context 'when there are no project dashboards' do
it 'returns an empty array' do
expect(all_dashboards).to be_empty
end
end
context 'when there are project dashboards available' do
let(:dashboard_path) { '.gitlab/dashboards/test.yml' }
let(:project) { project_with_dashboard(dashboard_path) }
it 'returns the dashboard attributes' do
expect(all_dashboards).to eq(
[{
path: dashboard_path,
display_name: 'test.yml',
default: false
}]
)
end
end
end
end
......@@ -29,4 +29,18 @@ describe Gitlab::Metrics::Dashboard::SystemDashboardService, :use_clean_rails_me
it_behaves_like 'valid dashboard service response'
end
end
describe '::all_dashboard_paths' do
it 'returns the dashboard attributes' do
all_dashboards = described_class.all_dashboard_paths(project)
expect(all_dashboards).to eq(
[{
path: described_class::SYSTEM_DASHBOARD_PATH,
display_name: described_class::SYSTEM_DASHBOARD_NAME,
default: true
}]
)
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