webpack/redux/reducers/RedHatRepositories/sets.js in katello-3.7.0.rc1 vs webpack/redux/reducers/RedHatRepositories/sets.js in katello-3.7.0.rc2

- old
+ new

@@ -3,39 +3,46 @@ import { REPOSITORY_SETS_REQUEST, REPOSITORY_SETS_SUCCESS, REPOSITORY_SETS_FAILURE, + REPOSITORY_SETS_UPDATE_RECOMMENDED, } from '../../consts'; import { initialState } from './sets.fixtures.js'; export default (state = initialState, action) => { - if (action.type === REPOSITORY_SETS_REQUEST) { - return state.set('loading', true); - } else if (action.type === REPOSITORY_SETS_SUCCESS) { - const { - page, per_page, subtotal, results, // eslint-disable-line camelcase - } = action.response; + const { payload } = action; - return Immutable({ - results, - pagination: { - page: Number(page), - // server can return per_page: null when there's error in the search query, - // don't store it in such case - // eslint-disable-next-line camelcase - perPage: Number(per_page || state.pagination.perPage), - }, - itemCount: Number(subtotal), - loading: false, - searchIsActive: !isEmpty(action.search), - search: action.search, - }); - } else if (action.type === REPOSITORY_SETS_FAILURE) { - return Immutable({ - error: action.error, - loading: false, - }); + switch (action.type) { + case REPOSITORY_SETS_REQUEST: + return state.set('loading', true); + + case REPOSITORY_SETS_UPDATE_RECOMMENDED: + return state + .set('recommended', payload); + + case REPOSITORY_SETS_SUCCESS: + return state + .set('results', payload.response.results) + .set('pagination', { + page: Number(payload.response.page), + // server can return per_page: null when there's error in the search query, + // don't store it in such case + // eslint-disable-next-line camelcase + perPage: Number(payload.response.per_page || state.pagination.perPage), + }) + .set('itemCount', Number(payload.response.subtotal)) + .set('loading', false) + .set('searchIsActive', !isEmpty(payload.search)) + .set('search', payload.search); + + case REPOSITORY_SETS_FAILURE: + return Immutable({ + error: payload, + loading: false, + }); + + default: + return state; } - return state; };