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