Commit 116955c4 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch '45739-add-metrics-to-operations-tab' into 'master'

Resolve "Add Metrics to Operations Tab"

Closes #45739

See merge request gitlab-org/gitlab-ce!20025
parents c0e50fdf 01248876
...@@ -20,6 +20,7 @@ export default class ShortcutsNavigation extends Shortcuts { ...@@ -20,6 +20,7 @@ export default class ShortcutsNavigation extends Shortcuts {
Mousetrap.bind('g s', () => findAndFollowLink('.shortcuts-snippets')); Mousetrap.bind('g s', () => findAndFollowLink('.shortcuts-snippets'));
Mousetrap.bind('g k', () => findAndFollowLink('.shortcuts-kubernetes')); Mousetrap.bind('g k', () => findAndFollowLink('.shortcuts-kubernetes'));
Mousetrap.bind('g e', () => findAndFollowLink('.shortcuts-environments')); Mousetrap.bind('g e', () => findAndFollowLink('.shortcuts-environments'));
Mousetrap.bind('g l', () => findAndFollowLink('.shortcuts-metrics'));
Mousetrap.bind('i', () => findAndFollowLink('.shortcuts-new-issue')); Mousetrap.bind('i', () => findAndFollowLink('.shortcuts-new-issue'));
this.enabledHelp.push('.hidden-shortcut.project'); this.enabledHelp.push('.hidden-shortcut.project');
......
...@@ -120,6 +120,16 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -120,6 +120,16 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end end
end end
def metrics_redirect
environment = project.default_environment
if environment
redirect_to environment_metrics_path(environment)
else
render :empty
end
end
def metrics def metrics
# Currently, this acts as a hint to load the metrics details into the cache # Currently, this acts as a hint to load the metrics details into the cache
# if they aren't there already # if they aren't there already
......
...@@ -1774,6 +1774,15 @@ class Project < ActiveRecord::Base ...@@ -1774,6 +1774,15 @@ class Project < ActiveRecord::Base
end end
end end
def default_environment
production_first = "(CASE WHEN name = 'production' THEN 0 ELSE 1 END), id ASC"
environments
.with_state(:available)
.reorder(production_first)
.first
end
def secret_variables_for(ref:, environment: nil) def secret_variables_for(ref:, environment: nil)
# EE would use the environment # EE would use the environment
if protected_for?(ref) if protected_for?(ref)
......
...@@ -179,6 +179,12 @@ ...@@ -179,6 +179,12 @@
%kbd e %kbd e
%td %td
Go to environments Go to environments
%tr
%td.shortcut
%kbd g
%kbd l
%td
Go to metrics
%tr %tr
%td.shortcut %td.shortcut
%kbd g %kbd g
......
...@@ -196,7 +196,7 @@ ...@@ -196,7 +196,7 @@
- if project_nav_tab? :operations - if project_nav_tab? :operations
= nav_link(controller: [:environments, :clusters, :user, :gcp]) do = nav_link(controller: [:environments, :clusters, :user, :gcp]) do
= link_to project_environments_path(@project), class: 'shortcuts-operations' do = link_to metrics_project_environments_path(@project), class: 'shortcuts-operations' do
.nav-icon-container .nav-icon-container
= sprite_icon('cloud-gear') = sprite_icon('cloud-gear')
%span.nav-item-name %span.nav-item-name
...@@ -204,14 +204,19 @@ ...@@ -204,14 +204,19 @@
%ul.sidebar-sub-level-items %ul.sidebar-sub-level-items
= nav_link(controller: [:environments, :clusters, :user, :gcp], html_options: { class: "fly-out-top-item" } ) do = nav_link(controller: [:environments, :clusters, :user, :gcp], html_options: { class: "fly-out-top-item" } ) do
= link_to project_environments_path(@project) do = link_to metrics_project_environments_path(@project) do
%strong.fly-out-top-item-name %strong.fly-out-top-item-name
= _('Operations') = _('Operations')
%li.divider.fly-out-top-item %li.divider.fly-out-top-item
- if project_nav_tab? :environments - if project_nav_tab? :environments
= nav_link(controller: :environments) do = nav_link(controller: :environments, action: [:metrics, :metrics_redirect]) do
= link_to project_environments_path(@project), title: 'Environments', class: 'shortcuts-environments' do = link_to metrics_project_environments_path(@project), title: _('Metrics'), class: 'shortcuts-metrics' do
%span
= _('Metrics')
= nav_link(controller: :environments, action: [:index, :folder, :show, :new, :edit, :create, :update, :stop, :terminal]) do
= link_to project_environments_path(@project), title: _('Environments'), class: 'shortcuts-environments' do
%span %span
= _('Environments') = _('Environments')
......
- page_title _("Metrics")
.row
.col-sm-12
.svg-content
= image_tag 'illustrations/operations_metrics_empty.svg'
.row.empty-environments
.col-sm-12.text-center
%h4
= s_('Metrics|No deployed environments')
.state-description
= s_('Metrics|Check out the CI/CD documentation on deploying to an environment')
.prepend-top-10
= link_to s_("Metrics|Learn about environments"), help_page_path('ci/environments'), class: 'btn btn-success'
...@@ -229,6 +229,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -229,6 +229,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
end end
collection do collection do
get :metrics, action: :metrics_redirect
get :folder, path: 'folders/*id', constraints: { format: /(html|json)/ } get :folder, path: 'folders/*id', constraints: { format: /(html|json)/ }
end end
......
...@@ -277,6 +277,25 @@ describe Projects::EnvironmentsController do ...@@ -277,6 +277,25 @@ describe Projects::EnvironmentsController do
end end
end end
describe 'GET #metrics_redirect' do
let(:project) { create(:project) }
it 'redirects to environment if it exists' do
environment = create(:environment, name: 'production', project: project)
get :metrics_redirect, namespace_id: project.namespace, project_id: project
expect(response).to redirect_to(environment_metrics_path(environment))
end
it 'redirects to empty page if no environment exists' do
get :metrics_redirect, namespace_id: project.namespace, project_id: project
expect(response).to be_ok
expect(response).to render_template 'empty'
end
end
describe 'GET #metrics' do describe 'GET #metrics' do
before do before do
allow(controller).to receive(:environment).and_return(environment) allow(controller).to receive(:environment).and_return(environment)
......
...@@ -110,6 +110,14 @@ describe 'User uses shortcuts', :js do ...@@ -110,6 +110,14 @@ describe 'User uses shortcuts', :js do
end end
context 'when navigating to the Operations pages' do context 'when navigating to the Operations pages' do
it 'redirects to the Metrics page' do
find('body').native.send_key('g')
find('body').native.send_key('l')
expect(page).to have_active_navigation('Operations')
expect(page).to have_active_sub_navigation('Metrics')
end
it 'redirects to the Environments page' do it 'redirects to the Environments page' do
find('body').native.send_key('g') find('body').native.send_key('g')
find('body').native.send_key('e') find('body').native.send_key('e')
......
...@@ -2292,6 +2292,28 @@ describe Project do ...@@ -2292,6 +2292,28 @@ describe Project do
end end
end end
describe '#default_environment' do
let(:project) { create(:project) }
it 'returns production environment when it exists' do
production = create(:environment, name: "production", project: project)
create(:environment, name: 'staging', project: project)
expect(project.default_environment).to eq(production)
end
it 'returns first environment when no production environment exists' do
create(:environment, name: 'staging', project: project)
create(:environment, name: 'foo', project: project)
expect(project.default_environment).to eq(project.environments.first)
end
it 'returns nil when no available environment exists' do
expect(project.default_environment).to be_nil
end
end
describe '#secret_variables_for' do describe '#secret_variables_for' do
let(:project) { create(:project) } let(:project) { create(:project) }
......
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