From d188b18bc5bb8ef1c9713b94c0c73fb9d60d608c Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Mon, 17 Jun 2019 15:28:15 +0530 Subject: [PATCH] Remove redux from detailed rating component --- .../apps/detailed-rating/DetailedRating.js | 4 +- .../components/apps/release/DetailedRating.js | 50 +++++++++++++------ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/detailed-rating/DetailedRating.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/detailed-rating/DetailedRating.js index da83fc878f..18fa46f812 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/detailed-rating/DetailedRating.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/detailed-rating/DetailedRating.js @@ -21,8 +21,8 @@ class DetailedRating extends React.Component{ this.getData(this.props.uuid); } - componentDidUpdate(nextProps) { - if (nextProps !== this.props) { + componentDidUpdate(prevProps, prevState) { + if (prevProps.uuid !== this.props.uuid) { this.getData(this.props.uuid); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js index b5dad1088c..f8dc026b8e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/DetailedRating.js @@ -1,31 +1,52 @@ import React from "react"; import {Row, Typography, Icon} from "antd"; import StarRatings from "react-star-ratings"; +import axios from "axios"; import "./DetailedRating.css"; -import {connect} from "react-redux"; -import {getDetailedRating} from "../../../js/actions"; +import config from "../../../../public/conf/config.json"; const { Text } = Typography; -// connecting state. with the component -const mapStateToProps= state => { - return {detailedRating : state.detailedRating} -}; +class DetailedRating extends React.Component{ -const mapDispatchToProps = dispatch => ({ - getDetailedRating: (uuid) => dispatch(getDetailedRating(uuid)) -}); + constructor(props){ + super(props); + this.state={ + detailedRating: null + } + } + componentDidMount() { + this.getData(this.props.uuid); + } + componentDidUpdate(prevProps, prevState) { + if (prevProps.uuid !== this.props.uuid) { + this.getData(this.props.uuid); + } + } -class ConnectedDetailedRating extends React.Component{ + getData = (uuid)=>{ + const request = "method=get&content-type=application/json&payload={}&api-endpoint=/application-mgt-store/v1.0/reviews/"+uuid+"/rating"; - componentDidMount() { - this.props.getDetailedRating(this.props.uuid); - } + return axios.post(config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + ).then(res => { + if (res.status === 200) { + let detailedRating = res.data.data; + this.setState({ + detailedRating + }) + } + + }).catch(function (error) { + if (error.response.status === 401) { + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort+'/publisher/login'; + } + }); + }; render() { - const detailedRating = this.props.detailedRating; + const detailedRating = this.state.detailedRating; console.log(detailedRating); @@ -96,6 +117,5 @@ class ConnectedDetailedRating extends React.Component{ } } -const DetailedRating = connect(mapStateToProps,mapDispatchToProps)(ConnectedDetailedRating); export default DetailedRating; \ No newline at end of file