Commit d7016ed8 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'set-multiple-custom-metrics-edit-path' into 'master'

Multiple metrics edit navigates to prom edit page

See merge request gitlab-org/gitlab!30666
parents 15145fc8 f1e987f3
...@@ -552,6 +552,7 @@ export default { ...@@ -552,6 +552,7 @@ export default {
<dashboard-panel <dashboard-panel
v-show="expandedPanel.panel" v-show="expandedPanel.panel"
ref="expandedPanel" ref="expandedPanel"
:settings-path="settingsPath"
:clipboard-text="generatePanelLink(expandedPanel.group, expandedPanel.panel)" :clipboard-text="generatePanelLink(expandedPanel.group, expandedPanel.panel)"
:graph-data="expandedPanel.panel" :graph-data="expandedPanel.panel"
:alerts-endpoint="alertsEndpoint" :alerts-endpoint="alertsEndpoint"
...@@ -610,6 +611,7 @@ export default { ...@@ -610,6 +611,7 @@ export default {
</div> </div>
<dashboard-panel <dashboard-panel
:settings-path="settingsPath"
:clipboard-text="generatePanelLink(groupData.group, graphData)" :clipboard-text="generatePanelLink(groupData.group, graphData)"
:graph-data="graphData" :graph-data="graphData"
:alerts-endpoint="alertsEndpoint" :alerts-endpoint="alertsEndpoint"
......
...@@ -82,6 +82,11 @@ export default { ...@@ -82,6 +82,11 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
settingsPath: {
type: String,
required: false,
default: null,
},
}, },
data() { data() {
return { return {
...@@ -196,6 +201,9 @@ export default { ...@@ -196,6 +201,9 @@ export default {
return Boolean(this.graphDataHasResult && !this.basicChartComponent); return Boolean(this.graphDataHasResult && !this.basicChartComponent);
}, },
editCustomMetricLink() { editCustomMetricLink() {
if (this.graphData.metrics.length > 1) {
return this.settingsPath;
}
return this.graphData?.metrics[0].edit_path; return this.graphData?.metrics[0].edit_path;
}, },
editCustomMetricLinkText() { editCustomMetricLinkText() {
......
---
title: Multiple metrics edit navigates to prom edit page
merge_request: 30666
author:
type: added
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
singleStatMetricsResult, singleStatMetricsResult,
graphDataPrometheusQueryRangeMultiTrack, graphDataPrometheusQueryRangeMultiTrack,
barMockData, barMockData,
propsData,
} from '../mock_data'; } from '../mock_data';
import { panelTypes } from '~/monitoring/constants'; import { panelTypes } from '~/monitoring/constants';
...@@ -60,6 +61,7 @@ describe('Dashboard Panel', () => { ...@@ -60,6 +61,7 @@ describe('Dashboard Panel', () => {
wrapper = shallowMount(DashboardPanel, { wrapper = shallowMount(DashboardPanel, {
propsData: { propsData: {
graphData, graphData,
settingsPath: propsData.settingsPath,
...props, ...props,
}, },
store, store,
...@@ -239,6 +241,7 @@ describe('Dashboard Panel', () => { ...@@ -239,6 +241,7 @@ describe('Dashboard Panel', () => {
describe('Edit custom metric dropdown item', () => { describe('Edit custom metric dropdown item', () => {
const findEditCustomMetricLink = () => wrapper.find({ ref: 'editMetricLink' }); const findEditCustomMetricLink = () => wrapper.find({ ref: 'editMetricLink' });
const mockEditPath = '/root/kubernetes-gke-project/prometheus/metrics/23/edit';
beforeEach(() => { beforeEach(() => {
createWrapper(); createWrapper();
...@@ -257,7 +260,7 @@ describe('Dashboard Panel', () => { ...@@ -257,7 +260,7 @@ describe('Dashboard Panel', () => {
metrics: [ metrics: [
{ {
...graphData.metrics[0], ...graphData.metrics[0],
edit_path: '/root/kubernetes-gke-project/prometheus/metrics/23/edit', edit_path: mockEditPath,
}, },
], ],
}, },
...@@ -266,10 +269,11 @@ describe('Dashboard Panel', () => { ...@@ -266,10 +269,11 @@ describe('Dashboard Panel', () => {
return wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(findEditCustomMetricLink().exists()).toBe(true); expect(findEditCustomMetricLink().exists()).toBe(true);
expect(findEditCustomMetricLink().text()).toBe('Edit metric'); expect(findEditCustomMetricLink().text()).toBe('Edit metric');
expect(findEditCustomMetricLink().attributes('href')).toBe(mockEditPath);
}); });
}); });
it('shows an "Edit metrics" link for a panel with multiple metrics', () => { it('shows an "Edit metrics" link pointing to settingsPath for a panel with multiple metrics', () => {
wrapper.setProps({ wrapper.setProps({
graphData: { graphData: {
...graphData, ...graphData,
...@@ -288,6 +292,7 @@ describe('Dashboard Panel', () => { ...@@ -288,6 +292,7 @@ describe('Dashboard Panel', () => {
return wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(findEditCustomMetricLink().text()).toBe('Edit metrics'); expect(findEditCustomMetricLink().text()).toBe('Edit metrics');
expect(findEditCustomMetricLink().attributes('href')).toBe(propsData.settingsPath);
}); });
}); });
}); });
...@@ -396,6 +401,7 @@ describe('Dashboard Panel', () => { ...@@ -396,6 +401,7 @@ describe('Dashboard Panel', () => {
wrapper = shallowMount(DashboardPanel, { wrapper = shallowMount(DashboardPanel, {
propsData: { propsData: {
clipboardText: exampleText, clipboardText: exampleText,
settingsPath: propsData.settingsPath,
graphData: { graphData: {
y_label: 'metric', y_label: 'metric',
...graphData, ...graphData,
...@@ -445,6 +451,7 @@ describe('Dashboard Panel', () => { ...@@ -445,6 +451,7 @@ describe('Dashboard Panel', () => {
wrapper = shallowMount(DashboardPanel, { wrapper = shallowMount(DashboardPanel, {
propsData: { propsData: {
graphData, graphData,
settingsPath: propsData.settingsPath,
namespace: mockNamespace, namespace: mockNamespace,
}, },
store, store,
...@@ -529,12 +536,12 @@ describe('Dashboard Panel', () => { ...@@ -529,12 +536,12 @@ describe('Dashboard Panel', () => {
}); });
describe.each` describe.each`
desc | metricsSavedToDb | propsData | isShown desc | metricsSavedToDb | props | isShown
${'with permission and no metrics in db'} | ${[]} | ${{}} | ${false} ${'with permission and no metrics in db'} | ${[]} | ${{}} | ${false}
${'with permission and related metrics in db'} | ${[graphData.metrics[0].metricId]} | ${{}} | ${true} ${'with permission and related metrics in db'} | ${[graphData.metrics[0].metricId]} | ${{}} | ${true}
${'without permission and related metrics in db'} | ${[graphData.metrics[0].metricId]} | ${{ prometheusAlertsAvailable: false }} | ${false} ${'without permission and related metrics in db'} | ${[graphData.metrics[0].metricId]} | ${{ prometheusAlertsAvailable: false }} | ${false}
${'with permission and unrelated metrics in db'} | ${['another_metric_id']} | ${{}} | ${false} ${'with permission and unrelated metrics in db'} | ${['another_metric_id']} | ${{}} | ${false}
`('$desc', ({ metricsSavedToDb, isShown, propsData }) => { `('$desc', ({ metricsSavedToDb, isShown, props }) => {
const showsDesc = isShown ? 'shows' : 'does not show'; const showsDesc = isShown ? 'shows' : 'does not show';
beforeEach(() => { beforeEach(() => {
...@@ -542,7 +549,7 @@ describe('Dashboard Panel', () => { ...@@ -542,7 +549,7 @@ describe('Dashboard Panel', () => {
createWrapper({ createWrapper({
alertsEndpoint: '/endpoint', alertsEndpoint: '/endpoint',
prometheusAlertsAvailable: true, prometheusAlertsAvailable: true,
...propsData, ...props,
}); });
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
......
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