From 941b6c5976d8b9aad57e054b2ef5d69e210004e9 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Wed, 13 Nov 2019 19:09:40 +0300 Subject: [PATCH] + client: use oldest param --- client/src/actions/queryLogs.js | 10 +++++++--- client/src/components/Logs/index.js | 14 ++++++-------- client/src/reducers/queryLogs.js | 7 ++++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/client/src/actions/queryLogs.js b/client/src/actions/queryLogs.js index 09e93a60..29f5bc45 100644 --- a/client/src/actions/queryLogs.js +++ b/client/src/actions/queryLogs.js @@ -14,9 +14,13 @@ export const getLogsSuccess = createAction('GET_LOGS_SUCCESS'); export const getLogs = config => async (dispatch) => { dispatch(getLogsRequest()); try { - const { filter, lastRowTime: older_than } = config; - const logs = normalizeLogs(await apiClient.getQueryLog({ ...filter, older_than })); - dispatch(getLogsSuccess({ logs, ...config })); + 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, + })); } catch (error) { dispatch(addErrorToast({ error })); dispatch(getLogsFailure(error)); diff --git a/client/src/components/Logs/index.js b/client/src/components/Logs/index.js index e61b19d1..fbb2e7df 100644 --- a/client/src/components/Logs/index.js +++ b/client/src/components/Logs/index.js @@ -41,10 +41,10 @@ class Logs extends Component { this.props.getLogsConfig(); } - getLogs = (lastRowTime, filter, page, pageSize, filtered) => { + getLogs = (older_than, filter, page, pageSize, filtered) => { if (this.props.queryLogs.enabled) { 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(); }; - handleLogsFiltering = debounce((lastRowTime, filter, page, pageSize, filtered) => { + handleLogsFiltering = debounce((older_than, filter, page, pageSize, filtered) => { this.props.getLogs({ - lastRowTime, + older_than, filter, page, pageSize, @@ -264,13 +264,11 @@ class Logs extends Component { fetchData = (state) => { const { pageSize, page, pages } = state; - const { allLogs, filter } = this.props.queryLogs; + const { filter, oldest } = this.props.queryLogs; const isLastPage = pages && (page + 1 === pages); if (isLastPage) { - const lastRow = allLogs[allLogs.length - 1]; - const lastRowTime = (lastRow && lastRow.time) || ''; - this.getLogs(lastRowTime, filter, page, pageSize, true); + this.getLogs(oldest, filter, page, pageSize, false); } else { this.props.setLogsPagination({ page, pageSize }); } diff --git a/client/src/reducers/queryLogs.js b/client/src/reducers/queryLogs.js index 2f04099b..ff59426f 100644 --- a/client/src/reducers/queryLogs.js +++ b/client/src/reducers/queryLogs.js @@ -28,12 +28,12 @@ const queryLogs = handleActions( [actions.getLogsFailure]: state => ({ ...state, processingGetLogs: false }), [actions.getLogsSuccess]: (state, { payload }) => { const { - logs, lastRowTime, page, pageSize, filtered, + logs, oldest, older_than, page, pageSize, filtered, } = payload; let logsWithOffset = state.allLogs.length > 0 ? state.allLogs : logs; let allLogs = logs; - if (lastRowTime) { + if (older_than) { logsWithOffset = [...state.allLogs, ...logs]; allLogs = [...state.allLogs, ...logs]; } else if (filtered) { @@ -49,6 +49,7 @@ const queryLogs = handleActions( return { ...state, + oldest, pages, total, allLogs, @@ -93,7 +94,7 @@ const queryLogs = handleActions( pages: 0, total: 0, enabled: true, - older_than: '', + oldest: '', filter: DEFAULT_LOGS_FILTER, }, );