1 import {Action} from 'redux';
6 UpdateDrawingBoardStatusAction,
7 UpdateGenericModalCriteria,
8 UpdateGenericModalHelper,
9 DeleteGenericModalHelper,
10 DeleteGenericModalTabelDataHelper,
11 UpdateGenericModalTableDataHelper, UpdateCurrentModalModeAction
12 } from "./global.actions";
13 import * as _ from "lodash";
15 export interface GlobalState {
17 flags : { [key: string]: boolean };
18 drawingBoardStatus : string;
19 genericModalCriteria : { [key: string]: any };
20 genericModalHelper : { [key: string]: any };
21 isUpdateModalMode?: boolean;
25 const initialState: GlobalState = {
28 drawingBoardStatus : null,
29 genericModalCriteria : {
32 genericModalHelper : {},
33 isUpdateModalMode : null
36 export const globalReducer =
37 function (state: GlobalState = initialState, action: Action): GlobalState {
38 switch (action.type) {
39 case GlobalActions.UPDATE_NAME:
40 return Object.assign(state, state, (<UpdateGlobalAction>action));
41 case GlobalActions.UPDATE_FLAGS:
42 Object.assign(state, (<UpdateFlagsAction>action));
43 return Object.assign({}, state);
44 case GlobalActions.UPDATE_DRAWING_BOARD_STATUS:
45 return Object.assign(state, state, (<UpdateDrawingBoardStatusAction>action));
46 case GlobalActions.UPDATE_GENERIC_MODAL_CRITERIA : {
47 const updateGenericModalCriteria = <UpdateGenericModalCriteria>action;
48 let newState = _.cloneDeep(state);
49 if(_.isNil(newState.genericModalCriteria)){
50 newState.genericModalCriteria = {};
52 newState.genericModalCriteria[updateGenericModalCriteria.field] = updateGenericModalCriteria.values;
55 case GlobalActions.UPDATE_GENERIC_MODAL_HELPER : {
56 const updateGenericModalHelper= <UpdateGenericModalHelper>action;
57 let newState = _.cloneDeep(state);
58 if(_.isNil(newState.genericModalHelper) ){newState.genericModalHelper = {}; }
59 if(_.isNil(newState.genericModalHelper[updateGenericModalHelper.field])){
60 newState.genericModalHelper[updateGenericModalHelper.field] = {};
62 newState.genericModalHelper[updateGenericModalHelper.field][updateGenericModalHelper.values[updateGenericModalHelper.uniqObjectField]] = updateGenericModalHelper.values;
65 case GlobalActions.DELETE_GENERIC_MODAL_HELPER : {
66 const deleteGenericModalHelper= <DeleteGenericModalHelper>action;
67 let newState = _.cloneDeep(state);
68 delete newState.genericModalHelper[deleteGenericModalHelper.field][deleteGenericModalHelper.uniqObjectField];
71 case GlobalActions.CLEAR_ALL_GENERIC_MODAL_HELPER : {
72 let newState = _.cloneDeep(state);
73 newState.genericModalHelper = {};
76 case GlobalActions.DELETE_GENERIC_MODAL_TABLE_DATA_HELPER : {
77 let newState = _.cloneDeep(state);
78 delete newState.genericModalHelper[(<DeleteGenericModalTabelDataHelper>action).field];
81 case GlobalActions.UPDATE_GENERIC_MODAL_TABLE_DATA_HELPER : {
82 let newState = _.cloneDeep(state);
83 newState.genericModalHelper[(<UpdateGenericModalTableDataHelper>action).field] = (<UpdateGenericModalTableDataHelper>action).values ;
86 case GlobalActions.UPDATE_CURRENT_MODAL_MODE : {
87 let newState = {...state};
88 if ((<UpdateCurrentModalModeAction>action).isUpdateModalMode === null){
89 delete newState.isUpdateModalMode;
91 newState.isUpdateModalMode = (<UpdateCurrentModalModeAction>action).isUpdateModalMode;