debian-mirror-gitlab/app/assets/javascripts/grafana_integration/store/actions.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-09-04 01:27:46 +05:30
import createFlash from '~/flash';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
2019-12-26 22:10:19 +05:30
import { refreshCurrentPage } from '~/lib/utils/url_utility';
2021-03-11 19:13:27 +05:30
import { __ } from '~/locale';
2019-12-26 22:10:19 +05:30
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);
export const setGrafanaEnabled = ({ commit }, enabled) =>
commit(mutationTypes.SET_GRAFANA_ENABLED, enabled);
export const updateGrafanaIntegration = ({ state, dispatch }) =>
axios
.patch(state.operationsSettingsEndpoint, {
project: {
grafana_integration_attributes: {
grafana_url: state.grafanaUrl,
token: state.grafanaToken,
enabled: state.grafanaEnabled,
},
},
})
.then(() => dispatch('receiveGrafanaIntegrationUpdateSuccess'))
2021-03-08 18:12:59 +05:30
.catch((error) => dispatch('receiveGrafanaIntegrationUpdateError', error));
2019-12-26 22:10:19 +05:30
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 : '';
2021-09-04 01:27:46 +05:30
createFlash({
message: `${__('There was an error saving your changes.')} ${message}`,
});
2019-12-26 22:10:19 +05:30
};