2019-09-04 14:39:35 +00:00
|
|
|
import { createAction } from 'redux-actions';
|
|
|
|
|
2019-09-05 09:12:58 +00:00
|
|
|
import apiClient from '../api/Api';
|
2019-09-04 14:39:35 +00:00
|
|
|
import { addErrorToast, addSuccessToast } from './index';
|
|
|
|
import { normalizeLogs } from '../helpers/helpers';
|
|
|
|
|
2019-09-20 12:05:10 +00:00
|
|
|
export const setLogsPagination = createAction('LOGS_PAGINATION');
|
2019-09-26 08:36:02 +00:00
|
|
|
export const setLogsFilter = createAction('LOGS_FILTER');
|
2019-09-20 12:05:10 +00:00
|
|
|
|
2019-09-04 14:39:35 +00:00
|
|
|
export const getLogsRequest = createAction('GET_LOGS_REQUEST');
|
|
|
|
export const getLogsFailure = createAction('GET_LOGS_FAILURE');
|
|
|
|
export const getLogsSuccess = createAction('GET_LOGS_SUCCESS');
|
|
|
|
|
2019-09-20 12:05:10 +00:00
|
|
|
export const getLogs = config => async (dispatch) => {
|
2019-09-04 14:39:35 +00:00
|
|
|
dispatch(getLogsRequest());
|
|
|
|
try {
|
2019-11-13 16:09:40 +00:00
|
|
|
const { filter, older_than } = config;
|
|
|
|
const rawLogs = await apiClient.getQueryLog({ ...filter, older_than });
|
|
|
|
const { data, oldest } = rawLogs;
|
|
|
|
const logs = normalizeLogs(data);
|
|
|
|
dispatch(getLogsSuccess({
|
|
|
|
logs, oldest, filter, ...config,
|
|
|
|
}));
|
2019-09-04 14:39:35 +00:00
|
|
|
} 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());
|
|
|
|
}
|
|
|
|
};
|