From 9dd7444cd7b78c0735266a174a631280b0089601 Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Sat, 26 Oct 2019 11:33:03 +0530 Subject: [PATCH] Add unrestricted roles field to Add new app form --- .../react-app/package.json | 3 +- .../AppDetailsDrawer/AppDetailsDrawer.js | 6 +- .../apps/list-apps/appsTable/AppsTable.js | 1 - .../new-app/subForms/NewAppDetailsForm.js | 106 ++++++++++++++---- .../apps/release/install/RoleInstall.js | 3 +- 5 files changed, 93 insertions(+), 26 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/package.json b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/package.json index dece5f9363..dbba25e052 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/package.json +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/package.json @@ -39,7 +39,8 @@ "redux-thunk": "^2.3.0", "shade-blend-color": "^1.0.0", "storm-react-diagrams": "^5.2.1", - "typescript": "^3.6.4" + "typescript": "^3.6.4", + "lodash.debounce": "latest" }, "devDependencies": { "@babel/core": "^7.5.0", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppDetailsDrawer/AppDetailsDrawer.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppDetailsDrawer/AppDetailsDrawer.js index fc54ab399b..6e5e6b4816 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppDetailsDrawer/AppDetailsDrawer.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/AppDetailsDrawer/AppDetailsDrawer.js @@ -509,8 +509,8 @@ class AppDetailsDrawer extends React.Component { title="Published" style={{ backgroundColor: '#52c41a', - borderRadius:"50%", - color:"white" + borderRadius: "50%", + color: "white" }} count={ - {/*display add new release only if app type is enterprise*/} {(app.type === "ENTERPRISE") && (
+
Add new release for the application diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/appsTable/AppsTable.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/appsTable/AppsTable.js index d008cf5609..faaaf7b99d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/appsTable/AppsTable.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/apps/list-apps/appsTable/AppsTable.js @@ -74,7 +74,6 @@ const columns = [ ) : ( { e.preventDefault(); const {formConfig} = this.props; @@ -58,13 +62,17 @@ class NewAppDetailsForm extends React.Component { this.setState({ loading: true }); - const {name, description, categories, tags, price, isSharedWithAllTenants, binaryFile, icon, screenshots, releaseDescription, releaseType} = values; + const {name, description, categories, tags, unrestrictedRoles} = values; + const unrestrictedRolesData = []; + unrestrictedRoles.map(val=>{ + unrestrictedRolesData.push(val.key); + }); const application = { name, description, categories, tags, - unrestrictedRoles: [], + unrestrictedRoles: unrestrictedRolesData, }; if (formConfig.installationType !== "WEB_CLIP") { @@ -141,15 +149,15 @@ class NewAppDetailsForm extends React.Component { const allowedDeviceTypes = []; // exclude mobile device types if installation type is custom - if(installationType==="CUSTOM"){ - allDeviceTypes.forEach(deviceType=>{ - if(!mobileDeviceTypes.includes(deviceType.name)){ + if (installationType === "CUSTOM") { + allDeviceTypes.forEach(deviceType => { + if (!mobileDeviceTypes.includes(deviceType.name)) { allowedDeviceTypes.push(deviceType); } }); - }else{ - allDeviceTypes.forEach(deviceType=>{ - if(mobileDeviceTypes.includes(deviceType.name)){ + } else { + allDeviceTypes.forEach(deviceType => { + if (mobileDeviceTypes.includes(deviceType.name)) { allowedDeviceTypes.push(deviceType); } }); @@ -168,9 +176,49 @@ class NewAppDetailsForm extends React.Component { }); }; + fetchRoles = value => { + const config = this.props.context; + this.lastFetchId += 1; + const fetchId = this.lastFetchId; + this.setState({data: [], fetching: true}); + + axios.get( + window.location.origin + config.serverConfig.invoker.uri + config.serverConfig.invoker.deviceMgt + "/roles?filter=" + value, + ).then(res => { + if (res.status === 200) { + if (fetchId !== this.lastFetchId) { + // for fetch callback order + return; + } + + const data = res.data.data.roles.map(role => ({ + text: role, + value: role, + })); + + this.setState({ + unrestrictedRoles: data, + fetching: false + }); + } + + }).catch((error) => { + handleApiError(error, "Error occurred while trying to load roles."); + this.setState({fetching: false}); + }); + }; + + handleRoleSearch = roleSearchValue => { + this.setState({ + roleSearchValue, + unrestrictedRoles: [], + fetching: false, + }); + }; + render() { const {formConfig} = this.props; - const {categories, tags, deviceTypes} = this.state; + const {categories, tags, deviceTypes, fetching, roleSearchValue, unrestrictedRoles} = this.state; const {getFieldDecorator} = this.props.form; return ( @@ -198,8 +246,7 @@ class NewAppDetailsForm extends React.Component {