From 336612904b64e8d3070481198f3723256e2e2906 Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Fri, 14 Jun 2019 13:48:05 +0530 Subject: [PATCH] Remove redux from release view in store --- .../react-app/src/components/apps/AppCard.js | 3 +- .../components/apps/release/ReleaseView.js | 3 +- .../react-app/src/index.js | 6 +- .../src/pages/dashboard/Dashboard.js | 12 +- .../src/pages/dashboard/apps/Apps.js | 13 -- .../pages/dashboard/apps/release/Release.js | 116 +++++++++--------- 6 files changed, 68 insertions(+), 85 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/AppCard.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/AppCard.js index 091dd984a7..6078e71479 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/AppCard.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/AppCard.js @@ -29,11 +29,10 @@ class ConnectedAppCard extends React.Component { render() { const app = this.props.app; const release = this.props.app.applicationReleases[0]; - // console.log(this.props); const description = (
- + icon diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js index d95377e1c9..7872e0f308 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js @@ -89,7 +89,8 @@ class ReleaseView extends React.Component { }; render() { - const release = this.props.release; + const app = this.props.app; + const release = app.applicationReleases[0]; return (
- Apps - Apps - Add New - App + Android + iOS + Web Clips - + {this.state.routes.map((route) => ( ))} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/Apps.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/Apps.js index 90e68ed1d0..1a64984858 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/Apps.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/Apps.js @@ -33,20 +33,7 @@ class Apps extends React.Component { render() { return (
-
- - - console.log(value)} - style={{ width: 200}} - /> - - -
diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/release/Release.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/release/Release.js index 27afea477e..5434ea66ef 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/release/Release.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/pages/dashboard/apps/release/Release.js @@ -1,61 +1,80 @@ import React from "react"; import '../../../../App.css'; -import {Skeleton, Typography, Row, Col, Card} from "antd"; -import {connect} from "react-redux"; +import {Skeleton, Typography, Row, Col, Card, message} from "antd"; import ReleaseView from "../../../../components/apps/release/ReleaseView"; -import {getRelease, setLoading} from "../../../../js/actions"; +import axios from "axios"; +import config from "../../../../../public/conf/config.json"; const {Title} = Typography; -const routes = [ - { - path: 'index', - breadcrumbName: 'store', - }, - { - path: 'first', - breadcrumbName: 'Dashboard', - }, - { - path: 'second', - breadcrumbName: 'Apps', - }, -]; - -const mapStateToProps = state => { - return { - release: state.release, - releaseLoading: state.loadingState.release - } -}; - -const mapDispatchToProps = dispatch => ({ - getRelease: (uuid) => dispatch(getRelease(uuid)), - setLoading: (stateToLoad) => dispatch(setLoading(stateToLoad)) -}); - -class ConnectedRelease extends React.Component { +class Release extends React.Component { routes; constructor(props) { super(props); this.routes = props.routes; + this.state={ + loading: true, + app: null + } } componentDidMount() { const {uuid} = this.props.match.params; - this.props.setLoading("release"); - this.props.getRelease(uuid); + this.fetchData(uuid); } - render() { + componentDidUpdate(prevProps, prevState, snapshot) { + if (prevProps !== this.props) { + this.fetchData(uuid); + } + } + + fetchData = (uuid)=>{ + const parameters = { + method: "get", + 'content-type': "application/json", + payload: "{}", + 'api-endpoint': "/application-mgt-store/v1.0/applications/" + uuid + }; + + //url-encode parameters + const request = Object.keys(parameters).map(key => key + '=' + parameters[key]).join('&'); + + //send request to the invoker + axios.post(config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + ).then(res => { + if (res.status === 200) { + let app = res.data.data; + + console.log(app); + + this.setState({ + app: app, + loading: false + }) + } + + }).catch((error) => { + if (error.hasOwnProperty("response") && error.response.status === 401) { + //todo display a popop with error + message.error('You are not logged in'); + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + '/store/login'; + } else { + message.error('Something went wrong... :('); + } + + this.setState({loading: false}); + }); + }; - const release = this.props.release; + render() { + const {app, loading} = this.state; let content = No Releases Found; - if (release != null) { - content = ; + if (app != null && app.applicationReleases.length!==0) { + content = ; } @@ -67,7 +86,7 @@ class ConnectedRelease extends React.Component { - + {content} @@ -76,29 +95,8 @@ class ConnectedRelease extends React.Component {
); - - - // //todo remove uppercase - // return ( - //
- //
- // - // - // - // - // - // - // - // - // - // - //
- //
- // - // ); } } -const Release = connect(mapStateToProps, mapDispatchToProps)(ConnectedRelease); export default Release;