mirror of
https://github.com/ansible/awx.git
synced 2026-02-16 10:40:01 -03:30
Only update selected instance groups if the select button is clicked in the modal
This commit is contained in:
@@ -34,11 +34,11 @@ class OrganizationAdd extends React.Component {
|
||||
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
this.onSelectChange = this.onSelectChange.bind(this);
|
||||
this.onLookupChange = this.onLookupChange.bind(this);
|
||||
this.onSubmit = this.onSubmit.bind(this);
|
||||
this.resetForm = this.resetForm.bind(this);
|
||||
this.onSuccess = this.onSuccess.bind(this);
|
||||
this.onCancel = this.onCancel.bind(this);
|
||||
this.updateSelectedInstanceGroups = this.updateSelectedInstanceGroups.bind(this);
|
||||
}
|
||||
|
||||
state = {
|
||||
@@ -65,30 +65,6 @@ class OrganizationAdd extends React.Component {
|
||||
this.setState({ custom_virtualenv: value });
|
||||
}
|
||||
|
||||
onLookupChange (row) {
|
||||
const { results, selectedInstanceGroups } = this.state;
|
||||
const selectedIndex = selectedInstanceGroups
|
||||
.findIndex(instanceGroup => instanceGroup.id === row.id);
|
||||
const resultsIndex = results.findIndex(instanceGroup => instanceGroup.id === row.id);
|
||||
if (selectedIndex > -1) {
|
||||
// Remove it from the list of selected instance groups
|
||||
selectedInstanceGroups.splice(selectedIndex, 1);
|
||||
if (resultsIndex > -1) {
|
||||
results[resultsIndex].isChecked = false;
|
||||
}
|
||||
this.setState({ selectedInstanceGroups, results });
|
||||
} else {
|
||||
// Add it to the list of selected instance groups
|
||||
if (resultsIndex > -1) {
|
||||
results[resultsIndex].isChecked = true;
|
||||
}
|
||||
this.setState(prevState => ({
|
||||
results,
|
||||
selectedInstanceGroups: [...prevState.selectedInstanceGroups, row]
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
async onSubmit () {
|
||||
const { api } = this.props;
|
||||
const { name, description, custom_virtualenv } = this.state;
|
||||
@@ -128,6 +104,10 @@ class OrganizationAdd extends React.Component {
|
||||
history.push(`/organizations/${id}`);
|
||||
}
|
||||
|
||||
updateSelectedInstanceGroups (selectedInstanceGroups) {
|
||||
this.setState({ selectedInstanceGroups });
|
||||
}
|
||||
|
||||
handleChange (_, evt) {
|
||||
this.setState({ [evt.target.name]: evt.target.value });
|
||||
}
|
||||
@@ -184,7 +164,7 @@ class OrganizationAdd extends React.Component {
|
||||
<FormGroup label="Instance Groups" fieldId="simple-form-instance-groups">
|
||||
<Lookup
|
||||
lookupHeader="Instance Groups"
|
||||
lookupChange={this.onLookupChange}
|
||||
onLookupSave={this.updateSelectedInstanceGroups}
|
||||
data={results}
|
||||
selected={selectedInstanceGroups}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user