Implement React Context API

- Move API GET request to /v2/config out to the top level of our App.
- Store /v2/config response data in sessionStorage.
- Use Context API to pass down relevant data to Organizations component.
- Wrap our AnsibleSelect component as a context consumer and pass in the list of Ansible Environments of the logged in user.
- Clear sessionStorage object when user logs out.
- Update unit tests.
This commit is contained in:
kialam
2018-12-17 11:44:11 -05:00
parent 7ea5ea2ecd
commit b8fc402d55
8 changed files with 115 additions and 41 deletions

View File

@@ -1,4 +1,5 @@
import React from 'react';
import {
FormGroup,
Select,
@@ -16,19 +17,19 @@ class AnsibleSelect extends React.Component {
}
render() {
const { hidden } = this.props;
if (hidden) {
return null;
} else {
if (this.props.data.length > 1) {
return (
<FormGroup label={this.props.labelName} fieldId="ansible-select">
<Select value={this.props.selected} onChange={this.onSelectChange} aria-label="Select Input">
{this.props.data.map((env, index) => (
<SelectOption isDisabled={env.disabled} key={index} value={env} label={env} />
{this.props.data.map((datum, index) => (
<SelectOption isDisabled={datum.disabled} key={index} value={datum} label={datum} />
))}
</Select>
</FormGroup>
);
)
}
else {
return null;
}
}
}