Skip to content

Commit

Permalink
Allianceorg action fixed->changed from dualisttoinput
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuldsce committed Mar 30, 2022
1 parent ba689e8 commit 8aa5df3
Showing 1 changed file with 36 additions and 74 deletions.
110 changes: 36 additions & 74 deletions src/pages/main/cloudlets/AllianceOrganization.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import * as actions from '../../../actions';
//Mex
import MexForms, { DUALLIST, INPUT, MAIN_HEADER } from '../../../hoc/forms/MexForms';
import MexForms, { INPUT, MAIN_HEADER, TEXT_AREA } from '../../../hoc/forms/MexForms';
//model
import { service, fields } from '../../../services';
import { showOrganizations } from '../../../services/modules/organization';
import { addClouldletAllianceOrgs, removeClouldletAllianceOrgs } from '../../../services/modules/cloudlet/cloudlet'

import { Grid } from '@material-ui/core';
import { perpetual } from '../../../helper/constant';
import { _sort } from '../../../helper/constant/operators';

Expand All @@ -22,7 +19,6 @@ class AllianceOrganization extends React.Component {
this._isMounted = false
//To avoid refeching data from server
this.cloudletData = undefined;
this.allianceList = [];
this.action = props.action ? props.action : perpetual.ACTION_ADD_ALLIANCE_ORG;
this.isAllianceCloudletAdd = (this.action === perpetual.ACTION_ADD_ALLIANCE_ORG);
}
Expand All @@ -41,16 +37,10 @@ class AllianceOrganization extends React.Component {
}

render() {
const { forms, activeIndex } = this.state
const { forms } = this.state
return (
<div>
<Grid container>
<Grid item xs={12}>
<div className="round_panel">
<MexForms forms={forms} reloadForms={this.reloadForms} />
</div>
</Grid>
</Grid>
<div className="round_panel">
<MexForms forms={forms} reloadForms={this.reloadForms} />
</div>
)
}
Expand All @@ -59,29 +49,22 @@ class AllianceOrganization extends React.Component {
this.props.onClose(false)
}

updateUI(form) {
if (form) {
if (form.field) {
if (form.formType === DUALLIST) {
switch (form.field) {
case fields.allianceOrganization:
form.options = this.allianceList.map(data => ({ value: data, label: data }))
break;
default:
form.options = undefined;
}
updateFormData = (forms, data) => {
for (let form of forms) {
if (form.field === fields.allianceOrganization) {
let allianceOrgs = data[fields.allianceOrganization]
if (allianceOrgs) {
let value = ''
let length = allianceOrgs.length - 1
allianceOrgs.forEach((org, i) => {
value = value + org + (i < length ? '\n' : '')
})
form.value = value
}
}
}
}

updateFormData = (forms) => {
for (let i = 0; i < forms.length; i++) {
let form = forms[i]
this.updateUI(form)
}
}

onCreateResponse = (mcList) => {
if (mcList && mcList.length > 0) {
this.props.handleLoadingSpinner(false)
Expand All @@ -99,60 +82,40 @@ class AllianceOrganization extends React.Component {

onCreate = async (data) => {
let allianceOrgs = data[fields.allianceOrganization]
if (allianceOrgs && allianceOrgs.length > 0) {
let requestList = []
let requestCall = this.isAllianceCloudletAdd ? addClouldletAllianceOrgs : removeClouldletAllianceOrgs
allianceOrgs.forEach(org => {
let requestData = {...data}
requestData[fields.allianceOrganization] = org
requestList.push(requestCall(requestData))
})
if (requestList && requestList.length > 0) {
this.props.handleLoadingSpinner(true)
service.multiAuthRequest(this, requestList, this.onCreateResponse)
}
}

}

filterAllianceCloudlets = () => {
let removeList = []
if (this.props.data) {
let selectedAllianceOrgs = this.props.data[fields.allianceOrganization]
if (selectedAllianceOrgs && selectedAllianceOrgs.length > 0) {
for (let i = 0; i < selectedAllianceOrgs.length; i++) {
let selectedAllianceOrg = selectedAllianceOrgs[i];
for (let j = 0; j < this.allianceList.length; j++) {
let allianceOrg = this.allianceList[j]
if (selectedAllianceOrg === allianceOrg) {
if (this.props.action === perpetual.ACTION_ADD_ALLIANCE_ORG) {
this.allianceList.splice(j, 1)
}
else if (this.props.action === perpetual.ACTION_REMOVE_ALLIANCE_ORG) {
removeList.push(allianceOrg)
}
break;
}
if (allianceOrgs) {
let oldOrgList = this.props.data[fields.allianceOrganization]
let orgList = allianceOrgs.split('\n')
if (orgList?.length > 0) {
if (this.isAllianceCloudletAdd && oldOrgList?.length > 0) {
orgList = orgList.filter(item => !oldOrgList.includes(item))
}
if (orgList?.length > 0) {
let requestList = []
let requestCall = this.isAllianceCloudletAdd ? addClouldletAllianceOrgs : removeClouldletAllianceOrgs
orgList.forEach(org => {
let requestData = { ...data }
requestData[fields.allianceOrganization] = org
requestList.push(requestCall(requestData))
})
if (requestList?.length > 0) {
this.props.handleLoadingSpinner(true)
service.multiAuthRequest(this, requestList, this.onCreateResponse)
}
}
}
}
this.allianceList = removeList.length > 0 ? removeList : this.allianceList
}

getFormData = async (data) => {
let organizationList = await service.showAuthSyncRequest(this, showOrganizations(this, { type: perpetual.OPERATOR }))
organizationList = _sort(organizationList.map(org => org[fields.organizationName]))
this.allianceList = organizationList.filter(org => org !== data[fields.operatorName])
if (this.allianceList && this.allianceList.length > 0) {
let allianceList = data[fields.allianceOrganization]
if (this.isAllianceCloudletAdd || allianceList?.length > 0) {
let action = this.props.action === perpetual.ACTION_REMOVE_ALLIANCE_ORG ? 'Remove' : 'Add'
this.filterAllianceCloudlets();
let forms = [
{ label: `${action} Alliance Organization`, formType: MAIN_HEADER, visible: true },
{ field: fields.region, label: 'Region', formType: INPUT, rules: { disabled: true }, visible: true, value: data[fields.region] },
{ field: fields.cloudletName, label: 'Cloudlet Name', formType: INPUT, rules: { disabled: true }, visible: true, value: data[fields.cloudletName] },
{ field: fields.operatorName, label: 'Operator', formType: INPUT, rules: { disabled: true }, visible: true, value: data[fields.operatorName] },
{ field: fields.allianceOrganization, label: 'Alliance Organization', formType: DUALLIST, visible: true },
{ field: fields.allianceOrganization, label: 'Alliance Organization', rules: { rows: 10 }, formType: TEXT_AREA, visible: true },
{ label: `${action}`, formType: 'Button', onClick: this.onCreate },
{ label: 'Cancel', formType: 'Button', onClick: this.onCancel }
]
Expand All @@ -178,7 +141,6 @@ class AllianceOrganization extends React.Component {

};


const mapDispatchProps = (dispatch) => {
return {
handleAlertInfo: (mode, msg) => { dispatch(actions.alertInfo(mode, msg)) },
Expand Down

0 comments on commit 8aa5df3

Please sign in to comment.