UNPKG

lml-main

Version:

This is now a mono repository published into many standalone packages.

62 lines 2.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Actions = require("../../jobs/actions"); const initialJobFlagsState = { active: null, expanded: {}, allExpanded: false, showingDirections: null, }; exports.jobFlagsReducer = (state = initialJobFlagsState, action) => { switch (action.type) { case Actions.SET_ACTIVE_JOB: { return setActiveJob(state, action); } case Actions.UNSET_ACTIVE_JOB: { return unsetActiveJob(state, action); } case Actions.SET_JOB_EXPANDED: { return setJobExpanded(state, action); } case Actions.SET_JOB_COLLAPSED: { return setJobCollapsed(state, action); } case Actions.SET_ALL_JOBS_EXPANDED: { return setAllJobsExpanded(state, action); } case Actions.SET_ALL_JOBS_COLLAPSED: { return setAllJobsCollapsed(state, action); } case Actions.SHOW_JOB_DIRECTIONS: { return showJobDirections(state, action); } case Actions.HIDE_JOB_DIRECTIONS: { return hideJobDirections(state, action); } default: { return state; } } }; const setActiveJob = (state, action) => (Object.assign({}, state, { active: action.refId })); const unsetActiveJob = (state, action) => { // If a refId has been supplied then check to make sure // that we are unsetting the right job. This might be // required if the active job has already changed and // we are trying to unset the previous active job if (action.refId && action.refId !== state.active) { return state; } return Object.assign({}, state, { active: null }); }; const setJobExpanded = (state, action) => (Object.assign({}, state, { expanded: Object.assign({}, state.expanded, { [action.refId]: true }) })); const setJobCollapsed = (state, action) => (Object.assign({}, state, { expanded: Object.keys(state.expanded).reduce((acc, curr) => { if (curr !== action.refId) acc[curr] = true; return acc; }, {}) })); const setAllJobsExpanded = (state, action) => (Object.assign({}, state, { allExpanded: !state.allExpanded })); const setAllJobsCollapsed = (state, action) => (Object.assign({}, state, { allExpanded: !state.allExpanded })); const showJobDirections = (state, action) => (Object.assign({}, state, { showingDirections: action.refId })); const hideJobDirections = (state, action) => state.showingDirections === action.refId ? (Object.assign({}, state, { showingDirections: null })) : state; //# sourceMappingURL=flags.js.map