+ client: server side pagination for the query logs
This commit is contained in:
@@ -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,
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user