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>
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 { mapState, mapActions } from 'vuex';
export default {
components: {
GlButton,
GlFormCheckbox,
GlFormGroup,
GlFormInput,
GlLink,
......@@ -15,7 +16,15 @@ export default {
return { placeholderUrl: 'https://my-url.grafana.net/my-dashboard' };
},
computed: {
...mapState(['operationsSettingsEndpoint', 'grafanaToken', 'grafanaUrl']),
...mapState(['operationsSettingsEndpoint', 'grafanaToken', 'grafanaUrl', 'grafanaEnabled']),
integrationEnabled: {
get() {
return this.grafanaEnabled;
},
set(grafanaEnabled) {
this.setGrafanaEnabled(grafanaEnabled);
},
},
localGrafanaToken: {
get() {
return this.grafanaToken;
......@@ -34,7 +43,12 @@ export default {
},
},
methods: {
...mapActions(['setGrafanaUrl', 'setGrafanaToken', 'updateGrafanaIntegration']),
...mapActions([
'setGrafanaUrl',
'setGrafanaToken',
'setGrafanaEnabled',
'updateGrafanaIntegration',
]),
},
};
</script>
......@@ -52,6 +66,13 @@ export default {
</div>
<div class="settings-content">
<form>
<gl-form-checkbox
id="grafana-integration-enabled"
v-model="integrationEnabled"
class="mb-4"
>
{{ s__('GrafanaIntegration|Active') }}
</gl-form-checkbox>
<gl-form-group
:label="s__('GrafanaIntegration|Grafana URL')"
label-for="grafana-url"
......
......@@ -4,7 +4,6 @@ import GrafanaIntegration from './components/grafana_integration.vue';
export default () => {
const el = document.querySelector('.js-grafana-integration');
return new Vue({
el,
store: store(el.dataset),
......
......@@ -9,6 +9,9 @@ export const setGrafanaUrl = ({ commit }, url) => commit(mutationTypes.SET_GRAFA
export const setGrafanaToken = ({ commit }, token) =>
commit(mutationTypes.SET_GRAFANA_TOKEN, token);
export const setGrafanaEnabled = ({ commit }, enabled) =>
commit(mutationTypes.SET_GRAFANA_ENABLED, enabled);
export const updateGrafanaIntegration = ({ state, dispatch }) =>
axios
.patch(state.operationsSettingsEndpoint, {
......@@ -16,6 +19,7 @@ export const updateGrafanaIntegration = ({ state, dispatch }) =>
grafana_integration_attributes: {
grafana_url: state.grafanaUrl,
token: state.grafanaToken,
enabled: state.grafanaEnabled,
},
},
})
......
export const SET_GRAFANA_URL = 'SET_GRAFANA_URL';
export const SET_GRAFANA_TOKEN = 'SET_GRAFANA_TOKEN';
export const SET_GRAFANA_ENABLED = 'SET_GRAFANA_ENABLED';
......@@ -7,4 +7,7 @@ export default {
[types.SET_GRAFANA_TOKEN](state, token) {
state.grafanaToken = token;
},
[types.SET_GRAFANA_ENABLED](state, enabled) {
state.grafanaEnabled = enabled;
},
};
import { parseBoolean } from '~/lib/utils/common_utils';
export default (initialState = {}) => ({
operationsSettingsEndpoint: initialState.operationsSettingsEndpoint,
grafanaToken: initialState.grafanaIntegrationToken || '',
grafanaUrl: initialState.grafanaIntegrationUrl || '',
grafanaEnabled: parseBoolean(initialState.grafanaIntegrationEnabled) || false,
});
.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 ""
msgid "GrafanaIntegration|API Token"
msgstr ""
msgid "GrafanaIntegration|Active"
msgstr ""
msgid "GrafanaIntegration|Embed Grafana charts in GitLab issues."
msgstr ""
......
......@@ -35,6 +35,15 @@ exports[`grafana integration component default state to match the default snapsh
class="settings-content"
>
<form>
<glformcheckbox-stub
class="mb-4"
id="grafana-integration-enabled"
>
Active
</glformcheckbox-stub>
<glformgroup-stub
description="Enter the base URL of the Grafana instance."
label="Grafana URL"
......
......@@ -86,6 +86,7 @@ describe('grafana integration component', () => {
grafana_integration_attributes: {
grafana_url: grafanaIntegrationUrl,
token: grafanaIntegrationToken,
enabled: false,
},
},
},
......
......@@ -25,4 +25,11 @@ describe('grafana integration mutations', () => {
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