From 68bcec0ce90144c497abcde6e1f2a4faec248059 Mon Sep 17 00:00:00 2001 From: Jayasanka Weerasinghe Date: Thu, 23 Apr 2020 20:21:14 +0530 Subject: [PATCH] Add Release deleting functionality to the APPM Publisher UI --- .../components/DeleteRelease/index.js | 87 +++++++++++++++++++ .../components/EditRelease/index.js | 4 +- .../Release/components/ReleaseView/index.js | 28 ++++-- 3 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/components/DeleteRelease/index.js diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/components/DeleteRelease/index.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/components/DeleteRelease/index.js new file mode 100644 index 00000000000..70767280973 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/components/DeleteRelease/index.js @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2020, Entgra (pvt) Ltd. (http://entgra.io) All Rights Reserved. + * + * Entgra (pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import React from 'react'; +import { Modal, Button, Icon, notification } from 'antd'; +import axios from 'axios'; +import { handleApiError } from '../../../../../../../../../../services/utils/errorHandler'; +import { withConfigContext } from '../../../../../../../../../../components/ConfigContext'; +import { withRouter } from 'react-router-dom'; +const { confirm } = Modal; + +class DeleteRelease extends React.Component { + showModal = () => { + confirm({ + title: 'Are you sure you want to delete the application release?', + content: + 'If you have multiple application releases, only the selected app release will be ' + + 'deleted. Otherwise, the whole application will be deleted. Further note, this will ' + + 'delete application artifacts permanently.\n' + + 'Be careful, this process cannot be undone.', + okText: 'Yes', + okType: 'danger', + cancelText: 'No', + onOk: this.deleteRelease, + }); + }; + + deleteRelease = () => { + const config = this.props.context; + const apiUrl = + window.location.origin + + config.serverConfig.invoker.uri + + config.serverConfig.invoker.publisher + + '/admin/applications/release/' + + this.props.uuid; + axios + .delete(apiUrl) + .then(res => { + if (res.status === 200) { + notification.success({ + message: 'Successfully deleted the release', + }); + this.props.history.push('/publisher'); + } + }) + .catch(error => { + handleApiError( + 'Something Went wrong when trying to delete the release, Please contact the administrator', + ); + this.setState({ + loading: false, + }); + }); + }; + + render() { + return ( + <> + + + ); + } +} + +export default withConfigContext(withRouter(DeleteRelease)); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/components/EditRelease/index.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/components/EditRelease/index.js index a4f77882239..790513658ff 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/components/EditRelease/index.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/components/EditRelease/index.js @@ -403,7 +403,7 @@ class EditReleaseModal extends React.Component { ); return ( -
+ <> -
+ ); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/index.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/index.js index b661a561d0e..e416d0d8a44 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/index.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/Apps/scenes/Release/components/ReleaseView/index.js @@ -34,6 +34,7 @@ import DetailedRating from '../../../../components/DetailedRating'; import EditRelease from './components/EditRelease'; import { withConfigContext } from '../../../../../../../../components/ConfigContext'; import Authorized from '../../../../../../../../components/Authorized/Authorized'; +import DeleteRelease from './components/DeleteRelease'; const { Title, Text, Paragraph } = Typography; @@ -51,10 +52,12 @@ class ReleaseView extends React.Component { return null; } let isAppUpdatable, - isAppInstallable = false; + isAppInstallable, + isDeletableState = false; if (lifecycle != null) { isAppUpdatable = lifecycle[currentLifecycleStatus].isAppUpdatable; isAppInstallable = lifecycle[currentLifecycleStatus].isAppInstallable; + isDeletableState = lifecycle[currentLifecycleStatus].isDeletableState; } const platform = app.deviceType; @@ -103,14 +106,21 @@ class ReleaseView extends React.Component { + <> + + + + } />