Commit 824a2106 authored by Tim Zallmann's avatar Tim Zallmann

Merge branch '214281-modify-dashboard-title' into 'master'

Change the title of the metrics dashboard page

See merge request gitlab-org/gitlab!30392
parents 62c5f15a 71956174
...@@ -147,6 +147,7 @@ export default { ...@@ -147,6 +147,7 @@ export default {
return { return {
selectedTimeRange: timeRangeFromUrl() || defaultTimeRange, selectedTimeRange: timeRangeFromUrl() || defaultTimeRange,
isRearrangingPanels: false, isRearrangingPanels: false,
originalDocumentTitle: document.title,
}; };
}, },
computed: { computed: {
...@@ -192,6 +193,9 @@ export default { ...@@ -192,6 +193,9 @@ export default {
}, },
deep: true, deep: true,
}, },
selectedDashboard(dashboard) {
this.prependToDocumentTitle(dashboard?.display_name);
},
}, },
created() { created() {
window.addEventListener('keyup', this.onKeyup); window.addEventListener('keyup', this.onKeyup);
...@@ -258,6 +262,11 @@ export default { ...@@ -258,6 +262,11 @@ export default {
// Collapse group if no data is available // Collapse group if no data is available
return !this.getMetricStates(groupKey).includes(metricStates.OK); return !this.getMetricStates(groupKey).includes(metricStates.OK);
}, },
prependToDocumentTitle(text) {
if (text) {
document.title = `${text} · ${this.originalDocumentTitle}`;
}
},
onTimeRangeZoom({ start, end }) { onTimeRangeZoom({ start, end }) {
updateHistory({ updateHistory({
url: mergeUrlParams({ start, end }, window.location.href), url: mergeUrlParams({ start, end }, window.location.href),
......
...@@ -6,7 +6,7 @@ module Metrics ...@@ -6,7 +6,7 @@ module Metrics
module Dashboard module Dashboard
class SelfMonitoringDashboardService < ::Metrics::Dashboard::PredefinedDashboardService class SelfMonitoringDashboardService < ::Metrics::Dashboard::PredefinedDashboardService
DASHBOARD_PATH = 'config/prometheus/self_monitoring_default.yml' DASHBOARD_PATH = 'config/prometheus/self_monitoring_default.yml'
DASHBOARD_NAME = 'Default' DASHBOARD_NAME = N_('Default dashboard')
SEQUENCE = [ SEQUENCE = [
STAGES::CustomMetricsInserter, STAGES::CustomMetricsInserter,
...@@ -23,7 +23,7 @@ module Metrics ...@@ -23,7 +23,7 @@ module Metrics
def all_dashboard_paths(_project) def all_dashboard_paths(_project)
[{ [{
path: DASHBOARD_PATH, path: DASHBOARD_PATH,
display_name: DASHBOARD_NAME, display_name: _(DASHBOARD_NAME),
default: true, default: true,
system_dashboard: false system_dashboard: false
}] }]
......
...@@ -6,7 +6,7 @@ module Metrics ...@@ -6,7 +6,7 @@ module Metrics
module Dashboard module Dashboard
class SystemDashboardService < ::Metrics::Dashboard::PredefinedDashboardService class SystemDashboardService < ::Metrics::Dashboard::PredefinedDashboardService
DASHBOARD_PATH = 'config/prometheus/common_metrics.yml' DASHBOARD_PATH = 'config/prometheus/common_metrics.yml'
DASHBOARD_NAME = 'Default' DASHBOARD_NAME = N_('Default dashboard')
SEQUENCE = [ SEQUENCE = [
STAGES::CommonMetricsInserter, STAGES::CommonMetricsInserter,
...@@ -22,7 +22,7 @@ module Metrics ...@@ -22,7 +22,7 @@ module Metrics
def all_dashboard_paths(_project) def all_dashboard_paths(_project)
[{ [{
path: DASHBOARD_PATH, path: DASHBOARD_PATH,
display_name: DASHBOARD_NAME, display_name: _(DASHBOARD_NAME),
default: true, default: true,
system_dashboard: true system_dashboard: true
}] }]
......
- page_title _("Metrics for environment"), @environment.name - page_title _("Metrics Dashboard"), @environment.name
.prometheus-container .prometheus-container
#prometheus-graphs{ data: metrics_data(@project, @environment) } #prometheus-graphs{ data: metrics_data(@project, @environment) }
---
title: Add metrics dashboard name to document title
merge_request: 30392
author:
type: added
...@@ -6988,6 +6988,9 @@ msgstr "" ...@@ -6988,6 +6988,9 @@ msgstr ""
msgid "Default classification label" msgid "Default classification label"
msgstr "" msgstr ""
msgid "Default dashboard"
msgstr ""
msgid "Default deletion adjourned period" msgid "Default deletion adjourned period"
msgstr "" msgstr ""
...@@ -13756,9 +13759,6 @@ msgstr "" ...@@ -13756,9 +13759,6 @@ msgstr ""
msgid "Metrics and profiling" msgid "Metrics and profiling"
msgstr "" msgstr ""
msgid "Metrics for environment"
msgstr ""
msgid "Metrics::Dashboard::Annotation|Annotation can't belong to both a cluster and an environment at the same time" msgid "Metrics::Dashboard::Annotation|Annotation can't belong to both a cluster and an environment at the same time"
msgstr "" msgstr ""
......
...@@ -134,7 +134,7 @@ describe MetricsDashboard do ...@@ -134,7 +134,7 @@ describe MetricsDashboard do
it 'adds starred dashboard information and sorts the list' do it 'adds starred dashboard information and sorts the list' do
all_dashboards = json_response['all_dashboards'].map { |dashboard| dashboard.slice('display_name', 'starred', 'user_starred_path') } all_dashboards = json_response['all_dashboards'].map { |dashboard| dashboard.slice('display_name', 'starred', 'user_starred_path') }
expected_response = [ expected_response = [
{ "display_name" => "Default", "starred" => false, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: 'config/prometheus/common_metrics.yml' }) }, { "display_name" => "Default dashboard", "starred" => false, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: 'config/prometheus/common_metrics.yml' }) },
{ "display_name" => "anomaly.yml", "starred" => false, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: '.gitlab/dashboards/anomaly.yml' }) }, { "display_name" => "anomaly.yml", "starred" => false, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: '.gitlab/dashboards/anomaly.yml' }) },
{ "display_name" => "errors.yml", "starred" => true, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: '.gitlab/dashboards/errors.yml' }) }, { "display_name" => "errors.yml", "starred" => true, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: '.gitlab/dashboards/errors.yml' }) },
{ "display_name" => "test.yml", "starred" => true, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: '.gitlab/dashboards/test.yml' }) } { "display_name" => "test.yml", "starred" => true, 'user_starred_path' => api_v4_projects_metrics_user_starred_dashboards_path(id: project.id, params: { dashboard_path: '.gitlab/dashboards/test.yml' }) }
......
...@@ -851,6 +851,62 @@ describe('Dashboard', () => { ...@@ -851,6 +851,62 @@ describe('Dashboard', () => {
}); });
}); });
describe('document title', () => {
const originalTitle = 'Original Title';
const defaultDashboardName = dashboardGitResponse[0].display_name;
beforeEach(() => {
document.title = originalTitle;
createShallowWrapper({ hasMetrics: true });
});
afterAll(() => {
document.title = '';
});
it('is prepended with default dashboard name by default', () => {
setupAllDashboards(store);
return wrapper.vm.$nextTick().then(() => {
expect(document.title.startsWith(`${defaultDashboardName} · `)).toBe(true);
});
});
it('is prepended with dashboard name if path is known', () => {
const dashboard = dashboardGitResponse[1];
const currentDashboard = dashboard.path;
setupAllDashboards(store, currentDashboard);
return wrapper.vm.$nextTick().then(() => {
expect(document.title.startsWith(`${dashboard.display_name} · `)).toBe(true);
});
});
it('is prepended with default dashboard name is path is not known', () => {
setupAllDashboards(store, 'unknown/path');
return wrapper.vm.$nextTick().then(() => {
expect(document.title.startsWith(`${defaultDashboardName} · `)).toBe(true);
});
});
it('is not modified when dashboard name is not provided', () => {
const dashboard = { ...dashboardGitResponse[1], display_name: null };
const currentDashboard = dashboard.path;
store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, [dashboard]);
store.commit(`monitoringDashboard/${types.SET_INITIAL_STATE}`, {
currentDashboard,
});
return wrapper.vm.$nextTick().then(() => {
expect(document.title).toBe(originalTitle);
});
});
});
describe('Dashboard dropdown', () => { describe('Dashboard dropdown', () => {
beforeEach(() => { beforeEach(() => {
createMountedWrapper({ hasMetrics: true }); createMountedWrapper({ hasMetrics: true });
......
...@@ -16,8 +16,13 @@ const setEnvironmentData = store => { ...@@ -16,8 +16,13 @@ const setEnvironmentData = store => {
store.commit(`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`, environmentData); store.commit(`monitoringDashboard/${types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS}`, environmentData);
}; };
export const setupAllDashboards = store => { export const setupAllDashboards = (store, path) => {
store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, dashboardGitResponse); store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, dashboardGitResponse);
if (path) {
store.commit(`monitoringDashboard/${types.SET_INITIAL_STATE}`, {
currentDashboard: path,
});
}
}; };
export const setupStoreWithDashboard = store => { export const setupStoreWithDashboard = store => {
...@@ -25,10 +30,6 @@ export const setupStoreWithDashboard = store => { ...@@ -25,10 +30,6 @@ export const setupStoreWithDashboard = store => {
`monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`, `monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`,
metricsDashboardPayload, metricsDashboardPayload,
); );
store.commit(
`monitoringDashboard/${types.RECEIVE_METRICS_DASHBOARD_SUCCESS}`,
metricsDashboardPayload,
);
}; };
export const setupStoreWithVariable = store => { export const setupStoreWithVariable = store => {
......
...@@ -142,7 +142,7 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi ...@@ -142,7 +142,7 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi
describe '.find_all_paths' do describe '.find_all_paths' do
let(:all_dashboard_paths) { described_class.find_all_paths(project) } let(:all_dashboard_paths) { described_class.find_all_paths(project) }
let(:system_dashboard) { { path: system_dashboard_path, display_name: 'Default', default: true, system_dashboard: true } } let(:system_dashboard) { { path: system_dashboard_path, display_name: 'Default dashboard', default: true, system_dashboard: true } }
it 'includes only the system dashboard by default' do it 'includes only the system dashboard by default' do
expect(all_dashboard_paths).to eq([system_dashboard]) expect(all_dashboard_paths).to eq([system_dashboard])
...@@ -163,7 +163,7 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi ...@@ -163,7 +163,7 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi
let(:self_monitoring_dashboard) do let(:self_monitoring_dashboard) do
{ {
path: self_monitoring_dashboard_path, path: self_monitoring_dashboard_path,
display_name: 'Default', display_name: 'Default dashboard',
default: true, default: true,
system_dashboard: false system_dashboard: false
} }
......
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