lml-main
Version:
This is now a mono repository published into many standalone packages.
50 lines • 2.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Actions = require("../../consolidations/actions");
const lodash_1 = require("lodash");
const initialConsolidationFlagsState = {
active: null,
expanded: [],
allExpanded: false,
};
exports.consolidationFlagsReducer = (state = initialConsolidationFlagsState, action) => {
switch (action.type) {
case Actions.SET_ACTIVE_CONSOLIDATION: {
return setActiveConsolidation(state, action);
}
case Actions.UNSET_ACTIVE_CONSOLIDATION: {
return unsetActiveConsolidation(state, action);
}
case Actions.SET_CONSOLIDATION_EXPANDED: {
return setConsolidationExpanded(state, action);
}
case Actions.SET_CONSOLIDATION_COLLAPSED: {
return setConsolidationCollapsed(state, action);
}
case Actions.SET_ALL_CONSOLIDATIONS_EXPANDED: {
return setAllConsolidationsExpanded(state, action);
}
case Actions.SET_ALL_CONSOLIDATIONS_COLLAPSED: {
return setAllConsolidationsCollapsed(state, action);
}
default: {
return state;
}
}
};
const setActiveConsolidation = (state, action) => (Object.assign({}, state, { active: action.refId }));
const unsetActiveConsolidation = (state, action) => {
// If a refId has been supplied then check to make sure
// that we are unsetting the right consolidation. This might be
// required if the active consolidation has already changed and
// we are trying to unset the previous active consolidation
if (action.refId && action.refId !== state.active) {
return state;
}
return Object.assign({}, state, { active: null });
};
const setConsolidationExpanded = (state, action) => (Object.assign({}, state, { expanded: lodash_1.union(state.expanded, [action.refId]) }));
const setConsolidationCollapsed = (state, action) => (Object.assign({}, state, { expanded: state.expanded.filter((s) => s !== action.refId) }));
const setAllConsolidationsExpanded = (state, action) => (Object.assign({}, state, { allExpanded: !state.allExpanded }));
const setAllConsolidationsCollapsed = (state, action) => (Object.assign({}, state, { allExpanded: !state.allExpanded }));
//# sourceMappingURL=flags.js.map