+ client: use oldest param
This commit is contained in:
parent
33093de6aa
commit
941b6c5976
|
@ -14,9 +14,13 @@ export const getLogsSuccess = createAction('GET_LOGS_SUCCESS');
|
||||||
export const getLogs = config => async (dispatch) => {
|
export const getLogs = config => async (dispatch) => {
|
||||||
dispatch(getLogsRequest());
|
dispatch(getLogsRequest());
|
||||||
try {
|
try {
|
||||||
const { filter, lastRowTime: older_than } = config;
|
const { filter, older_than } = config;
|
||||||
const logs = normalizeLogs(await apiClient.getQueryLog({ ...filter, older_than }));
|
const rawLogs = await apiClient.getQueryLog({ ...filter, older_than });
|
||||||
dispatch(getLogsSuccess({ logs, ...config }));
|
const { data, oldest } = rawLogs;
|
||||||
|
const logs = normalizeLogs(data);
|
||||||
|
dispatch(getLogsSuccess({
|
||||||
|
logs, oldest, filter, ...config,
|
||||||
|
}));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(addErrorToast({ error }));
|
dispatch(addErrorToast({ error }));
|
||||||
dispatch(getLogsFailure(error));
|
dispatch(getLogsFailure(error));
|
||||||
|
|
|
@ -41,10 +41,10 @@ class Logs extends Component {
|
||||||
this.props.getLogsConfig();
|
this.props.getLogsConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogs = (lastRowTime, filter, page, pageSize, filtered) => {
|
getLogs = (older_than, filter, page, pageSize, filtered) => {
|
||||||
if (this.props.queryLogs.enabled) {
|
if (this.props.queryLogs.enabled) {
|
||||||
this.props.getLogs({
|
this.props.getLogs({
|
||||||
lastRowTime, filter, page, pageSize, filtered,
|
older_than, filter, page, pageSize, filtered,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -53,9 +53,9 @@ class Logs extends Component {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
};
|
};
|
||||||
|
|
||||||
handleLogsFiltering = debounce((lastRowTime, filter, page, pageSize, filtered) => {
|
handleLogsFiltering = debounce((older_than, filter, page, pageSize, filtered) => {
|
||||||
this.props.getLogs({
|
this.props.getLogs({
|
||||||
lastRowTime,
|
older_than,
|
||||||
filter,
|
filter,
|
||||||
page,
|
page,
|
||||||
pageSize,
|
pageSize,
|
||||||
|
@ -264,13 +264,11 @@ class Logs extends Component {
|
||||||
|
|
||||||
fetchData = (state) => {
|
fetchData = (state) => {
|
||||||
const { pageSize, page, pages } = state;
|
const { pageSize, page, pages } = state;
|
||||||
const { allLogs, filter } = this.props.queryLogs;
|
const { filter, oldest } = this.props.queryLogs;
|
||||||
const isLastPage = pages && (page + 1 === pages);
|
const isLastPage = pages && (page + 1 === pages);
|
||||||
|
|
||||||
if (isLastPage) {
|
if (isLastPage) {
|
||||||
const lastRow = allLogs[allLogs.length - 1];
|
this.getLogs(oldest, filter, page, pageSize, false);
|
||||||
const lastRowTime = (lastRow && lastRow.time) || '';
|
|
||||||
this.getLogs(lastRowTime, filter, page, pageSize, true);
|
|
||||||
} else {
|
} else {
|
||||||
this.props.setLogsPagination({ page, pageSize });
|
this.props.setLogsPagination({ page, pageSize });
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,12 @@ const queryLogs = handleActions(
|
||||||
[actions.getLogsFailure]: state => ({ ...state, processingGetLogs: false }),
|
[actions.getLogsFailure]: state => ({ ...state, processingGetLogs: false }),
|
||||||
[actions.getLogsSuccess]: (state, { payload }) => {
|
[actions.getLogsSuccess]: (state, { payload }) => {
|
||||||
const {
|
const {
|
||||||
logs, lastRowTime, page, pageSize, filtered,
|
logs, oldest, older_than, page, pageSize, filtered,
|
||||||
} = payload;
|
} = payload;
|
||||||
let logsWithOffset = state.allLogs.length > 0 ? state.allLogs : logs;
|
let logsWithOffset = state.allLogs.length > 0 ? state.allLogs : logs;
|
||||||
let allLogs = logs;
|
let allLogs = logs;
|
||||||
|
|
||||||
if (lastRowTime) {
|
if (older_than) {
|
||||||
logsWithOffset = [...state.allLogs, ...logs];
|
logsWithOffset = [...state.allLogs, ...logs];
|
||||||
allLogs = [...state.allLogs, ...logs];
|
allLogs = [...state.allLogs, ...logs];
|
||||||
} else if (filtered) {
|
} else if (filtered) {
|
||||||
|
@ -49,6 +49,7 @@ const queryLogs = handleActions(
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
oldest,
|
||||||
pages,
|
pages,
|
||||||
total,
|
total,
|
||||||
allLogs,
|
allLogs,
|
||||||
|
@ -93,7 +94,7 @@ const queryLogs = handleActions(
|
||||||
pages: 0,
|
pages: 0,
|
||||||
total: 0,
|
total: 0,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
older_than: '',
|
oldest: '',
|
||||||
filter: DEFAULT_LOGS_FILTER,
|
filter: DEFAULT_LOGS_FILTER,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue