+ client: handle logs configuration
This commit is contained in:
committed by
Simon Zolin
parent
27f895cf46
commit
a753ae86cc
69
client/src/actions/queryLogs.js
Normal file
69
client/src/actions/queryLogs.js
Normal file
@@ -0,0 +1,69 @@
|
||||
import { createAction } from 'redux-actions';
|
||||
|
||||
import Api from '../api/Api';
|
||||
import { addErrorToast, addSuccessToast } from './index';
|
||||
import { normalizeLogs } from '../helpers/helpers';
|
||||
|
||||
const apiClient = new Api();
|
||||
|
||||
export const getLogsRequest = createAction('GET_LOGS_REQUEST');
|
||||
export const getLogsFailure = createAction('GET_LOGS_FAILURE');
|
||||
export const getLogsSuccess = createAction('GET_LOGS_SUCCESS');
|
||||
|
||||
export const getLogs = () => async (dispatch) => {
|
||||
dispatch(getLogsRequest());
|
||||
try {
|
||||
const logs = normalizeLogs(await apiClient.getQueryLog());
|
||||
dispatch(getLogsSuccess(logs));
|
||||
} catch (error) {
|
||||
dispatch(addErrorToast({ error }));
|
||||
dispatch(getLogsFailure(error));
|
||||
}
|
||||
};
|
||||
|
||||
export const clearLogsRequest = createAction('CLEAR_LOGS_REQUEST');
|
||||
export const clearLogsFailure = createAction('CLEAR_LOGS_FAILURE');
|
||||
export const clearLogsSuccess = createAction('CLEAR_LOGS_SUCCESS');
|
||||
|
||||
export const clearLogs = () => async (dispatch) => {
|
||||
dispatch(clearLogsRequest());
|
||||
try {
|
||||
await apiClient.clearQueryLog();
|
||||
dispatch(clearLogsSuccess());
|
||||
dispatch(addSuccessToast('query_log_cleared'));
|
||||
} catch (error) {
|
||||
dispatch(addErrorToast({ error }));
|
||||
dispatch(clearLogsFailure(error));
|
||||
}
|
||||
};
|
||||
|
||||
export const getLogsConfigRequest = createAction('GET_LOGS_CONFIG_REQUEST');
|
||||
export const getLogsConfigFailure = createAction('GET_LOGS_CONFIG_FAILURE');
|
||||
export const getLogsConfigSuccess = createAction('GET_LOGS_CONFIG_SUCCESS');
|
||||
|
||||
export const getLogsConfig = () => async (dispatch) => {
|
||||
dispatch(getLogsConfigRequest());
|
||||
try {
|
||||
const data = await apiClient.getQueryLogInfo();
|
||||
dispatch(getLogsConfigSuccess(data));
|
||||
} catch (error) {
|
||||
dispatch(addErrorToast({ error }));
|
||||
dispatch(getLogsConfigFailure());
|
||||
}
|
||||
};
|
||||
|
||||
export const setLogsConfigRequest = createAction('SET_LOGS_CONFIG_REQUEST');
|
||||
export const setLogsConfigFailure = createAction('SET_LOGS_CONFIG_FAILURE');
|
||||
export const setLogsConfigSuccess = createAction('SET_LOGS_CONFIG_SUCCESS');
|
||||
|
||||
export const setLogsConfig = config => async (dispatch) => {
|
||||
dispatch(setLogsConfigRequest());
|
||||
try {
|
||||
await apiClient.setQueryLogConfig(config);
|
||||
dispatch(addSuccessToast('config_successfully_saved'));
|
||||
dispatch(setLogsConfigSuccess(config));
|
||||
} catch (error) {
|
||||
dispatch(addErrorToast({ error }));
|
||||
dispatch(setLogsConfigFailure());
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user