diff options
author | Ittay Stern <ittay.stern@att.com> | 2019-07-07 19:23:03 +0300 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2019-07-08 16:13:43 +0300 |
commit | f792671ae247a931f34d902e9276202b5016ef9a (patch) | |
tree | 6104971e8074c9a3d720836276ff18619719ec02 /vid-webpack-master/src/app/shared/storeUtil/utils/global | |
parent | fc62274e8d15964d63c62bf0e2f4abc040252ee9 (diff) |
Merge from ecomp 718fd196 - Modern UI
Issue-ID: VID-378
Change-Id: I2736b98426e324ec3aa233b034229ba84d99839f
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils/global')
3 files changed, 233 insertions, 4 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.actions.ts index 609ec69f4..4af0243e6 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.actions.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.actions.ts @@ -3,7 +3,15 @@ import {Action, ActionCreator} from "redux"; export enum GlobalActions { UPDATE_NAME = 'UPDATE_NAME', UPDATE_FLAGS = 'UPDATE_FLAGS', - UPDATE_DRAWING_BOARD_STATUS = 'UPDATE_DRAWING_BOARD_STATUS' + UPDATE_DRAWING_BOARD_STATUS = 'UPDATE_DRAWING_BOARD_STATUS', + UPDATE_GENERIC_MODAL_CRITERIA = 'UPDATE_GENERIC_MODAL_CRITERIA', + UPDATE_GENERIC_MODAL_HELPER = 'UPDATE_GENERIC_MODAL_HELPER', + DELETE_GENERIC_MODAL_HELPER = 'DELETE_GENERIC_MODAL_HELPER', + CLEAR_ALL_GENERIC_MODAL_HELPER = 'CLEAR_ALL_GENERIC_MODAL_HELPER', + UPDATE_GENERIC_MODAL_TABLE_DATA_HELPER = 'UPDATE_GENERIC_MODAL_TABLE_DATA_HELPER', + DELETE_GENERIC_MODAL_TABLE_DATA_HELPER = 'DELETE_GENERIC_MODAL_TABLE_DATA_HELPER', + UPDATE_GENERIC_CURRNT_VRF_HELPER = 'UPDATE_GENERIC_CURRNT_VRF_HELPER', + DELETE_GENERIC_CURRNT_VRF_HELPER = 'DELETE_GENERIC_CURRNT_VRF_HELPER' } export interface UpdateGlobalAction extends Action { @@ -18,6 +26,33 @@ export interface UpdateDrawingBoardStatusAction extends Action{ drawingBoardStatus?: any; } +export interface UpdateGenericModalCriteria extends Action { + field: any; + values: any; +} + +export interface UpdateGenericModalTableDataHelper extends Action { + field: any; + values: any; +} +export interface UpdateGenericModalHelper extends Action { + field: any; + values: any; + uniqObjectField : string; +} + +export interface DeleteGenericModalHelper extends Action { + field: any; + uniqObjectField : string; +} + +export interface DeleteGenericModalTabelDataHelper extends Action { + field: any; +} + + +export interface ClearGenericModalHelper extends Action {} + export const updateName: ActionCreator<UpdateGlobalAction> = (name) => ({ type: GlobalActions.UPDATE_NAME, @@ -35,3 +70,39 @@ export const updateDrawingBoardStatus: ActionCreator<UpdateDrawingBoardStatusAct type: GlobalActions.UPDATE_DRAWING_BOARD_STATUS, drawingBoardStatus: drawingBoardStatus }); + + +export const updateGenericModalCriteria: ActionCreator<UpdateGenericModalCriteria> = (field, values) => ({ + type : GlobalActions.UPDATE_GENERIC_MODAL_CRITERIA, + field: field, + values: values +}); + +export const updateGenericModalhelper: ActionCreator<UpdateGenericModalHelper> = (field, values, uniqObjectField) => ({ + type : GlobalActions.UPDATE_GENERIC_MODAL_HELPER, + field: field, + values: values, + uniqObjectField : uniqObjectField +}); + +export const deleteGenericModalhelper: ActionCreator<DeleteGenericModalHelper> = (field, uniqObjectField) => ({ + type : GlobalActions.DELETE_GENERIC_MODAL_HELPER, + field: field, + uniqObjectField : uniqObjectField +}); + + +export const updateGenericModalTableDataHelper: ActionCreator<UpdateGenericModalTableDataHelper> = (field, values) => ({ + type : GlobalActions.UPDATE_GENERIC_MODAL_TABLE_DATA_HELPER, + field: field, + values: values, +}); + +export const deleteGenericModalTableDataHelper: ActionCreator<DeleteGenericModalTabelDataHelper> = (field) => ({ + type : GlobalActions.DELETE_GENERIC_MODAL_TABLE_DATA_HELPER, + field: field, +}); + +export const clearAllGenericModalhelper: ActionCreator<ClearGenericModalHelper> = (field, uniqObjectField) => ({ + type : GlobalActions.CLEAR_ALL_GENERIC_MODAL_HELPER +}); diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.spec.ts index 4fc80863a..c8aecdd57 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.spec.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.spec.ts @@ -1,4 +1,14 @@ -import {GlobalActions, UpdateFlagsAction, UpdateGlobalAction, UpdateDrawingBoardStatusAction} from "./global.actions"; +import { + GlobalActions, + UpdateFlagsAction, + UpdateGlobalAction, + UpdateDrawingBoardStatusAction, + UpdateGenericModalCriteria, + UpdateGenericModalHelper, + DeleteGenericModalHelper, + ClearGenericModalHelper, + UpdateGenericModalTableDataHelper +} from "./global.actions"; import {globalReducer} from "./global.reducers"; @@ -42,6 +52,96 @@ describe('globalReducer', () => { expect(globalDrawingBoardState).toBeDefined(); expect(globalDrawingBoardState.drawingBoardStatus).toEqual(drawingBoardStatus); }); + + test('#UPDATE_GENERIC_MODAL_CRITERIA : should update updateGenericModalCriteria object', ()=> { + const values = ["value1", "value2"]; + const fieldName = "someFieldName"; + let globalDrawingBoardState = globalReducer(<any>{global : {},genericModalCriteria : {}}, + <UpdateGenericModalCriteria>{ + type: GlobalActions.UPDATE_GENERIC_MODAL_CRITERIA, + field : fieldName, + values : values + }); + expect(globalDrawingBoardState).toBeDefined(); + expect(globalDrawingBoardState.genericModalCriteria[fieldName]).toEqual(values); + }); + + test('#UPDATE_GENERIC_MODAL_HELPER : should update updateGenericModalHelper object', ()=> { + const uniqObjectField = "uniqObjectField"; + const values = {name : "value1", uniqObjectField: uniqObjectField}; + const fieldName = "someFieldName"; + + let globalDrawingBoardState = globalReducer(<any>{global : {},genericModalHelper : {}}, + <UpdateGenericModalHelper>{ + type: GlobalActions.UPDATE_GENERIC_MODAL_HELPER, + field : fieldName, + values : values, + uniqObjectField : uniqObjectField + }); + expect(globalDrawingBoardState).toBeDefined(); + expect(globalDrawingBoardState.genericModalHelper[fieldName][uniqObjectField]).toEqual({"name": "value1", "uniqObjectField": "uniqObjectField"}); + }); + + test('#DELETE_GENERIC_MODAL_HELPER : should delete exist ', ()=> { + const uniqObjectField = "uniqObjectField"; + const fieldName = "someFieldName"; + + let globalDrawingBoardState = globalReducer(<any>{global : {},genericModalHelper : { + "someFieldName" : { + "uniqObjectField" : true + } + }}, + <DeleteGenericModalHelper>{ + type: GlobalActions.DELETE_GENERIC_MODAL_HELPER, + field : fieldName, + uniqObjectField : uniqObjectField + }); + expect(globalDrawingBoardState).toBeDefined(); + expect(globalDrawingBoardState.genericModalHelper[fieldName][uniqObjectField]).toBeUndefined(); + }); + + test('#CLEAR_ALL_GENERIC_MODAL_HELPER : should clear generic modal object', ()=> { + + let globalDrawingBoardState = globalReducer(<any>{global : {},genericModalHelper : { + "someFieldName" : { + "uniqObjectField" : true + } + }}, + <ClearGenericModalHelper>{ + type: GlobalActions.CLEAR_ALL_GENERIC_MODAL_HELPER + }); + expect(globalDrawingBoardState.genericModalHelper).toEqual({}); + }); + + test('#UPDATE_GENERIC_MODAL_TABLE_DATA_HELPER : should update table data with some values', ()=> { + const keyName: string = 'VPN_DATA'; + const someValue: string = 'SOME_VALUE'; + + let globalDrawingBoardState = globalReducer(<any>{global : {},genericModalHelper : { + + }}, + <UpdateGenericModalTableDataHelper>{ + type: GlobalActions.UPDATE_GENERIC_MODAL_TABLE_DATA_HELPER, + field : keyName, + values : someValue + }); + expect(globalDrawingBoardState.genericModalHelper[keyName]).toEqual(someValue); + }); + + test('#DELETE_GENERIC_MODAL_TABLE_DATA_HELPER : should delete table data', ()=> { + const keyName: string = 'VPN_DATA'; + const someValue: string = 'SOME_VALUE'; + + let globalDrawingBoardState = globalReducer(<any>{global : {},genericModalHelper : { + [keyName] : someValue + }}, + <UpdateGenericModalTableDataHelper>{ + type: GlobalActions.DELETE_GENERIC_MODAL_TABLE_DATA_HELPER, + field : keyName + }); + expect(globalDrawingBoardState.genericModalHelper[keyName]).toBeUndefined(); + }); + }); diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.ts index f9e083414..aedcce24b 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/global/global.reducers.ts @@ -1,16 +1,34 @@ import {Action} from 'redux'; -import {GlobalActions, UpdateFlagsAction, UpdateGlobalAction, UpdateDrawingBoardStatusAction} from "./global.actions"; +import { + GlobalActions, + UpdateFlagsAction, + UpdateGlobalAction, + UpdateDrawingBoardStatusAction, + UpdateGenericModalCriteria, + UpdateGenericModalHelper, + DeleteGenericModalHelper, + DeleteGenericModalTabelDataHelper, + UpdateGenericModalTableDataHelper +} from "./global.actions"; +import * as _ from "lodash"; export interface GlobalState { name : string; flags : { [key: string]: boolean }; drawingBoardStatus : string; + genericModalCriteria : { [key: string]: any }; + genericModalHelper : { [key: string]: any }; + } const initialState: GlobalState = { name : null, flags : null, - drawingBoardStatus : null + drawingBoardStatus : null, + genericModalCriteria : { + roles : [] + }, + genericModalHelper : {} }; export const globalReducer = @@ -23,6 +41,46 @@ export const globalReducer = return Object.assign({}, state); case GlobalActions.UPDATE_DRAWING_BOARD_STATUS: return Object.assign(state, state, (<UpdateDrawingBoardStatusAction>action)); + case GlobalActions.UPDATE_GENERIC_MODAL_CRITERIA : { + const updateGenericModalCriteria = <UpdateGenericModalCriteria>action; + let newState = _.cloneDeep(state); + if(_.isNil(newState.genericModalCriteria)){ + newState.genericModalCriteria = {}; + } + newState.genericModalCriteria[updateGenericModalCriteria.field] = updateGenericModalCriteria.values; + return newState; + } + case GlobalActions.UPDATE_GENERIC_MODAL_HELPER : { + const updateGenericModalHelper= <UpdateGenericModalHelper>action; + let newState = _.cloneDeep(state); + if(_.isNil(newState.genericModalHelper) ){newState.genericModalHelper = {}; } + if(_.isNil(newState.genericModalHelper[updateGenericModalHelper.field])){ + newState.genericModalHelper[updateGenericModalHelper.field] = {}; + } + newState.genericModalHelper[updateGenericModalHelper.field][updateGenericModalHelper.values[updateGenericModalHelper.uniqObjectField]] = updateGenericModalHelper.values; + return newState; + } + case GlobalActions.DELETE_GENERIC_MODAL_HELPER : { + const deleteGenericModalHelper= <DeleteGenericModalHelper>action; + let newState = _.cloneDeep(state); + delete newState.genericModalHelper[deleteGenericModalHelper.field][deleteGenericModalHelper.uniqObjectField]; + return newState; + } + case GlobalActions.CLEAR_ALL_GENERIC_MODAL_HELPER : { + let newState = _.cloneDeep(state); + newState.genericModalHelper = {}; + return newState; + } + case GlobalActions.DELETE_GENERIC_MODAL_TABLE_DATA_HELPER : { + let newState = _.cloneDeep(state); + delete newState.genericModalHelper[(<DeleteGenericModalTabelDataHelper>action).field]; + return newState; + } + case GlobalActions.UPDATE_GENERIC_MODAL_TABLE_DATA_HELPER : { + let newState = _.cloneDeep(state); + newState.genericModalHelper[(<UpdateGenericModalTableDataHelper>action).field] = (<UpdateGenericModalTableDataHelper>action).values ; + return newState; + } default: return state; } |