2020-08-20 05:09:55 -04:00
|
|
|
import { deprecatedCreateFlash as createFlash } from '~/flash';
|
2021-02-14 13:09:20 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-10-29 20:07:52 -04:00
|
|
|
import { refreshCurrentPage } from '~/lib/utils/url_utility';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { __ } from '~/locale';
|
2019-10-29 20:07:52 -04:00
|
|
|
import * as mutationTypes from './mutation_types';
|
|
|
|
|
|
|
|
export const setGrafanaUrl = ({ commit }, url) => commit(mutationTypes.SET_GRAFANA_URL, url);
|
|
|
|
|
|
|
|
export const setGrafanaToken = ({ commit }, token) =>
|
|
|
|
commit(mutationTypes.SET_GRAFANA_TOKEN, token);
|
|
|
|
|
2019-11-07 01:06:12 -05:00
|
|
|
export const setGrafanaEnabled = ({ commit }, enabled) =>
|
|
|
|
commit(mutationTypes.SET_GRAFANA_ENABLED, enabled);
|
|
|
|
|
2019-10-29 20:07:52 -04:00
|
|
|
export const updateGrafanaIntegration = ({ state, dispatch }) =>
|
|
|
|
axios
|
|
|
|
.patch(state.operationsSettingsEndpoint, {
|
|
|
|
project: {
|
|
|
|
grafana_integration_attributes: {
|
|
|
|
grafana_url: state.grafanaUrl,
|
|
|
|
token: state.grafanaToken,
|
2019-11-07 01:06:12 -05:00
|
|
|
enabled: state.grafanaEnabled,
|
2019-10-29 20:07:52 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(() => dispatch('receiveGrafanaIntegrationUpdateSuccess'))
|
2020-12-23 19:10:25 -05:00
|
|
|
.catch((error) => dispatch('receiveGrafanaIntegrationUpdateError', error));
|
2019-10-29 20:07:52 -04:00
|
|
|
|
|
|
|
export const receiveGrafanaIntegrationUpdateSuccess = () => {
|
|
|
|
/**
|
|
|
|
* The operations_controller currently handles successful requests
|
|
|
|
* by creating a flash banner messsage to notify the user.
|
|
|
|
*/
|
|
|
|
refreshCurrentPage();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const receiveGrafanaIntegrationUpdateError = (_, error) => {
|
|
|
|
const { response } = error;
|
|
|
|
const message = response.data && response.data.message ? response.data.message : '';
|
|
|
|
|
|
|
|
createFlash(`${__('There was an error saving your changes.')} ${message}`, 'alert');
|
|
|
|
};
|