2017-04-25 21:12:19 -07:00
|
|
|
import {
|
|
|
|
initializeState,
|
|
|
|
receiveNodes,
|
|
|
|
receiveEntities,
|
|
|
|
createUrnMapping,
|
|
|
|
createPageMapping
|
|
|
|
} from 'wherehows-web/reducers/entities';
|
2017-04-25 18:48:53 -07:00
|
|
|
import { ActionTypes as DatasetActions } from 'wherehows-web/actions/datasets';
|
|
|
|
import { ActionTypes } from 'wherehows-web/actions/browse/entity';
|
2017-04-18 02:49:06 -07:00
|
|
|
|
|
|
|
/**
|
2017-04-25 21:12:19 -07:00
|
|
|
* datasets root reducer
|
2017-04-25 18:48:53 -07:00
|
|
|
* Takes the `datasets` slice of the state tree and performs the specified reductions for each action
|
|
|
|
* @param {Object} state slice of the state tree this reducer is responsible for
|
2017-04-18 02:49:06 -07:00
|
|
|
* @param {Object} action Flux Standard Action representing the action to be preformed on the state
|
|
|
|
* @prop {String} action.type actionType
|
2017-04-21 15:43:48 -07:00
|
|
|
* @return {Object}
|
2017-04-18 02:49:06 -07:00
|
|
|
*/
|
2017-04-25 21:12:19 -07:00
|
|
|
export default (state = initializeState(), action = {}) => {
|
2017-04-18 02:49:06 -07:00
|
|
|
switch (action.type) {
|
2017-04-25 18:48:53 -07:00
|
|
|
// Action indicating a request for datasets by page
|
|
|
|
case DatasetActions.SELECT_PAGED_DATASETS:
|
|
|
|
case DatasetActions.REQUEST_PAGED_DATASETS:
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
query: Object.assign({}, state.query, {
|
|
|
|
page: action.payload.page
|
|
|
|
}),
|
|
|
|
baseURL: action.payload.baseURL,
|
|
|
|
isFetching: true
|
|
|
|
});
|
|
|
|
// Action indicating a receipt of datasets by page
|
|
|
|
case DatasetActions.RECEIVE_PAGED_DATASETS:
|
|
|
|
case DatasetActions.RECEIVE_PAGED_URN_DATASETS:
|
|
|
|
return Object.assign({}, state, {
|
2017-04-25 21:12:19 -07:00
|
|
|
isFetching: false,
|
|
|
|
byId: receiveEntities('datasets')(state.byId, action.payload),
|
|
|
|
byUrn: createUrnMapping('datasets')(state.byUrn, action.payload),
|
|
|
|
byPage: createPageMapping('datasets')(state.byPage, action.payload)
|
2017-04-25 18:48:53 -07:00
|
|
|
});
|
2017-04-18 02:49:06 -07:00
|
|
|
|
|
|
|
case ActionTypes.SELECT_PAGED_DATASETS:
|
|
|
|
case ActionTypes.REQUEST_PAGED_DATASETS:
|
|
|
|
return Object.assign({}, state, {
|
2017-04-21 15:43:48 -07:00
|
|
|
currentPage: action.payload.page,
|
|
|
|
pageBaseURL: action.payload.pageBaseURL,
|
|
|
|
isFetching: true
|
2017-04-18 02:49:06 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|