Home Reference Source

application/redux/reducers/assignment-view-reducers.js

  1. import _ from 'lodash';
  2. import {
  3. ASSIGNMENT_VIEW_UPDATE,
  4. ASSIGNMENT_VIEW_RESET,
  5. ASSIGNMENT_VIEW_NOTIFY_NEW,
  6. ASSIGNMENT_VIEW_CLEAR_NEW
  7. } from './../actions/assignment-view-actions';
  8.  
  9. const baseState = {
  10. filtersOn: false,
  11. hasNew: false,
  12. page: 1,
  13. type: 'unscheduled',
  14. keywords: null,
  15. workflow: null,
  16. status: null,
  17. sorter: 'modified_at',
  18. flip: false,
  19. hpd: false,
  20. cal: false,
  21. calview: 'issue',
  22. assignee: null,
  23. currentView: 'unassigned',
  24. issues: [],
  25. start: null,
  26. end: null,
  27. useDate: null
  28. };
  29.  
  30. export function assignmentView(state = null, action) {
  31. if (state === null) {
  32. state = baseState;
  33. }
  34.  
  35. switch (action.type) {
  36. case ASSIGNMENT_VIEW_UPDATE:
  37. let newState = Object.assign({}, state, action.payload);
  38. let testState = Object.assign({}, state, action.payload, {
  39. filtersOn: false,
  40. hasNew: false,
  41. page: 1,
  42. type: 'unscheduled',
  43. currentView: 'unassigned',
  44. calview: 'issue',
  45. issues: [],
  46. cal: false,
  47. start: null,
  48. end: null,
  49. useDate: null
  50. });
  51.  
  52. if (!_.isEqual(testState, baseState)) {
  53. newState.filtersOn = true;
  54. } else {
  55. newState.filtersOn = false;
  56. }
  57. return newState;
  58. case ASSIGNMENT_VIEW_RESET:
  59. let updateState = {};
  60. if (state.type) {
  61. updateState['type'] = state.type;
  62. }
  63. if (localStorage.getItem("assignmentCurrentView")) {
  64. updateState['currentView'] = localStorage.getItem("assignmentCurrentView");
  65. }
  66.  
  67. return Object.assign({}, baseState, updateState);
  68. case ASSIGNMENT_VIEW_NOTIFY_NEW:
  69. return Object.assign({}, state, {hasNew: true});
  70. case ASSIGNMENT_VIEW_CLEAR_NEW:
  71. return Object.assign({}, state, {hasNew: false});
  72. }
  73.  
  74. return state;
  75. };