webpack/scenes/Tasks/TaskActions.js in katello-3.8.1 vs webpack/scenes/Tasks/TaskActions.js in katello-3.9.0.rc1

- old
+ new

@@ -6,13 +6,26 @@ GET_TASK_SUCCESS, GET_TASK_FAILURE, TASK_BULK_SEARCH_REQUEST, TASK_BULK_SEARCH_SUCCESS, TASK_BULK_SEARCH_FAILURE, + RESET_TASKS, } from './TaskConstants'; export const bulkSearch = (extendedParams = {}) => (dispatch) => { + const params = { + search: Object.entries(propsToSnakeCase(extendedParams)) + .map((item) => { + if (item[0] === 'action') { + return `${item[0]}~${item[1]}`; + } + return `${item[0]}=${item[1]}`; + }) + .join(' and '), + }; + + const onBulkSearchSuccess = ({ data }) => dispatch({ type: TASK_BULK_SEARCH_SUCCESS, response: data, }); @@ -20,21 +33,22 @@ type: TASK_BULK_SEARCH_FAILURE, result, }); dispatch({ type: TASK_BULK_SEARCH_REQUEST }); - - const params = { - searches: [{ ...propsToSnakeCase(extendedParams) }], - }; - return api - .post('/tasks/bulk_search', params) + .get('/tasks', {}, params) .then(onBulkSearchSuccess) .catch(onBulkSearchFailure); }; +export const resetTasks = () => (dispatch) => { + dispatch({ + type: RESET_TASKS, + }); +}; + export const loadTask = (taskId, extendedParams = {}) => (dispatch) => { dispatch({ type: GET_TASK_REQUEST }); const params = { ...propsToSnakeCase(extendedParams), @@ -53,30 +67,40 @@ }; const isUnauthorized = action => (action.result && action.result.response && action.result.response.status === 401); -export const pollBulkSearch = (extendedParams = {}, interval) => (dispatch) => { - const triggerPolling = (action) => { - if (!isUnauthorized(action)) { - setTimeout(() => dispatch(pollBulkSearch(extendedParams, interval)), interval); +export const pollBulkSearch = (extendedParams = {}, interval, orgId) => + (dispatch, getState) => { + const triggerPolling = (action) => { + const { id } = getState().katello.organization; + if (!isUnauthorized(action)) { + if (id === orgId) { + setTimeout(() => dispatch(pollBulkSearch(extendedParams, interval, orgId)), interval); + } + } + }; + const { id, loading } = getState().katello.organization; + + if (id === orgId && !loading) { + return dispatch(bulkSearch(extendedParams)).then(triggerPolling); } + + return dispatch({ type: 'POLLING_IS_SKIPPED' }); }; - return dispatch(bulkSearch(extendedParams)).then(triggerPolling); -}; - -export const pollTaskUntilDone = (taskId, extendedParams = {}, interval) => dispatch => ( - new Promise((resolve, reject) => { +export const pollTaskUntilDone = (taskId, extendedParams = {}, interval, orgId) => + (dispatch, getState) => new Promise((resolve, reject) => { const pollUntilDone = (action) => { - if (isUnauthorized(action)) { + const { id, loading } = getState().katello.organization; + + if (isUnauthorized(action) || id !== orgId || loading) { reject(action.result); - } else if (action.response.pending !== false) { + } else if (action.response.pending) { setTimeout(() => dispatch(loadTask(taskId, extendedParams)).then(pollUntilDone), interval); } else { resolve(action.response); } }; return dispatch(loadTask(taskId, extendedParams)).then(pollUntilDone); - }) -); + });