Commit 7b67520a authored by Illya Klymov's avatar Illya Klymov

Merge branch '228761-add-info-to-panel-preview' into 'master'

Add ‘paste panel YAML into dashboard’ columns with buttons and message to panel preview page

See merge request gitlab-org/gitlab!38381
parents 6e6ab6e9 883f254a
...@@ -72,10 +72,6 @@ export default { ...@@ -72,10 +72,6 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
addDashboardDocumentationPath: {
type: String,
required: true,
},
settingsPath: { settingsPath: {
type: String, type: String,
required: true, required: true,
...@@ -409,7 +405,6 @@ export default { ...@@ -409,7 +405,6 @@ export default {
v-if="showHeader" v-if="showHeader"
ref="prometheusGraphsHeader" ref="prometheusGraphsHeader"
class="prometheus-graphs-header d-sm-flex flex-sm-wrap pt-2 pr-1 pb-0 pl-2 border-bottom bg-gray-light" class="prometheus-graphs-header d-sm-flex flex-sm-wrap pt-2 pr-1 pb-0 pl-2 border-bottom bg-gray-light"
:add-dashboard-documentation-path="addDashboardDocumentationPath"
:default-branch="defaultBranch" :default-branch="defaultBranch"
:rearrange-panels-available="rearrangePanelsAvailable" :rearrange-panels-available="rearrangePanelsAvailable"
:custom-metrics-available="customMetricsAvailable" :custom-metrics-available="customMetricsAvailable"
......
...@@ -107,10 +107,6 @@ export default { ...@@ -107,10 +107,6 @@ export default {
type: Object, type: Object,
required: true, required: true,
}, },
addDashboardDocumentationPath: {
type: String,
required: true,
},
}, },
data() { data() {
return { return {
...@@ -128,6 +124,7 @@ export default { ...@@ -128,6 +124,7 @@ export default {
'canAccessOperationsSettings', 'canAccessOperationsSettings',
'operationsSettingsPath', 'operationsSettingsPath',
'currentDashboard', 'currentDashboard',
'addDashboardDocumentationPath',
]), ]),
...mapGetters('monitoringDashboard', ['selectedDashboard', 'filteredEnvironments']), ...mapGetters('monitoringDashboard', ['selectedDashboard', 'filteredEnvironments']),
isOutOfTheBoxDashboard() { isOutOfTheBoxDashboard() {
......
<script> <script>
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import { GlCard, GlForm, GlFormGroup, GlFormTextarea, GlButton, GlAlert } from '@gitlab/ui'; import {
GlCard,
GlForm,
GlFormGroup,
GlFormTextarea,
GlButton,
GlSprintf,
GlAlert,
} from '@gitlab/ui';
import DashboardPanel from './dashboard_panel.vue'; import DashboardPanel from './dashboard_panel.vue';
const initialYml = `title: const initialYml = `title:
...@@ -18,6 +26,7 @@ export default { ...@@ -18,6 +26,7 @@ export default {
GlFormGroup, GlFormGroup,
GlFormTextarea, GlFormTextarea,
GlButton, GlButton,
GlSprintf,
GlAlert, GlAlert,
DashboardPanel, DashboardPanel,
}, },
...@@ -31,6 +40,8 @@ export default { ...@@ -31,6 +40,8 @@ export default {
'panelPreviewIsLoading', 'panelPreviewIsLoading',
'panelPreviewError', 'panelPreviewError',
'panelPreviewGraphData', 'panelPreviewGraphData',
'projectPath',
'addDashboardDocumentationPath',
]), ]),
}, },
methods: { methods: {
...@@ -43,45 +54,91 @@ export default { ...@@ -43,45 +54,91 @@ export default {
</script> </script>
<template> <template>
<div> <div>
<gl-card> <div class="gl-display-flex gl-mx-n3">
<template #header> <gl-card class="gl-flex-grow-1 gl-flex-basis-0 gl-mx-3">
<h2 class="gl-font-size-h2 gl-my-3">{{ s__('Metrics|Define and preview panel') }}</h2> <template #header>
</template> <h2 class="gl-font-size-h2 gl-my-3">{{ s__('Metrics|1. Define and preview panel') }}</h2>
<template #default> </template>
<gl-form @submit.prevent="onSubmit"> <template #default>
<gl-form-group <p>{{ s__('Metrics|Define panel YAML below to preview panel.') }}</p>
:label="s__('Metrics|Panel YAML')" <gl-form @submit.prevent="onSubmit">
:description="s__('Metrics|Define panel YAML to preview panel.')" <gl-form-group :label="s__('Metrics|Panel YAML')" label-for="panel-yml-input">
label-for="panel-yml-input" <gl-form-textarea
id="panel-yml-input"
v-model="yml"
class="gl-h-200! gl-font-monospace! gl-font-size-monospace!"
/>
</gl-form-group>
<div class="gl-text-right">
<gl-button
ref="clipboardCopyBtn"
variant="success"
category="secondary"
:data-clipboard-text="yml"
@click="$toast.show(s__('Metrics|Panel YAML copied'))"
>
{{ s__('Metrics|Copy YAML') }}
</gl-button>
<gl-button
type="submit"
variant="success"
:disabled="panelPreviewIsLoading"
class="js-no-auto-disable"
>
{{ s__('Metrics|Preview panel') }}
</gl-button>
</div>
</gl-form>
</template>
</gl-card>
<gl-card
class="gl-flex-grow-1 gl-flex-basis-0 gl-mx-3"
body-class="gl-display-flex gl-flex-direction-column"
>
<template #header>
<h2 class="gl-font-size-h2 gl-my-3">
{{ s__('Metrics|2. Paste panel YAML into dashboard') }}
</h2>
</template>
<template #default>
<div
class="gl-flex-grow-1 gl-display-flex gl-flex-direction-column gl-justify-content-center"
> >
<gl-form-textarea <p>
id="panel-yml-input" {{ s__('Metrics|Copy and paste the panel YAML into your dashboard YAML file.') }}
v-model="yml" <br />
class="gl-h-200! gl-font-monospace! gl-font-size-monospace!" <gl-sprintf
/> :message="
</gl-form-group> s__(
'Metrics|Dashboard files can be found in %{codeStart}.gitlab/dashboards%{codeEnd} at the root of this project.',
)
"
>
<template #code="{content}">
<code>{{ content }}</code>
</template>
</gl-sprintf>
</p>
</div>
<div class="gl-text-right"> <div class="gl-text-right">
<gl-button <gl-button
ref="clipboardCopyBtn" ref="viewDocumentationBtn"
variant="success"
category="secondary" category="secondary"
:data-clipboard-text="yml" variant="info"
@click="$toast.show(s__('Metrics|Panel YAML copied'))" target="_blank"
:href="addDashboardDocumentationPath"
> >
{{ s__('Metrics|Copy YAML') }} {{ s__('Metrics|View documentation') }}
</gl-button> </gl-button>
<gl-button <gl-button ref="openRepositoryBtn" variant="success" :href="projectPath">
type="submit" {{ s__('Metrics|Open repository') }}
variant="success"
:disabled="panelPreviewIsLoading"
class="js-no-auto-disable"
>
{{ s__('Metrics|Preview panel') }}
</gl-button> </gl-button>
</div> </div>
</gl-form> </template>
</template> </gl-card>
</gl-card> </div>
<gl-alert v-if="panelPreviewError" variant="warning" :dismissible="false"> <gl-alert v-if="panelPreviewError" variant="warning" :dismissible="false">
{{ panelPreviewError }} {{ panelPreviewError }}
......
...@@ -80,6 +80,7 @@ export default () => ({ ...@@ -80,6 +80,7 @@ export default () => ({
projectPath: null, projectPath: null,
operationsSettingsPath: '', operationsSettingsPath: '',
logsPath: invalidUrl, logsPath: invalidUrl,
addDashboardDocumentationPath: '',
// static paths // static paths
customDashboardBasePath: '', customDashboardBasePath: '',
......
...@@ -32,6 +32,7 @@ export const stateAndPropsFromDataset = (dataset = {}) => { ...@@ -32,6 +32,7 @@ export const stateAndPropsFromDataset = (dataset = {}) => {
logsPath, logsPath,
currentEnvironmentName, currentEnvironmentName,
customDashboardBasePath, customDashboardBasePath,
addDashboardDocumentationPath,
...dataProps ...dataProps
} = dataset; } = dataset;
...@@ -54,6 +55,7 @@ export const stateAndPropsFromDataset = (dataset = {}) => { ...@@ -54,6 +55,7 @@ export const stateAndPropsFromDataset = (dataset = {}) => {
logsPath, logsPath,
currentEnvironmentName, currentEnvironmentName,
customDashboardBasePath, customDashboardBasePath,
addDashboardDocumentationPath,
}, },
dataProps, dataProps,
}; };
......
...@@ -15094,6 +15094,12 @@ msgstr "" ...@@ -15094,6 +15094,12 @@ msgstr ""
msgid "MetricsSettings|User's local timezone" msgid "MetricsSettings|User's local timezone"
msgstr "" msgstr ""
msgid "Metrics|1. Define and preview panel"
msgstr ""
msgid "Metrics|2. Paste panel YAML into dashboard"
msgstr ""
msgid "Metrics|Add metric" msgid "Metrics|Add metric"
msgstr "" msgstr ""
...@@ -15115,6 +15121,9 @@ msgstr "" ...@@ -15115,6 +15121,9 @@ msgstr ""
msgid "Metrics|Copy YAML" msgid "Metrics|Copy YAML"
msgstr "" msgstr ""
msgid "Metrics|Copy and paste the panel YAML into your dashboard YAML file."
msgstr ""
msgid "Metrics|Create custom dashboard %{fileName}" msgid "Metrics|Create custom dashboard %{fileName}"
msgstr "" msgstr ""
...@@ -15133,10 +15142,10 @@ msgstr "" ...@@ -15133,10 +15142,10 @@ msgstr ""
msgid "Metrics|Current" msgid "Metrics|Current"
msgstr "" msgstr ""
msgid "Metrics|Define and preview panel" msgid "Metrics|Dashboard files can be found in %{codeStart}.gitlab/dashboards%{codeEnd} at the root of this project."
msgstr "" msgstr ""
msgid "Metrics|Define panel YAML to preview panel." msgid "Metrics|Define panel YAML below to preview panel."
msgstr "" msgstr ""
msgid "Metrics|Delete metric" msgid "Metrics|Delete metric"
......
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
import { redirectTo } from '~/lib/utils/url_utility'; import { redirectTo } from '~/lib/utils/url_utility';
const mockProjectPath = 'https://path/to/project'; const mockProjectPath = 'https://path/to/project';
const mockAddDashboardDocPath = '/doc/add-dashboard';
jest.mock('~/lib/utils/url_utility', () => ({ jest.mock('~/lib/utils/url_utility', () => ({
redirectTo: jest.fn(), redirectTo: jest.fn(),
...@@ -362,6 +363,7 @@ describe('Dashboard header', () => { ...@@ -362,6 +363,7 @@ describe('Dashboard header', () => {
describe('actions menu modals', () => { describe('actions menu modals', () => {
beforeEach(() => { beforeEach(() => {
store.state.monitoringDashboard.projectPath = mockProjectPath; store.state.monitoringDashboard.projectPath = mockProjectPath;
store.state.monitoringDashboard.addDashboardDocumentationPath = mockAddDashboardDocPath;
setupAllDashboards(store); setupAllDashboards(store);
createShallowWrapper(); createShallowWrapper();
...@@ -381,6 +383,9 @@ describe('Dashboard header', () => { ...@@ -381,6 +383,9 @@ describe('Dashboard header', () => {
it('"Create new dashboard" modal contains correct buttons', () => { it('"Create new dashboard" modal contains correct buttons', () => {
expect(findCreateDashboardModal().props('projectPath')).toBe(mockProjectPath); expect(findCreateDashboardModal().props('projectPath')).toBe(mockProjectPath);
expect(findCreateDashboardModal().props('addDashboardDocumentationPath')).toBe(
mockAddDashboardDocPath,
);
}); });
it('"Duplicate Dashboard" opens up a modal', () => { it('"Duplicate Dashboard" opens up a modal', () => {
......
...@@ -34,6 +34,8 @@ describe('dashboard invalid url parameters', () => { ...@@ -34,6 +34,8 @@ describe('dashboard invalid url parameters', () => {
const findTxtArea = () => findForm().find(GlFormTextarea); const findTxtArea = () => findForm().find(GlFormTextarea);
const findSubmitBtn = () => findForm().find('[type="submit"]'); const findSubmitBtn = () => findForm().find('[type="submit"]');
const findClipboardCopyBtn = () => wrapper.find({ ref: 'clipboardCopyBtn' }); const findClipboardCopyBtn = () => wrapper.find({ ref: 'clipboardCopyBtn' });
const findViewDocumentationBtn = () => wrapper.find({ ref: 'viewDocumentationBtn' });
const findOpenRepositoryBtn = () => wrapper.find({ ref: 'openRepositoryBtn' });
const findPanel = () => wrapper.find(DashboardPanel); const findPanel = () => wrapper.find(DashboardPanel);
beforeEach(() => { beforeEach(() => {
...@@ -108,6 +110,26 @@ describe('dashboard invalid url parameters', () => { ...@@ -108,6 +110,26 @@ describe('dashboard invalid url parameters', () => {
}); });
}); });
describe('instructions card', () => {
const mockDocsPath = '/docs-path';
const mockProjectPath = '/project-path';
beforeEach(() => {
store.state.monitoringDashboard.addDashboardDocumentationPath = mockDocsPath;
store.state.monitoringDashboard.projectPath = mockProjectPath;
createComponent();
});
it('displays next actions for the user', () => {
expect(findViewDocumentationBtn().exists()).toBe(true);
expect(findViewDocumentationBtn().attributes('href')).toBe(mockDocsPath);
expect(findOpenRepositoryBtn().exists()).toBe(true);
expect(findOpenRepositoryBtn().attributes('href')).toBe(mockProjectPath);
});
});
describe('when there is an error', () => { describe('when there is an error', () => {
const mockError = 'an error ocurred!'; const mockError = 'an error ocurred!';
......
...@@ -29,7 +29,6 @@ const datasetState = stateAndPropsFromDataset( ...@@ -29,7 +29,6 @@ const datasetState = stateAndPropsFromDataset(
// https://gitlab.com/gitlab-org/gitlab/-/issues/229256 // https://gitlab.com/gitlab-org/gitlab/-/issues/229256
export const dashboardProps = { export const dashboardProps = {
...datasetState.dataProps, ...datasetState.dataProps,
addDashboardDocumentationPath: 'https://path/to/docs',
alertsEndpoint: null, alertsEndpoint: null,
}; };
......
...@@ -611,7 +611,6 @@ export const storeVariables = [ ...@@ -611,7 +611,6 @@ export const storeVariables = [
export const dashboardHeaderProps = { export const dashboardHeaderProps = {
defaultBranch: 'master', defaultBranch: 'master',
addDashboardDocumentationPath: 'https://path/to/docs',
isRearrangingPanels: false, isRearrangingPanels: false,
selectedTimeRange: { selectedTimeRange: {
start: '2020-01-01T00:00:00.000Z', start: '2020-01-01T00:00:00.000Z',
......
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