+ client: separate filters from the table component
This commit is contained in:
committed by
Simon Zolin
parent
6b64d393bd
commit
e243e69a6e
@@ -4,8 +4,19 @@ import apiClient from '../api/Api';
|
||||
import { addErrorToast, addSuccessToast } from './index';
|
||||
import { normalizeLogs } from '../helpers/helpers';
|
||||
|
||||
const getLogsWithParams = async (config) => {
|
||||
const { older_than, filter, ...values } = config;
|
||||
const rawLogs = await apiClient.getQueryLog({ ...filter, older_than });
|
||||
const { data, oldest } = rawLogs;
|
||||
const logs = normalizeLogs(data);
|
||||
|
||||
return {
|
||||
logs, oldest, older_than, filter, ...values,
|
||||
};
|
||||
};
|
||||
|
||||
export const setLogsPagination = createAction('LOGS_PAGINATION');
|
||||
export const setLogsFilter = createAction('LOGS_FILTER');
|
||||
export const setLogsPage = createAction('SET_LOG_PAGE');
|
||||
|
||||
export const getLogsRequest = createAction('GET_LOGS_REQUEST');
|
||||
export const getLogsFailure = createAction('GET_LOGS_FAILURE');
|
||||
@@ -14,19 +25,30 @@ export const getLogsSuccess = createAction('GET_LOGS_SUCCESS');
|
||||
export const getLogs = config => async (dispatch) => {
|
||||
dispatch(getLogsRequest());
|
||||
try {
|
||||
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,
|
||||
}));
|
||||
const logs = await getLogsWithParams(config);
|
||||
dispatch(getLogsSuccess(logs));
|
||||
} catch (error) {
|
||||
dispatch(addErrorToast({ error }));
|
||||
dispatch(getLogsFailure(error));
|
||||
}
|
||||
};
|
||||
|
||||
export const setLogsFilterRequest = createAction('SET_LOGS_FILTER_REQUEST');
|
||||
export const setLogsFilterFailure = createAction('SET_LOGS_FILTER_FAILURE');
|
||||
export const setLogsFilterSuccess = createAction('SET_LOGS_FILTER_SUCCESS');
|
||||
|
||||
export const setLogsFilter = filter => async (dispatch) => {
|
||||
dispatch(setLogsFilterRequest());
|
||||
try {
|
||||
const logs = await getLogsWithParams({ older_than: '', filter });
|
||||
dispatch(setLogsFilterSuccess(logs));
|
||||
dispatch(setLogsPage(0));
|
||||
} catch (error) {
|
||||
dispatch(addErrorToast({ error }));
|
||||
dispatch(setLogsFilterFailure(error));
|
||||
}
|
||||
};
|
||||
|
||||
export const clearLogsRequest = createAction('CLEAR_LOGS_REQUEST');
|
||||
export const clearLogsFailure = createAction('CLEAR_LOGS_FAILURE');
|
||||
export const clearLogsSuccess = createAction('CLEAR_LOGS_SUCCESS');
|
||||
|
||||
Reference in New Issue
Block a user