From f66ad9ddd974a2f8d5866234347dc4abad0e698f Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Wed, 3 Jul 2019 03:41:34 +0530 Subject: [PATCH] Create filter payload in AppsTable component --- .../react-app/public/conf/config.json | 2 +- .../components/apps/list-apps/AppsTable.js | 38 ++- .../src/components/apps/list-apps/Filters.js | 309 +++++++++++++++--- .../src/components/apps/list-apps/ListApps.js | 20 +- 4 files changed, 299 insertions(+), 70 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/public/conf/config.json b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/public/conf/config.json index 5d9f074d94c..1411e8bef68 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/public/conf/config.json +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/public/conf/config.json @@ -11,7 +11,7 @@ "uri": "/publisher-ui-request-handler/invoke", "publisher": "/application-mgt-publisher/v1.0", "store": "/application-mgt-store/v1.0", - "admin" : "" + "deviceMgt" : "/device-mgt/v1.0" }, "loginUri": "/publisher-ui-request-handler/login", "platform": "publisher" diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppsTable.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppsTable.js index 56d5b5a70db..9a8441802cf 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppsTable.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppsTable.js @@ -66,15 +66,30 @@ class AppsTable extends React.Component { constructor(props) { super(props); this.state = { - pagination: { - total: 100 - }, - apps: [] + pagination: {}, + apps: [], + filters: {} }; } componentDidMount() { - this.fetch(); + const {filters} =this.props; + this.setState({ + filters + }); + this.fetch(filters); + + } + + componentDidUpdate(prevProps, prevState, snapshot) { + const {filters} =this.props; + if (prevProps.filters !== this.props.filters) { + console.log("d",this.props.filters); + this.setState({ + filters + }); + this.fetch(filters); + } } handleTableChange = (pagination, filters, sorter) => { @@ -84,7 +99,7 @@ class AppsTable extends React.Component { this.setState({ pagination: pager, }); - this.fetch({ + this.fetch(this.state.filters,{ results: pagination.pageSize, page: pagination.current, sortField: sorter.field, @@ -93,7 +108,7 @@ class AppsTable extends React.Component { }); }; - fetch = (params = {}) => { + fetch = (filters,params = {}) => { this.setState({loading: true}); if(!params.hasOwnProperty("page")){ @@ -102,8 +117,10 @@ class AppsTable extends React.Component { const data = { offset: 10 * (params.page - 1), - limit: 10 + limit: 10, + ...filters }; + console.log("f", data); axios.post( config.serverConfig.protocol + "://"+config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invoker.uri +config.serverConfig.invoker.publisher+"/applications", @@ -111,15 +128,16 @@ class AppsTable extends React.Component { ).then(res => { if (res.status === 200) { + const data = res.data.data; let apps = []; if (res.data.data.hasOwnProperty("applications")) { - apps = res.data.data.applications; + apps = data.applications; } const pagination = {...this.state.pagination}; // Read total count from server // pagination.total = data.totalCount; - pagination.total = 200; + pagination.total = data.pagination.count; this.setState({ loading: false, apps: apps, diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/Filters.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/Filters.js index 8604140a62a..eba53ee7934 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/Filters.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/Filters.js @@ -1,74 +1,277 @@ import React from "react"; -import {Avatar, Card, Col, Row, Table, Typography, Input, Divider, Checkbox, Select, Button} from "antd"; +import {Avatar, Card, Col, Row, Table, Typography, Input, Divider, Checkbox, Select, Button, Form, message} from "antd"; +import axios from "axios"; +import config from "../../../../public/conf/config.json"; const {Option} = Select; const {Title, Text} = Typography; -class Filters extends React.Component { + +class FiltersForm extends React.Component { constructor(props) { super(props); + this.state = { + categories: [], + tags: [], + deviceTypes: [] + }; + } + + handleSubmit = e => { + e.preventDefault(); + this.props.form.validateFields((err, values) => { + for (const [key, value] of Object.entries(values)) { + if (value === undefined) { + delete values[key]; + } + } + + this.props.setFilters(values); + }); + }; + + componentDidMount() { + this.getCategories(); + this.getTags(); + this.getDeviceTypes(); } + getCategories = () => { + axios.get( + config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invoker.uri + config.serverConfig.invoker.publisher + "/applications/categories", + { + headers: {'X-Platform': config.serverConfig.platform} + }).then(res => { + if (res.status === 200) { + let categories = JSON.parse(res.data.data); + this.setState({ + categories: categories, + loading: false + }); + } + + }).catch((error) => { + if (error.response.status === 401) { + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + '/publisher/login'; + } else { + message.warning('Something went wrong'); + + } + this.setState({ + loading: false + }); + }); + }; + + getTags = () => { + axios.get( + config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invoker.uri + config.serverConfig.invoker.publisher + "/applications/tags", + { + headers: {'X-Platform': config.serverConfig.platform} + }).then(res => { + if (res.status === 200) { + let tags = JSON.parse(res.data.data); + this.setState({ + tags: tags, + loading: false, + }); + } + + }).catch((error) => { + if (error.response.status === 401) { + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + '/publisher/login'; + } else { + message.warning('Something went wrong'); + + } + this.setState({ + loading: false + }); + }); + }; + + + getDeviceTypes = () => { + axios.get( + config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invoker.uri + config.serverConfig.invoker.deviceMgt + "/device-types", + { + headers: {'X-Platform': config.serverConfig.platform} + }).then(res => { + if (res.status === 200) { + const deviceTypes = JSON.parse(res.data.data); + this.setState({ + deviceTypes, + loading: false, + }); + } + + }).catch((error) => { + if (error.response.status === 401) { + window.location.href = config.serverConfig.protocol + "://" + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + '/publisher/login'; + } else { + message.warning('Something went wrong'); + + } + this.setState({ + loading: false + }); + }); + }; + render() { + const {categories, tags, deviceTypes} = this.state; + const {getFieldDecorator} = this.props.form; + return ( - - - Filter - - - - - Category -

- - - - Platform -

- Android
- iOS
- Windows
- Default
- - - Tags -

- - - - Type -

- Enterprise
- Public
- Web APP
- Web Clip
- - - Subscription -

- Free
- Paid
- +
+ + + Filter + + + + + + + + + + {/*Category*/} + {/*

*/} + + {getFieldDecorator('categories', { + rules: [{ + required: false, + message: 'Please select categories' + }], + })( + + )} + + {/**/} + {/**/} + {/**/} + {/**/} + + + + {getFieldDecorator('deviceTypes', { + rules: [{ + required: false, + message: 'Please select device types' + }], + })( + + )} + + + {/*Tags*/} + + {getFieldDecorator('tags', { + rules: [{ + required: false, + message: 'Please select tags' + }], + })( + + )} + + + + + {getFieldDecorator('appType', {})( + + )} + + + + + {getFieldDecorator('subscriptionType', {})( + + Free
+ Paid
+
, + )} +
+ +
); } } +const Filters = Form.create({name: 'filter-apps'})(FiltersForm); + + export default Filters; \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/ListApps.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/ListApps.js index 8100a25a05b..ea60b484814 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/ListApps.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/ListApps.js @@ -20,11 +20,12 @@ class ListApps extends React.Component { super(props); this.state = { isDrawerVisible: false, - selectedApp: null + selectedApp: null, + filters: {} } } - //handler to show app drawer + //handler to show app drawer showDrawer = (app) => { this.setState({ isDrawerVisible: true, @@ -39,12 +40,18 @@ class ListApps extends React.Component { }) }; + setFilters = (filters) => { + this.setState({ + filters + }); + }; + render() { - const {isDrawerVisible} = this.state; + const {isDrawerVisible, filters} = this.state; return ( - + @@ -61,8 +68,9 @@ class ListApps extends React.Component { - - + +