2016-02-25 20:40:35 -08:00
|
|
|
import { OrderedMap, fromJS } from 'immutable';
|
2016-02-25 12:31:21 -08:00
|
|
|
import { CONFIG_SUCCESS } from '../actions/config';
|
2016-10-21 20:42:14 -02:00
|
|
|
import { FILES, FOLDER } from '../constants/collectionTypes';
|
|
|
|
|
|
|
|
const hasProperty = (config, property) => ({}.hasOwnProperty.call(config, property));
|
2016-02-25 00:45:56 -08:00
|
|
|
|
2016-06-10 00:16:01 -03:00
|
|
|
const collections = (state = null, action) => {
|
2016-02-25 00:45:56 -08:00
|
|
|
switch (action.type) {
|
2016-02-25 12:31:21 -08:00
|
|
|
case CONFIG_SUCCESS:
|
2016-10-21 20:42:14 -02:00
|
|
|
const configCollections = action.payload && action.payload.collections;
|
2016-02-25 20:40:35 -08:00
|
|
|
return OrderedMap().withMutations((map) => {
|
2016-10-21 20:42:14 -02:00
|
|
|
(configCollections || []).forEach((configCollection) => {
|
|
|
|
if (hasProperty(configCollection, 'folder')) {
|
|
|
|
configCollection.type = FOLDER; // eslint-disable-line no-param-reassign
|
|
|
|
} else if (hasProperty(configCollection, 'files')) {
|
|
|
|
configCollection.type = FILES; // eslint-disable-line no-param-reassign
|
|
|
|
}
|
|
|
|
map.set(configCollection.name, fromJS(configCollection));
|
2016-02-25 00:45:56 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2016-06-18 12:29:03 -07:00
|
|
|
};
|
2016-06-10 00:16:01 -03:00
|
|
|
|
|
|
|
export default collections;
|