Commit bd562fdd authored by Reuben Pereira's avatar Reuben Pereira Committed by Bob Van Landuyt
Browse files

Make external_dashboard_url available to frontend

- On Operations settings page
- On Metrics dashboard page
parent 6ca5a7da9c2e
......@@ -30,7 +30,8 @@ def metrics_data(project, environment)
"environments-endpoint": project_environments_path(project, format: :json),
"project-path" => project_path(project),
"tags-path" => project_tags_path(project),
"has-metrics" => "#{environment.has_metrics?}"
"has-metrics" => "#{environment.has_metrics?}",
"external-dashboard-url" => project.metrics_setting_external_dashboard_url
}
end
end
......@@ -343,6 +343,10 @@ def share_project_description(project)
description.html_safe % { project_name: project.name }
end
def metrics_external_dashboard_url
@project.metrics_setting_external_dashboard_url
end
private
def get_project_nav_tabs(project, current_user)
......
......@@ -309,6 +309,7 @@ class Project < ApplicationRecord
delegate :group_clusters_enabled?, to: :group, allow_nil: true
delegate :root_ancestor, to: :namespace, allow_nil: true
delegate :last_pipeline, to: :commit, allow_nil: true
delegate :external_dashboard_url, to: :metrics_setting, allow_nil: true, prefix: true
# Validations
validates :creator, presence: true, on: :create
......
.js-operation-settings{ data: { external_dashboard: { path: '',
.js-operation-settings{ data: { external_dashboard: { path: metrics_external_dashboard_url,
help_page_path: help_page_path('user/project/operations/link_to_external_dashboard') } } }
# frozen_string_literal: true
require 'spec_helper'
describe EnvironmentsHelper do
set(:environment) { create(:environment) }
set(:project) { environment.project }
set(:user) { create(:user) }
describe '#metrics_data' do
before do
# This is so that this spec also passes in EE.
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:can?).and_return(true)
end
let(:metrics_data) { helper.metrics_data(project, environment) }
it 'returns data' do
expect(metrics_data).to include(
'settings-path' => edit_project_service_path(project, 'prometheus'),
'clusters-path' => project_clusters_path(project),
'current-environment-name': environment.name,
'documentation-path' => help_page_path('administration/monitoring/prometheus/index.md'),
'empty-getting-started-svg-path' => match_asset_path('/assets/illustrations/monitoring/getting_started.svg'),
'empty-loading-svg-path' => match_asset_path('/assets/illustrations/monitoring/loading.svg'),
'empty-no-data-svg-path' => match_asset_path('/assets/illustrations/monitoring/no_data.svg'),
'empty-unable-to-connect-svg-path' => match_asset_path('/assets/illustrations/monitoring/unable_to_connect.svg'),
'metrics-endpoint' => additional_metrics_project_environment_path(project, environment, format: :json),
'deployment-endpoint' => project_environment_deployments_path(project, environment, format: :json),
'environments-endpoint': project_environments_path(project, format: :json),
'project-path' => project_path(project),
'tags-path' => project_tags_path(project),
'has-metrics' => "#{environment.has_metrics?}",
'external-dashboard-url' => nil
)
end
context 'with metrics_setting' do
before do
create(:project_metrics_setting, project: project, external_dashboard_url: 'http://gitlab.com')
end
it 'adds external_dashboard_url' do
expect(metrics_data['external-dashboard-url']).to eq('http://gitlab.com')
end
end
end
end
......@@ -819,4 +819,26 @@ def grant_user_access(project, user, access)
expect(helper.can_import_members?).to eq true
end
end
describe '#metrics_external_dashboard_url' do
let(:project) { create(:project) }
before do
helper.instance_variable_set(:@project, project)
end
context 'metrics_setting exists' do
it 'returns external_dashboard_url' do
metrics_setting = create(:project_metrics_setting, project: project)
expect(helper.metrics_external_dashboard_url).to eq(metrics_setting.external_dashboard_url)
end
end
context 'metrics_setting does not exist' do
it 'returns nil' do
expect(helper.metrics_external_dashboard_url).to eq(nil)
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