Can't delete the second vfModule in drawing board - fix.
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / objectsToTree / models / vfModule / vfModule.model.info.ts
index 1b92eb8..b1a67a5 100644 (file)
@@ -74,19 +74,17 @@ export class VFModuleModelInfo implements ILevelNodeInfo {
 
   /***********************************************************
    * return vfModule model
-   * @param vfModuleModelId - current Model id
-   * @param instance
-   * @param serviceHierarchy - serviceHierarchy
+   * @param instanceModel - The model of the instance (usually extracted from
+   *        serviceHierarchy store)
    ************************************************************/
-  getModel = (vfModuleModelId: string, instance, serviceHierarchy): Partial<VfModule> => {
-    const model = this._sharedTreeService.modelByIdentifier(serviceHierarchy, this.name, vfModuleModelId);
-    if (!_.isNil(model)) {
-      return new VfModule(model, this._featureFlagsService.getAllFlags());
+  getModel = (instanceModel: any): Partial<VfModule> => {
+    if (!_.isNil(instanceModel)) {
+      return new VfModule(instanceModel, this._featureFlagsService.getAllFlags());
     }
     return {};
   };
 
-  createNode(instance: VfModuleInstance, currentModel: VfModule, parentModel: VNFModel, modelName: string, index: number): VfModuleTreeNode {
+  createNode(instance: VfModuleInstance, currentModel: VfModule, parentModel: VNFModel, modelName: string, index: number, serviceModelId: string): VfModuleTreeNode {
     let dynamicModelName = Object.keys(instance)[index];
     instance = instance[Object.keys(instance)[index]];
     const isEcompGeneratedNaming: boolean = this.isEcompGeneratedNaming(currentModel, parentModel);
@@ -96,7 +94,7 @@ export class VFModuleModelInfo implements ILevelNodeInfo {
 
     newVfModule.missingData = this._sharedTreeService.hasMissingData(instance, newVfModule.dynamicInputs, isEcompGeneratedNaming, []);
     newVfModule.typeName = this.typeName;
-    newVfModule.menuActions = this.getMenuAction(<any>newVfModule, currentModel.uuid);
+    newVfModule.menuActions = this.getMenuAction(<any>newVfModule, serviceModelId);
     newVfModule.isFailed = _.isNil(instance.isFailed) ? false : instance.isFailed;
     newVfModule.statusMessage = !_.isNil(instance.statusMessage) ? instance.statusMessage : "";
 
@@ -104,16 +102,16 @@ export class VFModuleModelInfo implements ILevelNodeInfo {
     return newVfModule;
   }
 
-  createInstanceTreeNode(instance: VfModuleInstance, currentModel: VfModule, parentModel: VNFModel, modelName: string): VfModuleTreeNode | VfModuleTreeNode[] {
+  createInstanceTreeNode(instance: any, model: any, parentModel: any, storeKey: string, serviceModelId: string): any {
     let numberOfChilds = Object.keys(instance).length;
     if (numberOfChilds > 1) {
       let result: VfModuleTreeNode[] = [];
       for (let i = 0; i < numberOfChilds; i++) {
-        result.push(this.createNode(instance, currentModel, parentModel, modelName, i));
+        result.push(this.createNode(instance, model, parentModel, storeKey, i, serviceModelId));
       }
       return result;
     } else {
-      return this.createNode(instance, currentModel, parentModel, modelName, 0);
+      return this.createNode(instance, model, parentModel, storeKey, 0, serviceModelId);
     }
   }
 
@@ -353,10 +351,10 @@ export class VFModuleModelInfo implements ILevelNodeInfo {
       },
       delete: {
         method: (node, serviceModelId) => {
-          this._store.dispatch(deleteActionVfModuleInstance(node.data.dynamicModelName, node.parent.data.vnfStoreKey, serviceModelId))
+          this._store.dispatch(deleteActionVfModuleInstance(node.data.dynamicModelName, node.parent.data.vnfStoreKey, serviceModelId, node.data.modelName))
         },
-        visible: (node) => this._sharedTreeService.shouldShowDelete(node),
-        enable: (node) => this._sharedTreeService.shouldShowDelete(node)
+        visible: (node) => this._sharedTreeService.shouldShowDelete(node, serviceModelId),
+        enable: (node) => this._sharedTreeService.shouldShowDelete(node, serviceModelId)
       },
       undoDelete: {
         method: (node, serviceModelId) => {
@@ -364,7 +362,7 @@ export class VFModuleModelInfo implements ILevelNodeInfo {
           this._store.dispatch(deleteVFModuleField(node.data.modelName,  node.parent.data.vnfStoreKey, node.data.servicedId ,node.data.dynamicModelName, 'retainAssignments'));
         },
         visible: (node) => this._sharedTreeService.shouldShowUndoDelete(node),
-        enable: (node, serviceModelId) => this._sharedTreeService.shouldShowUndoDelete(node) && this._sharedTreeService.shouldShowDelete(node.parent) && !this._sharedTreeService.isServiceOnDeleteMode(serviceModelId)
+        enable: (node, serviceModelId) => this._sharedTreeService.shouldShowUndoDelete(node) && this._sharedTreeService.shouldShowDelete(node.parent, serviceModelId) && !this._sharedTreeService.isServiceOnDeleteMode(serviceModelId)
       },
       upgrade: {
         method: (node, serviceModelId) => {