Commit c7e7a041 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'lm-grafana-auth-checkbox' into 'master'

frontend: Add grafana integration checkbox

See merge request gitlab-org/gitlab!19255
parents 2fc77624 850013f6
<script> <script>
import { GlButton, GlFormGroup, GlFormInput, GlLink } from '@gitlab/ui'; import { GlButton, GlFormGroup, GlFormInput, GlFormCheckbox, GlLink } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
export default { export default {
components: { components: {
GlButton, GlButton,
GlFormCheckbox,
GlFormGroup, GlFormGroup,
GlFormInput, GlFormInput,
GlLink, GlLink,
...@@ -15,7 +16,15 @@ export default { ...@@ -15,7 +16,15 @@ export default {
return { placeholderUrl: 'https://my-url.grafana.net/my-dashboard' }; return { placeholderUrl: 'https://my-url.grafana.net/my-dashboard' };
}, },
computed: { computed: {
...mapState(['operationsSettingsEndpoint', 'grafanaToken', 'grafanaUrl']), ...mapState(['operationsSettingsEndpoint', 'grafanaToken', 'grafanaUrl', 'grafanaEnabled']),
integrationEnabled: {
get() {
return this.grafanaEnabled;
},
set(grafanaEnabled) {
this.setGrafanaEnabled(grafanaEnabled);
},
},
localGrafanaToken: { localGrafanaToken: {
get() { get() {
return this.grafanaToken; return this.grafanaToken;
...@@ -34,7 +43,12 @@ export default { ...@@ -34,7 +43,12 @@ export default {
}, },
}, },
methods: { methods: {
...mapActions(['setGrafanaUrl', 'setGrafanaToken', 'updateGrafanaIntegration']), ...mapActions([
'setGrafanaUrl',
'setGrafanaToken',
'setGrafanaEnabled',
'updateGrafanaIntegration',
]),
}, },
}; };
</script> </script>
...@@ -52,6 +66,13 @@ export default { ...@@ -52,6 +66,13 @@ export default {
</div> </div>
<div class="settings-content"> <div class="settings-content">
<form> <form>
<gl-form-checkbox
id="grafana-integration-enabled"
v-model="integrationEnabled"
class="mb-4"
>
{{ s__('GrafanaIntegration|Active') }}
</gl-form-checkbox>
<gl-form-group <gl-form-group
:label="s__('GrafanaIntegration|Grafana URL')" :label="s__('GrafanaIntegration|Grafana URL')"
label-for="grafana-url" label-for="grafana-url"
......
...@@ -4,7 +4,6 @@ import GrafanaIntegration from './components/grafana_integration.vue'; ...@@ -4,7 +4,6 @@ import GrafanaIntegration from './components/grafana_integration.vue';
export default () => { export default () => {
const el = document.querySelector('.js-grafana-integration'); const el = document.querySelector('.js-grafana-integration');
return new Vue({ return new Vue({
el, el,
store: store(el.dataset), store: store(el.dataset),
......
...@@ -9,6 +9,9 @@ export const setGrafanaUrl = ({ commit }, url) => commit(mutationTypes.SET_GRAFA ...@@ -9,6 +9,9 @@ export const setGrafanaUrl = ({ commit }, url) => commit(mutationTypes.SET_GRAFA
export const setGrafanaToken = ({ commit }, token) => export const setGrafanaToken = ({ commit }, token) =>
commit(mutationTypes.SET_GRAFANA_TOKEN, token); commit(mutationTypes.SET_GRAFANA_TOKEN, token);
export const setGrafanaEnabled = ({ commit }, enabled) =>
commit(mutationTypes.SET_GRAFANA_ENABLED, enabled);
export const updateGrafanaIntegration = ({ state, dispatch }) => export const updateGrafanaIntegration = ({ state, dispatch }) =>
axios axios
.patch(state.operationsSettingsEndpoint, { .patch(state.operationsSettingsEndpoint, {
...@@ -16,6 +19,7 @@ export const updateGrafanaIntegration = ({ state, dispatch }) => ...@@ -16,6 +19,7 @@ export const updateGrafanaIntegration = ({ state, dispatch }) =>
grafana_integration_attributes: { grafana_integration_attributes: {
grafana_url: state.grafanaUrl, grafana_url: state.grafanaUrl,
token: state.grafanaToken, token: state.grafanaToken,
enabled: state.grafanaEnabled,
}, },
}, },
}) })
......
export const SET_GRAFANA_URL = 'SET_GRAFANA_URL'; export const SET_GRAFANA_URL = 'SET_GRAFANA_URL';
export const SET_GRAFANA_TOKEN = 'SET_GRAFANA_TOKEN'; export const SET_GRAFANA_TOKEN = 'SET_GRAFANA_TOKEN';
export const SET_GRAFANA_ENABLED = 'SET_GRAFANA_ENABLED';
...@@ -7,4 +7,7 @@ export default { ...@@ -7,4 +7,7 @@ export default {
[types.SET_GRAFANA_TOKEN](state, token) { [types.SET_GRAFANA_TOKEN](state, token) {
state.grafanaToken = token; state.grafanaToken = token;
}, },
[types.SET_GRAFANA_ENABLED](state, enabled) {
state.grafanaEnabled = enabled;
},
}; };
import { parseBoolean } from '~/lib/utils/common_utils';
export default (initialState = {}) => ({ export default (initialState = {}) => ({
operationsSettingsEndpoint: initialState.operationsSettingsEndpoint, operationsSettingsEndpoint: initialState.operationsSettingsEndpoint,
grafanaToken: initialState.grafanaIntegrationToken || '', grafanaToken: initialState.grafanaIntegrationToken || '',
grafanaUrl: initialState.grafanaIntegrationUrl || '', grafanaUrl: initialState.grafanaIntegrationUrl || '',
grafanaEnabled: parseBoolean(initialState.grafanaIntegrationEnabled) || false,
}); });
.js-grafana-integration{ data: { operations_settings_endpoint: project_settings_operations_path(@project), .js-grafana-integration{ data: { operations_settings_endpoint: project_settings_operations_path(@project),
grafana_integration: { url: grafana_integration_url, token: grafana_integration_token } } } grafana_integration: { url: grafana_integration_url, token: grafana_integration_token, enabled: grafana_integration_enabled?.to_s } } }
---
title: Add grafana integration active status checkbox
merge_request: 19255
author:
type: added
...@@ -8307,6 +8307,9 @@ msgstr "" ...@@ -8307,6 +8307,9 @@ msgstr ""
msgid "GrafanaIntegration|API Token" msgid "GrafanaIntegration|API Token"
msgstr "" msgstr ""
msgid "GrafanaIntegration|Active"
msgstr ""
msgid "GrafanaIntegration|Embed Grafana charts in GitLab issues." msgid "GrafanaIntegration|Embed Grafana charts in GitLab issues."
msgstr "" msgstr ""
......
...@@ -35,6 +35,15 @@ exports[`grafana integration component default state to match the default snapsh ...@@ -35,6 +35,15 @@ exports[`grafana integration component default state to match the default snapsh
class="settings-content" class="settings-content"
> >
<form> <form>
<glformcheckbox-stub
class="mb-4"
id="grafana-integration-enabled"
>
Active
</glformcheckbox-stub>
<glformgroup-stub <glformgroup-stub
description="Enter the base URL of the Grafana instance." description="Enter the base URL of the Grafana instance."
label="Grafana URL" label="Grafana URL"
......
...@@ -86,6 +86,7 @@ describe('grafana integration component', () => { ...@@ -86,6 +86,7 @@ describe('grafana integration component', () => {
grafana_integration_attributes: { grafana_integration_attributes: {
grafana_url: grafanaIntegrationUrl, grafana_url: grafanaIntegrationUrl,
token: grafanaIntegrationToken, token: grafanaIntegrationToken,
enabled: false,
}, },
}, },
}, },
......
...@@ -25,4 +25,11 @@ describe('grafana integration mutations', () => { ...@@ -25,4 +25,11 @@ describe('grafana integration mutations', () => {
expect(localState.grafanaToken).toBe(mockToken); expect(localState.grafanaToken).toBe(mockToken);
}); });
}); });
describe('SET_GRAFANA_ENABLED', () => {
it('updates grafanaEnabled for integration', () => {
mutations.SET_GRAFANA_ENABLED(localState, true);
expect(localState.grafanaEnabled).toBe(true);
});
});
}); });
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