From e07197743a7ceb763f4a6a485ade75a0819b225e Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Sat, 3 Aug 2019 20:23:05 +0530 Subject: [PATCH] Modify edit release component to update the release without refreshing --- .../components/apps/release/ReleaseView.js | 7 +++-- .../apps/release/edit-release/EditRelease.js | 12 +++++---- .../pages/dashboard/apps/release/Release.js | 27 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/ReleaseView.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/ReleaseView.js index e2ca4547f4..0f19866d1d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/ReleaseView.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/ReleaseView.js @@ -11,23 +11,22 @@ const {Title, Text, Paragraph} = Typography; class ReleaseView extends React.Component { render() { + const {app, release} = this.props; const config = this.props.context; - const app = this.props.app; - const release = (app !== null) ? app.applicationReleases[0] : null; const {lifecycle, currentLifecycleStatus} = this.props; + if (release == null || lifecycle == null) { return null; } const {isAppUpdatable, isAppInstallable} = lifecycle[currentLifecycleStatus]; - console.log(isAppInstallable, isAppUpdatable); - const platform = app.deviceType; const defaultPlatformIcons = config.defaultPlatformIcons; let icon = defaultPlatformIcons.default.icon; let color = defaultPlatformIcons.default.color; let theme = defaultPlatformIcons.default.theme; + if (defaultPlatformIcons.hasOwnProperty(platform)) { icon = defaultPlatformIcons[platform].icon; color = defaultPlatformIcons[platform].color; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/edit-release/EditRelease.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/edit-release/EditRelease.js index b4ffb5515f..500eae2a53 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/edit-release/EditRelease.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/release/edit-release/EditRelease.js @@ -94,10 +94,10 @@ class EditReleaseModal extends React.Component { releaseDescription: { value: release.description }, - price:{ + price: { value: release.price }, - isSharedWithAllTenants:{ + isSharedWithAllTenants: { value: release.isSharedWithAllTenants } }); @@ -231,6 +231,9 @@ class EditReleaseModal extends React.Component { data ).then(res => { if (res.status === 200) { + + const updatedRelease = res.data.data; + this.setState({ loading: false, visible: false, @@ -241,10 +244,9 @@ class EditReleaseModal extends React.Component { description: "Saved!", }); - - window.location.reload(); + // console.log(updatedRelease); + this.props.updateRelease(updatedRelease); } - }).catch((error) => { if (error.hasOwnProperty("response") && error.response.status === 401) { window.location.href = window.location.origin + '/publisher/login'; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/release/Release.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/release/Release.js index 66115abdf7..2ceffb9e8c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/release/Release.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/release/Release.js @@ -8,8 +8,6 @@ import {withConfigContext} from "../../../../context/ConfigContext"; const {Title} = Typography; - - class Release extends React.Component { routes; @@ -38,16 +36,16 @@ class Release extends React.Component { } } - changeCurrentLifecycleStatus = (status) =>{ + changeCurrentLifecycleStatus = (status) => { this.setState({ currentLifecycleStatus: status }); }; - updateRelease = (release) =>{ - this.setState({ - release - }); + updateRelease = (release) => { + this.setState({ + release + }); }; fetchData = (uuid) => { @@ -55,12 +53,12 @@ class Release extends React.Component { //send request to the invoker axios.get( - window.location.origin+ config.serverConfig.invoker.uri + config.serverConfig.invoker.publisher + "/applications/release/"+ uuid, + window.location.origin + config.serverConfig.invoker.uri + config.serverConfig.invoker.publisher + "/applications/release/" + uuid, ).then(res => { if (res.status === 200) { const app = res.data.data; const release = (app !== null) ? app.applicationReleases[0] : null; - const currentLifecycleStatus = (release!==null) ? release.currentStatus : null; + const currentLifecycleStatus = (release !== null) ? release.currentStatus : null; this.setState({ app: app, release: release, @@ -74,7 +72,7 @@ class Release extends React.Component { if (error.hasOwnProperty("response") && error.response.status === 401) { //todo display a popop with error message.error('You are not logged in'); - window.location.href = window.location.origin+ '/publisher/login'; + window.location.href = window.location.origin + '/publisher/login'; } else { notification["error"]({ message: "There was a problem", @@ -92,7 +90,7 @@ class Release extends React.Component { getLifecycle = () => { const config = this.props.context; axios.get( - window.location.origin+ config.serverConfig.invoker.uri + config.serverConfig.invoker.publisher + "/applications/lifecycle-config" + window.location.origin + config.serverConfig.invoker.uri + config.serverConfig.invoker.publisher + "/applications/lifecycle-config" ).then(res => { if (res.status === 200) { const lifecycle = res.data.data; @@ -103,7 +101,7 @@ class Release extends React.Component { }).catch(function (error) { if (error.hasOwnProperty("response") && error.response.status === 401) { - window.location.href = window.location.origin+ '/publisher/login'; + window.location.href = window.location.origin + '/publisher/login'; } else { notification["error"]({ message: "There was a problem", @@ -135,8 +133,9 @@ class Release extends React.Component { @@ -147,7 +146,7 @@ class Release extends React.Component { uuid={release.uuid} currentStatus={release.currentStatus.toUpperCase()} changeCurrentLifecycleStatus={this.changeCurrentLifecycleStatus} - lifecycle ={lifecycle} + lifecycle={lifecycle} />