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

Add default option for AnsibleSelect dropdown.

This commit is contained in:
kialam 2019-02-11 13:53:54 -05:00
parent fb7ccdb726
commit 97477b789a
No known key found for this signature in database
GPG Key ID: 2D0E60E4B8C7EA0F
2 changed files with 11 additions and 6 deletions

View File

@ -32,15 +32,17 @@ class AnsibleSelect extends React.Component {
render () {
const { count } = this.state;
const { labelName, selected, data } = this.props;
const { labelName, selected, data, defaultSelected } = this.props;
let elem;
if (count > 1) {
elem = (
<FormGroup label={labelName} fieldId="ansible-select">
<Select value={selected} onChange={this.onSelectChange} aria-label="Select Input">
{data.map((datum) => (
<SelectOption isDisabled={datum.disabled} key={datum} value={datum} label={datum} />
))}
<SelectOption isDisabled key="" value="" label={`Use Default ${labelName}`} />
{data.map((datum) =>
datum !== defaultSelected ?
(<SelectOption key={datum} value={datum} label={datum} />) : null)
}
</Select>
</FormGroup>
);

View File

@ -40,14 +40,15 @@ class OrganizationAdd extends React.Component {
this.onCancel = this.onCancel.bind(this);
this.updateSelectedInstanceGroups = this.updateSelectedInstanceGroups.bind(this);
}
state = {
name: '',
description: '',
results: [],
custom_virtualenv: '',
error: '',
selectedInstanceGroups: []
selectedInstanceGroups: [],
defaultEnv: '/venv/ansible/'
};
async componentDidMount () {
@ -129,6 +130,7 @@ class OrganizationAdd extends React.Component {
description,
custom_virtualenv,
selectedInstanceGroups,
defaultEnv,
error
} = this.state;
const enabled = name.length > 0; // TODO: add better form validation
@ -176,6 +178,7 @@ class OrganizationAdd extends React.Component {
selected={custom_virtualenv}
selectChange={this.onSelectChange}
data={custom_virtualenvs}
defaultSelected={defaultEnv}
/>
)}
</ConfigContext.Consumer>