Add new method to create payload

feature/appm-store/pbac
Kaveesha 5 years ago
parent ed67090e38
commit 2bf9977a99

@ -49,7 +49,7 @@ class AssignGroups extends React.Component {
}; };
// generate payload by adding Assign Groups // generate payload by adding Assign Groups
onHandleContinue = () => { onHandleContinue = (e, formName) => {
this.props.form.validateFields((err, values) => { this.props.form.validateFields((err, values) => {
if (!err) { if (!err) {
if (!values.users) { if (!values.users) {
@ -58,10 +58,10 @@ class AssignGroups extends React.Component {
if (values.deviceGroups === 'NONE') { if (values.deviceGroups === 'NONE') {
delete values.deviceGroups; delete values.deviceGroups;
} }
Object.assign(this.props.newPolicyPayload, values); this.props.getPolicyPayloadData(formName, values);
this.props.getNextStep();
} }
}); });
this.props.getNextStep();
}; };
getRolesList = () => { getRolesList = () => {
@ -239,7 +239,10 @@ class AssignGroups extends React.Component {
<Button style={{ marginRight: 8 }} onClick={this.props.getPrevStep}> <Button style={{ marginRight: 8 }} onClick={this.props.getPrevStep}>
Back Back
</Button> </Button>
<Button type="primary" onClick={this.onHandleContinue}> <Button
type="primary"
onClick={e => this.onHandleContinue(e, 'groupData')}
>
Continue Continue
</Button> </Button>
</div> </div>

@ -296,13 +296,13 @@ class ConfigureProfile extends React.Component {
}; };
// generate payload by adding policy configurations // generate payload by adding policy configurations
onHandleContinue = () => { onHandleContinue = (e, formname) => {
this.props.form.validateFields((err, values) => { this.props.form.validateFields((err, values) => {
if (!err) { if (!err) {
console.log(values); this.props.getPolicyPayloadData(formname, values);
this.props.getNextStep();
} }
}); });
this.props.getNextStep();
}; };
// generate form items // generate form items
@ -752,7 +752,10 @@ class ConfigureProfile extends React.Component {
<Button style={{ marginRight: 8 }} onClick={this.props.getPrevStep}> <Button style={{ marginRight: 8 }} onClick={this.props.getPrevStep}>
Back Back
</Button> </Button>
<Button type="primary" onClick={this.onHandleContinue}> <Button
type="primary"
onClick={e => this.onHandleContinue(e, 'configureProfileData')}
>
Continue Continue
</Button> </Button>
</div> </div>

@ -26,19 +26,13 @@ class PublishDevices extends React.Component {
this.config = this.props.context; this.config = this.props.context;
} }
onClickSavePolicy = (event, isPublish) => { onClickSavePolicy = (event, isPublish, formName) => {
this.props.form.validateFields((err, values) => { this.props.form.validateFields((err, values) => {
if (!err) { if (!err) {
let policyProfile = Object.assign(this.props.policyProfile, {
profileName: values.policyName,
});
Object.assign(values, { profile: policyProfile });
Object.assign(this.props.newPolicyPayload, values);
if (isPublish) { if (isPublish) {
Object.assign(this.props.newPolicyPayload, { Object.assign(values, { active: isPublish });
active: isPublish,
});
} }
this.props.getPolicyPayloadData(formName, values);
} }
}); });
}; };
@ -71,11 +65,18 @@ class PublishDevices extends React.Component {
<Button <Button
type="primary" type="primary"
style={{ marginRight: 8 }} style={{ marginRight: 8 }}
onClick={() => this.onClickSavePolicy(true)} onClick={e =>
this.onClickSavePolicy(e, true, 'publishDevicesData')
}
> >
Save & Publish Save & Publish
</Button> </Button>
<Button type="primary" onClick={this.onClickSavePolicy}> <Button
type="primary"
onClick={e =>
this.onClickSavePolicy(e, false, 'publishDevicesData')
}
>
Save Save
</Button> </Button>
</div> </div>

@ -35,12 +35,12 @@ class SelectPlatform extends React.Component {
this.getDeviceTypes(); this.getDeviceTypes();
} }
onClickCard = (e, type) => { onClickCard = (e, type, formname) => {
this.props.getPolicyConfigJson(type); this.props.getPolicyConfigJson(type);
let deviceType = { let deviceType = {
deviceType: type, deviceType: type,
}; };
Object.assign(this.props.policyProfile, deviceType); this.props.getPolicyPayloadData(formname, deviceType);
}; };
// fetch data from api // fetch data from api
@ -91,7 +91,9 @@ class SelectPlatform extends React.Component {
size="default" size="default"
style={{ width: 150 }} style={{ width: 150 }}
bordered={true} bordered={true}
onClick={e => this.onClickCard(e, data.name)} onClick={e =>
this.onClickCard(e, data.name, 'selectedPlatformData')
}
cover={ cover={
<Icon <Icon
type="android" type="android"

@ -45,17 +45,16 @@ class SelectPolicyType extends React.Component {
} }
// generate payload using Select policy type // generate payload using Select policy type
onHandleContinue = () => { onHandleContinue = (e, formName) => {
this.props.form.validateFields((err, values) => { this.props.form.validateFields((err, values) => {
if (!err) { if (!err) {
if (values.correctiveActions === 'NONE') { if (values.correctiveActions === 'NONE') {
values.correctiveActions = []; values.correctiveActions = [];
} }
Object.assign(this.props.newPolicyPayload, values); this.props.getPolicyPayloadData(formName, values);
this.props.getNextStep();
} }
console.log('aaaaaaa');
}); });
this.props.getNextStep();
}; };
fetchPolicies = () => { fetchPolicies = () => {
@ -156,7 +155,10 @@ class SelectPolicyType extends React.Component {
<Button style={{ marginRight: 8 }} onClick={this.props.getPrevStep}> <Button style={{ marginRight: 8 }} onClick={this.props.getPrevStep}>
Back Back
</Button> </Button>
<Button type="primary" onClick={this.onHandleContinue}> <Button
type="primary"
onClick={e => this.onHandleContinue(e, 'policyTypeData')}
>
Continue Continue
</Button> </Button>
</div> </div>

@ -37,9 +37,45 @@ class AddPolicy extends React.Component {
policyUIConfigurationsList: [], policyUIConfigurationsList: [],
newPolicyPayload: { compliance: 'enforce' }, newPolicyPayload: { compliance: 'enforce' },
policyProfile: {}, policyProfile: {},
payloadData: {},
}; };
} }
getPolicyPayloadData = (dataName, dataValue) => {
Object.defineProperty(this.state.payloadData, dataName, {
value: dataValue,
writable: true,
});
if (dataName === 'publishDevicesData') {
this.createPayload();
}
};
createPayload = () => {
const { newPolicyPayload } = this.state;
const {
publishDevicesData,
selectedPlatformData,
policyProfile,
policyTypeData,
groupData,
} = this.state.payloadData;
let profile = {
policyName: publishDevicesData.policyName,
devicetype: selectedPlatformData.deviceType,
};
let payload = Object.assign(
newPolicyPayload,
publishDevicesData,
policyProfile,
policyTypeData,
groupData,
{ profile: profile },
);
console.log(payload);
};
getPolicyConfigJson = type => { getPolicyConfigJson = type => {
this.setState({ isLoading: true }); this.setState({ isLoading: true });
@ -109,8 +145,7 @@ class AddPolicy extends React.Component {
> >
<SelectPlatform <SelectPlatform
getPolicyConfigJson={this.getPolicyConfigJson} getPolicyConfigJson={this.getPolicyConfigJson}
newPolicyPayload={this.state.newPolicyPayload} getPolicyPayloadData={this.getPolicyPayloadData}
policyProfile={this.state.policyProfile}
/> />
</div> </div>
<div <div
@ -118,7 +153,7 @@ class AddPolicy extends React.Component {
> >
<ConfigureProfile <ConfigureProfile
policyUIConfigurationsList={policyUIConfigurationsList} policyUIConfigurationsList={policyUIConfigurationsList}
policyProfile={this.state.policyProfile} getPolicyPayloadData={this.getPolicyPayloadData}
getPrevStep={this.getPrevStep} getPrevStep={this.getPrevStep}
getNextStep={this.getNextStep} getNextStep={this.getNextStep}
/> />
@ -127,7 +162,7 @@ class AddPolicy extends React.Component {
style={{ display: currentStepIndex === 2 ? 'unset' : 'none' }} style={{ display: currentStepIndex === 2 ? 'unset' : 'none' }}
> >
<SelectPolicyType <SelectPolicyType
newPolicyPayload={this.state.newPolicyPayload} getPolicyPayloadData={this.getPolicyPayloadData}
getPrevStep={this.getPrevStep} getPrevStep={this.getPrevStep}
getNextStep={this.getNextStep} getNextStep={this.getNextStep}
/> />
@ -136,7 +171,7 @@ class AddPolicy extends React.Component {
style={{ display: currentStepIndex === 3 ? 'unset' : 'none' }} style={{ display: currentStepIndex === 3 ? 'unset' : 'none' }}
> >
<AssignGroups <AssignGroups
newPolicyPayload={this.state.newPolicyPayload} getPolicyPayloadData={this.getPolicyPayloadData}
getPrevStep={this.getPrevStep} getPrevStep={this.getPrevStep}
getNextStep={this.getNextStep} getNextStep={this.getNextStep}
/> />
@ -145,8 +180,7 @@ class AddPolicy extends React.Component {
style={{ display: currentStepIndex === 4 ? 'unset' : 'none' }} style={{ display: currentStepIndex === 4 ? 'unset' : 'none' }}
> >
<PublishDevices <PublishDevices
newPolicyPayload={this.state.newPolicyPayload} getPolicyPayloadData={this.getPolicyPayloadData}
policyProfile={this.state.policyProfile}
getPrevStep={this.getPrevStep} getPrevStep={this.getPrevStep}
/> />
</div> </div>

Loading…
Cancel
Save