+ client: server side pagination for the query logs

This commit is contained in:
Ildar Kamalov
2019-09-20 15:05:10 +03:00
parent 81828c87c1
commit 9ac6049405
12 changed files with 323 additions and 99 deletions

View File

@@ -4,11 +4,54 @@ import * as actions from '../actions/queryLogs';
const queryLogs = handleActions(
{
[actions.setLogsPagination]: (state, { payload }) => {
const { page, pageSize } = payload;
const { allLogs } = state;
const rowsStart = pageSize * page;
const rowsEnd = (pageSize * page) + pageSize;
const logsSlice = allLogs.slice(rowsStart, rowsEnd);
const pages = Math.ceil(allLogs.length / pageSize);
return {
...state,
pages,
logs: logsSlice,
};
},
[actions.getLogsRequest]: state => ({ ...state, processingGetLogs: true }),
[actions.getLogsFailure]: state => ({ ...state, processingGetLogs: false }),
[actions.getLogsSuccess]: (state, { payload }) => {
const newState = { ...state, logs: payload, processingGetLogs: false };
return newState;
const {
logs, lastRowTime, page, pageSize, filtered, refreshLogs,
} = payload;
let logsWithOffset = state.allLogs.length > 0 ? state.allLogs : logs;
let allLogs = logs;
if (lastRowTime) {
logsWithOffset = [...state.allLogs, ...logs];
allLogs = [...state.allLogs, ...logs];
}
if (filtered || refreshLogs) {
logsWithOffset = logs;
allLogs = logs;
}
const pages = Math.ceil(logsWithOffset.length / pageSize);
const total = logsWithOffset.length;
const rowsStart = pageSize * page;
const rowsEnd = (pageSize * page) + pageSize;
const logsSlice = logsWithOffset.slice(rowsStart, rowsEnd);
return {
...state,
pages,
total,
allLogs,
logs: logsSlice,
processingGetLogs: false,
};
},
[actions.clearLogsRequest]: state => ({ ...state, processingClear: true }),
@@ -42,6 +85,10 @@ const queryLogs = handleActions(
processingSetConfig: false,
logs: [],
interval: 1,
allLogs: [],
pages: 0,
offset: 0,
total: 0,
enabled: true,
},
);