From db35d5e6a7f2ca7e5f59e70640575442fa33840e Mon Sep 17 00:00:00 2001 From: Kaveesha Mihirangi Date: Fri, 27 Mar 2020 16:56:49 +0000 Subject: [PATCH] Implement create, apply, edit, view policy features to device-mgt React App --- .../react-app/src/index.js | 12 + .../components/AssignGroups/index.js | 5 + .../components/ConfigureProfile/index.js | 97 +- .../components/PublishDevices/index.js | 4 +- .../components/SelectPlatform/index.js | 2 +- .../Policies/components/AddPolicy/index.js | 58 +- .../components/AssignGroups/index.js | 269 ++++++ .../components/ConfigureProfile/index.js | 873 ++++++++++++++++++ .../components/PublishDevices/index.js | 86 ++ .../components/SelectPolicyType/index.js | 182 ++++ .../Policies/components/EditPolicy/index.js | 273 ++++++ .../component/PolicyAction/index.js | 55 ++ .../component/PolicyBulkActionBar/index.js | 170 ++++ .../components/PoliciesTable/index.js | 227 ++++- .../component/PolicyInfo/index.js | 756 +++++++++++++++ .../component/ProfileOverview/index.js | 131 +++ .../components/PolicyProfile/index.js | 147 +++ .../scenes/EditSelectedPolicy/index.js | 69 ++ .../Policies/scenes/ViewPolicy/index.js | 68 ++ .../device/type/template/config/SubPanel.java | 11 + .../template/config/SubPanelValuesList.java | 27 + 21 files changed, 3468 insertions(+), 54 deletions(-) create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/EditPolicy/components/AssignGroups/index.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/EditPolicy/components/ConfigureProfile/index.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/EditPolicy/components/PublishDevices/index.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/EditPolicy/components/SelectPolicyType/index.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/EditPolicy/index.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/PoliciesTable/component/PolicyAction/index.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/PoliciesTable/component/PolicyBulkActionBar/index.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/PolicyProfile/component/PolicyInfo/index.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/PolicyProfile/component/ProfileOverview/index.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/PolicyProfile/index.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/scenes/EditSelectedPolicy/index.js create mode 100644 components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/scenes/ViewPolicy/index.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/template/config/SubPanelValuesList.java diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/index.js index 8d3539854a..90fb75fcd3 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/index.js @@ -42,6 +42,8 @@ import Roles from './scenes/Home/scenes/Roles'; import DeviceTypes from './scenes/Home/scenes/DeviceTypes'; import Certificates from './scenes/Home/scenes/Configurations/scenes/Certificates'; import Devices from './scenes/Home/scenes/Devices'; +import ViewPolicy from './scenes/Home/scenes/Policies/scenes/ViewPolicy'; +import EditSelectedPolicy from './scenes/Home/scenes/Policies/scenes/EditSelectedPolicy'; const routes = [ { @@ -94,6 +96,16 @@ const routes = [ component: AddNewPolicy, exact: true, }, + { + path: '/entgra/policy/view/:policyId', + component: ViewPolicy, + exact: true, + }, + { + path: '/entgra/policy/edit/:policyId', + component: EditSelectedPolicy, + exact: true, + }, { path: '/entgra/roles', component: Roles, diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js index 533d23ab11..e90d0fa9dd 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/AssignGroups/index.js @@ -52,12 +52,17 @@ class AssignGroups extends React.Component { onHandleContinue = (e, formName) => { this.props.form.validateFields((err, values) => { if (!err) { + if (typeof values.roles === 'string') { + values.roles = [values.roles]; + } if (!values.users) { delete values.users; } + if (values.deviceGroups === 'NONE') { delete values.deviceGroups; } + this.props.getPolicyPayloadData(formName, values); this.props.getNextStep(); } diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js index 7d0d45c27c..9e6fedb7e9 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/scenes/Home/scenes/Policies/components/AddPolicy/components/ConfigureProfile/index.js @@ -45,6 +45,8 @@ const { TabPane } = Tabs; const { Option } = Select; const { TextArea } = Input; +const subPanelpayloadAttributes = {}; + class ConfigureProfile extends React.Component { constructor(props) { super(props); @@ -54,6 +56,8 @@ class ConfigureProfile extends React.Component { isDisplayMain: 'none', activePanelKeys: [], activeSubPanelKeys: [], + subFormList: [], + subPanelpayloadAttributes: {}, count: 0, dataArray: [], customInputDataArray: [], @@ -297,17 +301,64 @@ class ConfigureProfile extends React.Component { // generate payload by adding policy configurations onHandleContinue = (e, formname) => { - this.props.form.validateFields((err, values) => { + const allFields = this.props.form.getFieldsValue(); + let activeFields = []; + // get currently active field list + for (let i = 0; i < this.state.activePanelKeys.length; i++) { + Object.keys(allFields).map(key => { + if (key.includes(`${this.state.activePanelKeys[i]}-`)) { + if ( + subPanelpayloadAttributes.hasOwnProperty( + `${this.state.activePanelKeys[i]}`, + ) + ) { + Object.keys( + subPanelpayloadAttributes[this.state.activePanelKeys[i]], + ).map(subPanel => { + if (`${this.state.activePanelKeys[i]}-${subPanel}` === true) { + if (key.includes(`-${subPanel}-`)) { + activeFields.push(key); + } + } else if (!key.includes(`-${subPanel}-`)) { + activeFields.push(key); + } + }); + } else { + activeFields.push(key); + } + } + }); + } + // validate fields and get profile features list + this.props.form.validateFields(activeFields, (err, values) => { if (!err) { - this.props.getPolicyPayloadData(formname, values); + let profileFeaturesList = []; + for (let i = 0; i < this.state.activePanelKeys.length; i++) { + let content = {}; + Object.entries(values).map(([key, value]) => { + if (key.includes(`${this.state.activePanelKeys[i]}-`)) { + content[ + key.replace(`${this.state.activePanelKeys[i]}-`, '') + ] = value; + } + }); + let feature = { + featureCode: this.state.activePanelKeys[i], + deviceType: 'android', + content: content, + }; + profileFeaturesList.push(feature); + } + this.props.getPolicyPayloadData(formname, profileFeaturesList); this.props.getNextStep(); } }); }; // generate form items - getPanelItems = panel => { + getPanelItems = (panel, panelId) => { const { getFieldDecorator } = this.props.form; + const subPanelList = {}; return panel.map((item, k) => { switch (item.type) { case 'select': @@ -407,7 +458,6 @@ class ConfigureProfile extends React.Component { style={{ display: 'block' }} > {getFieldDecorator(`${item.id}`, { - // valuePropName: 'option', initialValue: item.optional.initialDataIndex, })(