Code cleanup, renaming functions, use .all() on config promises

This commit is contained in:
mabashian
2019-04-26 11:02:16 -04:00
parent e5dda696d7
commit 8cfe74a854
7 changed files with 34 additions and 50 deletions

View File

@@ -76,7 +76,7 @@ class APIClient {
return this.http.post(API_ORGANIZATIONS, data);
}
callOrganizations () {
optionsOrganizations () {
return this.http.options(API_ORGANIZATIONS);
}

View File

@@ -78,28 +78,19 @@ class Provider extends Component {
const { api, handleHttpError } = this.props;
try {
const {
data: {
ansible_version,
custom_virtualenvs,
version
}
} = await api.getConfig();
const {
data: {
custom_logo,
custom_login_info
}
} = await api.getRoot();
const { data: { results: [me] } } = await api.getMe();
const [configRes, rootRes, meRes] = await Promise.all([
api.getConfig(),
api.getRoot(),
api.getMe()
]);
this.setState({
value: {
ansible_version,
custom_virtualenvs,
version,
custom_logo,
custom_login_info,
me
ansible_version: configRes.data.ansible_version,
custom_virtualenvs: configRes.data.custom_virtualenvs,
version: configRes.data.version,
custom_logo: rootRes.data.custom_logo,
custom_login_info: rootRes.data.custom_login_info,
me: meRes.data.results
}
});
} catch (err) {

View File

@@ -53,7 +53,7 @@ class AWXLogin extends Component {
try {
const { data } = await api.login(username, password);
updateConfig(data);
fetchMe();
await fetchMe();
this.setState({ isAuthenticated: true, isLoading: false });
} catch (error) {
handleHttpError(error) || this.setState({ isInputValid: false, isLoading: false });

View File

@@ -240,9 +240,6 @@ class Organization extends Component {
path="/organizations/:id/notifications"
render={() => (
<OrganizationNotifications
match={match}
location={location}
history={history}
canToggleNotifications={canToggleNotifications}
/>
)}

View File

@@ -73,7 +73,7 @@ class OrganizationsList extends Component {
this.onSelectAll = this.onSelectAll.bind(this);
this.onSelect = this.onSelect.bind(this);
this.updateUrl = this.updateUrl.bind(this);
this.callOrganizations = this.callOrganizations.bind(this);
this.fetchOptionsOrganizations = this.fetchOptionsOrganizations.bind(this);
this.fetchOrganizations = this.fetchOrganizations.bind(this);
this.handleOrgDelete = this.handleOrgDelete.bind(this);
this.handleOpenOrgDeleteModal = this.handleOpenOrgDeleteModal.bind(this);
@@ -82,7 +82,7 @@ class OrganizationsList extends Component {
componentDidMount () {
const queryParams = this.getQueryParams();
this.callOrganizations();
this.fetchOptionsOrganizations();
this.fetchOrganizations(queryParams);
}
@@ -240,11 +240,11 @@ class OrganizationsList extends Component {
}
}
async callOrganizations () {
async fetchOptionsOrganizations () {
const { api } = this.props;
try {
const { data } = await api.callOrganizations();
const { data } = await api.optionsOrganizations();
const { actions } = data;
const stateToUpdate = {
@@ -345,11 +345,14 @@ class OrganizationsList extends Component {
<Trans>
You dont have permission to delete the following Organizations:
</Trans>
{selected.map(row => (
<div key={row.id}>
{row.name}
</div>
))}
{selected
.filter(row => !row.summary_fields.user_capabilities.delete)
.map(row => (
<div key={row.id}>
{row.name}
</div>
))
}
</div>
) : undefined
}