Add delete button for archived VLM 70/128470/1
authorandre.schmid <andre.schmid@est.tech>
Mon, 11 Apr 2022 14:58:59 +0000 (15:58 +0100)
committerandre.schmid <andre.schmid@est.tech>
Mon, 11 Apr 2022 15:37:09 +0000 (16:37 +0100)
Adds a delete button for archived VLM in the VLM versions page.
Asks for a confirmation before deleting.
As VSP and VLM shares the same button, adds also a confirmation
before deleting the VSP.

Change-Id: I90af23cf3cff15d85292c895fdba7021aaa9649a
Issue-ID: SDC-3964
Signed-off-by: andre.schmid <andre.schmid@est.tech>
openecomp-ui/src/nfvo-utils/i18n/en.json
openecomp-ui/src/sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js
openecomp-ui/src/sdc-app/onboarding/versionsPage/VersionsPage.js
openecomp-ui/src/sdc-app/onboarding/versionsPage/VersionsPage.jsx
openecomp-ui/src/sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js

index 3a61fb3..f0613bc 100644 (file)
   "upload.status.validating": "Package is in validation",
   "upload.status.processing": "Package is being processed",
   "upload.status.success": "Package was successfully uploaded",
-  "upload.status.error": "Package upload resulted in error"
+  "upload.status.error": "Package upload resulted in error",
+  "vlm.delete.modal.title": "Delete Archived VLM",
+  "vlm.delete.archived.warning": "Deleting a Vendor Licence Model cannot be undone. Do you want to proceed?",
+  "vlm.delete.success": "The Vendor Licence Model was successfully deleted",
+  "vsp.delete.archived.warning": "Deleting a Vendor Software Product cannot be undone. Do you want to proceed?",
+  "vsp.delete.success": "The Vendor Software Product was successfully deleted",
+  "button.proceed.label": "Proceed",
+  "item.delete.success": "The item was successful deleted"
 }
index d6a3c8b..6bcee2e 100644 (file)
@@ -17,7 +17,6 @@ import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
 import Configuration from 'sdc-app/config/Configuration.js';
 import { actionTypes } from './LicenseModelConstants.js';
 import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
-import { actionsEnum as vcActionsEnum } from 'nfvo-components/panel/versionController/VersionControllerConstants.js';
 import i18n from 'nfvo-utils/i18n/i18n.js';
 import LicenseAgreementActionHelper from './licenseAgreement/LicenseAgreementActionHelper.js';
 import FeatureGroupsActionHelper from './featureGroups/FeatureGroupsActionHelper.js';
@@ -147,7 +146,7 @@ const LicenseModelActionHelper = {
             const onCommit = comment => {
                 return this.performVCAction(dispatch, {
                     licenseModelId,
-                    action: vcActionsEnum.COMMIT,
+                    action: VersionControllerActionsEnum.COMMIT,
                     version,
                     comment
                 }).then(() => {
@@ -176,7 +175,7 @@ const LicenseModelActionHelper = {
     performSubmitAction(dispatch, { licenseModelId, version }) {
         return putLicenseModelAction({
             itemId: licenseModelId,
-            action: vcActionsEnum.SUBMIT,
+            action: VersionControllerActionsEnum.SUBMIT,
             version
         }).then(() => {
             return ItemsHelper.checkItemStatus(dispatch, {
@@ -231,7 +230,7 @@ const LicenseModelActionHelper = {
                 return Promise.resolve(updatedVersion);
             }
             if (!inMerge) {
-                if (action === vcActionsEnum.SUBMIT) {
+                if (action === VersionControllerActionsEnum.SUBMIT) {
                     return this.manageSubmitAction(dispatch, {
                         licenseModelId,
                         version,
@@ -248,7 +247,7 @@ const LicenseModelActionHelper = {
                             itemType: itemTypes.LICENSE_MODEL,
                             itemId: licenseModelId
                         });
-                        if (action === vcActionsEnum.SYNC) {
+                        if (action === VersionControllerActionsEnum.SYNC) {
                             return MergeEditorActionHelper.analyzeSyncResult(
                                 dispatch,
                                 { itemId: licenseModelId, version }
@@ -286,6 +285,10 @@ const LicenseModelActionHelper = {
                 }
             });
         });
+    },
+
+    deleteLicenseModel(licenseModelId) {
+        return RestAPIUtil.destroy(`${baseUrl()}/${licenseModelId}`);
     }
 };
 
index 61c0d0a..b7d5417 100644 (file)
@@ -20,6 +20,9 @@ import VersionsPageCreationActionHelper from './creation/VersionsPageCreationAct
 import PermissionsActionHelper from '../permissions/PermissionsActionHelper.js';
 import { onboardingMethod as onboardingMethodType } from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js';
 import VersionsPageView from './VersionsPage.jsx';
+import { actionTypes as ModalActionTypes } from 'nfvo-components/modal/GlobalModalConstants';
+import i18n from 'nfvo-utils/i18n/i18n';
+import { itemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants';
 
 export const mapStateToProps = ({
     users: { userInfo },
@@ -99,8 +102,29 @@ export const mapActionsToProps = (
         onArchive: () => VersionsPageActionHelper.archiveItem(dispatch, itemId),
         onRestore: () =>
             VersionsPageActionHelper.restoreItemFromArchive(dispatch, itemId),
-        onDelete: () =>
-            VersionsPageActionHelper.deleteItemFromArchive(dispatch, itemId)
+        onDelete: () => {
+            let confirmMsgCode;
+            if (itemType === itemTypes.LICENSE_MODEL) {
+                confirmMsgCode = 'vlm.delete.archived.warning';
+            } else if (itemType === itemTypes.SOFTWARE_PRODUCT) {
+                confirmMsgCode = 'vsp.delete.archived.warning';
+            }
+            dispatch({
+                type: ModalActionTypes.GLOBAL_MODAL_WARNING,
+                data: {
+                    msg: i18n(confirmMsgCode),
+                    confirmationButtonText: i18n('button.proceed.label'),
+                    title: i18n('WARNING'),
+
+                    onConfirmed: () =>
+                        VersionsPageActionHelper.deleteArchivedItem(
+                            dispatch,
+                            itemId,
+                            itemType
+                        )
+                }
+            });
+        }
     };
 };
 
index 95c7530..e5bff51 100644 (file)
@@ -28,7 +28,6 @@ const ArchiveRestoreButton = ({
     deleteAction
 }) => (
     <div className="deprecate-btn-wrapper">
-        ,
         {isArchived ? (
             <div>
                 <Button
index 6ade7ff..506d594 100644 (file)
@@ -26,6 +26,7 @@ import {
 } from 'sdc-app/onboarding/OnboardingConstants.js';
 import { notificationActions } from 'nfvo-components/notification/NotificationsConstants.js';
 import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper';
+import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper';
 
 const VersionsPageActionHelper = {
     fetchVersions(dispatch, { itemType, itemId }) {
@@ -114,14 +115,28 @@ const VersionsPageActionHelper = {
         );
     },
 
-    async deleteItemFromArchive(dispatch, itemId) {
-        await SoftwareProductActionHelper.softwareProductDelete(itemId);
+    async deleteArchivedItem(dispatch, itemId, itemType) {
+        let successMsgCode;
+        if (itemType === itemTypes.LICENSE_MODEL) {
+            await LicenseModelActionHelper.deleteLicenseModel(itemId);
+            successMsgCode = 'vlm.delete.success';
+        } else if (itemType === itemTypes.SOFTWARE_PRODUCT) {
+            await SoftwareProductActionHelper.softwareProductDelete(itemId);
+            successMsgCode = 'vsp.delete.success';
+        } else {
+            console.error(
+                `Invalid item type "${itemType}". Expecting one of ${
+                    itemTypes.LICENSE_MODEL
+                } or ${itemTypes.SOFTWARE_PRODUCT}`
+            );
+            return;
+        }
         await ScreensHelper.loadScreen(dispatch, {
             screen: enums.SCREEN.ONBOARDING_CATALOG
         });
         dispatch(
             notificationActions.showSuccess({
-                message: i18n('Item successfully deleted')
+                message: i18n(successMsgCode)
             })
         );
     }