From fffad9eea4294097e48ff3a2802660e1f1a5a508 Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Tue, 30 Apr 2019 18:03:33 +0530 Subject: [PATCH] displayed modal title from redux --- .../react-app/src/components/apps/AppList.js | 2 +- .../src/components/apps/ReleaseModal.js | 68 +++++++++++++++++++ .../react-app/src/js/actions/index.js | 46 +++++++------ .../react-app/src/js/reducers/index.js | 15 +++- .../src/pages/dashboard/apps/Apps.js | 2 + 5 files changed, 111 insertions(+), 22 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/ReleaseModal.js diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/AppList.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/AppList.js index 08da7efe86..599e6be2d0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/AppList.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/AppList.js @@ -4,7 +4,7 @@ import {Col, Row} from "antd"; import {connect} from "react-redux"; import {getApps} from "../../js/actions"; -// connecting state.articles with the component +// connecting state.apps with the component const mapStateToProps= state => { return {apps : state.apps} }; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/ReleaseModal.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/ReleaseModal.js new file mode 100644 index 0000000000..bb09ca6e43 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/ReleaseModal.js @@ -0,0 +1,68 @@ +import React from "react"; +import {Modal, Button} from 'antd'; +import { connect } from 'react-redux'; + +// connecting state.releaseView with the component +const mapStateToProps = state => { + return {releaseView: state.releaseView} +}; + +class ConnectedReleaseModal extends React.Component { + constructor(props) { + super(props); + this.state = { + visible: false + }; + } + componentWillReceiveProps(nextProps) { + if (nextProps !== this.props) { + this.setState({ + visible: nextProps.releaseView.visible + }) + } + } + + showModal = () => { + this.setState({ + visible: true, + }); + }; + + handleOk = (e) => { + console.log(e); + this.setState({ + visible: false, + }); + }; + + handleCancel = (e) => { + console.log(e); + this.setState({ + visible: false, + }); + }; + + render() { + return ( +
+ + +

Some contents...

+

Some contents...

+

Some contents...

+
+
+ ); + } +} + +const ReleaseModal = connect(mapStateToProps,null)(ConnectedReleaseModal); + +export default ReleaseModal; \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/actions/index.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/actions/index.js index b589331769..cd9fc1adc6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/actions/index.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/actions/index.js @@ -2,30 +2,38 @@ import axios from "axios"; import ActionTypes from "../constants/ActionTypes"; import config from "../../../public/conf/config.json"; -export function getApps() { +export const getApps = () => dispatch => { - return (dispatch) => { - const request = "method=post&content-type=application/json&payload={}&api-endpoint=/application-mgt-publisher/v1.0/applications"; - return axios.post('https://'+config.serverConfig.hostname+':'+config.serverConfig.httpsPort+config.serverConfig.invokerUri, request - ).then(res => { - if (res.status === 200) { - let apps = []; + const request = "method=post&content-type=application/json&payload={}&api-endpoint=/application-mgt-publisher/v1.0/applications"; - if(res.data.data.hasOwnProperty("applications")){ - apps = res.data.data.applications; - } - console.log(res.data); - dispatch({type: ActionTypes.GET_APPS, payload: apps}); - } + return axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + ).then(res => { + if (res.status === 200) { + let apps = []; - }).catch(function (error) { - if (error.response.status === 401) { - window.location.href = 'https://localhost:9443/publisher/login'; + if (res.data.data.hasOwnProperty("applications")) { + apps = res.data.data.applications; } - }); + console.log(res.data); + dispatch({type: ActionTypes.GET_APPS, payload: apps}); + } + + }).catch(function (error) { + if (error.response.status === 401) { + window.location.href = 'https://localhost:9443/publisher/login'; + } + }); + - }; +}; +export const openReleasesModal = () => dispatch => { + dispatch({ + type: ActionTypes.OPEN_RELEASES_MODAL, + payload: { + title :"hi" + } + }); +}; -} \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/reducers/index.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/reducers/index.js index 5dcda40c8b..c2e5074064 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/reducers/index.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/js/reducers/index.js @@ -1,17 +1,28 @@ import ActionTypes from "../constants/ActionTypes"; const initialState = { - apps: [] + apps: [], + releaseView: { + visible: false, + title: "hi" + } }; function rootReducer(state = initialState, action) { if (action.type === ActionTypes.GET_APPS) { - console.log(11); return Object.assign({}, state, { apps: action.payload }); + } else if (action.type === ActionTypes.OPEN_RELEASES_MODAL) { + return Object.assign({}, state, { + releaseView: { + visible: true, + title: action.title + } + }); } return state; } + export default rootReducer; \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/Apps.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/Apps.js index 13477af124..e24f40a6ea 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/Apps.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/apps/Apps.js @@ -2,6 +2,7 @@ import React from "react"; import "antd/dist/antd.css"; import {PageHeader, Typography,Input, Button, Row, Col} from "antd"; import AppList from "../../../components/apps/AppList"; +import ReleaseModal from "../../../components/apps/ReleaseModal"; const Search = Input.Search; @@ -46,6 +47,7 @@ class Apps extends React.Component { +