1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Hook up add instance group functionality.

This commit is contained in:
kialam 2019-01-07 16:56:39 -05:00
parent f34ec4be10
commit 517ef8a2c9
No known key found for this signature in database
GPG Key ID: 2D0E60E4B8C7EA0F
4 changed files with 30 additions and 12 deletions

View File

@ -4,6 +4,7 @@ const API_LOGOUT = `${API_ROOT}logout/`;
const API_V2 = `${API_ROOT}v2/`; const API_V2 = `${API_ROOT}v2/`;
const API_CONFIG = `${API_V2}config/`; const API_CONFIG = `${API_V2}config/`;
const API_ORGANIZATIONS = `${API_V2}organizations/`; const API_ORGANIZATIONS = `${API_V2}organizations/`;
const API_INSTANCE_GROUPS = `${API_V2}instance_groups/`;
const LOGIN_CONTENT_TYPE = 'application/x-www-form-urlencoded'; const LOGIN_CONTENT_TYPE = 'application/x-www-form-urlencoded';
@ -68,6 +69,20 @@ class APIClient {
return this.http.get(endpoint); return this.http.get(endpoint);
} }
getInstanceGroups (){
return this.http.get(API_INSTANCE_GROUPS);
}
createInstanceGroups (url, selected) {
if (selected.length > 0) {
selected.forEach(select => {
this.http.post(url, { id: select.id });
});
}
return false;
}
} }
export default APIClient; export default APIClient;

View File

@ -127,9 +127,6 @@
} }
} }
.pf-c-modal-box {
width: 70%;
}
.awx-lookup { .awx-lookup {
min-height: 36px; min-height: 36px;
} }

View File

@ -35,7 +35,7 @@ class Lookup extends React.Component {
} }
onChecked(_, evt) { onChecked(_, evt) {
this.props.lookupChange(evt.target.id); this.props.lookupChange(evt.target.value);
}; };
wrapTags(tags) { wrapTags(tags) {
@ -54,7 +54,7 @@ class Lookup extends React.Component {
<span className="pf-c-input-group__text" aria-label="search" id="search" onClick={this.onLookup}><SearchIcon /></span> <span className="pf-c-input-group__text" aria-label="search" id="search" onClick={this.onLookup}><SearchIcon /></span>
<div className="pf-c-form-control">{this.wrapTags(this.props.data)}</div> <div className="pf-c-form-control">{this.wrapTags(this.props.data)}</div>
<Modal <Modal
isLarge className="awx-c-modal"
title={`Select ${this.props.lookup_header}`} title={`Select ${this.props.lookup_header}`}
isOpen={isModalOpen} isOpen={isModalOpen}
onClose={this.handleModalToggle} onClose={this.handleModalToggle}
@ -64,10 +64,11 @@ class Lookup extends React.Component {
<ListItem key={i.id}> <ListItem key={i.id}>
<Checkbox <Checkbox
label={i.name} label={i.name}
isChecked={i.isChecked} checked={i.isChecked}
onChange={this.onChecked} onChange={this.onChecked}
aria-label="result checkbox" aria-label="result checkbox"
id={`${i.id}`} id={`checked-${i.id}`}
value={i.id}
/> />
</ListItem>)} </ListItem>)}
</List> </List>

View File

@ -19,11 +19,9 @@ import {
} from '@patternfly/react-core'; } from '@patternfly/react-core';
import { ConfigContext } from '../../../context'; import { ConfigContext } from '../../../context';
import api from '../../../api';
import Lookup from '../../../components/Lookup'; import Lookup from '../../../components/Lookup';
import AnsibleSelect from '../../../components/AnsibleSelect' import AnsibleSelect from '../../../components/AnsibleSelect'
const { light } = PageSectionVariants; const { light } = PageSectionVariants;
class OrganizationAdd extends React.Component { class OrganizationAdd extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -58,10 +56,14 @@ class OrganizationAdd extends React.Component {
resetForm() { resetForm() {
this.setState({ this.setState({
...this.state,
name: '', name: '',
description: '' description: '',
});
let reset = [];
this.state.results.map((result) => {
reset.push({ id: result.id, name: result.name, isChecked: false });
}) })
this.setState({ results: reset });
} }
handleChange(_, evt) { handleChange(_, evt) {
@ -71,7 +73,10 @@ class OrganizationAdd extends React.Component {
async onSubmit() { async onSubmit() {
const { api } = this.props; const { api } = this.props;
const data = Object.assign({}, { ...this.state }); const data = Object.assign({}, { ...this.state });
await api.createOrganization(data); const { data: response } = await api.createOrganization(data);
const url = response.related.instance_groups;
const selected = this.state.results.filter(group => group.isChecked);
await api.createInstanceGroups(url, selected);
this.resetForm(); this.resetForm();
} }