aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2019-12-05 14:27:02 +0000
committerGerrit Code Review <gerrit@onap.org>2019-12-05 14:27:02 +0000
commit0b62c11d045393d514d9c31dedad7d80febddd80 (patch)
tree6415cb78aac43406508b5ffc59b700ce6ce07adb /vid-webpack-master/src/app
parentbfc61c4bb476d05ed0e06ecc9e68121e364cfceb (diff)
parentf6a327dfaf48614967e7e43c50dbab394498b786 (diff)
Merge "Create UseTemplate Action and Reducer to update state with template from BE."
Diffstat (limited to 'vid-webpack-master/src/app')
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/main.reducer.ts4
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.action.ts17
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.reducer.spec.ts18
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.reducer.ts20
4 files changed, 59 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/main.reducer.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/main.reducer.ts
index c02049eb9..a135563eb 100644
--- a/vid-webpack-master/src/app/shared/storeUtil/utils/main.reducer.ts
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/main.reducer.ts
@@ -9,9 +9,11 @@ import {VNFActions} from "./vnf/vnf.actions";
import {vnfReducer} from "./vnf/vnf.reducers";
import {generalReducer} from "./general/general.reducers";
import {serviceReducer} from "./service/service.reducers";
+import {useTemplateReducer} from "./useTemplate/useTemplate.reducer";
import {networkReducer} from "./network/network.reducers";
import {vfModuleReducer} from "./vfModule/vfModule.reducers";
import {ServiceInstance} from "../../models/serviceInstance";
+import {UseTemplateActions} from "./useTemplate/useTemplate.action";
import {SelectOptionInterface} from "../../models/selectOption";
import {ServiceType} from "../../models/serviceType";
import {VnfGroupActions} from "./vnfGroup/vnfGroup.actions";
@@ -72,6 +74,8 @@ export const MainReducer = function (state: ServiceState = initialState, action:
return crReducer(state, action);
}else if(Object.values(NcfActions).includes(action.type)){
return ncfReducer(state, action);
+ } else if(Object.values(UseTemplateActions).includes(action.type)) {
+ return useTemplateReducer(state, action);
} else {
return Object.assign({}, state);
}
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.action.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.action.ts
new file mode 100644
index 000000000..2cfd38482
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.action.ts
@@ -0,0 +1,17 @@
+import {Action, ActionCreator} from "redux";
+import {ServiceInstance} from "../../../models/serviceInstance";
+
+export enum UseTemplateActions {
+ CREATE_SERVICE_INSTANCE_FROM_TEMPLATE = 'CREATE_SERVICE_INSTANCE_FROM_TEMPLATE',
+}
+
+export interface CreateServiceInstanceFromTemplate extends Action {
+ serviceInstantiationTemplate?: ServiceInstance;
+ serviceModelId?: string;
+}
+
+export const createServiceInstanceFromTemplate: ActionCreator<CreateServiceInstanceFromTemplate> = (serviceInstantiationTemplate, serviceModelId) => ({
+ type: UseTemplateActions.CREATE_SERVICE_INSTANCE_FROM_TEMPLATE,
+ serviceInstantiationTemplate: serviceInstantiationTemplate,
+ serviceModelId: serviceModelId
+});
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.reducer.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.reducer.spec.ts
new file mode 100644
index 000000000..e0f46e13a
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.reducer.spec.ts
@@ -0,0 +1,18 @@
+import {ServiceInstance} from "../../../models/serviceInstance";
+import {useTemplateReducer} from "./useTemplate.reducer";
+import {CreateServiceInstanceFromTemplate, UseTemplateActions} from "./useTemplate.action";
+
+test('#CREATE_SERVICE_INSTANCE_FROM_TEMPLATE should add new service instance from template to redux ', () => {
+ let serviceFromTemplateInstance: ServiceInstance = <any>{
+ instanceName: 'templateInstanceName'
+ };
+ let serviceState = useTemplateReducer(<any>{
+ serviceInstance:{}},
+ <CreateServiceInstanceFromTemplate> {
+ type: UseTemplateActions.CREATE_SERVICE_INSTANCE_FROM_TEMPLATE,
+ serviceModelId: 'serviceModelID',
+ serviceInstantiationTemplate: serviceFromTemplateInstance,
+ })
+ expect (serviceState).toBeDefined();
+ expect (serviceState.serviceInstance['serviceModelID'].instanceName).toEqual('templateInstanceName');
+});
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.reducer.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.reducer.ts
new file mode 100644
index 000000000..5a06d6e0a
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/useTemplate/useTemplate.reducer.ts
@@ -0,0 +1,20 @@
+import {ServiceState} from "../main.reducer";
+import {Action} from "redux";
+import {
+ createServiceInstanceFromTemplate,
+ CreateServiceInstanceFromTemplate,
+ UseTemplateActions
+} from "./useTemplate.action";
+import * as _ from "lodash";
+
+export function useTemplateReducer(state: ServiceState, action: Action) : ServiceState {
+ switch (action.type) {
+ case UseTemplateActions.CREATE_SERVICE_INSTANCE_FROM_TEMPLATE : {
+ const updateServiceInstanceFromTemplateAction = <CreateServiceInstanceFromTemplate>action;
+ const uuid = updateServiceInstanceFromTemplateAction.serviceModelId;
+ let newState = _.cloneDeep(state);
+ newState.serviceInstance[uuid] = updateServiceInstanceFromTemplateAction.serviceInstantiationTemplate;
+ return newState;
+ }
+ }
+}